rustial-renderer-wgpu 1.0.0

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! Renderer-owned terrain depth / coordinate buffers.

/// Renderer-owned terrain interaction buffers.
///
/// These textures establish the Phase D renderer-depth foundation for
/// terrain-aware interaction, future picking, and broader pass-graph work.
pub struct TerrainInteractionBuffers {
    depth_texture: wgpu::Texture,
    depth_view: wgpu::TextureView,
    coord_texture: wgpu::Texture,
    coord_view: wgpu::TextureView,
    size: (u32, u32),
}

impl TerrainInteractionBuffers {
    /// Create interaction buffers for the given surface size.
    pub fn new(device: &wgpu::Device, width: u32, height: u32) -> Self {
        let size = (width.max(1), height.max(1));
        let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
            label: Some("rustial_terrain_interaction_depth"),
            size: wgpu::Extent3d {
                width: size.0,
                height: size.1,
                depth_or_array_layers: 1,
            },
            mip_level_count: 1,
            sample_count: 1,
            dimension: wgpu::TextureDimension::D2,
            format: wgpu::TextureFormat::Depth32Float,
            usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
            view_formats: &[],
        });
        let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());

        let coord_texture = device.create_texture(&wgpu::TextureDescriptor {
            label: Some("rustial_terrain_interaction_coords"),
            size: wgpu::Extent3d {
                width: size.0,
                height: size.1,
                depth_or_array_layers: 1,
            },
            mip_level_count: 1,
            sample_count: 1,
            dimension: wgpu::TextureDimension::D2,
            format: wgpu::TextureFormat::Rgba16Float,
            usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
            view_formats: &[],
        });
        let coord_view = coord_texture.create_view(&wgpu::TextureViewDescriptor::default());

        Self {
            depth_texture,
            depth_view,
            coord_texture,
            coord_view,
            size,
        }
    }

    /// Resize the interaction buffers.
    pub fn resize(&mut self, device: &wgpu::Device, width: u32, height: u32) {
        *self = Self::new(device, width, height);
    }

    /// Depth view storing terrain-depth prepass output.
    pub fn depth_view(&self) -> &wgpu::TextureView {
        &self.depth_view
    }

    /// Coordinate view storing terrain world/relative coordinate output.
    pub fn coord_view(&self) -> &wgpu::TextureView {
        &self.coord_view
    }

    /// Current buffer size in pixels.
    pub fn size(&self) -> (u32, u32) {
        self.size
    }

    /// Access the underlying depth texture.
    pub fn depth_texture(&self) -> &wgpu::Texture {
        &self.depth_texture
    }

    /// Access the underlying coordinate texture.
    pub fn coord_texture(&self) -> &wgpu::Texture {
        &self.coord_texture
    }
}