aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/android/mod.rs22
-rw-r--r--src/api/caca/mod.rs14
-rw-r--r--src/api/cocoa/headless.rs8
-rw-r--r--src/api/cocoa/mod.rs17
-rw-r--r--src/api/osmesa/mod.rs12
-rw-r--r--src/api/win32/init.rs1
-rw-r--r--src/api/win32/mod.rs1
-rw-r--r--src/headless.rs42
-rw-r--r--src/lib.rs35
-rw-r--r--src/platform/linux/api_dispatch.rs20
-rw-r--r--src/platform/linux/mod.rs11
-rw-r--r--src/platform/windows/mod.rs23
-rw-r--r--src/window.rs66
13 files changed, 138 insertions, 134 deletions
diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs
index ecea9b3..be5a79f 100644
--- a/src/api/android/mod.rs
+++ b/src/api/android/mod.rs
@@ -14,12 +14,14 @@ use events::MouseButton;
use std::collections::VecDeque;
use Api;
-use BuilderAttribs;
use ContextError;
use CursorState;
+use GlAttributes;
use GlContext;
use GlRequest;
use PixelFormat;
+use PixelFormatRequirements;
+use WindowAttributes;
use native_monitor::NativeMonitorId;
use api::egl;
@@ -104,15 +106,19 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
impl Window {
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
+ pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
use std::{mem, ptr};
+ let opengl = opengl.clone().map_sharing(|w| &w.context);
+
let native_window = unsafe { android_glue::get_native_window() };
if native_window.is_null() {
return Err(OsError(format!("Android's native window is null")));
}
- let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder.pf_reqs, &builder.opengl,
+ let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl,
egl::NativeDisplay::Android)
.and_then(|p| p.finish(native_window as *const _)));
@@ -255,9 +261,13 @@ pub struct HeadlessContext(EglContext);
impl HeadlessContext {
/// See the docs in the crate root file.
- pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- let context = try!(EglContext::new(egl::ffi::egl::Egl, &builder, egl::NativeDisplay::Android));
- let context = try!(context.finish_pbuffer(builder.window.dimensions.unwrap_or((800, 600)))); // TODO:
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
+ let opengl = opengl.clone().map_sharing(|c| &c.0);
+ let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl,
+ egl::NativeDisplay::Android));
+ let context = try!(context.finish_pbuffer(dimensions)); // TODO:
Ok(HeadlessContext(context))
}
}
diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs
index 3b4018e..c1a19c7 100644
--- a/src/api/caca/mod.rs
+++ b/src/api/caca/mod.rs
@@ -5,14 +5,16 @@ use libc;
use api::osmesa::{OsMesaContext, OsMesaCreationError};
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
use Event;
+use GlAttributes;
use GlContext;
use PixelFormat;
+use PixelFormatRequirements;
use CursorState;
use MouseCursor;
+use WindowAttributes;
use std::collections::VecDeque;
use std::path::Path;
@@ -84,8 +86,14 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
impl Window {
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- let opengl = match OsMesaContext::new(builder) {
+ pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
+ let opengl = opengl.clone().map_sharing(|w| &w.opengl);
+
+ let opengl = match OsMesaContext::new(window.dimensions.unwrap_or((800, 600)), pf_reqs,
+ &opengl)
+ {
Err(OsMesaCreationError::NotSupported) => return Err(CreationError::NotSupported),
Err(OsMesaCreationError::CreationError(e)) => return Err(e),
Ok(c) => c
diff --git a/src/api/cocoa/headless.rs b/src/api/cocoa/headless.rs
index ad1a464..f9bbffd 100644
--- a/src/api/cocoa/headless.rs
+++ b/src/api/cocoa/headless.rs
@@ -1,8 +1,9 @@
use ContextError;
use CreationError;
use CreationError::OsError;
-use BuilderAttribs;
+use GlAttributes;
use GlContext;
+use PixelFormatRequirements;
use libc;
use std::ptr;
@@ -27,8 +28,9 @@ pub struct HeadlessContext {
}
impl HeadlessContext {
- pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- let (width, height) = builder.window.dimensions.unwrap_or((1024, 768));
+ pub fn new((width, height): (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
let context = unsafe {
let attributes = [
NSOpenGLPFAAccelerated as u32,
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 35b7046..539545c 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -7,7 +7,6 @@ use CreationError::OsError;
use libc;
use Api;
-use BuilderAttribs;
use ContextError;
use GlAttributes;
use GlContext;
@@ -269,12 +268,14 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
impl Window {
#[cfg(feature = "window")]
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- if builder.opengl.sharing.is_some() {
+ pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
+ if opengl.sharing.is_some() {
unimplemented!()
}
- match builder.opengl.robustness {
+ match opengl.robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
return Err(CreationError::RobustnessNotSupported);
},
@@ -286,7 +287,7 @@ impl Window {
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
};
- let window = match Window::create_window(&builder.window)
+ let window = match Window::create_window(win_attribs)
{
Some(window) => window,
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
@@ -298,13 +299,13 @@ impl Window {
// TODO: perhaps we should return error from create_context so we can
// determine the cause of failure and possibly recover?
- let (context, pf) = match Window::create_context(*view, &builder.pf_reqs, &builder.opengl) {
+ let (context, pf) = match Window::create_context(*view, pf_reqs, opengl) {
Ok((context, pf)) => (context, pf),
Err(e) => { return Err(OsError(format!("Couldn't create OpenGL context: {}", e))); },
};
unsafe {
- if builder.window.transparent {
+ if win_attribs.transparent {
let clear_col = {
let cls = Class::get("NSColor").unwrap();
@@ -320,7 +321,7 @@ impl Window {
}
app.activateIgnoringOtherApps_(YES);
- if builder.window.visible {
+ if win_attribs.visible {
window.makeKeyAndOrderFront_(nil);
} else {
window.makeKeyWindow();
diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs
index 2debc7e..ca34e93 100644
--- a/src/api/osmesa/mod.rs
+++ b/src/api/osmesa/mod.rs
@@ -3,11 +3,12 @@
extern crate osmesa_sys;
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
+use GlAttributes;
use GlContext;
use PixelFormat;
+use PixelFormatRequirements;
use Robustness;
use libc;
use std::{mem, ptr};
@@ -32,20 +33,23 @@ impl From<CreationError> for OsMesaCreationError {
}
impl OsMesaContext {
- pub fn new(builder: BuilderAttribs) -> Result<OsMesaContext, OsMesaCreationError> {
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&OsMesaContext>) -> Result<OsMesaContext, OsMesaCreationError>
+ {
if let Err(_) = osmesa_sys::OsMesa::try_loading() {
return Err(OsMesaCreationError::NotSupported);
}
- let dimensions = builder.window.dimensions.unwrap();
+ if opengl.sharing.is_some() { unimplemented!() } // TODO: proper error
- match builder.opengl.robustness {
+ match opengl.robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
return Err(CreationError::RobustnessNotSupported.into());
},
_ => ()
}
+ // TODO: use `pf_reqs` for the format
// TODO: check OpenGL version and return `OpenGlVersionNotSupported` if necessary
Ok(OsMesaContext {
diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs
index 5628a98..7c7eb83 100644
--- a/src/api/win32/init.rs
+++ b/src/api/win32/init.rs
@@ -11,7 +11,6 @@ use super::WindowWrapper;
use super::Context;
use Api;
-use BuilderAttribs;
use CreationError;
use CreationError::OsError;
use CursorState;
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index eb31873..f580950 100644
--- a/src/api/win32/mod.rs
+++ b/src/api/win32/mod.rs
@@ -19,7 +19,6 @@ use GlContext;
use Api;
use PixelFormat;
use PixelFormatRequirements;
-use BuilderAttribs;
use WindowAttributes;
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
diff --git a/src/headless.rs b/src/headless.rs
index 83e35b3..4730eb4 100644
--- a/src/headless.rs
+++ b/src/headless.rs
@@ -1,10 +1,11 @@
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
+use GlAttributes;
use GlRequest;
use GlContext;
use PixelFormat;
+use PixelFormatRequirements;
use Robustness;
use WindowAttributes;
@@ -14,28 +15,25 @@ use libc;
use platform;
/// Object that allows you to build headless contexts.
-pub struct HeadlessRendererBuilder {
- attribs: BuilderAttribs<'static>,
+pub struct HeadlessRendererBuilder<'a> {
+ dimensions: (u32, u32),
+ pf_reqs: PixelFormatRequirements,
+ opengl: GlAttributes<&'a platform::HeadlessContext>,
}
-impl HeadlessRendererBuilder {
+impl<'a> HeadlessRendererBuilder<'a> {
/// Initializes a new `HeadlessRendererBuilder` with default values.
- pub fn new(width: u32, height: u32) -> HeadlessRendererBuilder {
+ pub fn new(width: u32, height: u32) -> HeadlessRendererBuilder<'a> {
HeadlessRendererBuilder {
- attribs: BuilderAttribs {
- headless: true,
- window: WindowAttributes {
- dimensions: Some((width, height)),
- .. Default::default()
- },
- .. BuilderAttribs::new()
- },
+ dimensions: (width, height),
+ pf_reqs: Default::default(),
+ opengl: Default::default(),
}
}
/// Sets how the backend should choose the OpenGL API and version.
- pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder {
- self.attribs.opengl.version = request;
+ pub fn with_gl(mut self, request: GlRequest) -> HeadlessRendererBuilder<'a> {
+ self.opengl.version = request;
self
}
@@ -43,14 +41,14 @@ impl HeadlessRendererBuilder {
///
/// 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.attribs.opengl.debug = flag;
+ pub fn with_gl_debug_flag(mut self, flag: bool) -> HeadlessRendererBuilder<'a> {
+ self.opengl.debug = flag;
self
}
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
- pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder {
- self.attribs.opengl.robustness = robustness;
+ pub fn with_gl_robustness(mut self, robustness: Robustness) -> HeadlessRendererBuilder<'a> {
+ self.opengl.robustness = robustness;
self
}
@@ -59,15 +57,15 @@ impl HeadlessRendererBuilder {
/// Error should be very rare and only occur in case of permission denied, incompatible system,
/// out of memory, etc.
pub fn build(self) -> Result<HeadlessContext, CreationError> {
- platform::HeadlessContext::new(self.attribs).map(|w| HeadlessContext { context: w })
+ platform::HeadlessContext::new(self.dimensions, &self.pf_reqs, &self.opengl)
+ .map(|w| HeadlessContext { context: w })
}
/// Builds the headless context.
///
/// The context is build in a *strict* way. That means that if the backend couldn't give
/// you what you requested, an `Err` will be returned.
- pub fn build_strict(mut self) -> Result<HeadlessContext, CreationError> {
- self.attribs.strict = true;
+ pub fn build_strict(self) -> Result<HeadlessContext, CreationError> {
self.build()
}
}
diff --git a/src/lib.rs b/src/lib.rs
index aa51d5a..a75a47a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -362,40 +362,7 @@ pub struct PixelFormat {
pub multisampling: Option<u16>,
pub srgb: bool,
}
-
-/// Attributes
-// FIXME: remove `pub` (https://github.com/rust-lang/rust/issues/23585)
-#[derive(Clone)]
-#[doc(hidden)]
-pub struct BuilderAttribs<'a> {
- #[allow(dead_code)]
- headless: bool,
- strict: bool,
- pf_reqs: PixelFormatRequirements,
- window: WindowAttributes,
- opengl: GlAttributes<&'a platform::Window>,
-}
-
-impl BuilderAttribs<'static> {
- fn new() -> BuilderAttribs<'static> {
- BuilderAttribs {
- headless: false,
- strict: false,
- pf_reqs: Default::default(),
- window: Default::default(),
- opengl: Default::default(),
- }
- }
-}
-
-impl<'a> BuilderAttribs<'a> {
- fn choose_pixel_format<T, I>(&self, iter: I) -> Result<(T, PixelFormat), CreationError>
- where I: IntoIterator<Item=(T, PixelFormat)>, T: Clone
- {
- self.pf_reqs.choose_pixel_format(iter)
- }
-}
-
+
/// VERY UNSTABLE! Describes how the backend should choose a pixel format.
#[derive(Clone, Debug)]
#[allow(missing_docs)]
diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs
index 0fae6a0..46c58bb 100644
--- a/src/platform/linux/api_dispatch.rs
+++ b/src/platform/linux/api_dispatch.rs
@@ -6,14 +6,16 @@ pub use api::x11::{WaitEventsIterator, PollEventsIterator};*/
use std::collections::VecDeque;
use std::sync::Arc;
-use BuilderAttribs;
use ContextError;
use CreationError;
use CursorState;
use Event;
+use GlAttributes;
use GlContext;
use MouseCursor;
use PixelFormat;
+use PixelFormatRequirements;
+use WindowAttributes;
use libc;
use api::wayland;
@@ -161,28 +163,26 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
impl Window {
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- let window = builder.window;
- let pf_reqs = builder.pf_reqs;
- let opengl = builder.opengl;
-
+ pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
match *BACKEND {
Backend::Wayland => {
- let opengl = opengl.map_sharing(|w| match w {
+ let opengl = opengl.clone().map_sharing(|w| match w {
&Window::Wayland(ref w) => w,
_ => panic!() // TODO: return an error
});
- wayland::Window::new(&window, &pf_reqs, &opengl).map(Window::Wayland)
+ wayland::Window::new(window, pf_reqs, &opengl).map(Window::Wayland)
},
Backend::X(ref connec) => {
- let opengl = opengl.map_sharing(|w| match w {
+ let opengl = opengl.clone().map_sharing(|w| match w {
&Window::X(ref w) => w,
_ => panic!() // TODO: return an error
});
- x11::Window::new(connec, &window, &pf_reqs, &opengl).map(Window::X)
+ x11::Window::new(connec, window, pf_reqs, &opengl).map(Window::X)
},
Backend::Error(ref error) => Err(CreationError::NoBackendAvailable(Box::new(error.clone())))
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 3525ce5..f5d663b 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -1,11 +1,12 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
+use GlAttributes;
use GlContext;
use PixelFormat;
+use PixelFormatRequirements;
use libc;
use api::osmesa::{self, OsMesaContext};
@@ -25,8 +26,12 @@ pub type MonitorID = (); // TODO: hack to make things work
pub struct HeadlessContext(OsMesaContext);
impl HeadlessContext {
- pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- match OsMesaContext::new(builder) {
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
+ let opengl = opengl.clone().map_sharing(|c| &c.0);
+
+ match OsMesaContext::new(dimensions, pf_reqs, &opengl) {
Ok(c) => return Ok(HeadlessContext(c)),
Err(osmesa::OsMesaCreationError::NotSupported) => (),
Err(osmesa::OsMesaCreationError::CreationError(e)) => return Err(e),
diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs
index 51f7567..af9261f 100644
--- a/src/platform/windows/mod.rs
+++ b/src/platform/windows/mod.rs
@@ -7,11 +7,13 @@ pub use api::win32::{WindowProxy, PollEventsIterator, WaitEventsIterator};
use libc;
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
use PixelFormat;
+use PixelFormatRequirements;
+use GlAttributes;
use GlContext;
+use WindowAttributes;
use api::egl::ffi::egl::Egl;
use api::egl;
@@ -57,8 +59,10 @@ pub struct Window(win32::Window);
impl Window {
/// See the docs in the crate root file.
- pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- win32::Window::new(&builder.window, &builder.pf_reqs, &builder.opengl.clone().map_sharing(|w| &w.0),
+ pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
+ {
+ win32::Window::new(window, pf_reqs, &opengl.clone().map_sharing(|w| &w.0),
EGL.as_ref().map(|w| &w.0)).map(|w| Window(w))
}
}
@@ -86,15 +90,15 @@ pub enum HeadlessContext {
}
impl HeadlessContext {
- pub fn new(mut builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
- builder.window.visible = false;
-
+ pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
+ opengl: &GlAttributes<&HeadlessContext>) -> Result<HeadlessContext, CreationError>
+ {
// if EGL is available, we try using EGL first
// if EGL returns an error, we try the hidden window method
if let &Some(ref egl) = &*EGL {
- let context = EglContext::new(egl.0.clone(), &builder.pf_reqs, &builder.opengl.clone().map_sharing(|_| unimplemented!()), // TODO:
+ let context = EglContext::new(egl.0.clone(), pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), // TODO:
egl::NativeDisplay::Other(None))
- .and_then(|prototype| prototype.finish_pbuffer(builder.window.dimensions.unwrap_or((800, 600)))) // TODO:
+ .and_then(|prototype| prototype.finish_pbuffer(dimensions))
.map(|ctxt| HeadlessContext::EglPbuffer(ctxt));
if let Ok(context) = context {
@@ -102,7 +106,8 @@ impl HeadlessContext {
}
}
- let window = try!(win32::Window::new(&builder.window, &builder.pf_reqs, &builder.opengl.clone().map_sharing(|w| &w.0),
+ let window = try!(win32::Window::new(&WindowAttributes { visible: false, .. Default::default() },
+ pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()), //TODO:
EGL.as_ref().map(|w| &w.0)));
Ok(HeadlessContext::HiddenWindow(window))
}
diff --git a/src/window.rs b/src/window.rs
index 85d3440..246f5c9 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -2,17 +2,19 @@ use std::collections::vec_deque::IntoIter as VecDequeIter;
use std::default::Default;
use Api;
-use BuilderAttribs;
use ContextError;
use CreationError;
use CursorState;
use Event;
+use GlAttributes;
use GlContext;
use GlProfile;
use GlRequest;
use MouseCursor;
use PixelFormat;
+use PixelFormatRequirements;
use Robustness;
+use WindowAttributes;
use native_monitor::NativeMonitorId;
use gl_common;
@@ -22,14 +24,18 @@ use platform;
/// Object that allows you to build windows.
pub struct WindowBuilder<'a> {
- attribs: BuilderAttribs<'a>
+ pf_reqs: PixelFormatRequirements,
+ window: WindowAttributes,
+ opengl: GlAttributes<&'a platform::Window>,
}
impl<'a> WindowBuilder<'a> {
/// Initializes a new `WindowBuilder` with default values.
pub fn new() -> WindowBuilder<'a> {
WindowBuilder {
- attribs: BuilderAttribs::new(),
+ pf_reqs: Default::default(),
+ window: Default::default(),
+ opengl: Default::default(),
}
}
@@ -37,13 +43,13 @@ impl<'a> WindowBuilder<'a> {
///
/// Width and height are in pixels.
pub fn with_dimensions(mut self, width: u32, height: u32) -> WindowBuilder<'a> {
- self.attribs.window.dimensions = Some((width, height));
+ self.window.dimensions = Some((width, height));
self
}
/// Requests a specific title for the window.
pub fn with_title(mut self, title: String) -> WindowBuilder<'a> {
- self.attribs.window.title = title;
+ self.window.title = title;
self
}
@@ -52,7 +58,7 @@ impl<'a> WindowBuilder<'a> {
/// If you don't specify dimensions for the window, it will match the monitor's.
pub fn with_fullscreen(mut self, monitor: MonitorID) -> WindowBuilder<'a> {
let MonitorID(monitor) = monitor;
- self.attribs.window.monitor = Some(monitor);
+ self.window.monitor = Some(monitor);
self
}
@@ -60,19 +66,19 @@ impl<'a> WindowBuilder<'a> {
///
/// There are some exceptions, like FBOs or VAOs. See the OpenGL documentation.
pub fn with_shared_lists(mut self, other: &'a Window) -> WindowBuilder<'a> {
- self.attribs.opengl.sharing = Some(&other.window);
+ self.opengl.sharing = Some(&other.window);
self
}
/// Sets how the backend should choose the OpenGL API and version.
pub fn with_gl(mut self, request: GlRequest) -> WindowBuilder<'a> {
- self.attribs.opengl.version = request;
+ self.opengl.version = request;
self
}
/// Sets the desired OpenGL context profile.
pub fn with_gl_profile(mut self, profile: GlProfile) -> WindowBuilder<'a> {
- self.attribs.opengl.profile = Some(profile);
+ self.opengl.profile = Some(profile);
self
}
@@ -81,25 +87,25 @@ impl<'a> WindowBuilder<'a> {
/// The default value for this flag is `cfg!(debug_assertions)`, 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<'a> {
- self.attribs.opengl.debug = flag;
+ self.opengl.debug = flag;
self
}
/// Sets the robustness of the OpenGL context. See the docs of `Robustness`.
pub fn with_gl_robustness(mut self, robustness: Robustness) -> WindowBuilder<'a> {
- self.attribs.opengl.robustness = robustness;
+ self.opengl.robustness = robustness;
self
}
/// Requests that the window has vsync enabled.
pub fn with_vsync(mut self) -> WindowBuilder<'a> {
- self.attribs.opengl.vsync = true;
+ self.opengl.vsync = true;
self
}
/// Sets whether the window will be initially hidden or visible.
pub fn with_visibility(mut self, visible: bool) -> WindowBuilder<'a> {
- self.attribs.window.visible = visible;
+ self.window.visible = visible;
self
}
@@ -110,56 +116,56 @@ impl<'a> WindowBuilder<'a> {
/// Will panic if `samples` is not a power of two.
pub fn with_multisampling(mut self, samples: u16) -> WindowBuilder<'a> {
assert!(samples.is_power_of_two());
- self.attribs.pf_reqs.multisampling = Some(samples);
+ self.pf_reqs.multisampling = Some(samples);
self
}
/// Sets the number of bits in the depth buffer.
pub fn with_depth_buffer(mut self, bits: u8) -> WindowBuilder<'a> {
- self.attribs.pf_reqs.depth_bits = Some(bits);
+ self.pf_reqs.depth_bits = Some(bits);
self
}
/// Sets the number of bits in the stencil buffer.
pub fn with_stencil_buffer(mut self, bits: u8) -> WindowBuilder<'a> {
- self.attribs.pf_reqs.stencil_bits = Some(bits);
+ self.pf_reqs.stencil_bits = Some(bits);
self
}
/// Sets the number of bits in the color buffer.
pub fn with_pixel_format(mut self, color_bits: u8, alpha_bits: u8) -> WindowBuilder<'a> {
- self.attribs.pf_reqs.color_bits = Some(color_bits);
- self.attribs.pf_reqs.alpha_bits = Some(alpha_bits);
+ self.pf_reqs.color_bits = Some(color_bits);
+ self.pf_reqs.alpha_bits = Some(alpha_bits);
self
}
/// Request the backend to be stereoscopic.
pub fn with_stereoscopy(mut self) -> WindowBuilder<'a> {
- self.attribs.pf_reqs.stereoscopy = true;
+ self.pf_reqs.stereoscopy = true;
self
}
/// Sets whether sRGB should be enabled on the window. `None` means "I don't care".
pub fn with_srgb(mut self, srgb_enabled: Option<bool>) -> WindowBuilder<'a> {
- self.attribs.pf_reqs.srgb = srgb_enabled;
+ self.pf_reqs.srgb = srgb_enabled;
self
}
/// Sets whether the background of the window should be transparent.
pub fn with_transparency(mut self, transparent: bool) -> WindowBuilder<'a> {
- self.attribs.window.transparent = transparent;
+ self.window.transparent = transparent;
self
}
/// Sets whether the window should have a border, a title bar, etc.
pub fn with_decorations(mut self, decorations: bool) -> WindowBuilder<'a> {
- self.attribs.window.decorations = decorations;
+ self.window.decorations = decorations;
self
}
/// Enables multitouch
pub fn with_multitouch(mut self) -> WindowBuilder<'a> {
- self.attribs.window.multitouch = true;
+ self.window.multitouch = true;
self
}
@@ -169,25 +175,25 @@ impl<'a> WindowBuilder<'a> {
/// out of memory, etc.
pub fn build(mut self) -> Result<Window, CreationError> {
// resizing the window to the dimensions of the monitor when fullscreen
- if self.attribs.window.dimensions.is_none() && self.attribs.window.monitor.is_some() {
- self.attribs.window.dimensions = Some(self.attribs.window.monitor.as_ref().unwrap().get_dimensions())
+ if self.window.dimensions.is_none() && self.window.monitor.is_some() {
+ self.window.dimensions = Some(self.window.monitor.as_ref().unwrap().get_dimensions())
}
// default dimensions
- if self.attribs.window.dimensions.is_none() {
- self.attribs.window.dimensions = Some((1024, 768));
+ if self.window.dimensions.is_none() {
+ self.window.dimensions = Some((1024, 768));
}
// building
- platform::Window::new(self.attribs).map(|w| Window { window: w })
+ platform::Window::new(&self.window, &self.pf_reqs, &self.opengl)
+ .map(|w| Window { window: w })
}
/// Builds the window.
///
/// The context is build in a *strict* way. That means that if the backend couldn't give
/// you what you requested, an `Err` will be returned.
- pub fn build_strict(mut self) -> Result<Window, CreationError> {
- self.attribs.strict = true;
+ pub fn build_strict(self) -> Result<Window, CreationError> {
self.build()
}
}