render: add a frame parameter to all shaders
This commit is contained in:
parent
73c3ced3d7
commit
9dff0119a4
@ -21,8 +21,8 @@ struct IdleShader {
|
||||
}
|
||||
|
||||
impl Shader for IdleShader {
|
||||
fn draw(&self, coords: &VirtualCoordinates) -> RGB8 {
|
||||
Hsv::new_srgb(self.frame.wrapping_add(coords.x).wrapping_add(coords.y), 255, 255).into_rgb8()
|
||||
fn draw(&self, coords: &VirtualCoordinates, frame: u8) -> RGB8 {
|
||||
Hsv::new_srgb(frame.wrapping_add(coords.x).wrapping_add(coords.y), 255, 255).into_rgb8()
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ struct TestShader {
|
||||
}
|
||||
|
||||
impl Shader for TestShader {
|
||||
fn draw(&self, coords: &VirtualCoordinates) -> RGB8 {
|
||||
fn draw(&self, coords: &VirtualCoordinates, _frame: usize) -> RGB8 {
|
||||
match self.pattern {
|
||||
Pattern::Red => RGB8::new(255, 0, 0),
|
||||
Pattern::Green => RGB8::new(0, 255, 0),
|
||||
|
@ -40,7 +40,8 @@ T::Color: HardwarePixel,
|
||||
pixmap: StrideMapping,
|
||||
target: T,
|
||||
pixbuf: [T::Color; PIXEL_NUM],
|
||||
max_mw: u32
|
||||
max_mw: u32,
|
||||
frame: usize
|
||||
}
|
||||
|
||||
impl<T: SmartLedsWrite, S: Surface, const PIXEL_NUM: usize> Debug for SmartLedDisplay<T, S, PIXEL_NUM> where
|
||||
@ -63,7 +64,8 @@ T::Color: HardwarePixel,
|
||||
surfaces: Some(SurfacePool::new()),
|
||||
target,
|
||||
max_mw,
|
||||
pixmap: StrideMapping::new()
|
||||
pixmap: StrideMapping::new(),
|
||||
frame: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +112,7 @@ Rgb<u8>: From<T::Color>
|
||||
if idx >= PIXEL_NUM {
|
||||
continue;
|
||||
}
|
||||
self.pixbuf[idx] = self.pixbuf[idx].saturating_add(shader.draw(&virt_coords));
|
||||
self.pixbuf[idx] = self.pixbuf[idx].saturating_add(shader.draw(&virt_coords, self.frame));
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -134,6 +136,7 @@ Rgb<u8>: From<T::Color> {
|
||||
if let Err(_) = self.target.write(brightness(self.pixbuf.iter().cloned().map(|x| { x.into() }), b)) {
|
||||
panic!("Could not write frame");
|
||||
}
|
||||
self.frame += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ use std::marker::PhantomData;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait Shader: Send + Debug {
|
||||
fn draw(&self, surface_coords: &VirtualCoordinates) -> RGB8;
|
||||
fn draw(&self, surface_coords: &VirtualCoordinates, frame: usize) -> RGB8;
|
||||
}
|
||||
|
||||
pub trait Surfaces<T: Surface>: Debug {
|
||||
|
Loading…
x
Reference in New Issue
Block a user