public void Dispose() { if (mProgram != 0) { Gles.glDeleteProgram(mProgram); mProgram = 0; } if (mVertexPositionBuffer != 0) { Gles.glDeleteBuffers(1, ref mVertexPositionBuffer); mVertexPositionBuffer = 0; } if (mVertexColorBuffer != 0) { Gles.glDeleteBuffers(1, ref mVertexColorBuffer); mVertexColorBuffer = 0; } if (mIndexBuffer != 0) { Gles.glDeleteBuffers(1, ref mIndexBuffer); mIndexBuffer = 0; } }
private static GLuint CompileProgram(string vsSource, string fsSource) { GLuint program = Gles.glCreateProgram(); if (program == 0) { throw new Exception("Program creation failed"); } GLuint vs = CompileShader(Gles.GL_VERTEX_SHADER, vsSource); GLuint fs = CompileShader(Gles.GL_FRAGMENT_SHADER, fsSource); if (vs == 0 || fs == 0) { Gles.glDeleteShader(fs); Gles.glDeleteShader(vs); Gles.glDeleteProgram(program); return(0); } Gles.glAttachShader(program, vs); Gles.glDeleteShader(vs); Gles.glAttachShader(program, fs); Gles.glDeleteShader(fs); Gles.glLinkProgram(program); Gles.glGetProgramiv(program, Gles.GL_LINK_STATUS, out GLint linkStatus); if (linkStatus == 0) { Gles.glGetProgramiv(program, Gles.GL_INFO_LOG_LENGTH, out GLint infoLogLength); StringBuilder infoLog = new StringBuilder(infoLogLength); Gles.glGetProgramInfoLog(program, (GLsizei)infoLog.Capacity, out GLsizei length, infoLog); string errorMessage = "Program link failed: " + infoLog; throw new Exception(errorMessage); } return(program); }