Struct 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 is_compute(&self) -> bool

Returns true if the loaded shader is a compute shader.

Source

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.

Source

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.

Source

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.

Source

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.

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_as<T>(&mut self, name: &str) -> Option<&mut T>
where InputType: TryAsMut<T>,

Optionally returns a reference to the underlying type of a variable in the uniforms.

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_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.

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

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], 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.

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 iter_targets(&self) -> impl Iterator<Item = TargetDescriptor<'_>>

Iterate over the names and peristence states of the storage texture targets in the document.

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>,

Source§

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>,

Source§

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,