pub struct Immediate { /* private fields */ }
Expand description
Immediate
wraps a Renderer
with an immediate-mode API with
functions like Immediate::draw_sprite
. This API is less
modular and may be less efficient, but is simpler for some use
cases.
Implementations§
source§impl Immediate
impl Immediate
sourcepub fn auto_clear(&mut self, c: bool)
pub fn auto_clear(&mut self, c: bool)
Whether this renderer should clear its counters/state during rendering. If set to false, it will accumulate drawing commands from multiple frames until Immediate::clear is called.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the render state. If done in the middle of a frame this
cancels out earlier draw commands, and if done between frames
(when auto_clear
is false) will set up the renderer for the
next frame.
sourcepub fn set_present_mode(&mut self, mode: PresentMode)
pub fn set_present_mode(&mut self, mode: PresentMode)
Changes the present mode for this renderer
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 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 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,
count_estimate: usize,
camera: Camera2D
) -> usize
pub fn sprite_group_add( &mut self, tex: &Texture, count_estimate: usize, camera: Camera2D ) -> usize
Create a new sprite group sized to fit count_estimate
.
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 ensure_sprites_size(&mut self, which: usize, num: usize)
pub fn ensure_sprites_size(&mut self, which: usize, num: usize)
Makes sure that the size of the given sprite group is at least as large as num.
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 draw_sprite(
&mut self,
group: usize,
transform: Transform,
sheet_region: SheetRegion
)
pub fn draw_sprite( &mut self, group: usize, transform: Transform, sheet_region: SheetRegion )
Draws a sprite with the given transform and sheet region
sourcepub fn draw_sprites(
&mut self,
group: usize,
howmany: usize
) -> (&mut [Transform], &mut [SheetRegion])
pub fn draw_sprites( &mut self, group: usize, howmany: usize ) -> (&mut [Transform], &mut [SheetRegion])
Gets a block of howmany
sprites to draw into, as per [Renderer::get_sprites_mut]
sourcepub fn draw_text<B: RangeBounds<char>>(
&mut self,
group: usize,
bitfont: &BitFont<B>,
text: &str,
screen_pos: [f32; 2],
depth: u16,
char_height: f32
) -> ([f32; 2], usize)
pub fn draw_text<B: RangeBounds<char>>( &mut self, group: usize, bitfont: &BitFont<B>, text: &str, screen_pos: [f32; 2], depth: u16, char_height: f32 ) -> ([f32; 2], usize)
Draws a line of text with the given crate::bitfont::BitFont
.
sourcepub fn draw_nineslice(
&mut self,
group: usize,
ninesl: &NineSlice,
x: f32,
y: f32,
w: f32,
h: f32,
z_offset: u16
) -> usize
pub fn draw_nineslice( &mut self, group: usize, ninesl: &NineSlice, x: f32, y: f32, w: f32, h: f32, z_offset: u16 ) -> usize
Draws the sprites of a crate::nineslice::NineSlice
.
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).
Sets the given camera for all flat mesh groups.
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 ensure_meshes_size(&mut self, which: MeshGroup, idx: usize, num: usize)
pub fn ensure_meshes_size(&mut self, which: MeshGroup, idx: usize, num: usize)
Makes sure that the mesh instance slice for the given mesh group and index is at least big enough to hold num
.
sourcepub fn draw_mesh(&mut self, which: MeshGroup, idx: usize, trf: Transform3D)
pub fn draw_mesh(&mut self, which: MeshGroup, idx: usize, trf: Transform3D)
Draws a textured, unlit mesh with the given crate::meshes::Transform3D
.
sourcepub fn draw_meshes(
&mut self,
group: MeshGroup,
idx: usize,
howmany: usize
) -> &mut [Transform3D]
pub fn draw_meshes( &mut self, group: MeshGroup, idx: usize, howmany: usize ) -> &mut [Transform3D]
Gets a block of howmany
mesh instances to draw into, as per [Renderer::get_meshes_mut]
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 ensure_flats_size(&mut self, which: MeshGroup, idx: usize, num: usize)
pub fn ensure_flats_size(&mut self, which: MeshGroup, idx: usize, num: usize)
Makes sure that the flats instance slice for the given mesh group and index is at least big enough to hold num
.
sourcepub fn draw_flat(&mut self, which: MeshGroup, idx: usize, trf: Transform3D)
pub fn draw_flat(&mut self, which: MeshGroup, idx: usize, trf: Transform3D)
Draws a flat mesh (of the given group and mesh index) with the given crate::meshes::Transform3D
.
sourcepub fn draw_flats(
&mut self,
group: MeshGroup,
idx: usize,
howmany: usize
) -> &mut [Transform3D]
pub fn draw_flats( &mut self, group: MeshGroup, idx: usize, howmany: usize ) -> &mut [Transform3D]
Gets a block of howmany
flatmesh instances to draw into, as per [Renderer::get_flats_mut]
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 Immediate
impl<T> FrendererEvents<T> for Immediate
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 Immediate
impl !RefUnwindSafe for Immediate
impl Send for Immediate
impl Sync for Immediate
impl Unpin for Immediate
impl !UnwindSafe for Immediate
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.