예제 #1
0
        private WebGLProgram InitProgram(WebGLContext gl, string vsSource, string fsSource)
        {
            var vertexShader   = this.LoadShader(gl, ShaderType.VERTEX_SHADER, vsSource);
            var fragmentShader = this.LoadShader(gl, ShaderType.FRAGMENT_SHADER, fsSource);

            var program = gl.CreateProgram();

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

            gl.DeleteShader(vertexShader);
            gl.DeleteShader(fragmentShader);

            if (!gl.GetProgramParameter <bool>(program, ProgramParameter.LINK_STATUS))
            {
                string info = gl.GetProgramInfoLog(program);
                throw new Exception("An error occured while linking the program: " + info);
            }

            return(program);
        }
예제 #2
0
        private WebGLShader LoadShader(WebGLContext gl, ShaderType type, string source)
        {
            var shader = gl.CreateShader(type);

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

            if (!gl.GetShaderParameter <bool>(shader, ShaderParameter.COMPILE_STATUS))
            {
                string info = gl.GetShaderInfoLog(shader);
                gl.DeleteShader(shader);
                throw new Exception("An error occured while compiling the shader: " + info);
            }

            return(shader);
        }