diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index bbc110dd..a58001de 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -11,6 +11,7 @@ use Api; use BuilderAttribs; use CreationError; use GlContext; +use GlProfile; use GlRequest; use PixelFormat; use native_monitor::NativeMonitorId; @@ -470,11 +471,11 @@ impl Window { } fn create_context(view: id, builder: &BuilderAttribs) -> Result<(Option, Option), CreationError> { - let profile = match (builder.gl_version, builder.gl_version.to_gl_version(), builder.gl_core) { - (GlRequest::Latest, _, Some(false)) => NSOpenGLProfileVersionLegacy as u32, + let profile = match (builder.gl_version, builder.gl_version.to_gl_version(), builder.gl_profile) { + (GlRequest::Latest, _, Some(GlProfile::Compatibility)) => NSOpenGLProfileVersionLegacy as u32, (GlRequest::Latest, _, _) => NSOpenGLProfileVersion4_1Core as u32, - (_, Some(1 ... 2, _), Some(true)) | - (_, Some(3 ... 4, _), Some(false)) => + (_, Some(1 ... 2, _), Some(GlProfile::Core)) | + (_, Some(3 ... 4, _), Some(GlProfile::Compatibility)) => return Err(CreationError::NotSupported), (_, Some(1 ... 2, _), _) => NSOpenGLProfileVersionLegacy as u32, (_, Some(3, 0 ... 2), _) => NSOpenGLProfileVersion3_2Core as u32, diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index b0efc379..cb61dfa7 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -3,6 +3,7 @@ use BuilderAttribs; use CreationError; use GlContext; +use GlProfile; use GlRequest; use Api; 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(if core { - ffi::glx_extra::CONTEXT_CORE_PROFILE_BIT_ARB - } else { - ffi::glx_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB - } as libc::c_int - ); + attributes.push(flag as libc::c_int); } if builder.gl_debug { diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index 3837069c..e5b0b3a0 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -17,6 +17,7 @@ use BuilderAttribs; use CreationError; use CreationError::OsError; use CursorState; +use GlProfile; use GlRequest; 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, "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(if core { - gl::wgl_extra::CONTEXT_CORE_PROFILE_BIT_ARB - } else { - gl::wgl_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB - } as libc::c_int - ); + attributes.push(flag as libc::c_int); } else { return Err(CreationError::NotSupported); } diff --git a/src/lib.rs b/src/lib.rs index 713efefa..d52077d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,6 +137,15 @@ pub enum Api { 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. #[derive(Debug, Copy, Clone)] pub enum GlRequest { @@ -277,7 +286,7 @@ pub struct BuilderAttribs<'a> { title: String, monitor: Option, gl_version: GlRequest, - gl_core: Option, + gl_profile: Option, gl_debug: bool, vsync: bool, visible: bool, @@ -300,7 +309,7 @@ impl BuilderAttribs<'static> { title: "glutin window".to_string(), monitor: None, gl_version: GlRequest::Latest, - gl_core: None, + gl_profile: None, gl_debug: cfg!(debug_assertions), vsync: false, visible: true, @@ -327,7 +336,7 @@ impl<'a> BuilderAttribs<'a> { title: self.title, monitor: self.monitor, gl_version: self.gl_version, - gl_core: self.gl_core, + gl_profile: self.gl_profile, gl_debug: self.gl_debug, vsync: self.vsync, visible: self.visible, diff --git a/src/window.rs b/src/window.rs index 8898e1ec..c21b82dc 100644 --- a/src/window.rs +++ b/src/window.rs @@ -7,6 +7,7 @@ use CreationError; use CursorState; use Event; use GlContext; +use GlProfile; use GlRequest; use MouseCursor; use PixelFormat; @@ -67,9 +68,9 @@ impl<'a> WindowBuilder<'a> { self } - /// Sets the Core/Compatibility flag of the created OpenGL context. - pub fn with_gl_core_profile(mut self, core: bool) -> WindowBuilder<'a> { - self.attribs.gl_core = Some(core); + /// Sets the desired OpenGL context profile. + pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> { + self.attribs.gl_profile = Some(profile); self } @@ -130,9 +131,9 @@ impl<'a> WindowBuilder<'a> { self } - /// Sets whether sRGB should be enabled on the window. - pub fn with_srgb(mut self, srgb: bool) -> WindowBuilder<'a> { - self.attribs.srgb = Some(srgb); + /// Sets whether sRGB should be enabled on the window. `None` means "I don't care". + pub fn with_srgb(mut self, srgb_enabled: Option) -> WindowBuilder<'a> { + self.attribs.srgb = srgb_enabled; self }