Struct tweak_shader::RenderContext
source · pub struct RenderContext { /* private fields */ }
Expand description
The main rendering and bookkeeping context.
Implementations§
source§impl RenderContext
impl RenderContext
sourcepub fn new<Src: AsRef<str>>(
source: Src,
format: TextureFormat,
device: &Device,
queue: &Queue
) -> Result<Self, Error>
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.
sourcepub fn list_set_up_jobs(&self) -> &[UserJobs]
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.
sourcepub fn render(
&mut self,
queue: &Queue,
device: &Device,
view: &TextureView,
width: u32,
height: u32
)
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.
sourcepub fn encode_render(
&mut self,
queue: &Queue,
device: &Device,
command_encoder: &mut CommandEncoder,
view: &TextureView,
width: u32,
height: u32
)
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
.
sourcepub fn iter_inputs_mut(&mut self) -> impl Iterator<Item = (&str, MutInput<'_>)>
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.
sourcepub fn iter_inputs(&self) -> impl Iterator<Item = (&str, &InputType)>
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.
sourcepub fn get_input_mut(&mut self, name: &str) -> Option<MutInput<'_>>
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
sourcepub fn get_input(&self, name: &str) -> Option<&InputType>
pub fn get_input(&self, name: &str) -> Option<&InputType>
Returns an option of the custom input of the given name if it exists
sourcepub fn load_audio_stream_raw<S: AsRef<str>>(
&mut self,
name: S,
channels: u16,
samples: usize
) -> Option<&mut [f32]>
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.
sourcepub fn load_video_stream_raw<S: AsRef<str>>(
&mut self,
name: S,
height: u32,
width: u32
) -> Option<&mut [u8]>
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
.
sourcepub 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]
)
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.
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.
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.
sourcepub fn get_texture_view(&mut self, variable_name: &str) -> Option<TextureView>
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.
sourcepub fn load_texture(
&mut self,
data: Vec<u8>,
variable_name: String,
width: u32,
height: u32
) -> bool
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.
sourcepub fn error_state(
device: &Device,
queue: &Queue,
output_format: TextureFormat
) -> Self
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.
sourcepub fn render_to_vec<'a>(
&'a mut self,
queue: &'a Queue,
device: &'a Device,
width: u32,
height: u32
) -> Vec<u8>
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.
sourcepub fn render_to_slice<'a>(
&'a mut self,
queue: &'a Queue,
device: &'a Device,
width: u32,
height: u32,
slice: &mut [u8]
)
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.
sourcepub fn remove_texture(&mut self, var: &str) -> bool
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.
sourcepub fn is_stateful(&mut self) -> bool
pub fn is_stateful(&mut self) -> bool
Returns true if this render context builds up a state over its runtime using persistent targets
sourcepub fn copy_resources_into(
&mut self,
other: &mut Self,
device: &Device,
queue: &Queue
)
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
sourcepub fn set_mouse_down(&mut self)
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.
sourcepub fn set_mouse_up(&mut self)
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.
sourcepub fn set_mouse_input(&mut self, new_position: [f32; 2])
pub fn set_mouse_input(&mut self, new_position: [f32; 2])
Updates the mouse
uniform.
sourcepub fn update_frame_count(&mut self, frame: u32)
pub fn update_frame_count(&mut self, frame: u32)
Updates the frame_index
utility uniform member.
sourcepub fn update_datetime(&mut self, date: [f32; 4])
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.
sourcepub fn update_delta(&mut self, delta: f32)
pub fn update_delta(&mut self, delta: f32)
Updates the time_delta
utility uniform with the delta value.
sourcepub fn update_time(&mut self, time: f32)
pub fn update_time(&mut self, time: f32)
Updates the time
uniform member.
sourcepub fn update_resolution(&mut self, res: [f32; 2])
pub fn update_resolution(&mut self, res: [f32; 2])
Updates the resolution
uniform member.