aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-07-21 17:49:52 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-07-21 17:49:52 +0200
commit04a651320ba00571a0b2af9ae25c6d6c696c2803 (patch)
tree7ba2cf8fbc9ebd9acb1f7854ee4bfef7a5028a44
parentca1eb8dc533301060e2b2768646b15d79c8be60c (diff)
parent7fe828bed3c1e01c0868d83eada0f2f36209c989 (diff)
downloadglutin-04a651320ba00571a0b2af9ae25c6d6c696c2803.tar.gz
glutin-04a651320ba00571a0b2af9ae25c6d6c696c2803.zip
Merge pull request #532 from tomaka/precise-errors
Precise errors
-rw-r--r--src/api/cocoa/mod.rs8
-rw-r--r--src/api/egl/mod.rs24
-rw-r--r--src/api/glx/mod.rs3
-rw-r--r--src/api/osmesa/mod.rs4
-rw-r--r--src/api/wgl/mod.rs8
-rw-r--r--src/lib.rs12
6 files changed, 36 insertions, 23 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 332244e..5ea57ae 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -335,7 +335,7 @@ impl Window {
match builder.gl_robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
},
_ => ()
}
@@ -512,11 +512,11 @@ impl Window {
},
(_, Some((1 ... 2, _)), Some(GlProfile::Core)) |
(_, Some((3 ... 4, _)), Some(GlProfile::Compatibility)) =>
- return Err(CreationError::NotSupported),
+ return Err(CreationError::OpenGlVersionNotSupported),
(_, 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),
+ _ => return Err(CreationError::OpenGlVersionNotSupported),
};
// NOTE: OS X no longer has the concept of setting individual
@@ -603,7 +603,7 @@ impl Window {
Err(CreationError::NotSupported)
}
} else {
- Err(CreationError::NotSupported)
+ Err(CreationError::NoAvailablePixelFormat)
}
}
}
diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs
index d22c009..328a11e 100644
--- a/src/api/egl/mod.rs
+++ b/src/api/egl/mod.rs
@@ -68,7 +68,7 @@ impl Context {
} else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 {
(None, Api::OpenGlEs)
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
} else {
(None, Api::OpenGlEs)
@@ -77,21 +77,21 @@ impl Context {
GlRequest::Specific(Api::OpenGlEs, version) => {
if egl_version >= (1, 2) {
if egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
}
(Some(version), Api::OpenGlEs)
},
GlRequest::Specific(Api::OpenGl, version) => {
if egl_version < (1, 4) {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
if egl.BindAPI(ffi::egl::OPENGL_API) == 0 {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
(Some(version), Api::OpenGl)
},
- GlRequest::Specific(_, _) => return Err(CreationError::NotSupported),
+ GlRequest::Specific(_, _) => return Err(CreationError::OpenGlVersionNotSupported),
GlRequest::GlThenGles { opengles_version, opengl_version } => {
if egl_version >= (1, 4) {
if egl.BindAPI(ffi::egl::OPENGL_API) != 0 {
@@ -99,7 +99,7 @@ impl Context {
} else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 {
(Some(opengles_version), Api::OpenGlEs)
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
} else {
(Some(opengles_version), Api::OpenGlEs)
@@ -245,7 +245,7 @@ impl<'a> ContextPrototype<'a> {
{
ctxt
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
} else {
@@ -267,7 +267,7 @@ impl<'a> ContextPrototype<'a> {
{
ctxt
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
}
};
@@ -434,7 +434,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
context_attributes.push(ffi::egl::NO_RESET_NOTIFICATION as libc::c_int);
flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as libc::c_int;
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
}
},
@@ -454,7 +454,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
context_attributes.push(ffi::egl::LOSE_CONTEXT_ON_RESET as libc::c_int);
flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as libc::c_int;
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
}
},
@@ -488,7 +488,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
// robustness is not supported
match gl_robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
},
_ => ()
}
@@ -504,7 +504,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
if context.is_null() {
match egl.GetError() as u32 {
- ffi::egl::BAD_ATTRIBUTE => return Err(CreationError::NotSupported),
+ ffi::egl::BAD_ATTRIBUTE => return Err(CreationError::OpenGlVersionNotSupported),
e => panic!("eglCreateContext failed: 0x{:x}", e),
}
}
diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs
index e0adde7..65819f8 100644
--- a/src/api/glx/mod.rs
+++ b/src/api/glx/mod.rs
@@ -301,7 +301,7 @@ fn create_context(glx: &ffi::glx::Glx, extra_functions: &ffi::glx_extra::Glx, ex
} else {
match robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
},
_ => ()
}
@@ -328,6 +328,7 @@ fn create_context(glx: &ffi::glx::Glx, extra_functions: &ffi::glx_extra::Glx, ex
};
if context.is_null() {
+ // TODO: check for errors and return `OpenGlVersionNotSupported`
return Err(CreationError::OsError(format!("GL context creation failed")));
}
diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs
index db0a1e7..056e2d1 100644
--- a/src/api/osmesa/mod.rs
+++ b/src/api/osmesa/mod.rs
@@ -41,11 +41,13 @@ impl OsMesaContext {
match builder.gl_robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
- return Err(CreationError::NotSupported.into());
+ return Err(CreationError::RobustnessNotSupported.into());
},
_ => ()
}
+ // TODO: check OpenGL version and return `OpenGlVersionNotSupported` if necessary
+
Ok(OsMesaContext {
width: dimensions.0,
height: dimensions.1,
diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs
index 222620c..89538f1 100644
--- a/src/api/wgl/mod.rs
+++ b/src/api/wgl/mod.rs
@@ -235,7 +235,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_ES2_PROFILE_BIT_EXT as libc::c_int);
} else {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::OpenGlVersionNotSupported);
}
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
@@ -243,7 +243,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
attributes.push(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int);
attributes.push(minor as libc::c_int);
},
- GlRequest::Specific(_, _) => return Err(CreationError::NotSupported),
+ GlRequest::Specific(_, _) => return Err(CreationError::OpenGlVersionNotSupported),
GlRequest::GlThenGles { opengl_version: (major, minor), .. } => {
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
attributes.push(major as libc::c_int);
@@ -290,7 +290,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
} else {
match builder.gl_robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
- return Err(CreationError::NotSupported);
+ return Err(CreationError::RobustnessNotSupported);
},
_ => ()
}
@@ -573,5 +573,5 @@ fn choose_dummy_pixel_format<I>(iter: I) -> Result<libc::c_int, CreationError>
}
}
- backup_id.ok_or(CreationError::NotSupported)
+ backup_id.ok_or(CreationError::OsError("No available pixel format".to_string()))
}
diff --git a/src/lib.rs b/src/lib.rs
index d43dcfb..9821c9f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -108,7 +108,11 @@ pub trait GlContext {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CreationError {
OsError(String),
+ /// TODO: remove this error
NotSupported,
+ RobustnessNotSupported,
+ OpenGlVersionNotSupported,
+ NoAvailablePixelFormat,
}
impl CreationError {
@@ -116,6 +120,12 @@ impl CreationError {
match *self {
CreationError::OsError(ref text) => &text,
CreationError::NotSupported => "Some of the requested attributes are not supported",
+ CreationError::RobustnessNotSupported => "Your requested robustness, but it is \
+ not supported.",
+ CreationError::OpenGlVersionNotSupported => "The requested OpenGL version is not \
+ supported.",
+ CreationError::NoAvailablePixelFormat => "Couldn't find any pixel format that matches \
+ the criterias.",
}
}
}
@@ -465,7 +475,7 @@ impl<'a> BuilderAttribs<'a> {
}
current_result.or(current_software_result)
- .ok_or(CreationError::NotSupported)
+ .ok_or(CreationError::NoAvailablePixelFormat)
}
}