You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I had an application which was previously using some SDL2 Rust bindings and was later rewritten to use winit + glutin, which happens to use a legacy OpenGL 2.1 context on macOS. The code that creates the context looks roughly like this:
let gl_display = gl_config.display();let context_attributes = ContextAttributesBuilder::new().with_context_api(ContextApi::OpenGl(Some(Version::new(self.gl_version_major,self.gl_version_minor,)))).with_profile(GlProfile::Compatibility)// <--- I'm requesting a compatibility context.build(raw_window_handle);let gl_context = unsafe{
gl_display
.create_context(&gl_config,&context_attributes).expect("failed to create context")};
However, I end up with an OpenGL 4.1 core context, with all legacy OpenGL features disabled.
I had a look through the cgl module and found this piece of code, which seems to indicate that we will always try to create an OpenGL context with the latest version of OpenGL regardless of the profile specified in the ContextAttributesBuilder:
If I change that array locally so that NSOpenGLProfileVersionLegacy is the first element, then the NSOpenGLPixelFormat object gets created with the legacy OpenGL context correctly as expected, and my application works properly.
It seems that we don't have the ContextAttributes object yet when calling Display::find_configs. SDL2's behaviour is to use NSOpenGLProfileVersionLegacy by default unless a core profile is specified, then favour NSOpenGLProfileVersion3_2Core.
I'm not very familiar with glutin's internals, so not sure what the cleanest approach would be here, but I had some potential ideas:
Maybe we could fix this by creating two NSOpenGLPixelFormat objects and storing both in cgl's ConfigInner type, one for the "compatibility" profile with NSOpenGLProfileVersionLegacy, and one for the "core" profile using either NSOpenGLProfileVersion4_1Core and NSOpenGLProfileVersion3_2Core (similar to the existing logic)?
Maybe a cleaner option would be to defer the creation of the NSOpenGLPixelFormat by instead storing the Vec<NSOpenGLPixelFormatAttribute> directly in cgl's ConfigInner type, then setting NSOpenGLPFAOpenGLProfile correctly and create the NSOpenGLPixelFormat object later when we have access to the ContextAttributes object: https://github.com/rust-windowing/glutin/blob/master/glutin/src/api/cgl/context.rs#L49
Thanks for your time! I'm happy to contribute a PR if any of the above approaches sound reasonable.
The text was updated successfully, but these errors were encountered:
Hello! I had an application which was previously using some SDL2 Rust bindings and was later rewritten to use winit + glutin, which happens to use a legacy OpenGL 2.1 context on macOS. The code that creates the context looks roughly like this:
However, I end up with an OpenGL 4.1 core context, with all legacy OpenGL features disabled.
I had a look through the cgl module and found this piece of code, which seems to indicate that we will always try to create an OpenGL context with the latest version of OpenGL regardless of the profile specified in the
ContextAttributesBuilder
:glutin/glutin/src/api/cgl/config.rs
Lines 106 to 118 in 9228126
If I change that array locally so that
NSOpenGLProfileVersionLegacy
is the first element, then theNSOpenGLPixelFormat
object gets created with the legacy OpenGL context correctly as expected, and my application works properly.It seems that we don't have the
ContextAttributes
object yet when callingDisplay::find_configs
. SDL2's behaviour is to useNSOpenGLProfileVersionLegacy
by default unless a core profile is specified, then favourNSOpenGLProfileVersion3_2Core
.I'm not very familiar with glutin's internals, so not sure what the cleanest approach would be here, but I had some potential ideas:
NSOpenGLPixelFormat
objects and storing both incgl
'sConfigInner
type, one for the "compatibility" profile withNSOpenGLProfileVersionLegacy
, and one for the "core" profile using eitherNSOpenGLProfileVersion4_1Core
andNSOpenGLProfileVersion3_2Core
(similar to the existing logic)?NSOpenGLPixelFormat
by instead storing theVec<NSOpenGLPixelFormatAttribute>
directly incgl
'sConfigInner
type, then settingNSOpenGLPFAOpenGLProfile
correctly and create theNSOpenGLPixelFormat
object later when we have access to theContextAttributes
object: https://github.com/rust-windowing/glutin/blob/master/glutin/src/api/cgl/context.rs#L49Thanks for your time! I'm happy to contribute a PR if any of the above approaches sound reasonable.
The text was updated successfully, but these errors were encountered: