Introduced GlProfile enum

This commit is contained in:
Dzmitry Malyshau 2015-04-30 23:06:22 -04:00
parent a42f1f5833
commit 171986c7e8
5 changed files with 42 additions and 27 deletions

View file

@ -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,

View file

@ -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 {

View file

@ -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);
}