pub struct SceneRenderer { /* private fields */ }Expand description
Unified renderer over the CPU and GPU paths. See the crate docs.
Implementations§
Source§impl SceneRenderer
impl SceneRenderer
Sourcepub fn new(window: Arc<Window>, opts: &RenderOptions) -> Self
pub fn new(window: Arc<Window>, opts: &RenderOptions) -> Self
Build a renderer for window. Selects the GPU backend when
opts.want_gpu and WGPU initialises; otherwise the CPU
backend. Never fails — a missing/incompatible GPU silently
yields the CPU path (the message is logged to stderr).
Sourcepub fn adapter_info(&self) -> Option<&str>
pub fn adapter_info(&self) -> Option<&str>
The GPU adapter description when on the GPU backend, else
None.
Sourcepub fn set_sky_panorama(&mut self, rgba: &[u8], w: u32, h: u32)
pub fn set_sky_panorama(&mut self, rgba: &[u8], w: u32, h: u32)
Upload an equirectangular sky panorama (RGBA8, w×h) for the
GPU marcher’s sky sampling. No-op on the CPU backend, which
samples the Sky passed in each FrameParams instead.
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Follow a window resize. CPU resizes its framebuffer lazily, so this only matters to the GPU swapchain — but it’s safe to call for both.
Sourcepub fn render(
&mut self,
scene: &mut Scene,
camera: &Camera,
frame: &FrameParams<'_>,
)
pub fn render( &mut self, scene: &mut Scene, camera: &Camera, frame: &FrameParams<'_>, )
Render scene from view with frame params and present to
the window. The CPU backend fills sky, runs the opticast
compositor, and presents via softbuffer; the GPU backend
uploads/refreshes the scene and runs the compute marcher, then
the sprite pass.
Sourcepub fn set_sprites(&mut self, set: &SpriteSet)
pub fn set_sprites(&mut self, set: &SpriteSet)
Register sprite models + instances. The CPU backend builds a per-instance draw list; the GPU backend builds an instanced model registry. Call once at setup (or again to replace).
Sourcepub fn carve_active_sprite(&mut self) -> u32
pub fn carve_active_sprite(&mut self) -> u32
Carve the next z-layer off the SpriteSet::carve_model and
re-upload (the demo’s G hotkey + GPU.12 copy-on-modify). GPU
only; a no-op on the CPU backend. Returns the voxels removed.
Sourcepub fn request_capture(&mut self)
pub fn request_capture(&mut self)
Request that the next render capture its
framebuffer for take_capture. CPU only
(the GPU swapchain isn’t read back) — a no-op on GPU.
Sourcepub fn take_capture(&mut self) -> Option<(Vec<u32>, u32, u32)>
pub fn take_capture(&mut self) -> Option<(Vec<u32>, u32, u32)>
Take the most recently captured frame as packed 0x00RRGGBB
pixels + dimensions, or None if no capture is ready / GPU.
Sourcepub fn pick_depth(&self, x: u32, y: u32) -> Option<f32>
pub fn pick_depth(&self, x: u32, y: u32) -> Option<f32>
Screen→world picking input: the world-space hit distance t at
window pixel (x, y) from the last rendered frame, or None
for out-of-bounds pixels and sky / no-hit. The host reconstructs
the world hit point as cam.pos + t * normalize(ray_dir), where
ray_dir is the same per-pixel ray the frame was rendered with
(see the backend’s projection).
t is the distance to the nearest scene-grid surface
(terrain + grids); sprites do not occlude it (the sprite pass
reads depth read-only), so a cursor sprite under the pointer is
transparent to the pick.
Cost: the CPU backend reads its in-memory z-buffer (free); the
GPU backend stages the depth buffer and blocks on a device poll
(cheap at click time — do not call every frame). The GPU path
only has depth when the last frame drew sprites (write_depth).
Sourcepub fn pixel_ray(&self, camera: &Camera, x: f64, y: f64) -> Option<[f64; 3]>
pub fn pixel_ray(&self, camera: &Camera, x: f64, y: f64) -> Option<[f64; 3]>
World-space view-ray direction (un-normalised) for window pixel
(x, y), under the projection the last frame rendered with.
The backends differ (CPU setcamera vs GPU vertical-FOV
pinhole), so this hides which one is active. None before the
first frame. Intersect it with a plane for tile picking, or feed
it to Self::pick for a voxel.
Sourcepub fn view_ray(&self, camera: &Camera, x: f64, y: f64) -> Option<Ray>
pub fn view_ray(&self, camera: &Camera, x: f64, y: f64) -> Option<Ray>
Canonical screen→world unproject: the full view Ray
(camera.pos origin + unit direction) for window pixel
(x, y), under whichever projection the last frame used. The
one entry point both backends honour — hosts never reconstruct
the projection. None before the first frame or for a
degenerate ray.
Compose with roxlap_scene::Scene::raycast for depth-free
picking that’s identical on CPU and GPU:
renderer.view_ray(cam, x, y).and_then(|r| scene.raycast(r.origin, r.dir, max)).
Sourcepub fn pick(
&self,
scene: &Scene,
camera: &Camera,
x: u32,
y: u32,
) -> Option<PickHit>
pub fn pick( &self, scene: &Scene, camera: &Camera, x: u32, y: u32, ) -> Option<PickHit>
One-call screen→world voxel pick: unproject pixel (x, y) with
the active backend’s projection, read the last frame’s depth
there, reconstruct the world hit, and resolve it to the owning
grid + grid-local voxel via Scene::resolve_voxel. None on
sky / no-hit, or when no grid claims the surface.
scene and camera must be the ones the last frame rendered;
the projection (size + FOV / hx,hy,hz) is taken from that
frame. Cheap on CPU (in-memory z-buffer); on GPU it stages the
depth buffer (a click-time device poll — not per frame).
Auto Trait Implementations§
impl !RefUnwindSafe for SceneRenderer
impl !Sync for SceneRenderer
impl !UnwindSafe for SceneRenderer
impl Freeze for SceneRenderer
impl Send for SceneRenderer
impl Unpin for SceneRenderer
impl UnsafeUnpin for SceneRenderer
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.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 more