Exemple #1
0
        protected WebGLProgram SetUpProgram(
            WebGLRenderingContextBase gl,
            string vertexShaderSource   = "void main() {}",
            string fragmentShaderSource = "void main() {}")
        {
            var vertexShader = gl.CreateShader(WebGLRenderingContextBase.VERTEX_SHADER);

            gl.ShaderSource(vertexShader, vertexShaderSource);
            gl.CompileShader(vertexShader);
            var fragmentShader = gl.CreateShader(WebGLRenderingContextBase.FRAGMENT_SHADER);

            gl.ShaderSource(fragmentShader, fragmentShaderSource);
            gl.CompileShader(fragmentShader);
            var program = gl.CreateProgram();

            gl.AttachShader(program, vertexShader);
            gl.AttachShader(program, fragmentShader);
            gl.LinkProgram(program);

            return(program);
        }
Exemple #2
0
        public static WebGLShader GetShader(this WebGLRenderingContextBase gl, string shaderSource, uint type)
        {
            var shader = gl.CreateShader(type);

            gl.ShaderSource(shader, shaderSource);
            gl.CompileShader(shader);

            var message = gl.GetShaderInfoLog(shader);

            if (message.Length > 0)
            {
                var msg = $"Shader Error: {message}";
                throw new Exception(msg);
            }

            return(shader);
        }