pub struct Renderer { /* private fields */ }Expand description
Low-level GPU renderer built on wgpu
Handles rendering pipelines, surface configuration, resources (textures, buffers), & drawing
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub async fn new(
window: impl Into<SurfaceTarget<'static>> + WindowHandle,
) -> Self
pub async fn new( window: impl Into<SurfaceTarget<'static>> + WindowHandle, ) -> Self
Creates a renderer & initializes GPU state using the window’s surface
Sets up wgpu, pipelines, default texture & camera resources
Sourcepub fn set_clear_color(&mut self, color: [f64; 4])
pub fn set_clear_color(&mut self, color: [f64; 4])
Sets the clear color for future render passes
Sourcepub fn begin_frame(&mut self, target: &mut dyn RenderTarget) -> Option<Frame>
pub fn begin_frame(&mut self, target: &mut dyn RenderTarget) -> Option<Frame>
Begins a frame with the given render target
Sourcepub fn begin_render_pass<'a>(
&'a self,
encoder: &'a mut CommandEncoder,
view: &'a TextureView,
) -> RenderPass<'a>
pub fn begin_render_pass<'a>( &'a self, encoder: &'a mut CommandEncoder, view: &'a TextureView, ) -> RenderPass<'a>
Begins a render pass with the given encoder and target view.
Clears the view (set by Self::set_clear_color)
Sourcepub fn draw_batch(
&self,
r_pass: &mut RenderPass<'_>,
batch: &mut GeometryBatch,
texture_id: Option<usize>,
shader_id: Option<usize>,
)
pub fn draw_batch( &self, r_pass: &mut RenderPass<'_>, batch: &mut GeometryBatch, texture_id: Option<usize>, shader_id: Option<usize>, )
Draws a geometry batch within an existing render pass
Sourcepub fn upload_camera_matrix(&mut self, view_proj: [[f32; 4]; 4])
pub fn upload_camera_matrix(&mut self, view_proj: [[f32; 4]; 4])
Uploads the given view-projection matrix to the GPU for use in vertex transforms
Sourcepub fn create_offscreen_target(
&self,
width: u32,
height: u32,
format: TextureFormat,
) -> OffscreenTarget
pub fn create_offscreen_target( &self, width: u32, height: u32, format: TextureFormat, ) -> OffscreenTarget
Create an offscreen render target
Sourcepub fn add_offscreen_texture(
&mut self,
offscreen: &mut OffscreenTarget,
) -> usize
pub fn add_offscreen_texture( &mut self, offscreen: &mut OffscreenTarget, ) -> usize
Adds an offscreen target texture & returns its id
Sourcepub fn add_texture(&mut self, data: &[u8]) -> usize
pub fn add_texture(&mut self, data: &[u8]) -> usize
Adds a new texture from image bytes & returns its id
Sourcepub fn add_texture_raw(&mut self, w: u32, h: u32, data: &[u8]) -> usize
pub fn add_texture_raw(&mut self, w: u32, h: u32, data: &[u8]) -> usize
Adds a texture from raw RGBA bytes & returns its id
Sourcepub fn update_texture(&mut self, index: usize, data: &[u8])
pub fn update_texture(&mut self, index: usize, data: &[u8])
Replaces an existing texture with new image data
Sourcepub fn update_texture_raw(&mut self, index: usize, w: u32, h: u32, data: &[u8])
pub fn update_texture_raw(&mut self, index: usize, w: u32, h: u32, data: &[u8])
Replaces an existing texture with raw RGBA bytes
Sourcepub fn add_shader(&mut self, wgsl_source: &str) -> usize
pub fn add_shader(&mut self, wgsl_source: &str) -> usize
Creates a custom shader pipeline from WGSL source code Returns the pipeline index for use in draw calls
Sourcepub fn add_uniform(&mut self, data: &[u8]) -> usize
pub fn add_uniform(&mut self, data: &[u8]) -> usize
Creates a uniform buffer and returns its id
Sourcepub fn update_uniform(&mut self, id: usize, data: &[u8])
pub fn update_uniform(&mut self, id: usize, data: &[u8])
Updates an existing uniform buffer with new data
Sourcepub fn add_shader_with_uniforms(
&mut self,
wgsl_source: &str,
uniform_ids: &[usize],
) -> usize
pub fn add_shader_with_uniforms( &mut self, wgsl_source: &str, uniform_ids: &[usize], ) -> usize
Creates a custom shader pipeline with associated uniform buffers Returns the pipeline index for use in draw calls