Struct frenderer::frenderer::Renderer

source ·
pub struct Renderer {
    pub gpu: WGPU,
    /* private fields */
}
Expand description

A wrapper over GPU state, surface, depth texture, and some renderers.

Fields§

§gpu: WGPU

Implementations§

source§

impl Renderer

source

pub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float

The format used for depth textures within frenderer.

source

pub async fn with_surface( width: u32, height: u32, surf_width: u32, surf_height: u32, instance: Arc<Instance>, surface: Option<Surface<'static>> ) -> Result<Self, Box<dyn Error>>

Creates a Renderer and its internal crate::gpu::WGPU using a wgpu wgpu::Instance and wgpu::Surface, along with the rendering resolution (w, h) and surface dimensions.

source

pub fn with_gpu( width: u32, height: u32, surf_width: u32, surf_height: u32, gpu: WGPU, surface: Option<Surface<'static>> ) -> Self

Create a new Renderer with a full set of GPU resources, a render size (width,`height), a surface size, and a surface.

source

pub fn set_present_mode(&mut self, mode: PresentMode)

Change the presentation mode used by the swapchain

source

pub fn surface(&self) -> Option<&Surface<'static>>

Returns the current surface

source

pub fn create_surface(&mut self, window: Arc<Window>)

Creates a new surface for this renderer

source

pub fn resize_surface(&mut self, w: u32, h: u32)

Resize the internal surface texture (typically called when the window or canvas size changes).

source

pub fn resize_render(&mut self, w: u32, h: u32)

Resize the internal color and depth targets (the actual rendering resolution).

source

pub fn do_uploads(&mut self)

Uploads sprite, mesh, and flat data accessed since the last time Renderer::do_uploads was called. Call this manually if you want, or let Renderer::render call it automatically.

source

pub fn render(&mut self)

Acquire the next frame, create a wgpu::RenderPass, draw into it, and submit the encoder. This also queues uploads of mesh, sprite, or other instance data, so if you don’t use Renderer::render in your code be sure to call Renderer::do_uploads if you’re using the built-in mesh, flat, or sprite renderers.

source

pub fn render_into<'s, 'pass>(&'s self, rpass: &mut RenderPass<'pass>)
where 's: 'pass,

Renders all the frenderer stuff into a given wgpu::RenderPass. Just does rendering of the built-in renderers, with no data uploads, encoder submission, or frame acquire/present.

source

pub fn render_setup( &self ) -> Option<(SurfaceTexture, TextureView, CommandEncoder)>

Convenience method for acquiring a surface texture, view, and command encoder. If this returns None it means the surface isn’t ready yet.

source

pub fn render_finish(&self, frame: SurfaceTexture, encoder: CommandEncoder)

Convenience method for submitting a command encoder and presenting the swapchain image.

source

pub fn surface_size(&self) -> (u32, u32)

Returns the size of the surface onto which the rendered image is stretched

source

pub fn render_size(&self) -> (u32, u32)

Returns the size of the internal rendering texture (i.e., the rendering resolution)

source

pub fn create_array_texture( &self, images: &[&[u8]], format: TextureFormat, (width, height): (u32, u32), label: Option<&str> ) -> Texture

Creates an array texture on the renderer’s GPU.

source

pub fn create_texture( &self, image: &[u8], format: TextureFormat, (width, height): (u32, u32), label: Option<&str> ) -> Texture

Creates a single texture on the renderer’s GPU.

source

pub fn sprite_group_add( &mut self, tex: &Texture, world_transforms: Vec<Transform>, sheet_regions: Vec<SheetRegion>, camera: Camera2D ) -> usize

Create a new sprite group sized to fit world_transforms and sheet_regions, which should be the same length. Returns the sprite group index corresponding to this group.

source

pub fn sprite_group_count(&self) -> usize

Returns the number of sprite groups (including placeholders for removed groups).

source

pub fn sprite_group_remove(&mut self, which: usize)

Deletes a sprite group, leaving an empty group slot behind (this might get recycled later).

source

pub fn sprite_group_size(&self, which: usize) -> usize

Reports the size of the given sprite group. Panics if the given sprite group is not populated.

source

pub fn sprite_group_resize(&mut self, which: usize, len: usize) -> usize

Resizes a sprite group. If the new size is smaller, this is very cheap; if it’s larger than it’s ever been before, it might involve reallocating the Vec<Transform>, Vec<SheetRegion>, or the GPU buffer used to draw sprites, so it could be expensive.

Panics if the given sprite group is not populated.

source

pub fn sprite_group_set_camera(&mut self, which: usize, camera: Camera2D)

Set the given camera transform on a specific sprite group. Uploads to the GPU. Panics if the given sprite group is not populated.

source

pub fn sprites_mut( &mut self, which: usize, range: impl RangeBounds<usize> ) -> (&mut [Transform], &mut [SheetRegion])

Get a mutable slice of a specified sprite group’s world transforms and texture regions. Marks these sprites for later upload. Since this causes an upload later on, call it as few times as possible per frame. Most importantly, don’t call it with lots of tiny or overlapped regions.

Panics if the given sprite group is not populated or the range is out of bounds.

source

pub fn mesh_set_camera(&mut self, camera: Camera3D)

Sets the given camera for all textured mesh groups.

source

pub fn mesh_group_add( &mut self, texture: &Texture, vertices: Vec<Vertex>, indices: Vec<u32>, mesh_info: Vec<MeshEntry> ) -> MeshGroup

Add a mesh group with the given array texture. All meshes in the group pull from the same vertex buffer, and each submesh is defined in terms of a range of indices within that buffer. When loading your mesh resources from whatever format they’re stored in, fill out vertex and index vecs while tracking the beginning and end of each mesh and submesh (see crate::meshes::MeshEntry for details).

source

pub fn mesh_group_remove(&mut self, which: MeshGroup)

Deletes a mesh group, leaving an empty placeholder.

source

pub fn mesh_group_count(&self) -> usize

Returns how many mesh groups there are.

source

pub fn mesh_group_size(&self, which: MeshGroup) -> usize

Returns how many meshes there are in the given mesh group.

source

pub fn mesh_instance_count(&self, which: MeshGroup, mesh_number: usize) -> usize

Returns how many mesh instances there are in the given mesh of the given mesh group.

source

pub fn mesh_instance_resize( &mut self, which: MeshGroup, idx: usize, len: usize ) -> usize

Change the number of instances of the given mesh of the given mesh group.

source

pub fn meshes_mut( &mut self, which: MeshGroup, idx: usize, range: impl RangeBounds<usize> ) -> &mut [Transform3D]

Gets the (mutable) transforms of every instance of the given mesh of a mesh group. Since this causes an upload later on, call it as few times as possible per frame. Most importantly, don’t call it with lots of tiny regions or overlapped regions.

source

pub fn flat_set_camera(&mut self, camera: Camera3D)

Sets the given camera for all flat mesh groups.

source

pub fn flat_group_add( &mut self, material_colors: &[[f32; 4]], vertices: Vec<FlatVertex>, indices: Vec<u32>, mesh_info: Vec<MeshEntry> ) -> MeshGroup

Add a flat mesh group with the given color materials. All meshes in the group pull from the same vertex buffer, and each submesh is defined in terms of a range of indices within that buffer. When loading your mesh resources from whatever format they’re stored in, fill out vertex and index vecs while tracking the beginning and end of each mesh and submesh (see crate::meshes::MeshEntry for details).

source

pub fn flat_group_remove(&mut self, which: MeshGroup)

Deletes a mesh group, leaving an empty placeholder.

source

pub fn flat_group_count(&self) -> usize

Returns how many mesh groups there are.

source

pub fn flat_group_size(&self, which: MeshGroup) -> usize

Returns how many meshes there are in the given mesh group.

source

pub fn flat_instance_count(&self, which: MeshGroup, mesh_number: usize) -> usize

Returns how many mesh instances there are in the given mesh of the given mesh group.

source

pub fn flat_instance_resize( &mut self, which: MeshGroup, idx: usize, len: usize ) -> usize

Change the number of instances of the given mesh of the given mesh group.

source

pub fn flats_mut( &mut self, which: MeshGroup, idx: usize, range: impl RangeBounds<usize> ) -> &mut [Transform3D]

Gets the (mutable) transforms of every instance of the given mesh of a mesh group. Since this causes an upload later on, call it as few times as possible per frame. Most importantly, don’t call it with lots of tiny regions or overlapped regions.

source

pub fn post_transform(&self) -> [f32; 16]

Returns the current geometric transform used in postprocessing (a 4x4 column-major homogeneous matrix)

source

pub fn post_color_transform(&self) -> [f32; 16]

Returns the current color transform used in postprocessing (a 4x4 column-major homogeneous matrix)

source

pub fn post_saturation(&self) -> f32

Returns the current saturation value in postprocessing (a value between -1 and 1, with 0.0 meaning an identity transformation)

source

pub fn post_set(&mut self, trf: [f32; 16], color_trf: [f32; 16], sat: f32)

Sets all postprocessing parameters

source

pub fn post_set_transform(&mut self, trf: [f32; 16])

Sets the postprocessing geometric transform (a 4x4 column-major homogeneous matrix)

source

pub fn post_set_color_transform(&mut self, trf: [f32; 16])

Sets the postprocessing color transform (a 4x4 column-major homogeneous matrix)

source

pub fn post_set_saturation(&mut self, sat: f32)

Sets the postprocessing saturation value (a number between -1 and 1, with 0.0 meaning an identity transformation)

source

pub fn post_set_lut(&mut self, lut: &Texture)

Sets the postprocessing color lookup table texture

source

pub fn config(&self) -> &SurfaceConfiguration

Gets the surface configuration

source

pub fn depth_texture(&self) -> &Texture

Gets a reference to the active depth texture

source

pub fn depth_texture_view(&self) -> &TextureView

Gets a view on the active depth texture

Trait Implementations§

source§

impl Frenderer for Renderer

source§

fn render(&mut self)

source§

impl<T> FrendererEvents<T> for Renderer

source§

fn handle_event( &mut self, clock: &mut Clock, window: &Arc<Window>, evt: &Event<T>, _target: &EventLoopWindowTarget<T>, input: &mut Input ) -> EventPhase

Call handle_event on your crate::frenderer::Renderer with a given crate::clock::Clock to let Frenderer figure out “the right thing to do” for the current winit event. See crate::clock::Clock for details on the timestep computation.
source§

impl From<Renderer> for Immediate

source§

fn from(rend: Renderer) -> Self

Converts to this type from the input type.

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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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

source§

impl<T> WasmNotSendSync for T

source§

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