Trait pxl::Program [−][src]
pub trait Program: 'static { fn new() -> Self
where
Self: Sized; fn dimensions(&self) -> (usize, usize); fn vertex_shader(&self) -> &str { ... } fn fragment_shader(&self) -> &str { ... } fn title(&self) -> &str { ... } fn should_quit(&mut self) -> bool { ... } fn tick(&mut self, _events: &[Event]) { ... } fn render(&mut self, _pixels: &mut [Pixel]) { ... } fn synthesizer(&self) -> Option<Arc<Mutex<Synthesizer>>> { ... } }
Trait representing a pxl::Program
To run a program, see the run
function below.
Required Methods
fn new() -> Self where
Self: Sized,
Self: Sized,
Initialize a new Program object
fn dimensions(&self) -> (usize, usize)
Return the desired width and height of pixel surface
Will be called immediately before calling render()
.
Determines the length of the pixel slice passed to
render()
. If (256, 256) is returned, the pixel
slice passed to render()
will contain 256 * 256,
elements.
Provided Methods
fn vertex_shader(&self) -> &str
Return the vertex shader to be used in the runtime's rendering pipeline
Will be called immediately before calling render()
See vertex_shader.glsl
for details of the interface
that custom vertex shaders should adhere to.
fn fragment_shader(&self) -> &str
Return the fragment shader to be used in the runtime's rendering pipeline
Will be called immediately before calling render()
See fragment_shader.glsl
for details of the interface
that custom fragment shaders should adhere to.
fn title(&self) -> &str
Return the title of the program
Called by the runtime to set the window title
fn should_quit(&mut self) -> bool
Return true if the program should stop running
Called by the runtime at the end of every pass through the event loop
fn tick(&mut self, _events: &[Event])
Process events and update the state of the program
Called by the runtime 60 times per second.
events
β events that have occurred since the last call totick
fn render(&mut self, _pixels: &mut [Pixel])
Draw to the display
Called by the runtime whenever the display is ready to present a new frame
WIDTH β first element of the tuple returned by dimensions()
HEIGHT β second element of the tuple returned by dimensions()
pixels
β a slice of pixels withWIDTH * HEIGHT
elementspixels[x + y * WIDTH]
is thex
th pixel in they
th row, with(0,0)
starting in the upper left corner of the screen
fn synthesizer(&self) -> Option<Arc<Mutex<Synthesizer>>>
The program's synthesizer
Will be called by the runtime during initialization. If it returns Some, the contained Synthesizer will be moved to a dedicated audio thread and called periodically to produce samples for the outgoing audio stream.
In order to prevent buffer underruns, avoid locking the Mutex
containing the Synthesizer for long periods of time.