コード例 #1
0
            public GLShader(GlInterface gl, int shaderType, string source)
            {
                if (source == null)
                {
                    throw new ArgumentNullException(nameof(source));
                }

                this.gl = gl;

                ShaderId = gl.CreateShader(shaderType);
                using (var b = new Utf8Buffer(source))
                {
                    void *[] pstr = new void *[2];
                    long[]   len  = new long[2];
                    pstr[0] = (void *)b.DangerousGetHandle();
                    len[0]  = b.ByteLen;

                    fixed(void **ppstr = pstr)
                    fixed(long *plen = len)
                    gl.ShaderSource(ShaderId, 1, (IntPtr)ppstr, (IntPtr)plen);
                }
                gl.CompileShader(ShaderId);
                int compile_succeeded;

                gl.GetShaderiv(ShaderId, GL_COMPILE_STATUS, &compile_succeeded);

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

                    throw new InvalidOperationException($"Failed to compile shader : {log}");
                }
            }