render: derive Debug

This commit is contained in:
Victoria Fischer 2024-11-02 15:21:07 +01:00
parent 1b08bc5f52
commit c096d83ab3

View File

@ -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<F: FnMut(&dyn Shader)>(&self, f: F);
fn set_shader(&mut self, shader: Box<dyn Shader>);
fn clear_shader(&mut self);
}
pub trait Surfaces<T: Surface> {
pub trait Surfaces<T: Surface>: Debug {
fn new_surface(&mut self) -> Result<T, io::Error>;
}
@ -28,6 +29,7 @@ pub trait Display<T: Surface>: Surfaces<T> {
fn render_frame(&mut self);
}
#[derive(Debug)]
pub struct ShaderBinding {
shader: Option<Box<dyn Shader>>,
}
@ -37,6 +39,14 @@ pub struct BoundSurface<T> {
pub binding: T
}
impl Debug for BoundSurface<Rc<RefCell<ShaderBinding>>> {
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<Rc<RefCell<ShaderBinding>>>;
impl Default for BoundSurface<Rc<RefCell<ShaderBinding>>>{
@ -68,7 +78,6 @@ impl Surface for BoundSurface<Rc<RefCell<ShaderBinding>>> {
#[cfg(feature="threads")]
pub type SharedSurface = BoundSurface<Arc<Mutex<ShaderBinding>>>;
#[cfg(feature="threads")]
impl Default for BoundSurface<Arc<Mutex<ShaderBinding>>> {
fn default() -> Self {
@ -97,10 +106,25 @@ impl Surface for BoundSurface<Arc<Mutex<ShaderBinding>>> {
}
}
#[cfg(feature="threads")]
impl Debug for BoundSurface<Arc<Mutex<ShaderBinding>>> {
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<S: Surface + Default> {
surfaces: Vec<S>
}
impl<S: Surface + Debug> Debug for SurfacePool<S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.surfaces.fmt(f)
}
}
impl<S: Surface + Default> SurfacePool<S> {
pub const fn new() -> Self {
Self {