smithay/src/backend/glium.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2017-03-07 10:53:57 +00:00
use glium::backend::Backend;
use glium::SwapBuffersError as GliumSwapBuffersError;
2017-03-18 16:27:49 +00:00
use std::os::raw::c_void;
use ::backend::graphics::opengl::{OpenglGraphicsBackend, SwapBuffersError};
2017-03-07 10:53:57 +00:00
impl From<SwapBuffersError> for GliumSwapBuffersError
{
fn from(error: SwapBuffersError) -> Self {
match error {
SwapBuffersError::ContextLost => GliumSwapBuffersError::ContextLost,
SwapBuffersError::AlreadySwapped => GliumSwapBuffersError::AlreadySwapped,
}
}
}
2017-03-18 16:27:49 +00:00
pub struct GliumGraphicBackend<T: OpenglGraphicsBackend>(T);
pub trait IntoGlium: OpenglGraphicsBackend + Sized
{
fn into_glium(self) -> GliumGraphicBackend<Self>;
}
impl<T: OpenglGraphicsBackend> IntoGlium for T
{
fn into_glium(self) -> GliumGraphicBackend<Self>
{
GliumGraphicBackend(self)
}
}
unsafe impl<T: OpenglGraphicsBackend> Backend for GliumGraphicBackend<T>
2017-03-07 10:53:57 +00:00
{
2017-03-18 16:27:49 +00:00
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
self.0.swap_buffers().map_err(Into::into)
2017-03-07 10:53:57 +00:00
}
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void
{
2017-03-18 16:27:49 +00:00
self.0.get_proc_address(symbol) as *const c_void
2017-03-07 10:53:57 +00:00
}
fn get_framebuffer_dimensions(&self) -> (u32, u32) {
2017-03-18 16:27:49 +00:00
self.0.get_framebuffer_dimensions()
2017-03-07 10:53:57 +00:00
}
fn is_current(&self) -> bool {
2017-03-18 16:27:49 +00:00
self.0.is_current()
2017-03-07 10:53:57 +00:00
}
unsafe fn make_current(&self) {
2017-03-18 16:27:49 +00:00
self.0.make_current()
2017-03-07 10:53:57 +00:00
}
}