Fix glium support

This commit is contained in:
Drakulix 2017-03-18 17:27:49 +01:00
parent 55e56ffc6d
commit 3120683b24
1 changed files with 25 additions and 8 deletions

View File

@ -1,7 +1,9 @@
use glium::backend::Backend; use glium::backend::Backend;
use glium::SwapBuffersError as GliumSwapBuffersError; use glium::SwapBuffersError as GliumSwapBuffersError;
use ::backend::graphics::opengl::{OpenglRenderer, SwapBuffersError}; use std::os::raw::c_void;
use ::backend::graphics::opengl::{OpenglGraphicsBackend, SwapBuffersError};
impl From<SwapBuffersError> for GliumSwapBuffersError impl From<SwapBuffersError> for GliumSwapBuffersError
{ {
@ -13,26 +15,41 @@ impl From<SwapBuffersError> for GliumSwapBuffersError
} }
} }
impl<T: OpenglRenderer> Backend for T pub struct GliumGraphicBackend<T: OpenglGraphicsBackend>(T);
pub trait IntoGlium: OpenglGraphicsBackend + Sized
{ {
fn swap_buffers(&self) -> Result<(), SwapBuffersError> { fn into_glium(self) -> GliumGraphicBackend<Self>;
self.swap_buffers().map_err(|x| x.into) }
impl<T: OpenglGraphicsBackend> IntoGlium for T
{
fn into_glium(self) -> GliumGraphicBackend<Self>
{
GliumGraphicBackend(self)
}
}
unsafe impl<T: OpenglGraphicsBackend> Backend for GliumGraphicBackend<T>
{
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
self.0.swap_buffers().map_err(Into::into)
} }
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void
{ {
self.get_proc_address(symbol) self.0.get_proc_address(symbol) as *const c_void
} }
fn get_framebuffer_dimensions(&self) -> (u32, u32) { fn get_framebuffer_dimensions(&self) -> (u32, u32) {
self.get_framebuffer_dimensions() self.0.get_framebuffer_dimensions()
} }
fn is_current(&self) -> bool { fn is_current(&self) -> bool {
self.is_current() self.0.is_current()
} }
unsafe fn make_current(&self) { unsafe fn make_current(&self) {
self.make_current() self.0.make_current()
} }
} }