Skip to main content

CpuSurfaceProvider

Trait CpuSurfaceProvider 

Source
pub trait CpuSurfaceProvider: Send + Sync {
    // Required method
    fn bake(
        &self,
        frame: &FaceFrame,
        chunk: &Chunk,
        tile_res: u32,
    ) -> ChunkSurface;

    // Provided methods
    fn sample_height(&self, _dir: Vector3) -> Option<f32> { ... }
    fn poll_refresh(&self) -> Vec<Chunk> { ... }
    fn set_wanted(&self, _ids: &HashSet<ChunkId>) { ... }
    fn base_ready(&self) -> bool { ... }
    fn height_scale(&self) -> f32 { ... }
    fn resources_in_flight(&self) -> usize { ... }
    fn cache_dir(&self) -> Option<String> { ... }
}
Expand description

A source of CPU-baked chunk surfaces (colour/height/normal). Implementors run on the bake worker pool (bake is called off the main thread, so it must be Send + Sync and use interior mutability for any shared state). The other hooks run on the main thread.

Required Methods§

Source

fn bake(&self, frame: &FaceFrame, chunk: &Chunk, tile_res: u32) -> ChunkSurface

Resample this chunk’s surface at tile_res × tile_res. Called on a bake worker thread. A streaming provider may also enqueue any data it still needs (a side effect) so poll_refresh can later report the chunk for a re-bake once that data arrives.

Provided Methods§

Source

fn sample_height(&self, _dir: Vector3) -> Option<f32>

Surface displacement at dir, in the height buffer’s unit (multiply by height_scale · radius for world units). Steers LOD toward the displaced surface. None ⇒ no data (treated as sea level).

Source

fn poll_refresh(&self) -> Vec<Chunk>

Chunks whose awaited data has arrived and should be re-baked (streaming). Called each frame on the main thread; a non-streaming provider returns empty. Returns whole [Chunk]s (not just ids) so the caller can re-queue a bake directly.

Source

fn set_wanted(&self, _ids: &HashSet<ChunkId>)

Camera-driven cancellation hint: the set of chunk ids still in view. Streaming providers drop bookkeeping / downloads for anything else.

Source

fn base_ready(&self) -> bool

Is enough data present for the surface to be shown (the GPU surface_enabled gate)? A streaming provider returns false until its base map lands; a self-contained provider (noise) is always ready.

Source

fn height_scale(&self) -> f32

Per-height-unit displaced-radius factor for the GPU: the surface radius becomes radius · (1 + height · height_scale).

Source

fn resources_in_flight(&self) -> usize

External resource fetches in flight (streaming providers; for the HUD).

Source

fn cache_dir(&self) -> Option<String>

Absolute path of any on-disk cache this provider uses (for the HUD).

Implementors§