From ba5adfa1e13e8be0dec888b3fbcb54fd30a9a673 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 20 Jul 2015 19:34:34 +0200 Subject: Add CreationError::RobustnessNotSupported --- src/api/cocoa/mod.rs | 2 +- src/api/egl/mod.rs | 6 +++--- src/api/glx/mod.rs | 2 +- src/api/osmesa/mod.rs | 2 +- src/api/wgl/mod.rs | 2 +- src/lib.rs | 3 +++ 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 332244e..680c621 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); }, _ => () } diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs index d22c009..3d6d681 100644 --- a/src/api/egl/mod.rs +++ b/src/api/egl/mod.rs @@ -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); }, _ => () } diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index e0adde7..753bd74 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); }, _ => () } diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index db0a1e7..15225b3 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -41,7 +41,7 @@ impl OsMesaContext { match builder.gl_robustness { Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => { - return Err(CreationError::NotSupported.into()); + return Err(CreationError::RobustnessNotSupported.into()); }, _ => () } diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs index 222620c..a90baff 100644 --- a/src/api/wgl/mod.rs +++ b/src/api/wgl/mod.rs @@ -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); }, _ => () } diff --git a/src/lib.rs b/src/lib.rs index d43dcfb..d5f563a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,6 +109,7 @@ pub trait GlContext { pub enum CreationError { OsError(String), NotSupported, + RobustnessNotSupported, } impl CreationError { @@ -116,6 +117,8 @@ 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.", } } } -- cgit v1.2.3 From 43dabf131aa9f76610e1cfd0685e3b36de8c2ebd Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 20 Jul 2015 19:38:57 +0200 Subject: Add CreationError::OpenGlVersionNotSupported --- src/api/cocoa/mod.rs | 4 ++-- src/api/egl/mod.rs | 18 +++++++++--------- src/api/glx/mod.rs | 1 + src/api/osmesa/mod.rs | 2 ++ src/api/wgl/mod.rs | 4 ++-- src/lib.rs | 3 +++ 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 680c621..6fc91b4 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -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 diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs index 3d6d681..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); } } }; @@ -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 753bd74..65819f8 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -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 15225b3..056e2d1 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -46,6 +46,8 @@ impl OsMesaContext { _ => () } + // 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 a90baff..54a9a9a 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); diff --git a/src/lib.rs b/src/lib.rs index d5f563a..b543702 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,6 +110,7 @@ pub enum CreationError { OsError(String), NotSupported, RobustnessNotSupported, + OpenGlVersionNotSupported, } impl CreationError { @@ -119,6 +120,8 @@ impl CreationError { 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.", } } } -- cgit v1.2.3 From 57a1d546e7ea80731a20f0771676f66f0cf595f9 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 20 Jul 2015 19:42:32 +0200 Subject: Add CreationError::NoAvailablePixelFormat --- src/api/cocoa/mod.rs | 2 +- src/api/wgl/mod.rs | 2 +- src/lib.rs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 6fc91b4..5ea57ae 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -603,7 +603,7 @@ impl Window { Err(CreationError::NotSupported) } } else { - Err(CreationError::NotSupported) + Err(CreationError::NoAvailablePixelFormat) } } } diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs index 54a9a9a..89538f1 100644 --- a/src/api/wgl/mod.rs +++ b/src/api/wgl/mod.rs @@ -573,5 +573,5 @@ fn choose_dummy_pixel_format(iter: I) -> Result } } - 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 b543702..9b45ae9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,6 +111,7 @@ pub enum CreationError { NotSupported, RobustnessNotSupported, OpenGlVersionNotSupported, + NoAvailablePixelFormat, } impl CreationError { @@ -122,6 +123,8 @@ impl CreationError { not supported.", CreationError::OpenGlVersionNotSupported => "The requested OpenGL version is not \ supported.", + CreationError::NoAvailablePixelFormat => "Couldn't find any pixel format that matches \ + the criterias.", } } } @@ -471,7 +474,7 @@ impl<'a> BuilderAttribs<'a> { } current_result.or(current_software_result) - .ok_or(CreationError::NotSupported) + .ok_or(CreationError::NoAvailablePixelFormat) } } -- cgit v1.2.3 From 7fe828bed3c1e01c0868d83eada0f2f36209c989 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 20 Jul 2015 19:43:36 +0200 Subject: Add smaall TODO --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 9b45ae9..9821c9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,6 +108,7 @@ pub trait GlContext { #[derive(Clone, Debug, PartialEq, Eq)] pub enum CreationError { OsError(String), + /// TODO: remove this error NotSupported, RobustnessNotSupported, OpenGlVersionNotSupported, -- cgit v1.2.3