Add CreationError::OpenGlVersionNotSupported

This commit is contained in:
Pierre Krieger 2015-07-20 19:38:57 +02:00
parent ba5adfa1e1
commit 43dabf131a
6 changed files with 19 additions and 13 deletions

View file

@ -512,11 +512,11 @@ impl Window {
}, },
(_, Some((1 ... 2, _)), Some(GlProfile::Core)) | (_, Some((1 ... 2, _)), Some(GlProfile::Core)) |
(_, Some((3 ... 4, _)), Some(GlProfile::Compatibility)) => (_, Some((3 ... 4, _)), Some(GlProfile::Compatibility)) =>
return Err(CreationError::NotSupported), return Err(CreationError::OpenGlVersionNotSupported),
(_, Some((1 ... 2, _)), _) => NSOpenGLProfileVersionLegacy as u32, (_, Some((1 ... 2, _)), _) => NSOpenGLProfileVersionLegacy as u32,
(_, Some((3, 0 ... 2)), _) => NSOpenGLProfileVersion3_2Core as u32, (_, Some((3, 0 ... 2)), _) => NSOpenGLProfileVersion3_2Core as u32,
(_, Some((3 ... 4, _)), _) => NSOpenGLProfileVersion4_1Core 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 // NOTE: OS X no longer has the concept of setting individual

View file

@ -68,7 +68,7 @@ impl Context {
} else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 { } else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 {
(None, Api::OpenGlEs) (None, Api::OpenGlEs)
} else { } else {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
} else { } else {
(None, Api::OpenGlEs) (None, Api::OpenGlEs)
@ -77,21 +77,21 @@ impl Context {
GlRequest::Specific(Api::OpenGlEs, version) => { GlRequest::Specific(Api::OpenGlEs, version) => {
if egl_version >= (1, 2) { if egl_version >= (1, 2) {
if egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 { if egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
} }
(Some(version), Api::OpenGlEs) (Some(version), Api::OpenGlEs)
}, },
GlRequest::Specific(Api::OpenGl, version) => { GlRequest::Specific(Api::OpenGl, version) => {
if egl_version < (1, 4) { if egl_version < (1, 4) {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
if egl.BindAPI(ffi::egl::OPENGL_API) == 0 { if egl.BindAPI(ffi::egl::OPENGL_API) == 0 {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
(Some(version), Api::OpenGl) (Some(version), Api::OpenGl)
}, },
GlRequest::Specific(_, _) => return Err(CreationError::NotSupported), GlRequest::Specific(_, _) => return Err(CreationError::OpenGlVersionNotSupported),
GlRequest::GlThenGles { opengles_version, opengl_version } => { GlRequest::GlThenGles { opengles_version, opengl_version } => {
if egl_version >= (1, 4) { if egl_version >= (1, 4) {
if egl.BindAPI(ffi::egl::OPENGL_API) != 0 { if egl.BindAPI(ffi::egl::OPENGL_API) != 0 {
@ -99,7 +99,7 @@ impl Context {
} else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 { } else if egl.BindAPI(ffi::egl::OPENGL_ES_API) != 0 {
(Some(opengles_version), Api::OpenGlEs) (Some(opengles_version), Api::OpenGlEs)
} else { } else {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
} else { } else {
(Some(opengles_version), Api::OpenGlEs) (Some(opengles_version), Api::OpenGlEs)
@ -245,7 +245,7 @@ impl<'a> ContextPrototype<'a> {
{ {
ctxt ctxt
} else { } else {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
} else { } else {
@ -267,7 +267,7 @@ impl<'a> ContextPrototype<'a> {
{ {
ctxt ctxt
} else { } 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() { if context.is_null() {
match egl.GetError() as u32 { 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), e => panic!("eglCreateContext failed: 0x{:x}", e),
} }
} }

View file

@ -328,6 +328,7 @@ fn create_context(glx: &ffi::glx::Glx, extra_functions: &ffi::glx_extra::Glx, ex
}; };
if context.is_null() { if context.is_null() {
// TODO: check for errors and return `OpenGlVersionNotSupported`
return Err(CreationError::OsError(format!("GL context creation failed"))); return Err(CreationError::OsError(format!("GL context creation failed")));
} }

View file

@ -46,6 +46,8 @@ impl OsMesaContext {
_ => () _ => ()
} }
// TODO: check OpenGL version and return `OpenGlVersionNotSupported` if necessary
Ok(OsMesaContext { Ok(OsMesaContext {
width: dimensions.0, width: dimensions.0,
height: dimensions.1, height: dimensions.1,

View file

@ -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_PROFILE_MASK_ARB as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_ES2_PROFILE_BIT_EXT as libc::c_int); attributes.push(gl::wgl_extra::CONTEXT_ES2_PROFILE_BIT_EXT as libc::c_int);
} else { } else {
return Err(CreationError::NotSupported); return Err(CreationError::OpenGlVersionNotSupported);
} }
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); 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(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int);
attributes.push(minor 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), .. } => { GlRequest::GlThenGles { opengl_version: (major, minor), .. } => {
attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int);
attributes.push(major as libc::c_int); attributes.push(major as libc::c_int);

View file

@ -110,6 +110,7 @@ pub enum CreationError {
OsError(String), OsError(String),
NotSupported, NotSupported,
RobustnessNotSupported, RobustnessNotSupported,
OpenGlVersionNotSupported,
} }
impl CreationError { impl CreationError {
@ -119,6 +120,8 @@ impl CreationError {
CreationError::NotSupported => "Some of the requested attributes are not supported", CreationError::NotSupported => "Some of the requested attributes are not supported",
CreationError::RobustnessNotSupported => "Your requested robustness, but it is \ CreationError::RobustnessNotSupported => "Your requested robustness, but it is \
not supported.", not supported.",
CreationError::OpenGlVersionNotSupported => "The requested OpenGL version is not \
supported.",
} }
} }
} }