mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Introduced GlProfile enum
This commit is contained in:
parent
a42f1f5833
commit
171986c7e8
|
@ -11,6 +11,7 @@ use Api;
|
||||||
use BuilderAttribs;
|
use BuilderAttribs;
|
||||||
use CreationError;
|
use CreationError;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
|
use GlProfile;
|
||||||
use GlRequest;
|
use GlRequest;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
use native_monitor::NativeMonitorId;
|
use native_monitor::NativeMonitorId;
|
||||||
|
@ -470,11 +471,11 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_context(view: id, builder: &BuilderAttribs) -> Result<(Option<IdRef>, Option<PixelFormat>), CreationError> {
|
fn create_context(view: id, builder: &BuilderAttribs) -> Result<(Option<IdRef>, Option<PixelFormat>), CreationError> {
|
||||||
let profile = match (builder.gl_version, builder.gl_version.to_gl_version(), builder.gl_core) {
|
let profile = match (builder.gl_version, builder.gl_version.to_gl_version(), builder.gl_profile) {
|
||||||
(GlRequest::Latest, _, Some(false)) => NSOpenGLProfileVersionLegacy as u32,
|
(GlRequest::Latest, _, Some(GlProfile::Compatibility)) => NSOpenGLProfileVersionLegacy as u32,
|
||||||
(GlRequest::Latest, _, _) => NSOpenGLProfileVersion4_1Core as u32,
|
(GlRequest::Latest, _, _) => NSOpenGLProfileVersion4_1Core as u32,
|
||||||
(_, Some(1 ... 2, _), Some(true)) |
|
(_, Some(1 ... 2, _), Some(GlProfile::Core)) |
|
||||||
(_, Some(3 ... 4, _), Some(false)) =>
|
(_, Some(3 ... 4, _), Some(GlProfile::Compatibility)) =>
|
||||||
return Err(CreationError::NotSupported),
|
return Err(CreationError::NotSupported),
|
||||||
(_, Some(1 ... 2, _), _) => NSOpenGLProfileVersionLegacy as u32,
|
(_, Some(1 ... 2, _), _) => NSOpenGLProfileVersionLegacy as u32,
|
||||||
(_, Some(3, 0 ... 2), _) => NSOpenGLProfileVersion3_2Core as u32,
|
(_, Some(3, 0 ... 2), _) => NSOpenGLProfileVersion3_2Core as u32,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use BuilderAttribs;
|
use BuilderAttribs;
|
||||||
use CreationError;
|
use CreationError;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
|
use GlProfile;
|
||||||
use GlRequest;
|
use GlRequest;
|
||||||
use Api;
|
use Api;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
|
@ -52,14 +53,15 @@ impl Context {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(core) = builder.gl_core {
|
if let Some(profile) = builder.gl_profile {
|
||||||
|
let flag = match profile {
|
||||||
|
GlProfile::Compatibility =>
|
||||||
|
ffi::glx_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
||||||
|
GlProfile::Core =>
|
||||||
|
ffi::glx_extra::CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
|
};
|
||||||
attributes.push(ffi::glx_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
|
attributes.push(ffi::glx_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
|
||||||
attributes.push(if core {
|
attributes.push(flag as libc::c_int);
|
||||||
ffi::glx_extra::CONTEXT_CORE_PROFILE_BIT_ARB
|
|
||||||
} else {
|
|
||||||
ffi::glx_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
|
|
||||||
} as libc::c_int
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if builder.gl_debug {
|
if builder.gl_debug {
|
||||||
|
|
|
@ -17,6 +17,7 @@ use BuilderAttribs;
|
||||||
use CreationError;
|
use CreationError;
|
||||||
use CreationError::OsError;
|
use CreationError::OsError;
|
||||||
use CursorState;
|
use CursorState;
|
||||||
|
use GlProfile;
|
||||||
use GlRequest;
|
use GlRequest;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
|
|
||||||
|
@ -374,17 +375,18 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(core) = builder.gl_core {
|
if let Some(profile) = builder.gl_profile {
|
||||||
if is_extension_supported(extra_functions, hdc,
|
if is_extension_supported(extra_functions, hdc,
|
||||||
"WGL_ARB_create_context_profile")
|
"WGL_ARB_create_context_profile")
|
||||||
{
|
{
|
||||||
|
let flag = match profile {
|
||||||
|
GlProfile::Compatibility =>
|
||||||
|
gl::wgl_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
||||||
|
GlProfile::Core =>
|
||||||
|
gl::wgl_extra::CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
|
};
|
||||||
attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
|
attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
|
||||||
attributes.push(if core {
|
attributes.push(flag as libc::c_int);
|
||||||
gl::wgl_extra::CONTEXT_CORE_PROFILE_BIT_ARB
|
|
||||||
} else {
|
|
||||||
gl::wgl_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
|
|
||||||
} as libc::c_int
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return Err(CreationError::NotSupported);
|
return Err(CreationError::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -137,6 +137,15 @@ pub enum Api {
|
||||||
WebGl,
|
WebGl,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Describes the requested OpenGL context profiles.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum GlProfile {
|
||||||
|
/// Include all the immediate more functions and definitions.
|
||||||
|
Compatibility,
|
||||||
|
/// Include all the future-compatible functions and definitions.
|
||||||
|
Core,
|
||||||
|
}
|
||||||
|
|
||||||
/// Describes the OpenGL API and version that are being requested when a context is created.
|
/// Describes the OpenGL API and version that are being requested when a context is created.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum GlRequest {
|
pub enum GlRequest {
|
||||||
|
@ -277,7 +286,7 @@ pub struct BuilderAttribs<'a> {
|
||||||
title: String,
|
title: String,
|
||||||
monitor: Option<platform::MonitorID>,
|
monitor: Option<platform::MonitorID>,
|
||||||
gl_version: GlRequest,
|
gl_version: GlRequest,
|
||||||
gl_core: Option<bool>,
|
gl_profile: Option<GlProfile>,
|
||||||
gl_debug: bool,
|
gl_debug: bool,
|
||||||
vsync: bool,
|
vsync: bool,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
|
@ -300,7 +309,7 @@ impl BuilderAttribs<'static> {
|
||||||
title: "glutin window".to_string(),
|
title: "glutin window".to_string(),
|
||||||
monitor: None,
|
monitor: None,
|
||||||
gl_version: GlRequest::Latest,
|
gl_version: GlRequest::Latest,
|
||||||
gl_core: None,
|
gl_profile: None,
|
||||||
gl_debug: cfg!(debug_assertions),
|
gl_debug: cfg!(debug_assertions),
|
||||||
vsync: false,
|
vsync: false,
|
||||||
visible: true,
|
visible: true,
|
||||||
|
@ -327,7 +336,7 @@ impl<'a> BuilderAttribs<'a> {
|
||||||
title: self.title,
|
title: self.title,
|
||||||
monitor: self.monitor,
|
monitor: self.monitor,
|
||||||
gl_version: self.gl_version,
|
gl_version: self.gl_version,
|
||||||
gl_core: self.gl_core,
|
gl_profile: self.gl_profile,
|
||||||
gl_debug: self.gl_debug,
|
gl_debug: self.gl_debug,
|
||||||
vsync: self.vsync,
|
vsync: self.vsync,
|
||||||
visible: self.visible,
|
visible: self.visible,
|
||||||
|
|
|
@ -7,6 +7,7 @@ use CreationError;
|
||||||
use CursorState;
|
use CursorState;
|
||||||
use Event;
|
use Event;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
|
use GlProfile;
|
||||||
use GlRequest;
|
use GlRequest;
|
||||||
use MouseCursor;
|
use MouseCursor;
|
||||||
use PixelFormat;
|
use PixelFormat;
|
||||||
|
@ -67,9 +68,9 @@ impl<'a> WindowBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the Core/Compatibility flag of the created OpenGL context.
|
/// Sets the desired OpenGL context profile.
|
||||||
pub fn with_gl_core_profile(mut self, core: bool) -> WindowBuilder<'a> {
|
pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> {
|
||||||
self.attribs.gl_core = Some(core);
|
self.attribs.gl_profile = Some(profile);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +131,9 @@ impl<'a> WindowBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets whether sRGB should be enabled on the window.
|
/// Sets whether sRGB should be enabled on the window. `None` means "I don't care".
|
||||||
pub fn with_srgb(mut self, srgb: bool) -> WindowBuilder<'a> {
|
pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> {
|
||||||
self.attribs.srgb = Some(srgb);
|
self.attribs.srgb = srgb_enabled;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue