aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/win32')
-rw-r--r--src/api/win32/init.rs35
-rw-r--r--src/api/win32/mod.rs81
2 files changed, 68 insertions, 48 deletions
diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs
index 5cdd6b8..e5b0b3a 100644
--- a/src/api/win32/init.rs
+++ b/src/api/win32/init.rs
@@ -17,6 +17,7 @@ use BuilderAttribs;
use CreationError;
use CreationError::OsError;
use CursorState;
+use GlProfile;
use GlRequest;
use PixelFormat;
@@ -205,7 +206,12 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
// calling SetPixelFormat
let pixel_format = {
let formats = if extra_functions.GetPixelFormatAttribivARB.is_loaded() {
- enumerate_arb_pixel_formats(&extra_functions, &real_window)
+ let f = enumerate_arb_pixel_formats(&extra_functions, &real_window);
+ if f.is_empty() {
+ enumerate_native_pixel_formats(&real_window)
+ } else {
+ f
+ }
} else {
enumerate_native_pixel_formats(&real_window)
};
@@ -369,6 +375,23 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
},
}
+ if let Some(profile) = builder.gl_profile {
+ if is_extension_supported(extra_functions, hdc,
+ "WGL_ARB_create_context_profile")
+ {
+ let flag = match profile {
+ GlProfile::Compatibility =>
+ gl::wgl_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
+ GlProfile::Core =>
+ gl::wgl_extra::CONTEXT_CORE_PROFILE_BIT_ARB,
+ };
+ attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int);
+ attributes.push(flag as libc::c_int);
+ } else {
+ return Err(CreationError::NotSupported);
+ }
+ }
+
if builder.gl_debug {
attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int);
attributes.push(gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int);
@@ -433,9 +456,7 @@ unsafe fn enumerate_native_pixel_formats(hdc: &WindowWrapper) -> Vec<(PixelForma
result.push((PixelFormat {
hardware_accelerated: (output.dwFlags & winapi::PFD_GENERIC_FORMAT) == 0,
- red_bits: output.cRedBits,
- green_bits: output.cGreenBits,
- blue_bits: output.cBlueBits,
+ color_bits: output.cRedBits + output.cGreenBits + output.cBlueBits,
alpha_bits: output.cAlphaBits,
depth_bits: output.cDepthBits,
stencil_bits: output.cStencilBits,
@@ -484,9 +505,9 @@ unsafe fn enumerate_arb_pixel_formats(extra: &gl::wgl_extra::Wgl, hdc: &WindowWr
result.push((PixelFormat {
hardware_accelerated: true,
- red_bits: get_info(index, gl::wgl_extra::RED_BITS_ARB) as u8,
- green_bits: get_info(index, gl::wgl_extra::GREEN_BITS_ARB) as u8,
- blue_bits: get_info(index, gl::wgl_extra::BLUE_BITS_ARB) as u8,
+ color_bits: get_info(index, gl::wgl_extra::RED_BITS_ARB) as u8 +
+ get_info(index, gl::wgl_extra::GREEN_BITS_ARB) as u8 +
+ get_info(index, gl::wgl_extra::BLUE_BITS_ARB) as u8,
alpha_bits: get_info(index, gl::wgl_extra::ALPHA_BITS_ARB) as u8,
depth_bits: get_info(index, gl::wgl_extra::DEPTH_BITS_ARB) as u8,
stencil_bits: get_info(index, gl::wgl_extra::STENCIL_BITS_ARB) as u8,
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index dd3e685..d0caea7 100644
--- a/src/api/win32/mod.rs
+++ b/src/api/win32/mod.rs
@@ -14,7 +14,9 @@ use std::sync::mpsc::Receiver;
use libc;
use {CreationError, Event, MouseCursor};
use CursorState;
+use GlContext;
+use Api;
use PixelFormat;
use BuilderAttribs;
@@ -195,7 +197,7 @@ impl Window {
unsafe {
user32::SetWindowPos(self.window.0, ptr::null_mut(), 0, 0, x as libc::c_int,
- y as libc::c_int, winapi::SWP_NOZORDER | winapi::SWP_NOREPOSITION);
+ y as libc::c_int, winapi::SWP_NOZORDER | winapi::SWP_NOREPOSITION | winapi::SWP_NOMOVE);
user32::UpdateWindow(self.window.0);
}
}
@@ -218,37 +220,6 @@ impl Window {
}
}
- /// See the docs in the crate root file.
- pub unsafe fn make_current(&self) {
- // TODO: check return value
- gl::wgl::MakeCurrent(self.window.1 as *const libc::c_void,
- self.context.0 as *const libc::c_void);
- }
-
- /// See the docs in the crate root file.
- pub fn is_current(&self) -> bool {
- unsafe { gl::wgl::GetCurrentContext() == self.context.0 as *const libc::c_void }
- }
-
- /// See the docs in the crate root file.
- pub fn get_proc_address(&self, addr: &str) -> *const () {
- let addr = CString::new(addr.as_bytes()).unwrap();
- let addr = addr.as_ptr();
-
- unsafe {
- let p = gl::wgl::GetProcAddress(addr) as *const ();
- if !p.is_null() { return p; }
- kernel32::GetProcAddress(self.gl_library, addr) as *const ()
- }
- }
-
- /// See the docs in the crate root file.
- pub fn swap_buffers(&self) {
- unsafe {
- gdi32::SwapBuffers(self.window.1);
- }
- }
-
pub fn platform_display(&self) -> *mut libc::c_void {
unimplemented!()
}
@@ -257,15 +228,6 @@ impl Window {
self.window.0 as *mut libc::c_void
}
- /// See the docs in the crate root file.
- pub fn get_api(&self) -> ::Api {
- ::Api::OpenGl
- }
-
- pub fn get_pixel_format(&self) -> PixelFormat {
- self.pixel_format.clone()
- }
-
pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) {
}
@@ -362,6 +324,43 @@ impl Window {
}
}
+impl GlContext for Window {
+ unsafe fn make_current(&self) {
+ // TODO: check return value
+ gl::wgl::MakeCurrent(self.window.1 as *const libc::c_void,
+ self.context.0 as *const libc::c_void);
+ }
+
+ fn is_current(&self) -> bool {
+ unsafe { gl::wgl::GetCurrentContext() == self.context.0 as *const libc::c_void }
+ }
+
+ fn get_proc_address(&self, addr: &str) -> *const libc::c_void {
+ let addr = CString::new(addr.as_bytes()).unwrap();
+ let addr = addr.as_ptr();
+
+ unsafe {
+ let p = gl::wgl::GetProcAddress(addr) as *const _;
+ if !p.is_null() { return p; }
+ kernel32::GetProcAddress(self.gl_library, addr) as *const _
+ }
+ }
+
+ fn swap_buffers(&self) {
+ unsafe {
+ gdi32::SwapBuffers(self.window.1);
+ }
+ }
+
+ fn get_api(&self) -> Api {
+ Api::OpenGl
+ }
+
+ fn get_pixel_format(&self) -> PixelFormat {
+ self.pixel_format.clone()
+ }
+}
+
pub struct PollEventsIterator<'a> {
window: &'a Window,
}