Skip to main content

GpuRenderer

Struct GpuRenderer 

Source
pub struct GpuRenderer { /* private fields */ }
Expand description

WGPU-backed renderer. Owns the device, queue, and surface bound to the host’s winit window. Self::render is the GPU.1 clear-to-colour path; Self::render_chunk is GPU.3’s single-chunk DDA marcher.

Implementations§

Source§

impl GpuRenderer

Source

pub async fn new( window: Arc<Window>, settings: GpuRendererSettings, ) -> Result<Self, GpuInitError>

Stand up the device + surface + swapchain on window. Async because wgpu::Adapter/Device requests are.

§Errors

Returns GpuInitError if surface creation, adapter selection, or device request fails. Hosts treat any error as “fall back to the CPU path”.

Source

pub fn new_blocking( window: Arc<Window>, settings: GpuRendererSettings, ) -> Result<Self, GpuInitError>

Synchronous wrapper for hosts that don’t have an async runtime. Internally pollster::block_ons Self::new.

§Errors

See Self::new.

Source

pub fn adapter_info(&self) -> &str

Human-readable adapter description — name + backend + device type. The demo host prints this in the title bar.

Source

pub fn window(&self) -> &Window

Source

pub fn device(&self) -> &Device

Borrow the underlying wgpu device — hosts use this to build chunk uploads (GpuChunkResident::upload(gpu.device(), …)).

Source

pub fn queue(&self) -> &Queue

Borrow the wgpu queue — hosts use this for read-back paths (GpuChunkResident::read_voxel_blocking(gpu.device(), gpu.queue(), …)).

Source

pub fn set_sky_panorama(&mut self, rgba: &[u8], width: u32, height: u32)

GPU.8 — upload an equirectangular panorama as the scene’s sky texture. rgba is row-major, width × height pixels, 4 bytes per pixel (R, G, B, A). The shader samples it with u = atan2(dir.x, dir.y) / (2π) + 0.5 (azimuth) and v = acos(-dir.z) / π (elevation), matching standard equirectangular layout (top of image = zenith for voxlap’s +z = down basis).

§Panics

If rgba.len() != (width * height * 4) as usize.

Source

pub fn set_fog(&mut self, color: [f32; 3], near: f32, far: f32)

GPU.8 — set the fog blend. color is per-channel [0, 1]; near/far are world-space ray distances in voxel units. Hits with t < near show their full colour; hits with t > far show color exclusively; in between is a smoothstep blend.

Source

pub fn resize(&mut self, width: u32, height: u32)

Re-configure the swapchain to a new physical size. Call from WindowEvent::Resized. Drops the chunk-DDA storage texture so Self::render_chunk rebuilds it at the new size.

Source

pub fn render(&mut self)

GPU.1 render: single render pass clearing the swapchain to a slowly drifting colour, then presenting. Voxels arrive in GPU.3+.

Source

pub fn render_chunk( &mut self, resident: &GpuChunkResident, camera: &Camera, max_scan_dist: u32, )

GPU.3 single-chunk render. Dispatches chunk_dda.wgsl against resident’s storage buffers, then blits the low-res storage texture to the swapchain. camera.position is in chunk-local voxel units (host translates from world coords). max_scan_dist caps the per-pixel DDA loop — scene-demo wires + / - through this each frame.

§Panics

Internally expects the chunk-DDA resources to be built — they are constructed at the top of this function if missing. Cannot fire in normal control flow.

Source

pub fn render_grid( &mut self, grid: &GpuGridResident, camera: &Camera, max_outer_steps: u32, )

GPU.4 render — outer DDA over chunk indices + inner DDA into non-empty chunks. camera.position is in grid-local voxel units. max_outer_steps caps how many chunks the outer DDA may traverse per ray (scene-demo wires + / - through this).

§Panics

Internally expects the grid-DDA resources to be built; they are constructed at the top of this function if missing.

Source

pub fn render_scene( &mut self, scene: &GpuSceneResident, cameras: &[Camera], fov_y_rad: f32, max_outer_steps: u32, )

GPU.5 render — multi-grid scene marcher. cameras[i] is the world camera transformed into grid i’s local frame (caller-supplied; see scene-demo’s redraw_gpu for the glam-based transform). fov_y_rad is the shared vertical FOV; max_outer_steps caps per-ray chunk-DDA work for each grid.

§Panics

If cameras.len() != scene.grid_count or scene.grid_count > MAX_SCENE_GRIDS.

Source

pub fn set_sprite_instances( &mut self, registry: &SpriteModelRegistry, instances: &[SpriteInstance], )

GPU.10.1 — upload a sprite model registry + its instances for the DDA path. An empty instance slice clears all sprites.

Source

pub fn set_sprite_lod_px(&mut self, px: f32)

GPU.10.4 — set the LOD pixel threshold: a sprite steps to the next mip once a mip-0 voxel would project below px screen pixels. 1.0 is the natural “no sub-pixel voxels” default; larger values force LOD in closer (useful for inspection). Clamped to ≥ 0.25.

Source

pub fn set_scene_mip_scan_dist(&mut self, dist: f32)

GPU.11.1 — set the scene-grid LOD scan distance (world units). A chunk entered at world-t t is marched at mip floor(log2(max(t, msd) / msd)), clamped to its grid’s mip ladder. 0 disables LOD (always mip-0). Larger values push the coarser mips farther out — the axis-aligned-mip-beams mitigation lever (GPU.11.2). Default 64 (matches CPU mip_scan_dist).

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more