Remove BuilderAttribs
This commit is contained in:
parent
a8d3342468
commit
62bafe2130
13 changed files with 138 additions and 134 deletions
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use super::WindowWrapper;
|
|||
use super::Context;
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use CreationError;
|
||||
use CreationError::OsError;
|
||||
use CursorState;
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue