luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.
MIT License
568 stars 108 forks source link

BindAPI() creates a GLx dependency on OSx #84

Closed Zukapin closed 6 years ago

Zukapin commented 6 years ago

Not sure if this is a bug, but it took me awhile to track down.

Using BindAPI() in OpenGL.Net/Gl.cs calls QueryVersionContext(), which calls DeviceContext.GetCurrentContext(), to verify a current context exists. https://github.com/luca-piccioni/OpenGL.Net/blob/0b30190612ec52364539d244a02fde6fb5de0fa5/OpenGL.Net/Gl.cs#L359-L361

On OSx, if you're not using GLx for windowing, DeviceContext.GetCurrentContext() will always fail with a 'NotSupportedException'. https://github.com/luca-piccioni/OpenGL.Net/blob/0b30190612ec52364539d244a02fde6fb5de0fa5/OpenGL.Net/DeviceContext.cs#L688-L692

I'm using SDL2 as my windowing and context creation, so BindAPI() always fails. It seems like I could work around this with an explicit GL version and extension suite call to BindAPI, but is the check to see if a current context exists required?

luca-piccioni commented 6 years ago

On this specific issue, I have to say that the check is really pedantic since the context is not effectively used in the method. But, a current context is really required, and the check is used to verify it. The BindAPI overload taking the GL version works because the BindAPI must not determine the runtime GL context version.

It is a good catch since BindAPI should not rely on GL platform API. But I cannot support OSX since I have no such system. Anyway, I think it should work all the same. There are no other GetCurrentContext references in the solution.

Zukapin commented 6 years ago

Ah. Wasn't sure if there was going to be a better way of fixing it.

Thank you!

Miigon commented 6 years ago

I'm using SDL2 as my windowing and context creation, so BindAPI() always fails.

That's right. There is NO easy way to use OpenGL without also using X11(glx). Apple gave us NSOpenGL, which is an Objective-C/Swift API. And there is no OpenGL API for C. GLEW creates a wrapper and thus translates the C API call to Objective-C API call(NSOpenGL).