diff options
author | Dzmitry Malyshau <kvarkus@gmail.com> | 2015-04-30 23:06:22 -0400 |
---|---|---|
committer | Dzmitry Malyshau <kvarkus@gmail.com> | 2015-05-01 07:32:48 -0400 |
commit | 171986c7e86063862d16208296c011cd5828bcad (patch) | |
tree | e750667b22097fba290848ed2510bd67a80a6ae6 /src | |
parent | a42f1f58333a9899d36e18e641f3f52517dd58b1 (diff) | |
download | glutin-171986c7e86063862d16208296c011cd5828bcad.tar.gz glutin-171986c7e86063862d16208296c011cd5828bcad.zip |
Introduced GlProfile enum
Diffstat (limited to 'src')
-rw-r--r-- | src/api/cocoa/mod.rs | 9 | ||||
-rw-r--r-- | src/api/glx/mod.rs | 16 | ||||
-rw-r--r-- | src/api/win32/init.rs | 16 | ||||
-rw-r--r-- | src/lib.rs | 15 | ||||
-rw-r--r-- | src/window.rs | 13 |
5 files changed, 42 insertions, 27 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index bbc110d..a58001d 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<IdRef>, Option<PixelFormat>), 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 b0efc37..cb61dfa 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 3837069..e5b0b3a 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); } @@ -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<platform::MonitorID>, gl_version: GlRequest, - gl_core: Option<bool>, + gl_profile: Option<GlProfile>, 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 8898e1e..c21b82d 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<bool>) -> WindowBuilder<'a> { + self.attribs.srgb = srgb_enabled; self } |