render: derive Debug
This commit is contained in:
parent
1b08bc5f52
commit
c096d83ab3
@ -7,18 +7,19 @@ use rgb::RGB8;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::geometry::*;
|
use crate::geometry::*;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub trait Shader: Send {
|
pub trait Shader: Send + Debug {
|
||||||
fn draw(&self, surface_coords: VirtualCoordinates) -> RGB8;
|
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 with_shader<F: FnMut(&dyn Shader)>(&self, f: F);
|
||||||
fn set_shader(&mut self, shader: Box<dyn Shader>);
|
fn set_shader(&mut self, shader: Box<dyn Shader>);
|
||||||
fn clear_shader(&mut self);
|
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>;
|
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);
|
fn render_frame(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ShaderBinding {
|
pub struct ShaderBinding {
|
||||||
shader: Option<Box<dyn Shader>>,
|
shader: Option<Box<dyn Shader>>,
|
||||||
}
|
}
|
||||||
@ -37,6 +39,14 @@ pub struct BoundSurface<T> {
|
|||||||
pub binding: 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>>>;
|
pub type SimpleSurface = BoundSurface<Rc<RefCell<ShaderBinding>>>;
|
||||||
|
|
||||||
impl Default for 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")]
|
#[cfg(feature="threads")]
|
||||||
pub type SharedSurface = BoundSurface<Arc<Mutex<ShaderBinding>>>;
|
pub type SharedSurface = BoundSurface<Arc<Mutex<ShaderBinding>>>;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature="threads")]
|
#[cfg(feature="threads")]
|
||||||
impl Default for BoundSurface<Arc<Mutex<ShaderBinding>>> {
|
impl Default for BoundSurface<Arc<Mutex<ShaderBinding>>> {
|
||||||
fn default() -> Self {
|
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> {
|
pub struct SurfacePool<S: Surface + Default> {
|
||||||
surfaces: Vec<S>
|
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> {
|
impl<S: Surface + Default> SurfacePool<S> {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user