luca-piccioni / OpenGL.Net

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

Switching context version bug (Windows Forms GLControl) #108

Closed PaulD1er closed 6 years ago

PaulD1er commented 6 years ago

Hello,

I'm having a bit of trouble with the context version. I'm using OpenGl.Net.WinForms for a WPF application, almost everything work perfectly. I am using another API that is only compatible with openGL version 1.*, so I've tried to switch the context version by changing the property "ContextVersion" : image But the issue is that I'm style having issue with the versions and when logging the context version with "Gl.QueryContextVersion()" or "KhronosVersion.Parse(Gl.GetString(StringName.Version))" it gives me another version than the one I've set in ContextVersion (It display version=4.513507). But when logging the version directly from the GLControl.ContextVersion it displays the correct version.

luca-piccioni commented 6 years ago

So, you're requesting a GL 1.5 and the driver returns a GL 4.5, right?

This is a behavior allowed by GL: as long the returned context is compatible with the version requested, the GL driver can return a greater version.

Typically drivers returns the last version implemented for GL contextes with version less than 3.2. Probably the GL context returned implements the compatibility profile.

The Control property is just a designer value, and does not reflect the actual GL version running.

By default, function pointers are loaded depending on current GL context version. If you wish to load only GL 1.5 function, there is an overload og Gl.Bind that allows you to specify the actual version to be used.

PaulD1er commented 6 years ago

So, you're requesting a GL 1.5 and the driver returns a GL 4.5, right?

Yeah, exactly. First thanks for your explanations and solution, unfortunately either I'm still doing something wrong or it doesn't give the expected result. I've tried to call Gl.BindAPI (As shown in the image below) from my main before my GLControl and context are created. image And it still gives me a higher GL version. It probably is due because I'm not doing it right but if not would there be a way to disable the compatibility profile to force OpenGL to return a context with the wanted version ?

luca-piccioni commented 6 years ago

You're not doing anything wrong: you cannot force the driver to return a specific GL version, if a greater version is compatible.

The Bind call you execute will load only GL 1.5 entry points, resetting other GL function pointers to null. In this way, you are sure that you cannot call any method not defined in GL 1.5. However, the GL functions pointers are executing on GL 4.5, hence glGetString is returning values accordingly.

luca-piccioni commented 6 years ago

The compatibility profile is a feature introduced by GL 3.1,in order to execute older code on newer GL versions.

Indeed, in order to be compatoble with OpenGL 1.5,the context must have the compatibility profile bit.

luca-piccioni commented 6 years ago

Another issue: you shall call Gl.BindAPI when you have a context current, indeed after GlControl is created.

PaulD1er commented 6 years ago

Ok, well thanks again for your help ! It seems then that my main problem do not come from the OpenGL version but at least I've learn stuff.