Struct tweak_shader::RenderContext

source ·
pub struct RenderContext { /* private fields */ }
Expand description

The main rendering and bookkeeping context.

Implementations§

source§

impl RenderContext

source

pub fn new<Src: AsRef<str>>( source: Src, format: TextureFormat, device: &Device, queue: &Queue ) -> Result<Self, Error>

Creates a new RenderContext with a pipeline corresponding to the shader file capable of rendering to texture views with the specified format.

Warning: may throw a validation error to the device, if you are not certain whether or not you are passing in valid shaders you should handles these by pushing the proper error scopes.

source

pub fn list_set_up_jobs(&self) -> &[UserJobs]

Returns a slice of jobs the user should complete. see UserJobs for more information. handling these jobs is totally optional.

source

pub fn render( &mut self, queue: &Queue, device: &Device, view: &TextureView, width: u32, height: u32 )

Renders the shader maintained by this context to the provided texture view. this will produce validation errors if the view format does not match the format the context was configured with in RenderContext::new.

source

pub fn encode_render( &mut self, queue: &Queue, device: &Device, command_encoder: &mut CommandEncoder, view: &TextureView, width: u32, height: u32 )

Encodes the renderpasses and buffer copies in the correct order into command encoder targeting view.

source

pub fn iter_inputs_mut(&mut self) -> impl Iterator<Item = (&str, MutInput<'_>)>

Returns a iterator over mutable custom values and names of the inputs provided by the user, as well as the raw bytes of all the uniforms maintained by the RenderContext that do not have input pragmas.

source

pub fn iter_inputs(&self) -> impl Iterator<Item = (&str, &InputType)>

Returns a iterator over custom values and names of the inputs provided by the user, as well as the raw bytes of all the uniforms maintained by the RenderContext that do not have input pragmas.

source

pub fn get_input_mut(&mut self, name: &str) -> Option<MutInput<'_>>

Returns an option of a mutable reference to the custom input of the given name if it exists

source

pub fn get_input(&self, name: &str) -> Option<&InputType>

Returns an option of the custom input of the given name if it exists

source

pub fn load_audio_stream_raw<S: AsRef<str>>( &mut self, name: S, channels: u16, samples: usize ) -> Option<&mut [f32]>

Provides access to the raw float array of sample data that will be converted into a texture for the audio stream with the name name

  • The data must be in a planar format.
  • The data may have an FFT performed on it returns None if the name provided does not correspond to a valid audio input.
source

pub fn load_video_stream_raw<S: AsRef<str>>( &mut self, name: S, height: u32, width: u32 ) -> Option<&mut [u8]>

Provides access to the raw byte array of rgba8unormsrgb formatted pixels that will be uploaded into the texture with name name. This causes the context to allocate memory large enough to store a frame of your video until you call RenderContext::remove_texture.

source

pub fn load_image_immediate<S: AsRef<str>>( &mut self, name: S, height: u32, width: u32, bytes_per_row: u32, device: &Device, queue: &Queue, format: &TextureFormat, data: &[u8] )

Loads a texture of the specified format into the variable with name name immediately.

source

pub fn load_shared_texture( &mut self, texture: &Texture, variable_name: &str ) -> bool

Creates a texture view and maps it to the pipeline in place of a locally stored texture. this will fail if you try to override a render target texture.

source

pub fn load_shared_texture_view( &mut self, texture: TextureView, width: u32, height: u32, variable_name: &str ) -> bool

maps a texture view to the pipeline in place of a locally stored texture. this will fail if you try to override a render target texture.

source

pub fn get_texture_view(&mut self, variable_name: &str) -> Option<TextureView>

If a texture is loaded in the pipeline under variable_name this will return a new view into it.

source

pub fn load_texture( &mut self, data: Vec<u8>, variable_name: String, width: u32, height: u32 ) -> bool

Queues the texture with variable_name to be written to with the data in data. data is assumed to be in rgba8unormsrgb format. data will NOT be loaded if it is the wrong size or if you attempt to write to a render pass target texture.

source

pub fn error_state( device: &Device, queue: &Queue, output_format: TextureFormat ) -> Self

returns an instance of the render context in a default error state displaying a test card Useful when displaying errors to the user if you don’t want to bail the program and have no visual fallback.

source

pub fn render_to_vec<'a>( &'a mut self, queue: &'a Queue, device: &'a Device, width: u32, height: u32 ) -> Vec<u8>

Renders the shader at provided resolution and writes the result to a vector in the texture format that the context was configured with.

§Warning!

this function is pretty wasteful and memory intensive It is mostly here as a utitlity to ffi interfaces.

source

pub fn render_to_slice<'a>( &'a mut self, queue: &'a Queue, device: &'a Device, width: u32, height: u32, slice: &mut [u8] )

Renders the shader at provided resolution and writes the result to the user provided slice in the texture format that the context was configured with.

§Panics!

if the provided slice does not exactly match the buffer size requirements of the resolution and output format specified in the context.

source

pub fn remove_texture(&mut self, var: &str) -> bool

Removes a texture with the variable name var from the pipeline, It will be replaced with a placeholder texture which is a 1x1 transparent pixel. returns true if the texture existed.

source

pub fn is_stateful(&mut self) -> bool

Returns true if this render context builds up a state over its runtime using persistent targets

source

pub fn copy_resources_into( &mut self, other: &mut Self, device: &Device, queue: &Queue )

copy all common textures and common uniform values from self to other. Will not copy textures loaded with load_shared_texture

source

pub fn set_mouse_down(&mut self)

Call this to put the mouse in the down position, this resets the z and w components of the mouse uniform to the most recent mouse position.

source

pub fn set_mouse_up(&mut self)

Call this to put the mouse in the down up position, this sets the sign of the z and w components of the mouse uniform negative.

source

pub fn set_mouse_input(&mut self, new_position: [f32; 2])

Updates the mouse uniform.

source

pub fn update_frame_count(&mut self, frame: u32)

Updates the frame_index utility uniform member.

source

pub fn update_datetime(&mut self, date: [f32; 4])

Updates the date utility uniform member with values corresponding to year, month, day, and seconds since midnight.

source

pub fn update_delta(&mut self, delta: f32)

Updates the time_delta utility uniform with the delta value.

source

pub fn update_time(&mut self, time: f32)

Updates the time uniform member.

source

pub fn update_resolution(&mut self, res: [f32; 2])

Updates the resolution uniform member.

Trait Implementations§

source§

impl Debug for RenderContext

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,