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
impl Renderer
sourcepub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float
pub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float
The format used for depth textures within frenderer.
sourcepub 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>>
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.
sourcepub fn with_gpu(
width: u32,
height: u32,
surf_width: u32,
surf_height: u32,
gpu: WGPU,
surface: Option<Surface<'static>>
) -> Self
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.
sourcepub fn set_present_mode(&mut self, mode: PresentMode)
pub fn set_present_mode(&mut self, mode: PresentMode)
Change the presentation mode used by the swapchain
sourcepub fn create_surface(&mut self, window: Arc<Window>)
pub fn create_surface(&mut self, window: Arc<Window>)
Creates a new surface for this renderer
sourcepub fn resize_surface(&mut self, w: u32, h: u32)
pub fn resize_surface(&mut self, w: u32, h: u32)
Resize the internal surface texture (typically called when the window or canvas size changes).
sourcepub fn resize_render(&mut self, w: u32, h: u32)
pub fn resize_render(&mut self, w: u32, h: u32)
Resize the internal color and depth targets (the actual rendering resolution).
sourcepub fn do_uploads(&mut self)
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.
sourcepub fn render(&mut self)
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.
sourcepub fn render_into<'s, 'pass>(&'s self, rpass: &mut RenderPass<'pass>)where
's: 'pass,
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.
sourcepub fn render_setup(
&self
) -> Option<(SurfaceTexture, TextureView, CommandEncoder)>
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.
sourcepub fn render_finish(&self, frame: SurfaceTexture, encoder: CommandEncoder)
pub fn render_finish(&self, frame: SurfaceTexture, encoder: CommandEncoder)
Convenience method for submitting a command encoder and presenting the swapchain image.
sourcepub fn surface_size(&self) -> (u32, u32)
pub fn surface_size(&self) -> (u32, u32)
Returns the size of the surface onto which the rendered image is stretched
sourcepub fn render_size(&self) -> (u32, u32)
pub fn render_size(&self) -> (u32, u32)
Returns the size of the internal rendering texture (i.e., the rendering resolution)
sourcepub fn create_array_texture(
&self,
images: &[&[u8]],
format: TextureFormat,
(width, height): (u32, u32),
label: Option<&str>
) -> Texture
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.
sourcepub fn create_texture(
&self,
image: &[u8],
format: TextureFormat,
(width, height): (u32, u32),
label: Option<&str>
) -> Texture
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.
sourcepub fn sprite_group_add(
&mut self,
tex: &Texture,
world_transforms: Vec<Transform>,
sheet_regions: Vec<SheetRegion>,
camera: Camera2D
) -> usize
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.
sourcepub fn sprite_group_count(&self) -> usize
pub fn sprite_group_count(&self) -> usize
Returns the number of sprite groups (including placeholders for removed groups).
sourcepub fn sprite_group_remove(&mut self, which: usize)
pub fn sprite_group_remove(&mut self, which: usize)
Deletes a sprite group, leaving an empty group slot behind (this might get recycled later).
sourcepub fn sprite_group_size(&self, which: usize) -> usize
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.
sourcepub fn sprite_group_resize(&mut self, which: usize, len: usize) -> usize
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.
sourcepub fn sprite_group_set_camera(&mut self, which: usize, camera: Camera2D)
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.
sourcepub fn sprites_mut(
&mut self,
which: usize,
range: impl RangeBounds<usize>
) -> (&mut [Transform], &mut [SheetRegion])
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.
sourcepub fn mesh_set_camera(&mut self, camera: Camera3D)
pub fn mesh_set_camera(&mut self, camera: Camera3D)
Sets the given camera for all textured mesh groups.
sourcepub fn mesh_group_add(
&mut self,
texture: &Texture,
vertices: Vec<Vertex>,
indices: Vec<u32>,
mesh_info: Vec<MeshEntry>
) -> MeshGroup
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).
sourcepub fn mesh_group_remove(&mut self, which: MeshGroup)
pub fn mesh_group_remove(&mut self, which: MeshGroup)
Deletes a mesh group, leaving an empty placeholder.
sourcepub fn mesh_group_count(&self) -> usize
pub fn mesh_group_count(&self) -> usize
Returns how many mesh groups there are.
sourcepub fn mesh_group_size(&self, which: MeshGroup) -> usize
pub fn mesh_group_size(&self, which: MeshGroup) -> usize
Returns how many meshes there are in the given mesh group.
sourcepub fn mesh_instance_count(&self, which: MeshGroup, mesh_number: usize) -> usize
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.
sourcepub fn mesh_instance_resize(
&mut self,
which: MeshGroup,
idx: usize,
len: usize
) -> usize
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.
sourcepub fn meshes_mut(
&mut self,
which: MeshGroup,
idx: usize,
range: impl RangeBounds<usize>
) -> &mut [Transform3D]
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.
sourcepub fn flat_set_camera(&mut self, camera: Camera3D)
pub fn flat_set_camera(&mut self, camera: Camera3D)
Sets the given camera for all flat mesh groups.
sourcepub fn flat_group_add(
&mut self,
material_colors: &[[f32; 4]],
vertices: Vec<FlatVertex>,
indices: Vec<u32>,
mesh_info: Vec<MeshEntry>
) -> MeshGroup
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).
sourcepub fn flat_group_remove(&mut self, which: MeshGroup)
pub fn flat_group_remove(&mut self, which: MeshGroup)
Deletes a mesh group, leaving an empty placeholder.
sourcepub fn flat_group_count(&self) -> usize
pub fn flat_group_count(&self) -> usize
Returns how many mesh groups there are.
sourcepub fn flat_group_size(&self, which: MeshGroup) -> usize
pub fn flat_group_size(&self, which: MeshGroup) -> usize
Returns how many meshes there are in the given mesh group.
sourcepub fn flat_instance_count(&self, which: MeshGroup, mesh_number: usize) -> usize
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.
sourcepub fn flat_instance_resize(
&mut self,
which: MeshGroup,
idx: usize,
len: usize
) -> usize
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.
sourcepub fn flats_mut(
&mut self,
which: MeshGroup,
idx: usize,
range: impl RangeBounds<usize>
) -> &mut [Transform3D]
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.
sourcepub fn post_transform(&self) -> [f32; 16]
pub fn post_transform(&self) -> [f32; 16]
Returns the current geometric transform used in postprocessing (a 4x4 column-major homogeneous matrix)
sourcepub fn post_color_transform(&self) -> [f32; 16]
pub fn post_color_transform(&self) -> [f32; 16]
Returns the current color transform used in postprocessing (a 4x4 column-major homogeneous matrix)
sourcepub fn post_saturation(&self) -> f32
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)
sourcepub fn post_set(&mut self, trf: [f32; 16], color_trf: [f32; 16], sat: f32)
pub fn post_set(&mut self, trf: [f32; 16], color_trf: [f32; 16], sat: f32)
Sets all postprocessing parameters
sourcepub fn post_set_transform(&mut self, trf: [f32; 16])
pub fn post_set_transform(&mut self, trf: [f32; 16])
Sets the postprocessing geometric transform (a 4x4 column-major homogeneous matrix)
sourcepub fn post_set_color_transform(&mut self, trf: [f32; 16])
pub fn post_set_color_transform(&mut self, trf: [f32; 16])
Sets the postprocessing color transform (a 4x4 column-major homogeneous matrix)
sourcepub fn post_set_saturation(&mut self, sat: f32)
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)
sourcepub fn post_set_lut(&mut self, lut: &Texture)
pub fn post_set_lut(&mut self, lut: &Texture)
Sets the postprocessing color lookup table texture
sourcepub fn config(&self) -> &SurfaceConfiguration
pub fn config(&self) -> &SurfaceConfiguration
Gets the surface configuration
sourcepub fn depth_texture(&self) -> &Texture
pub fn depth_texture(&self) -> &Texture
Gets a reference to the active depth texture
sourcepub fn depth_texture_view(&self) -> &TextureView
pub fn depth_texture_view(&self) -> &TextureView
Gets a view on the active depth texture
Trait Implementations§
source§impl<T> FrendererEvents<T> for Renderer
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
fn handle_event( &mut self, clock: &mut Clock, window: &Arc<Window>, evt: &Event<T>, _target: &EventLoopWindowTarget<T>, input: &mut Input ) -> EventPhase
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.Auto Trait Implementations§
impl !Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl !UnwindSafe for Renderer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.