Skip to main content

figments_render/
output.rs

1#![allow(async_fn_in_trait)]
2
3use figments::{liber8tion::interpolate::Fract8, prelude::*};
4
5use crate::gamma::GammaCurve;
6
7pub trait Brightness {
8    fn set_brightness(&mut self, brightness: Fract8);
9    fn set_on(&mut self, is_on: bool);
10}
11
12pub trait GammaCorrected {
13    fn set_gamma(&mut self, gamma: GammaCurve);
14}
15
16/// A hardware output that provides an interface to the underlying hardware pixels, including actually turning pixels into photons
17pub trait Output<'a, SampleSpace: CoordinateSpace>: Sample<'a, SampleSpace> {
18    type Error;
19    type Controls: Brightness + GammaCorrected;
20
21    /// Commits the contents of the underlying pixel buffers to hardware
22    fn commit(&mut self)  -> Result<(), Self::Error>;
23
24    fn controls(&mut self) -> Option<&mut Self::Controls>;
25}
26
27/// A hardware output that provides an interface to the underlying hardware pixels, including actually turning pixels into photons, but async flavored
28pub trait OutputAsync<'a, SampleSpace: CoordinateSpace>: Sample<'a, SampleSpace> {
29    type Error;
30    type Controls: Brightness + GammaCorrected;
31
32    /// Commits the contents of the underlying pixel buffers to hardware
33    async fn commit_async(&mut self) -> Result<(), Self::Error>;
34
35    fn controls(&mut self) -> Option<&mut Self::Controls>;
36}
37
38#[derive(Default, Debug, Clone, Copy)]
39pub struct NullControls {}
40
41#[expect(unused_variables)]
42impl Brightness for NullControls {
43    fn set_brightness(&mut self, brightness: Fract8) {}
44    fn set_on(&mut self, is_on: bool) {}
45}
46
47#[allow(unused_variables)]
48impl GammaCorrected for NullControls {
49    fn set_gamma(&mut self, gamma: GammaCurve) {}
50}