Skip to main content

figments/surfaces/
null.rs

1use core::marker::PhantomData;
2
3use crate::{liber8tion::interpolate::Fract8, prelude::*};
4
5
6/// A buffer pool that does nothing. Useful for testing.
7pub struct NullBufferPool<U, Space: CoordinateSpace, P>(NullSurface<U, Space, P>);
8/// A surface that does nothing. Useful for testing.
9pub struct NullSurface<U, Space: CoordinateSpace, P>(PhantomData<Space>, PhantomData<U>, PhantomData<P>);
10
11impl<U: Default, Space: CoordinateSpace, P> Default for NullSurface<U, Space, P> {
12    fn default() -> Self {
13        Self(Default::default(), Default::default(), Default::default())
14    }
15}
16
17impl<U: Default, Space: CoordinateSpace, P> Default for NullBufferPool<U, Space, P> {
18    fn default() -> Self {
19        Self(Default::default())
20    }
21}
22
23impl<U, Space: CoordinateSpace, P> core::fmt::Debug for NullBufferPool<U, Space, P> {
24    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
25        f.debug_tuple("NullBufferPool").finish()
26    }
27}
28
29impl<U: Default + core::fmt::Debug, Space: CoordinateSpace, P> core::fmt::Debug for NullSurface<U, Space, P> {
30    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
31        f.debug_tuple("NullSurface").finish()
32    }
33}
34
35#[expect(unused_variables)]
36impl<U, Space: CoordinateSpace, P> Surface for NullSurface<U, Space, P> {
37    type Uniforms = U;
38
39    type CoordinateSpace = Space;
40
41    type Pixel = P;
42
43    fn set_shader<T: Shader<Self::Uniforms, Self::CoordinateSpace, Self::Pixel> + 'static>(&mut self, shader: T) {}
44
45    fn clear_shader(&mut self) {}
46
47    fn set_rect(&mut self, rect: Rectangle<Self::CoordinateSpace>) {}
48
49    fn set_opacity(&mut self, opacity: Fract8) {}
50
51    fn set_visible(&mut self, visible: bool) {}
52
53    fn set_offset(&mut self, offset: Coordinates<Self::CoordinateSpace>) {}
54}
55
56#[expect(unused_variables)]
57impl<U: Default, Space: CoordinateSpace, P> Surfaces for NullBufferPool<U, Space, P> {
58    type Surface = NullSurface<U, Space, P>;
59
60    type Error = ();
61
62    fn new_surface(&mut self, area: Rectangle<Space>) -> Result<Self::Surface, Self::Error> {
63        Ok(NullSurface::default())
64    }
65}
66
67#[expect(unused_variables)]
68impl<U: Default, Space: CoordinateSpace, P> RenderSource<U, Space, P, P> for NullBufferPool<U, Space, P> {
69    fn render_to<'a, Smp>(&'a self, output: &'a mut Smp, uniforms: &U)
70        where 
71            Smp: Sample<'a, Space> + ?Sized {}
72}