luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BindAPI() creates a GLx dependency on OSx

Zukapin opened this issue · comments

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.

OpenGL.Net/OpenGL.Net/Gl.cs

Lines 359 to 361 in 0b30190

IntPtr ctx = DeviceContext.GetCurrentContext();
if (ctx == IntPtr.Zero)
throw new InvalidOperationException("no current context");

On OSx, if you're not using GLx for windowing, DeviceContext.GetCurrentContext() will always fail with a 'NotSupportedException'.

case Platform.Id.MacOS:
if (Glx.IsRequired)
return Glx.GetCurrentContext();
else
throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true");

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?

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.

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

Thank you!

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).