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 is_compute(&self) -> bool
pub fn is_compute(&self) -> bool
Returns true if the loaded shader is a compute shader.
Sourcepub fn set_compute_target(&mut self, uniform_name: &str) -> Result<(), Error>
pub fn set_compute_target(&mut self, uniform_name: &str) -> Result<(), Error>
If the shader is a compute shader, then subsequent calls to
render_to_vec
and render_to_slice
. will yield data from those
storage textures.
Sourcepub fn render<T: Into<Option<TextureView>>>(
&mut self,
queue: &Queue,
device: &Device,
command_encoder: &mut CommandEncoder,
target: T,
width: u32,
height: u32,
)
pub fn render<T: Into<Option<TextureView>>>( &mut self, queue: &Queue, device: &Device, command_encoder: &mut CommandEncoder, target: T, 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 = (&String, MutInput<'_>)>
pub fn iter_inputs_mut( &mut self, ) -> impl Iterator<Item = (&String, 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 = (&String, &InputType)>
pub fn iter_inputs(&self) -> impl Iterator<Item = (&String, &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_as<T>(&mut self, name: &str) -> Option<&mut T>
pub fn get_input_as<T>(&mut self, name: &str) -> Option<&mut T>
Optionally returns a reference to the underlying type of a variable in the uniforms.
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_texture<S: AsRef<str>>(
&mut self,
name: S,
texture_desc: TextureDesc<'_>,
device: &Device,
queue: &Queue,
)
pub fn load_texture<S: AsRef<str>>( &mut self, name: S, texture_desc: TextureDesc<'_>, device: &Device, queue: &Queue, )
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.
Sourcepub fn get_texture(&mut self, variable_name: &str) -> Option<&Texture>
pub fn get_texture(&mut self, variable_name: &str) -> Option<&Texture>
If a texture is loaded in the pipeline under variable_name
this will reference to it.
this includes storage textures
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],
stride: Option<u32>,
)
pub fn render_to_slice<'a>( &'a mut self, queue: &'a Queue, device: &'a Device, width: u32, height: u32, slice: &mut [u8], stride: Option<u32>, )
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 iter_targets(&self) -> impl Iterator<Item = TargetDescriptor<'_>>
pub fn iter_targets(&self) -> impl Iterator<Item = TargetDescriptor<'_>>
Iterate over the names and peristence states of the storage texture targets in the document.
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.