//! Backend-agnostic helpers shared by every [`crate::gfx::RenderBackend`].
//!
//! Kept separate from any GPU code so the contract and its support types do not
//! depend on the `runtime` feature.

/// A camera-space uniform block, the data every backend must get to its shader:
/// just the view-projection matrix for now. Lighting, time, and per-eye index
/// would join this struct as the engine grows.
///
/// `#[repr(C)]` + `Pod`/`Zeroable` for direct GPU upload. Layout must match the
/// `Camera` uniform in the WGSL shader (`gfx/shaders/sprite.wgsl`).
#[repr(C)]
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
pub struct CameraUniform {
    pub view_proj: [[f32; 4]; 4],
}

impl CameraUniform {
    pub fn new() -> Self {
        Self {
            view_proj: crate::math::Mat4::IDENTITY.to_cols_array_2d(),
        }
    }

    pub fn from_matrix(m: crate::math::Mat4) -> Self {
        Self {
            view_proj: m.to_cols_array_2d(),
        }
    }
}

impl Default for CameraUniform {
    fn default() -> Self {
        Self::new()
    }
}
