aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorDzmitry Malyshau <kvarkus@gmail.com>2015-04-29 23:05:47 -0400
committerDzmitry Malyshau <kvarkus@gmail.com>2015-04-30 22:50:15 -0400
commita42f1f58333a9899d36e18e641f3f52517dd58b1 (patch)
tree8e11e18d3bb3fc4f5a3a5a65eb7c895d515c105c /src/api
parentc1ca5d1d87166daa20d4ae2a9a0a7c8d4ba2ba63 (diff)
downloadglutin-a42f1f58333a9899d36e18e641f3f52517dd58b1.tar.gz
glutin-a42f1f58333a9899d36e18e641f3f52517dd58b1.zip
Implemented gl_core flag
Diffstat (limited to 'src/api')
-rw-r--r--src/api/cocoa/mod.rs29
-rw-r--r--src/api/glx/mod.rs12
-rw-r--r--src/api/win32/init.rs16
3 files changed, 40 insertions, 17 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 7114a87..bbc110d 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -9,6 +9,7 @@ use libc;
use Api;
use BuilderAttribs;
+use CreationError;
use GlContext;
use GlRequest;
use PixelFormat;
@@ -334,7 +335,6 @@ impl Window {
Some(window) => window,
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
};
-
let view = match Window::create_view(*window) {
Some(view) => view,
None => { return Err(OsError(format!("Couldn't create NSView"))); },
@@ -469,18 +469,17 @@ impl Window {
}
}
- fn create_context(view: id, builder: &BuilderAttribs) -> (Option<IdRef>, Option<PixelFormat>) {
- let profile = match builder.gl_version {
- GlRequest::Latest => NSOpenGLProfileVersion4_1Core as u32,
- GlRequest::Specific(Api::OpenGl, (1 ... 2, _)) => NSOpenGLProfileVersionLegacy as u32,
- GlRequest::Specific(Api::OpenGl, (3, 0)) => NSOpenGLProfileVersionLegacy as u32,
- GlRequest::Specific(Api::OpenGl, (3, 1 ... 2)) => NSOpenGLProfileVersion3_2Core as u32,
- GlRequest::Specific(Api::OpenGl, _) => NSOpenGLProfileVersion4_1Core as u32,
- GlRequest::Specific(_, _) => panic!("Only the OpenGL API is supported"), // FIXME: return Result
- GlRequest::GlThenGles { opengl_version: (1 ... 2, _), .. } => NSOpenGLProfileVersionLegacy as u32,
- GlRequest::GlThenGles { opengl_version: (3, 0), .. } => NSOpenGLProfileVersionLegacy as u32,
- GlRequest::GlThenGles { opengl_version: (3, 1 ... 2), .. } => NSOpenGLProfileVersion3_2Core as u32,
- GlRequest::GlThenGles { .. } => NSOpenGLProfileVersion4_1Core as u32,
+ 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,
+ (GlRequest::Latest, _, _) => NSOpenGLProfileVersion4_1Core as u32,
+ (_, Some(1 ... 2, _), Some(true)) |
+ (_, Some(3 ... 4, _), Some(false)) =>
+ return Err(CreationError::NotSupported),
+ (_, Some(1 ... 2, _), _) => NSOpenGLProfileVersionLegacy as u32,
+ (_, Some(3, 0 ... 2), _) => NSOpenGLProfileVersion3_2Core as u32,
+ (_, Some(3 ... 4, _), _) => NSOpenGLProfileVersion4_1Core as u32,
+ _ => return Err(CreationError::NotSupported),
};
// NOTE: OS X no longer has the concept of setting individual
@@ -517,7 +516,7 @@ impl Window {
// attribute list must be null terminated.
attributes.push(0);
- unsafe {
+ Ok(unsafe {
let pixelformat = IdRef::new(NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes));
if let Some(pixelformat) = pixelformat.non_nil() {
@@ -575,7 +574,7 @@ impl Window {
} else {
(None, None)
}
- }
+ })
}
pub fn is_closed(&self) -> bool {
diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs
index 7aa77e7..b0efc37 100644
--- a/src/api/glx/mod.rs
+++ b/src/api/glx/mod.rs
@@ -52,6 +52,16 @@ impl Context {
},
}
+ if let Some(core) = builder.gl_core {
+ 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
+ );
+ }
+
if builder.gl_debug {
attributes.push(ffi::glx_extra::CONTEXT_FLAGS_ARB as libc::c_int);
attributes.push(ffi::glx_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int);
@@ -184,8 +194,6 @@ unsafe impl Sync for Context {}
impl Drop for Context {
fn drop(&mut self) {
- use std::ptr;
-
unsafe {
// we don't call MakeCurrent(0, 0) because we are not sure that the context
// is still the current one
diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs
index 39b9d97..3837069 100644
--- a/src/api/win32/init.rs
+++ b/src/api/win32/init.rs
@@ -374,6 +374,22 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
},
}
+ if let Some(core) = builder.gl_core {
+ if is_extension_supported(extra_functions, hdc,
+ "WGL_ARB_create_context_profile")
+ {
+ 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
+ );
+ } else {
+ return Err(CreationError::NotSupported);
+ }
+ }
+
if builder.gl_debug {
attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int);