aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2014-11-24 19:35:31 +0100
committerPierre Krieger <pierre.krieger1708@gmail.com>2014-11-27 15:26:42 +0100
commit729551f82859673fcf9b4b26dbb145184a2a7ca7 (patch)
tree6e556313801c3d959ae3d05455deadd66797dcd0 /src
parent596132dc9300f43385e5bb8c3f24df49cfe8529d (diff)
downloadglutin-729551f82859673fcf9b4b26dbb145184a2a7ca7.tar.gz
glutin-729551f82859673fcf9b4b26dbb145184a2a7ca7.zip
Implement multisampling for x11
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs14
-rw-r--r--src/win32/init.rs3
-rw-r--r--src/win32/mod.rs6
-rw-r--r--src/x11/window/mod.rs11
4 files changed, 28 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7a64e70..0e61649 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -94,6 +94,7 @@ pub struct WindowBuilder<'a> {
gl_debug: bool,
vsync: bool,
visible: bool,
+ multisampling: Option<u16>,
}
#[cfg(feature = "window")]
@@ -109,6 +110,7 @@ impl<'a> WindowBuilder<'a> {
gl_debug: cfg!(ndebug),
vsync: false,
visible: true,
+ multisampling: None,
}
}
@@ -173,6 +175,18 @@ impl<'a> WindowBuilder<'a> {
self
}
+ /// Sets the multisampling level to request.
+ ///
+ /// # Panic
+ ///
+ /// Will panic if `samples` is not a power of two.
+ pub fn with_multisampling(mut self, samples: u16) -> WindowBuilder<'a> {
+ use std::num::UnsignedInt;
+ assert!(samples.is_power_of_two());
+ self.multisampling = Some(samples);
+ self
+ }
+
/// Builds the window.
///
/// 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 29b45cb..62c1f54 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -16,7 +16,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
builder_monitor: Option<super::MonitorID>,
builder_gl_version: Option<(uint, uint)>, builder_debug: bool,
builder_vsync: bool, builder_hidden: bool,
- builder_sharelists: Option<ffi::HGLRC>) -> Result<Window, CreationError>
+ builder_sharelists: Option<ffi::HGLRC>, builder_multisampling: Option<u16>)
+ -> Result<Window, CreationError>
{
use std::mem;
use std::os;
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index ef2e3ea..f08c033 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -26,7 +26,7 @@ impl HeadlessContext {
pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> {
let HeadlessRendererBuilder { dimensions, gl_version, gl_debug } = builder;
init::new_window(Some(dimensions), "".to_string(), None, gl_version, gl_debug, false, true,
- None)
+ None, None)
.map(|w| HeadlessContext(w))
}
@@ -70,9 +70,9 @@ 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,
- gl_debug, vsync, visible, sharing } = builder;
+ gl_debug, vsync, visible, sharing, multisampling } = builder;
init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync,
- !visible, sharing.map(|w| w.window.context))
+ !visible, sharing.map(|w| w.window.context), multisampling)
}
}
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 8662fdc..72c7133 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -58,7 +58,7 @@ impl Window {
// getting the FBConfig
let fb_config = unsafe {
- const VISUAL_ATTRIBUTES: [libc::c_int, ..23] = [
+ let mut visual_attributes = vec![
ffi::GLX_X_RENDERABLE, 1,
ffi::GLX_DRAWABLE_TYPE, ffi::GLX_WINDOW_BIT,
ffi::GLX_RENDER_TYPE, ffi::GLX_RGBA_BIT,
@@ -73,10 +73,17 @@ impl Window {
0
];
+ if let Some(val) = builder.multisampling {
+ visual_attributes.push(ffi::glx::SAMPLE_BUFFERS as libc::c_int);
+ visual_attributes.push(1);
+ visual_attributes.push(ffi::glx::SAMPLES as libc::c_int);
+ visual_attributes.push(val as libc::c_int);
+ }
+
let mut num_fb: libc::c_int = mem::uninitialized();
let fb = ffi::glx::ChooseFBConfig(display, ffi::XDefaultScreen(display),
- VISUAL_ATTRIBUTES.as_ptr(), &mut num_fb);
+ visual_attributes.as_ptr(), &mut num_fb);
if fb.is_null() {
return Err(OsError(format!("glx::ChooseFBConfig failed")));
}