pub struct Renderer { /* private fields */ }Expand description
The main renderer responsible for GPU rendering operations.
The renderer manages the complete rendering pipeline including:
- GPU context (device, queue, surface)
- Resource management (buffers, textures, bind groups)
- Pipeline caching (shader compilation, PSO creation)
- Frame rendering (scene extraction, command submission)
§Lifecycle
- Create with
Renderer::new(no GPU resources allocated) - Initialize GPU with
Renderer::init - Render frames with
Renderer::begin_frame - Clean up with
Renderer::maybe_prune
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn new(
init_config: RendererInitConfig,
settings: RendererSettings,
) -> Renderer
pub fn new( init_config: RendererInitConfig, settings: RendererSettings, ) -> Renderer
Phase 1: Create configuration (no GPU resources yet).
This only stores the render settings. GPU resources are
allocated when init is called.
§Arguments
init_config- Static GPU/device configuration (consumed at init time)settings- Runtime rendering settings (can be changed later viaupdate_settings)
Sourcepub fn size(&self) -> (u32, u32)
pub fn size(&self) -> (u32, u32)
Returns the current surface size in pixels as (width, height).
Sourcepub async fn init<W>(
&mut self,
window: W,
width: u32,
height: u32,
) -> Result<(), Error>
pub async fn init<W>( &mut self, window: W, width: u32, height: u32, ) -> Result<(), Error>
Phase 2: Initialize GPU context with window handle.
This method:
- Creates the wgpu instance and adapter
- Requests a device with required features/limits
- Configures the surface for presentation
- Initializes resource manager and pipeline cache
pub fn resize(&mut self, width: u32, height: u32)
Sourcepub fn begin_frame<'a>(
&'a mut self,
scene: &'a mut Scene,
camera: &'a RenderCamera,
assets: &'a AssetServer,
frame_time: FrameTime,
) -> Option<FrameComposer<'a>>
pub fn begin_frame<'a>( &'a mut self, scene: &'a mut Scene, camera: &'a RenderCamera, assets: &'a AssetServer, frame_time: FrameTime, ) -> Option<FrameComposer<'a>>
Begins building a new frame for rendering.
Returns a FrameComposer that provides a chainable API for
configuring the render pipeline via custom pass hooks.
§Usage
// Method 1: Use default built-in passes
if let Some(composer) = renderer.begin_frame(scene, camera, assets, time) {
composer.render();
}
// Method 2: With custom hooks (e.g., UI overlay)
if let Some(composer) = renderer.begin_frame(scene, camera, assets, time) {
composer
.add_custom_pass(HookStage::AfterPostProcess, |graph, bb| {
ui_pass.target_tex = bb.surface_out;
graph.add_pass(&mut ui_pass);
})
.render();
}§Returns
Returns Some(FrameComposer) if frame preparation succeeds,
or None if rendering should be skipped (e.g., window size is 0).
Sourcepub fn maybe_prune(&mut self)
pub fn maybe_prune(&mut self)
Performs periodic resource cleanup.
Should be called after each frame to release unused GPU resources. Uses internal heuristics to avoid expensive cleanup every frame.
Sourcepub fn render_path(&self) -> &RenderPath
pub fn render_path(&self) -> &RenderPath
Returns the current RenderPath.
Sourcepub fn settings(&self) -> &RendererSettings
pub fn settings(&self) -> &RendererSettings
Returns a reference to the current runtime renderer settings.
Sourcepub fn init_config(&self) -> &RendererInitConfig
pub fn init_config(&self) -> &RendererInitConfig
Returns a reference to the init-time configuration.
Sourcepub fn update_settings(&mut self, new_settings: RendererSettings)
pub fn update_settings(&mut self, new_settings: RendererSettings)
Applies new runtime settings, performing an internal diff to update only the parts that actually changed.
This is the single entry point for all runtime configuration
changes. Callers (UI panels, scripting layers, etc.) should maintain
their own RendererSettings instance, mutate it, and pass it here.
Sourcepub fn set_render_path(&mut self, path: RenderPath)
pub fn set_render_path(&mut self, path: RenderPath)
Switches the active render path at runtime.
Convenience wrapper around update_settings
for changing only the render path.
Sourcepub fn device(&self) -> Option<&Device>
pub fn device(&self) -> Option<&Device>
Returns a reference to the wgpu Device.
Useful for external plugins to initialize GPU resources.
Sourcepub fn queue(&self) -> Option<&Queue>
pub fn queue(&self) -> Option<&Queue>
Returns a reference to the wgpu Queue.
Useful for external plugins to submit commands.
Sourcepub fn surface_format(&self) -> Option<TextureFormat>
pub fn surface_format(&self) -> Option<TextureFormat>
Returns the surface texture format.
Useful for external plugins to configure render pipelines.
Sourcepub fn wgpu_ctx(&self) -> Option<&WgpuContext>
pub fn wgpu_ctx(&self) -> Option<&WgpuContext>
Returns a reference to the WgpuContext.
For external plugins that need access to low-level GPU resources. Only available after renderer initialization.
pub fn dump_graph_mermaid(&self) -> Option<String>
Auto Trait Implementations§
impl !Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl !Send for Renderer
impl !Sync for Renderer
impl Unpin for Renderer
impl UnsafeUnpin 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.