diff --git a/src/render.rs b/src/render.rs index 80ff5f3..f45bdd3 100644 --- a/src/render.rs +++ b/src/render.rs @@ -7,18 +7,19 @@ use rgb::RGB8; use std::sync::{Arc, Mutex}; use crate::geometry::*; +use std::fmt::Debug; -pub trait Shader: Send { +pub trait Shader: Send + Debug { fn draw(&self, surface_coords: VirtualCoordinates) -> RGB8; } -pub trait Surface: Default + Clone { +pub trait Surface: Default + Clone + Debug { fn with_shader(&self, f: F); fn set_shader(&mut self, shader: Box); fn clear_shader(&mut self); } -pub trait Surfaces { +pub trait Surfaces: Debug { fn new_surface(&mut self) -> Result; } @@ -28,6 +29,7 @@ pub trait Display: Surfaces { fn render_frame(&mut self); } +#[derive(Debug)] pub struct ShaderBinding { shader: Option>, } @@ -37,6 +39,14 @@ pub struct BoundSurface { pub binding: T } +impl Debug for BoundSurface>> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BoundSurface") + .field("shader", &self.binding.borrow().shader) + .finish() + } +} + pub type SimpleSurface = BoundSurface>>; impl Default for BoundSurface>>{ @@ -68,7 +78,6 @@ impl Surface for BoundSurface>> { #[cfg(feature="threads")] pub type SharedSurface = BoundSurface>>; - #[cfg(feature="threads")] impl Default for BoundSurface>> { fn default() -> Self { @@ -97,10 +106,25 @@ impl Surface for BoundSurface>> { } } +#[cfg(feature="threads")] +impl Debug for BoundSurface>> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BoundSurface") + .field("shader", &self.binding.lock().unwrap().shader) + .finish() + } +} + pub struct SurfacePool { surfaces: Vec } +impl Debug for SurfacePool { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.surfaces.fmt(f) + } +} + impl SurfacePool { pub const fn new() -> Self { Self {