aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/win32
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-04-30 13:23:37 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-04-30 16:57:07 +0200
commitaa58f4149a65783b07c0dc401b5854ed80c4915e (patch)
treedd5d06aa46a1e18f0b93c2960dacc2cea9c81982 /src/api/win32
parenta08388bca1ca275fd1455ceae26ab06c02c81111 (diff)
downloadglutin-aa58f4149a65783b07c0dc401b5854ed80c4915e.tar.gz
glutin-aa58f4149a65783b07c0dc401b5854ed80c4915e.zip
Add a GlContext trait
Diffstat (limited to 'src/api/win32')
-rw-r--r--src/api/win32/mod.rs79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index dd3e685..e6f5cb8 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;
@@ -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,
}