giawa / opengl4csharp

OpenGL 4 Bindings (partially based on OpenTK) for C#
Other
232 stars 61 forks source link

Throw exception when shader compiling or linking fails #15

Closed TheAIBot closed 5 years ago

TheAIBot commented 5 years ago

Currently shader compilation and program linking fails silently which causes unexpected issues elsewhere when you try to use the shader/program.

Code now checks if compilation/linking is succesful and if not then it throws an error with the error log from opengl.

giawa commented 5 years ago

Hey there. Thanks for the pull request! Do you mind merging your pull request with the latest commit of the dotnetcore branch? It looks like Travis CI dropped support for the version of .net core I was using, so I have updated the repository to use .net core 2.0. That way this pull request can pass checks prior to accepting.

As an aside, you can get the equivalent of Gl.GetShaderInfoLog(ShaderID); by calling ShaderLog (similarly, ProgramLog exists on the ShaderProgram object). Lastly, I'm not sure if it is worth it, but in GlMethods.cs there are static arrays instantiated for making calls similar to:

int[] shaderStatus = new int[1];
Gl.GetShaderiv(ShaderID, ShaderParameter.CompileStatus, shaderStatus);

As written, this pull request will allocate a new array for each shader, and an array per program. In managed memory world this is bad, since it puts more pressure on the garbage collector. That's why many of these similar calls exist in GlMethods.cs, to avoid allocation of arrays. I don't think shaders are created that often, so this is probably fine for now, but it's worth keeping in mind.