Remove most OpenGL stuff and make it compile on win32
This commit is contained in:
parent
bd605478d1
commit
10bb03c5f0
20 changed files with 30 additions and 3616 deletions
|
|
@ -9,15 +9,10 @@ use super::WindowState;
|
|||
use super::Window;
|
||||
use super::MonitorId;
|
||||
use super::WindowWrapper;
|
||||
use super::Context;
|
||||
|
||||
use Api;
|
||||
use CreationError;
|
||||
use CreationError::OsError;
|
||||
use CursorState;
|
||||
use GlAttributes;
|
||||
use GlRequest;
|
||||
use PixelFormatRequirements;
|
||||
use WindowAttributes;
|
||||
|
||||
use std::ffi::{OsStr};
|
||||
|
|
@ -29,28 +24,8 @@ use kernel32;
|
|||
use dwmapi;
|
||||
use user32;
|
||||
|
||||
use api::wgl::Context as WglContext;
|
||||
use api::egl;
|
||||
use api::egl::Context as EglContext;
|
||||
use api::egl::ffi::egl::Egl;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum RawContext {
|
||||
Egl(egl::ffi::egl::types::EGLContext),
|
||||
Wgl(winapi::HGLRC),
|
||||
}
|
||||
|
||||
unsafe impl Send for RawContext {}
|
||||
unsafe impl Sync for RawContext {}
|
||||
|
||||
pub fn new_window(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||
opengl: &GlAttributes<RawContext>, egl: Option<&Egl>)
|
||||
-> Result<Window, CreationError>
|
||||
{
|
||||
let egl = egl.map(|e| e.clone());
|
||||
pub fn new_window(window: &WindowAttributes) -> Result<Window, CreationError> {
|
||||
let window = window.clone();
|
||||
let pf_reqs = pf_reqs.clone();
|
||||
let opengl = opengl.clone();
|
||||
|
||||
// initializing variables to be sent to the task
|
||||
|
||||
|
|
@ -64,7 +39,7 @@ pub fn new_window(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
|||
thread::spawn(move || {
|
||||
unsafe {
|
||||
// creating and sending the `Window`
|
||||
match init(title, &window, &pf_reqs, &opengl, egl) {
|
||||
match init(title, &window) {
|
||||
Ok(w) => tx.send(Ok(w)).ok(),
|
||||
Err(e) => {
|
||||
tx.send(Err(e)).ok();
|
||||
|
|
@ -90,17 +65,7 @@ pub fn new_window(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
|||
rx.recv().unwrap()
|
||||
}
|
||||
|
||||
unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||
opengl: &GlAttributes<RawContext>, egl: Option<Egl>)
|
||||
-> Result<Window, CreationError>
|
||||
{
|
||||
let opengl = opengl.clone().map_sharing(|sharelists| {
|
||||
match sharelists {
|
||||
RawContext::Wgl(c) => c,
|
||||
_ => unimplemented!()
|
||||
}
|
||||
});
|
||||
|
||||
unsafe fn init(title: Vec<u16>, window: &WindowAttributes) -> Result<Window, CreationError> {
|
||||
// registering the window class
|
||||
let class_name = register_window_class();
|
||||
|
||||
|
|
@ -172,32 +137,6 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pf_reqs: &PixelFormat
|
|||
WindowWrapper(handle, hdc)
|
||||
};
|
||||
|
||||
// creating the OpenGL context
|
||||
let context = match opengl.version {
|
||||
GlRequest::Specific(Api::OpenGlEs, (_major, _minor)) => {
|
||||
if let Some(egl) = egl {
|
||||
if let Ok(c) = EglContext::new(egl, &pf_reqs, &opengl.clone().map_sharing(|_| unimplemented!()),
|
||||
egl::NativeDisplay::Other(Some(ptr::null())))
|
||||
.and_then(|p| p.finish(real_window.0))
|
||||
{
|
||||
Context::Egl(c)
|
||||
|
||||
} else {
|
||||
try!(WglContext::new(&pf_reqs, &opengl, real_window.0)
|
||||
.map(Context::Wgl))
|
||||
}
|
||||
|
||||
} else {
|
||||
// falling back to WGL, which is always available
|
||||
try!(WglContext::new(&pf_reqs, &opengl, real_window.0)
|
||||
.map(Context::Wgl))
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
try!(WglContext::new(&pf_reqs, &opengl, real_window.0).map(Context::Wgl))
|
||||
}
|
||||
};
|
||||
|
||||
// making the window transparent
|
||||
if window.transparent {
|
||||
let bb = winapi::DWM_BLURBEHIND {
|
||||
|
|
@ -240,7 +179,6 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pf_reqs: &PixelFormat
|
|||
// building the struct
|
||||
Ok(Window {
|
||||
window: real_window,
|
||||
context: context,
|
||||
events_receiver: events_receiver,
|
||||
window_state: window_state,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,15 +10,9 @@ use std::sync::{
|
|||
};
|
||||
use std::sync::mpsc::Receiver;
|
||||
use libc;
|
||||
use ContextError;
|
||||
use {CreationError, Event, MouseCursor};
|
||||
use CursorState;
|
||||
use GlAttributes;
|
||||
use GlContext;
|
||||
|
||||
use Api;
|
||||
use PixelFormat;
|
||||
use PixelFormatRequirements;
|
||||
use WindowAttributes;
|
||||
|
||||
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
|
||||
|
|
@ -27,12 +21,6 @@ use winapi;
|
|||
use user32;
|
||||
use kernel32;
|
||||
|
||||
use api::wgl::Context as WglContext;
|
||||
use api::egl::Context as EglContext;
|
||||
use api::egl::ffi::egl::Egl;
|
||||
|
||||
use self::init::RawContext;
|
||||
|
||||
mod callback;
|
||||
mod event;
|
||||
mod init;
|
||||
|
|
@ -58,9 +46,6 @@ pub struct Window {
|
|||
/// Main handle for the window.
|
||||
window: WindowWrapper,
|
||||
|
||||
/// OpenGL context.
|
||||
context: Context,
|
||||
|
||||
/// Receiver for the events dispatched by the window callback.
|
||||
events_receiver: Receiver<Event>,
|
||||
|
||||
|
|
@ -71,11 +56,6 @@ pub struct Window {
|
|||
unsafe impl Send for Window {}
|
||||
unsafe impl Sync for Window {}
|
||||
|
||||
enum Context {
|
||||
Egl(EglContext),
|
||||
Wgl(WglContext),
|
||||
}
|
||||
|
||||
/// A simple wrapper that destroys the window when it is destroyed.
|
||||
// FIXME: remove `pub` (https://github.com/rust-lang/rust/issues/23585)
|
||||
#[doc(hidden)]
|
||||
|
|
@ -109,18 +89,8 @@ impl WindowProxy {
|
|||
|
||||
impl Window {
|
||||
/// See the docs in the crate root file.
|
||||
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||
opengl: &GlAttributes<&Window>, egl: Option<&Egl>)
|
||||
-> Result<Window, CreationError>
|
||||
{
|
||||
let opengl = opengl.clone().map_sharing(|sharing| {
|
||||
match sharing.context {
|
||||
Context::Wgl(ref c) => RawContext::Wgl(c.get_hglrc()),
|
||||
Context::Egl(_) => unimplemented!(), // FIXME:
|
||||
}
|
||||
});
|
||||
|
||||
init::new_window(window, pf_reqs, &opengl, egl)
|
||||
pub fn new(window: &WindowAttributes) -> Result<Window, CreationError> {
|
||||
init::new_window(window)
|
||||
}
|
||||
|
||||
/// See the docs in the crate root file.
|
||||
|
|
@ -369,56 +339,6 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
#[inline]
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.make_current(),
|
||||
Context::Egl(ref c) => c.make_current(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_current(&self) -> bool {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.is_current(),
|
||||
Context::Egl(ref c) => c.is_current(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_proc_address(&self, addr: &str) -> *const () {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.get_proc_address(addr),
|
||||
Context::Egl(ref c) => c.get_proc_address(addr),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.swap_buffers(),
|
||||
Context::Egl(ref c) => c.swap_buffers(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_api(&self) -> Api {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.get_api(),
|
||||
Context::Egl(ref c) => c.get_api(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_pixel_format(&self) -> PixelFormat {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.get_pixel_format(),
|
||||
Context::Egl(ref c) => c.get_pixel_format(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PollEventsIterator<'a> {
|
||||
window: &'a Window,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue