Add a GlContext trait
This commit is contained in:
parent
a08388bca1
commit
aa58f4149a
12 changed files with 332 additions and 190 deletions
|
|
@ -3,9 +3,11 @@
|
|||
use libc;
|
||||
use api::osmesa::OsMesaContext;
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use CreationError;
|
||||
use Event;
|
||||
use GlContext;
|
||||
use PixelFormat;
|
||||
use CursorState;
|
||||
use MouseCursor;
|
||||
|
|
@ -169,34 +171,6 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
pub unsafe fn make_current(&self) {
|
||||
self.opengl.make_current()
|
||||
}
|
||||
|
||||
pub fn is_current(&self) -> bool {
|
||||
self.opengl.is_current()
|
||||
}
|
||||
|
||||
pub fn get_proc_address(&self, addr: &str) -> *const () {
|
||||
self.opengl.get_proc_address(addr) as *const _
|
||||
}
|
||||
|
||||
pub fn swap_buffers(&self) {
|
||||
unsafe {
|
||||
let canvas = (self.libcaca.caca_get_canvas)(self.display);
|
||||
let width = (self.libcaca.caca_get_canvas_width)(canvas);
|
||||
let height = (self.libcaca.caca_get_canvas_height)(canvas);
|
||||
|
||||
let buffer = self.opengl.get_framebuffer().chunks(self.opengl.get_dimensions().0 as usize)
|
||||
.flat_map(|i| i.iter().cloned()).rev().collect::<Vec<u32>>();
|
||||
|
||||
(self.libcaca.caca_dither_bitmap)(canvas, 0, 0, width as libc::c_int,
|
||||
height as libc::c_int, self.dither,
|
||||
buffer.as_ptr() as *const _);
|
||||
(self.libcaca.caca_refresh_display)(self.display);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn platform_display(&self) -> *mut libc::c_void {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
@ -205,10 +179,6 @@ impl Window {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn get_api(&self) -> ::Api {
|
||||
self.opengl.get_api()
|
||||
}
|
||||
|
||||
pub fn get_pixel_format(&self) -> PixelFormat {
|
||||
unimplemented!();
|
||||
}
|
||||
|
|
@ -232,6 +202,44 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
self.opengl.make_current()
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
self.opengl.is_current()
|
||||
}
|
||||
|
||||
fn get_proc_address(&self, addr: &str) -> *const libc::c_void {
|
||||
self.opengl.get_proc_address(addr)
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
unsafe {
|
||||
let canvas = (self.libcaca.caca_get_canvas)(self.display);
|
||||
let width = (self.libcaca.caca_get_canvas_width)(canvas);
|
||||
let height = (self.libcaca.caca_get_canvas_height)(canvas);
|
||||
|
||||
let buffer = self.opengl.get_framebuffer().chunks(self.opengl.get_dimensions().0 as usize)
|
||||
.flat_map(|i| i.iter().cloned()).rev().collect::<Vec<u32>>();
|
||||
|
||||
(self.libcaca.caca_dither_bitmap)(canvas, 0, 0, width as libc::c_int,
|
||||
height as libc::c_int, self.dither,
|
||||
buffer.as_ptr() as *const _);
|
||||
(self.libcaca.caca_refresh_display)(self.display);
|
||||
};
|
||||
}
|
||||
|
||||
fn get_api(&self) -> Api {
|
||||
self.opengl.get_api()
|
||||
}
|
||||
|
||||
fn get_pixel_format(&self) -> PixelFormat {
|
||||
self.opengl.get_pixel_format()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Window {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue