Example #1
0
            public GLShaderProgram(GlInterface gl, string vertex_shader_source, string fragment_shader_source)
            {
                this.gl        = gl;
                this.GlVersion = gl.ContextInfo.Version;

                vertex_shader_source   = GetShader(false, vertex_shader_source);
                fragment_shader_source = GetShader(true, fragment_shader_source);

                vertex_shader   = new GLShader(gl, GL_VERTEX_SHADER, vertex_shader_source);
                fragment_shader = new GLShader(gl, GL_FRAGMENT_SHADER, fragment_shader_source);

                ProgramId = gl.CreateProgram();
                gl.AttachShader(ProgramId, vertex_shader.ShaderId);
                gl.AttachShader(ProgramId, fragment_shader.ShaderId);
                gl.LinkProgram(ProgramId);
                int link_succeeded;

                gl.GetProgramiv(ProgramId, GL_LINK_STATUS, &link_succeeded);

                if (link_succeeded == 0)
                {
                    byte[] buf = new byte[MaxErrorLength];
                    string log;
                    fixed(byte *pbuf = buf)
                    {
                        gl.GetProgramInfoLog(ProgramId, MaxErrorLength, out int log_length, pbuf);
                        log = Encoding.UTF8.GetString(pbuf, log_length);
                    }

                    throw new InvalidOperationException($"Failed to link program : {log}");
                }
            }