Merge pull request #104 from tomaka/debug-flag

Add support for the OpenGL debug flag
This commit is contained in:
tomaka 2014-11-09 17:03:10 +01:00
commit 7d00bedbdb
4 changed files with 39 additions and 6 deletions

View file

@ -91,6 +91,7 @@ pub struct WindowBuilder {
title: String, title: String,
monitor: Option<winimpl::MonitorID>, monitor: Option<winimpl::MonitorID>,
gl_version: Option<(uint, uint)>, gl_version: Option<(uint, uint)>,
gl_debug: bool,
vsync: bool, vsync: bool,
visible: bool, visible: bool,
} }
@ -104,6 +105,7 @@ impl WindowBuilder {
title: "glutin window".to_string(), title: "glutin window".to_string(),
monitor: None, monitor: None,
gl_version: None, gl_version: None,
gl_debug: cfg!(ndebug),
vsync: false, vsync: false,
visible: true, visible: true,
} }
@ -141,6 +143,15 @@ impl WindowBuilder {
self 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. /// Requests that the window has vsync enabled.
pub fn with_vsync(mut self) -> WindowBuilder { pub fn with_vsync(mut self) -> WindowBuilder {
self.vsync = true; self.vsync = true;
@ -178,6 +189,7 @@ impl WindowBuilder {
pub struct HeadlessRendererBuilder { pub struct HeadlessRendererBuilder {
dimensions: (uint, uint), dimensions: (uint, uint),
gl_version: Option<(uint, uint)>, gl_version: Option<(uint, uint)>,
gl_debug: bool,
} }
#[cfg(feature = "headless")] #[cfg(feature = "headless")]
@ -187,6 +199,7 @@ impl HeadlessRendererBuilder {
HeadlessRendererBuilder { HeadlessRendererBuilder {
dimensions: (width, height), dimensions: (width, height),
gl_version: None, gl_version: None,
gl_debug: cfg!(ndebug),
} }
} }
@ -199,6 +212,15 @@ impl HeadlessRendererBuilder {
self 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. /// Builds the headless context.
/// ///
/// Error should be very rare and only occur in case of permission denied, incompatible system, /// Error should be very rare and only occur in case of permission denied, incompatible system,

View file

@ -16,8 +16,8 @@ local_data_key!(WINDOW: (ffi::HWND, Sender<Event>))
pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String, pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String,
builder_monitor: Option<super::MonitorID>, builder_monitor: Option<super::MonitorID>,
builder_gl_version: Option<(uint, uint)>, builder_vsync: bool, builder_gl_version: Option<(uint, uint)>, builder_debug: bool,
builder_hidden: bool) -> Result<Window, CreationError> builder_vsync: bool, builder_hidden: bool) -> Result<Window, CreationError>
{ {
use std::mem; use std::mem;
use std::os; 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); 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); attributes.push(0);
let ctxt = unsafe { let ctxt = unsafe {

View file

@ -24,8 +24,8 @@ pub struct HeadlessContext(Window);
impl HeadlessContext { impl HeadlessContext {
/// See the docs in the crate root file. /// See the docs in the crate root file.
pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> { pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> {
let HeadlessRendererBuilder { dimensions, gl_version } = builder; let HeadlessRendererBuilder { dimensions, gl_version, gl_debug } = builder;
init::new_window(Some(dimensions), "".to_string(), None, gl_version, false, true) init::new_window(Some(dimensions), "".to_string(), None, gl_version, gl_debug, false, true)
.map(|w| HeadlessContext(w)) .map(|w| HeadlessContext(w))
} }
@ -68,8 +68,9 @@ pub struct Window {
impl Window { impl Window {
/// See the docs in the crate root file. /// See the docs in the crate root file.
pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> { pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> {
let WindowBuilder { dimensions, title, monitor, gl_version, vsync, visible } = builder; let WindowBuilder { dimensions, title, monitor, gl_version,
init::new_window(dimensions, title, monitor, gl_version, vsync, !visible) gl_debug, vsync, visible } = builder;
init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync, !visible)
} }
} }

View file

@ -225,6 +225,11 @@ impl Window {
attributes.push(version.val1() as libc::c_int); 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); attributes.push(0);
// loading the extra GLX functions // loading the extra GLX functions