Remove BuilderAttribs

This commit is contained in:
Pierre Krieger 2015-09-21 13:15:43 +02:00
parent a8d3342468
commit 62bafe2130
13 changed files with 138 additions and 134 deletions

View file

@ -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))
}
}

View file

@ -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

View file

@ -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,

View file

@ -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();

View file

@ -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 {

View file

@ -11,7 +11,6 @@ use super::WindowWrapper;
use super::Context;
use Api;
use BuilderAttribs;
use CreationError;
use CreationError::OsError;
use CursorState;

View file

@ -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};

View file

@ -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()
}
}

View file

@ -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)]

View file

@ -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())))

View file

@ -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),

View file

@ -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))
}

View file

@ -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()
}
}