pub struct ViewportRenderer { /* private fields */ }Expand description
High-level renderer wrapping all GPU resources and providing framework-agnostic
prepare() and paint() methods.
Implementations§
Source§impl ViewportRenderer
impl ViewportRenderer
Sourcepub fn pick_scene_gpu(
&mut self,
device: &Device,
queue: &Queue,
cursor: Vec2,
frame: &FrameData,
) -> Option<GpuPickHit>
pub fn pick_scene_gpu( &mut self, device: &Device, queue: &Queue, cursor: Vec2, frame: &FrameData, ) -> Option<GpuPickHit>
GPU object-ID pick: renders the scene to an offscreen R32Uint texture
and reads back the single pixel under cursor.
This is O(1) in mesh complexity : every object is rendered with a flat
u32 ID, and only one pixel is read back. For triangle-level queries
(barycentric scalar probe, exact world position), use the CPU
crate::interaction::picking::pick_scene path instead.
The pipeline is lazily initialized on first call : zero overhead when this method is never invoked.
§Arguments
device: wgpu devicequeue: wgpu queuecursor: cursor position in viewport-local pixels (top-left origin)frame: current grouped frame data (camera, scene surfaces, viewport size)
§Returns
Some(GpuPickHit) if an object is under the cursor, None if empty space.
Source§impl ViewportRenderer
impl ViewportRenderer
Sourcepub fn paint(&self, render_pass: &mut RenderPass<'static>, frame: &FrameData)
pub fn paint(&self, render_pass: &mut RenderPass<'static>, frame: &FrameData)
Issue draw calls for the viewport. Call inside a wgpu::RenderPass.
This method requires a 'static render pass (as provided by egui’s
CallbackTrait). For non-static render passes (iced, manual wgpu),
use paint_to.
Sourcepub fn paint_to<'rp>(
&'rp self,
render_pass: &mut RenderPass<'rp>,
frame: &FrameData,
)
pub fn paint_to<'rp>( &'rp self, render_pass: &mut RenderPass<'rp>, frame: &FrameData, )
Issue draw calls into a render pass with any lifetime.
Identical to paint but accepts a render pass with a
non-'static lifetime, making it usable from iced, raw wgpu, or any
framework that creates its own render pass.
Sourcepub fn render_viewport(
&mut self,
device: &Device,
queue: &Queue,
output_view: &TextureView,
id: ViewportId,
frame: &FrameData,
) -> CommandBuffer
pub fn render_viewport( &mut self, device: &Device, queue: &Queue, output_view: &TextureView, id: ViewportId, frame: &FrameData, ) -> CommandBuffer
High-level HDR render for a single viewport identified by id.
Unlike render, this method does not call
prepare internally. The caller must have already called
prepare_scene and
prepare_viewport for id before invoking this.
This is the right entry point for multi-viewport frames:
- Call
prepare_sceneonce. - Call
prepare_viewportfor each viewport. - Call
render_viewportfor each viewport with its ownoutput_view.
Returns a wgpu::CommandBuffer ready to submit.
Sourcepub fn render(
&mut self,
device: &Device,
queue: &Queue,
output_view: &TextureView,
frame: &FrameData,
) -> CommandBuffer
pub fn render( &mut self, device: &Device, queue: &Queue, output_view: &TextureView, frame: &FrameData, ) -> CommandBuffer
High-level HDR render method. Handles the full post-processing pipeline: scene -> HDR texture -> (bloom) -> (SSAO) -> tone map -> output_view.
When frame.post_process.enabled is false, falls back to a simple LDR render
pass targeting output_view directly.
Returns a CommandBuffer ready to submit.
Sourcepub fn render_offscreen(
&mut self,
device: &Device,
queue: &Queue,
frame: &FrameData,
width: u32,
height: u32,
) -> Vec<u8> ⓘ
pub fn render_offscreen( &mut self, device: &Device, queue: &Queue, frame: &FrameData, width: u32, height: u32, ) -> Vec<u8> ⓘ
Render a frame to an offscreen texture and return raw RGBA bytes.
Creates a temporary wgpu::Texture render target of the given dimensions,
runs all render passes (shadow, scene, post-processing) into it via
render(), then copies the result back to CPU memory.
No OS window or wgpu::Surface is required. The caller is responsible for
initialising the wgpu adapter with compatible_surface: None and for
constructing a valid FrameData (including viewport_size matching
width/height).
Returns width * height * 4 bytes in RGBA8 layout. The caller encodes to
PNG/EXR independently : no image codec dependency in this crate.
Source§impl ViewportRenderer
impl ViewportRenderer
Sourcepub fn new(device: &Device, target_format: TextureFormat) -> Self
pub fn new(device: &Device, target_format: TextureFormat) -> Self
Create a new renderer with default settings (no MSAA). Call once at application startup.
Sourcepub fn with_sample_count(
device: &Device,
target_format: TextureFormat,
sample_count: u32,
) -> Self
pub fn with_sample_count( device: &Device, target_format: TextureFormat, sample_count: u32, ) -> Self
Create a new renderer with the specified MSAA sample count (1, 2, or 4).
When using MSAA (sample_count > 1), the caller must create multisampled color and depth textures and use them as render pass attachments with the final surface texture as the resolve target.
Sourcepub fn resources(&self) -> &ViewportGpuResources
pub fn resources(&self) -> &ViewportGpuResources
Access the underlying GPU resources (e.g. for mesh uploads).
Sourcepub fn last_frame_stats(&self) -> FrameStats
pub fn last_frame_stats(&self) -> FrameStats
Performance counters from the last completed frame.
Sourcepub fn resources_mut(&mut self) -> &mut ViewportGpuResources
pub fn resources_mut(&mut self) -> &mut ViewportGpuResources
Mutable access to the underlying GPU resources (e.g. for mesh uploads).
Sourcepub fn upload_environment_map(
&mut self,
device: &Device,
queue: &Queue,
pixels: &[f32],
width: u32,
height: u32,
)
pub fn upload_environment_map( &mut self, device: &Device, queue: &Queue, pixels: &[f32], width: u32, height: u32, )
Upload an equirectangular HDR environment map and precompute IBL textures.
pixels is row-major RGBA f32 data (4 floats per texel), width×height.
This rebuilds camera bind groups so shaders immediately see the new textures.
Sourcepub fn create_viewport(&mut self, device: &Device) -> ViewportId
pub fn create_viewport(&mut self, device: &Device) -> ViewportId
Create a new viewport slot and return its handle.
The returned ViewportId is stable for the lifetime of the renderer.
Pass it to prepare_viewport,
paint_viewport, and
render_viewport each frame.
Also set CameraFrame::viewport_index to id.0 when building the
FrameData for this viewport:
let id = renderer.create_viewport(&device);
let frame = FrameData {
camera: CameraFrame::from_camera(&cam, size).with_viewport_index(id.0),
..Default::default()
};Sourcepub fn destroy_viewport(&mut self, id: ViewportId)
pub fn destroy_viewport(&mut self, id: ViewportId)
Release the heavy GPU texture memory (HDR targets, OIT, bloom, SSAO) held
by id.
The slot index is not reclaimed : future calls with this ViewportId will
lazily recreate the texture resources as needed. This is useful when a
viewport is hidden or minimised and you want to reduce VRAM pressure without
invalidating the handle.
Sourcepub fn prepare_scene(
&mut self,
device: &Device,
queue: &Queue,
frame: &FrameData,
scene_effects: &SceneEffects<'_>,
)
pub fn prepare_scene( &mut self, device: &Device, queue: &Queue, frame: &FrameData, scene_effects: &SceneEffects<'_>, )
Prepare shared scene data. Call once per frame, before any
prepare_viewport calls.
frame provides the scene content (frame.scene) and the primary camera
used for shadow cascade framing (frame.camera). In a multi-viewport
setup use any one viewport’s FrameData here : typically the perspective
view : as the shadow framing reference.
scene_effects carries the scene-global effects: lighting, environment
map, and compute filters. Obtain it by constructing SceneEffects
directly or via EffectsFrame::split.
Sourcepub fn prepare_viewport(
&mut self,
device: &Device,
queue: &Queue,
id: ViewportId,
frame: &FrameData,
)
pub fn prepare_viewport( &mut self, device: &Device, queue: &Queue, id: ViewportId, frame: &FrameData, )
Prepare per-viewport GPU state (camera, clip planes, overlays, axes).
Call once per viewport per frame, after prepare_scene.
id must have been obtained from create_viewport.
frame.camera.viewport_index must equal id.0; use
CameraFrame::with_viewport_index when building the frame.
Sourcepub fn paint_viewport(
&self,
render_pass: &mut RenderPass<'static>,
id: ViewportId,
frame: &FrameData,
)
pub fn paint_viewport( &self, render_pass: &mut RenderPass<'static>, id: ViewportId, frame: &FrameData, )
Issue draw calls for id into a 'static render pass (as provided by egui callbacks).
This is the method to use from an egui/eframe CallbackTrait::paint implementation.
Call prepare_scene and prepare_viewport
first (in CallbackTrait::prepare), then set the render pass viewport/scissor to confine
drawing to the correct quadrant, and call this method.
For non-'static render passes (winit, iced, manual wgpu), use
paint_viewport_to.
Sourcepub fn paint_viewport_to<'rp>(
&'rp self,
render_pass: &mut RenderPass<'rp>,
id: ViewportId,
frame: &FrameData,
)
pub fn paint_viewport_to<'rp>( &'rp self, render_pass: &mut RenderPass<'rp>, id: ViewportId, frame: &FrameData, )
Issue draw calls for id into a render pass with any lifetime.
Identical to paint_viewport but accepts a render pass with a
non-'static lifetime, making it usable from winit, iced, or raw wgpu where the encoder
creates its own render pass.
Auto Trait Implementations§
impl Freeze for ViewportRenderer
impl !RefUnwindSafe for ViewportRenderer
impl Send for ViewportRenderer
impl Sync for ViewportRenderer
impl Unpin for ViewportRenderer
impl UnsafeUnpin for ViewportRenderer
impl !UnwindSafe for ViewportRenderer
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>, which can then be
downcast into Box<dyn 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>, which 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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.