Skip to main content

Renderer

Struct Renderer 

Source
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

Source

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

Source

pub fn instance(&self) -> &Instance

Returns a reference to the underlying wgpu Instance

Source

pub fn adapter(&self) -> &Adapter

Returns a reference to the underlying wgpu Adapter

Source

pub fn device(&self) -> &Device

Returns a reference to the underlying wgpu Device

Source

pub fn queue(&self) -> &Queue

Returns a reference to the underlying wgpu Queue

Source

pub fn set_clear_color(&mut self, color: [f64; 4])

Sets the clear color for future render passes

Source

pub fn begin_frame(&mut self, target: &mut dyn RenderTarget) -> Option<Frame>

Begins a frame with the given render target

Source

pub fn end_frame(&mut self, frame: Frame)

Ends the frame by submitting commands and presenting

Source

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)

Source

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

Source

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

Source

pub fn create_offscreen_target( &self, width: u32, height: u32, format: TextureFormat, ) -> OffscreenTarget

Create an offscreen render target

Source

pub fn add_offscreen_texture( &mut self, offscreen: &mut OffscreenTarget, ) -> usize

Adds an offscreen target texture & returns its id

Source

pub fn add_texture(&mut self, data: &[u8]) -> usize

Adds a new texture from image bytes & returns its id

Source

pub fn add_texture_raw(&mut self, w: u32, h: u32, data: &[u8]) -> usize

Adds a texture from raw RGBA bytes & returns its id

Source

pub fn update_texture(&mut self, index: usize, data: &[u8])

Replaces an existing texture with new image data

Source

pub fn update_texture_raw(&mut self, index: usize, w: u32, h: u32, data: &[u8])

Replaces an existing texture with raw RGBA bytes

Source

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

Source

pub fn add_uniform(&mut self, data: &[u8]) -> usize

Creates a uniform buffer and returns its id

Source

pub fn update_uniform(&mut self, id: usize, data: &[u8])

Updates an existing uniform buffer with new data

Source

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

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> 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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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