Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::mem;
use std::mem::size_of;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
use std::rc::Rc;
use std::str;

pub use ffi::types::*;
Expand Down Expand Up @@ -80,20 +79,27 @@ macro_rules! declare_gl_apis {
$($(unsafe $($garbo)*)* fn $name(&self $(, $arg:$t)*) $(-> $retty)* ;)+
}

impl Gl for ErrorCheckingGl {
impl<T> Gl for ErrorCheckingGl<T>
where
T: Gl,
{
$($(unsafe $($garbo)*)* fn $name(&self $(, $arg:$t)*) $(-> $retty)* {
let rv = self.gl.$name($($arg,)*);
assert_eq!(self.gl.get_error(), 0);
rv
})+
}

impl<F: Fn(&Gl, &str, GLenum)> Gl for ErrorReactingGl<F> {
impl<T, F> Gl for ErrorReactingGl<T, F>
where
T: Gl,
F: Fn(&Gl, &str, GLenum),
{
$($(unsafe $($garbo)*)* fn $name(&self $(, $arg:$t)*) $(-> $retty)* {
let rv = self.gl.$name($($arg,)*);
let error = self.gl.get_error();
if error != 0 {
(self.callback)(&*self.gl, stringify!($name), error);
(self.callback)(&self.gl, stringify!($name), error);
}
rv
})+
Expand Down Expand Up @@ -561,26 +567,34 @@ declare_gl_apis! {
fn get_debug_messages(&self) -> Vec<DebugMessage>;
}

//#[deprecated(since = "0.6.11", note = "use ErrorReactingGl instead")]
pub struct ErrorCheckingGl {
gl: Rc<Gl>,
pub struct ErrorCheckingGl<T> {
gl: T,
}

impl ErrorCheckingGl {
pub fn wrap(fns: Rc<Gl>) -> Rc<Gl> {
Rc::new(ErrorCheckingGl { gl: fns }) as Rc<Gl>
impl<T> ErrorCheckingGl<T>
where
T: Gl,
{
#[inline]
pub fn wrap(gl: T) -> Self {
Self { gl }
}
}

/// A wrapper around GL context that calls a specified callback on each GL error.
pub struct ErrorReactingGl<F> {
gl: Rc<Gl>,
pub struct ErrorReactingGl<T, F> {
gl: T,
callback: F,
}

impl<F: 'static + Fn(&Gl, &str, GLenum)> ErrorReactingGl<F> {
pub fn wrap(fns: Rc<Gl>, callback: F) -> Rc<Gl> {
Rc::new(ErrorReactingGl { gl: fns, callback }) as Rc<Gl>
impl<T, F> ErrorReactingGl<T, F>
where
T: Gl,
F: 'static + Fn(&Gl, &str, GLenum),
{
#[inline]
pub fn wrap(gl: T, callback: F) -> Self {
ErrorReactingGl { gl, callback }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gl_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub struct GlFns {
}

impl GlFns {
pub unsafe fn load_with<'a, F>(loadfn: F) -> Rc<Gl>
#[inline]
pub unsafe fn load_with<'a, F>(loadfn: F) -> Self
where
F: FnMut(&str) -> *const c_void,
{
let ffi_gl_ = GlFfi::load_with(loadfn);
Rc::new(GlFns { ffi_gl_: ffi_gl_ }) as Rc<Gl>
Self { ffi_gl_: GlFfi::load_with(loadfn) }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gles_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub struct GlesFns {
}

impl GlesFns {
pub unsafe fn load_with<'a, F>(loadfn: F) -> Rc<Gl>
#[inline]
pub unsafe fn load_with<'a, F>(loadfn: F) -> Self
where
F: FnMut(&str) -> *const c_void,
{
let ffi_gl_ = GlesFfi::load_with(loadfn);
Rc::new(GlesFns { ffi_gl_: ffi_gl_ }) as Rc<Gl>
Self { ffi_gl_: GlesFfi::load_with(loadfn) }
}
}

Expand Down