aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-06-26 11:34:14 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-06-26 11:34:14 +0200
commit86300dfb793abeb53db0780fbf99bf4f007c88b8 (patch)
tree3659b09a7d7992a1e57ccaa9c20ab79d2a9a6222 /src
parent4349de5541bb3049b7f7a7b46616daa578b7665c (diff)
parentbff79c02cebd6ddba88918053d4fcd39bbd09b11 (diff)
downloadglutin-86300dfb793abeb53db0780fbf99bf4f007c88b8.tar.gz
glutin-86300dfb793abeb53db0780fbf99bf4f007c88b8.zip
Merge pull request #500 from tomaka/no-error
Add support for the EGL_KHR_create_context_no_error extension
Diffstat (limited to 'src')
-rw-r--r--src/api/egl/mod.rs73
-rw-r--r--src/api/glx/mod.rs3
-rw-r--r--src/api/wgl/mod.rs3
-rw-r--r--src/lib.rs7
4 files changed, 64 insertions, 22 deletions
diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs
index 07c70b0..1a6cc06 100644
--- a/src/api/egl/mod.rs
+++ b/src/api/egl/mod.rs
@@ -349,7 +349,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
format!("")
};
- let mut context_attributes = vec![];
+ let mut context_attributes = Vec::with_capacity(10);
let mut flags = 0;
if egl_version >= &(1, 5) ||
@@ -361,30 +361,62 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
context_attributes.push(ffi::egl::CONTEXT_MINOR_VERSION as i32);
context_attributes.push(version.1 as i32);
- if egl_version >= &(1, 5) ||
- extensions.contains("EGL_EXT_create_context_robustness ") ||
- extensions.ends_with("EGL_EXT_create_context_robustness")
- {
- match gl_robustness {
- Robustness::RobustNoResetNotification | Robustness::TryRobustNoResetNotification => {
- context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as libc::c_int);
+ // handling robustness
+ let supports_robustness = egl_version >= &(1, 5) ||
+ extensions.contains("EGL_EXT_create_context_robustness ") ||
+ extensions.ends_with("EGL_EXT_create_context_robustness");
+
+ match gl_robustness {
+ Robustness::NotRobust => (),
+
+ Robustness::NoError => {
+ if extensions.contains("EGL_KHR_create_context_no_error ") ||
+ extensions.ends_with("EGL_KHR_create_context_no_error")
+ {
+ context_attributes.push(ffi::egl::CONTEXT_OPENGL_NO_ERROR_KHR as libc::c_int);
+ context_attributes.push(1);
+ }
+ },
+
+ Robustness::RobustNoResetNotification => {
+ if supports_robustness {
+ context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY
+ as libc::c_int);
context_attributes.push(ffi::egl::NO_RESET_NOTIFICATION as libc::c_int);
flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as libc::c_int;
- },
- Robustness::RobustLoseContextOnReset | Robustness::TryRobustLoseContextOnReset => {
- context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as libc::c_int);
+ } else {
+ return Err(CreationError::NotSupported);
+ }
+ },
+
+ Robustness::TryRobustNoResetNotification => {
+ if supports_robustness {
+ context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY
+ as libc::c_int);
+ context_attributes.push(ffi::egl::NO_RESET_NOTIFICATION as libc::c_int);
+ flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as libc::c_int;
+ }
+ },
+
+ Robustness::RobustLoseContextOnReset => {
+ if supports_robustness {
+ context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY
+ as libc::c_int);
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;
- },
- Robustness::NotRobust => ()
- }
- } else {
- match gl_robustness {
- Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
+ } else {
return Err(CreationError::NotSupported);
- },
- _ => ()
- }
+ }
+ },
+
+ Robustness::TryRobustLoseContextOnReset => {
+ if supports_robustness {
+ context_attributes.push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY
+ as libc::c_int);
+ 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;
+ }
+ },
}
if gl_debug {
@@ -400,6 +432,7 @@ unsafe fn create_context(egl: &ffi::egl::Egl, display: ffi::egl::types::EGLDispl
context_attributes.push(flags);
} else if egl_version >= &(1, 3) && api == Api::OpenGlEs {
+ // robustness is not supported
match gl_robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
return Err(CreationError::NotSupported);
diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs
index 2c15e18..d286813 100644
--- a/src/api/glx/mod.rs
+++ b/src/api/glx/mod.rs
@@ -246,7 +246,8 @@ fn create_context(glx: &ffi::glx::Glx, extra_functions: &ffi::glx_extra::Glx, ex
attributes.push(ffi::glx_extra::LOSE_CONTEXT_ON_RESET_ARB as libc::c_int);
flags = flags | ffi::glx_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as libc::c_int;
},
- Robustness::NotRobust => ()
+ Robustness::NotRobust => (),
+ Robustness::NoError => (),
}
} else {
match robustness {
diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs
index 55fd22a..a71bb34 100644
--- a/src/api/wgl/mod.rs
+++ b/src/api/wgl/mod.rs
@@ -281,7 +281,8 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
attributes.push(gl::wgl_extra::LOSE_CONTEXT_ON_RESET_ARB as libc::c_int);
flags = flags | gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as libc::c_int;
},
- Robustness::NotRobust => ()
+ Robustness::NotRobust => (),
+ Robustness::NoError => (),
}
} else {
match builder.gl_robustness {
diff --git a/src/lib.rs b/src/lib.rs
index 64b0ace..3dcf0f9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -205,6 +205,13 @@ pub enum Robustness {
/// shaders.
NotRobust,
+ /// The driver doesn't check anything. This option is very dangerous. Please know what you're
+ /// doing before using it. See the `GL_KHR_no_error` extension.
+ ///
+ /// Since this option is purely an optimisation, no error will be returned if the backend
+ /// doesn't support it. Instead it will automatically fall back to `NotRobust`.
+ NoError,
+
/// Everything is checked to avoid any crash. The driver will attempt to avoid any problem,
/// but if a problem occurs the behavior is implementation-defined. You are just guaranteed not
/// to get a crash.