diff options
author | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-11-09 16:07:58 +0100 |
---|---|---|
committer | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-11-09 16:44:53 +0100 |
commit | 8c1b2dd63370fe102b2a447e7840fc038413b6cc (patch) | |
tree | c3bf069645933f06c5942d258bb4c3f54f75b58d /src | |
parent | 9ee0875d4e6cdd7d8e66afc9d39efe99197a2b54 (diff) | |
download | glutin-8c1b2dd63370fe102b2a447e7840fc038413b6cc.tar.gz glutin-8c1b2dd63370fe102b2a447e7840fc038413b6cc.zip |
Add support for the OpenGL debug flag
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 22 | ||||
-rw-r--r-- | src/win32/init.rs | 9 | ||||
-rw-r--r-- | src/win32/mod.rs | 9 | ||||
-rw-r--r-- | src/x11/window/mod.rs | 5 |
4 files changed, 39 insertions, 6 deletions
@@ -91,6 +91,7 @@ pub struct WindowBuilder { title: String, monitor: Option<winimpl::MonitorID>, gl_version: Option<(uint, uint)>, + gl_debug: bool, vsync: bool, visible: bool, } @@ -104,6 +105,7 @@ impl WindowBuilder { title: "glutin window".to_string(), monitor: None, gl_version: None, + gl_debug: cfg!(ndebug), vsync: false, visible: true, } @@ -141,6 +143,15 @@ impl WindowBuilder { self } + /// Sets the *debug* flag for the OpenGL context. + /// + /// The default value for this flag is `cfg!(ndebug)`, which means that it's enabled + /// when you run `cargo build` and disabled when you run `cargo build --release`. + pub fn with_gl_debug_flag(mut self, flag: bool) -> WindowBuilder { + self.gl_debug = flag; + self + } + /// Requests that the window has vsync enabled. pub fn with_vsync(mut self) -> WindowBuilder { self.vsync = true; @@ -178,6 +189,7 @@ impl WindowBuilder { pub struct HeadlessRendererBuilder { dimensions: (uint, uint), gl_version: Option<(uint, uint)>, + gl_debug: bool, } #[cfg(feature = "headless")] @@ -187,6 +199,7 @@ impl HeadlessRendererBuilder { HeadlessRendererBuilder { dimensions: (width, height), gl_version: None, + gl_debug: cfg!(ndebug), } } @@ -199,6 +212,15 @@ impl HeadlessRendererBuilder { self } + /// Sets the *debug* flag for the OpenGL context. + /// + /// The default value for this flag is `cfg!(ndebug)`, which means that it's enabled + /// when you run `cargo build` and disabled when you run `cargo build --release`. + pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder { + self.gl_debug = flag; + self + } + /// Builds the headless context. /// /// Error should be very rare and only occur in case of permission denied, incompatible system, diff --git a/src/win32/init.rs b/src/win32/init.rs index 88ff069..90d6184 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -16,8 +16,8 @@ local_data_key!(WINDOW: (ffi::HWND, Sender<Event>)) pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String, builder_monitor: Option<super::MonitorID>, - builder_gl_version: Option<(uint, uint)>, builder_vsync: bool, - builder_hidden: bool) -> Result<Window, CreationError> + builder_gl_version: Option<(uint, uint)>, builder_debug: bool, + builder_vsync: bool, builder_hidden: bool) -> Result<Window, CreationError> { use std::mem; use std::os; @@ -298,6 +298,11 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin attributes.push(version.val1() as libc::c_int); } + if builder_debug { + attributes.push(ffi::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int); + attributes.push(ffi::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int); + } + attributes.push(0); let ctxt = unsafe { diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 282b0bb..b282385 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -24,8 +24,8 @@ pub struct HeadlessContext(Window); impl HeadlessContext { /// See the docs in the crate root file. pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> { - let HeadlessRendererBuilder { dimensions, gl_version } = builder; - init::new_window(Some(dimensions), "".to_string(), None, gl_version, false, true) + let HeadlessRendererBuilder { dimensions, gl_version, gl_debug } = builder; + init::new_window(Some(dimensions), "".to_string(), None, gl_version, gl_debug, false, true) .map(|w| HeadlessContext(w)) } @@ -68,8 +68,9 @@ pub struct Window { impl Window { /// See the docs in the crate root file. pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> { - let WindowBuilder { dimensions, title, monitor, gl_version, vsync, visible } = builder; - init::new_window(dimensions, title, monitor, gl_version, vsync, !visible) + let WindowBuilder { dimensions, title, monitor, gl_version, + gl_debug, vsync, visible } = builder; + init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync, !visible) } } diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 34d0d3b..38b4559 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -225,6 +225,11 @@ impl Window { attributes.push(version.val1() 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); + } + attributes.push(0); // loading the extra GLX functions |