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

Initialize a new Program object

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

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.

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.

Return the title of the program

Called by the runtime to set the window title

Return true if the program should stop running

Called by the runtime at the end of every pass through the event loop

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 to tick

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 with WIDTH * HEIGHT elements pixels[x + y * WIDTH] is the xth pixel in the yth row, with (0,0) starting in the upper left corner of the screen

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.

Implementors