feat: render and manage textures :3

This commit is contained in:
zack 2025-04-05 20:54:38 -04:00
parent 2501390225
commit 74a1be796f
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
21 changed files with 2908 additions and 320 deletions

View file

@ -8,5 +8,7 @@ ash.workspace = true
gpu-allocator.workspace = true
thiserror.workspace = true
tracing.workspace = true
gltf.workspace = true
gfx_hal = { path = "../gfx_hal" }
image = { version = "0.25.6", features = ["rayon"] }

View file

@ -34,6 +34,12 @@ pub enum ResourceManagerError {
#[error("Error occurred in GfxHal: {0}")]
GfxHalError(#[from] gfx_hal::error::GfxHalError),
#[error("I/O Error occurred: {0}")]
Io(#[from] std::io::Error),
#[error("Image Error occurred: {0}")]
ImageError(#[from] image::ImageError),
#[error("An unexpected error occurred: {0}")]
Other(String),
}

View file

@ -13,6 +13,7 @@ unsafe fn as_byte_slice<T: Sized>(data: &[T]) -> &[u8] {
/// Represents geometry data (verticies and indicies) stored in GPU buffers managed by
/// ResourceManager. Handles automatic cleanup via a `Drop` implementation.
#[derive(Clone)]
pub struct Geometry {
resource_manager: Arc<ResourceManager>,
pub vertex_buffer: BufferHandle,

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,59 @@
use std::sync::Arc;
use ash::vk;
use crate::{ImageHandle, SamplerHandle};
#[derive(Debug, Clone)]
pub struct Texture {
pub handle: ImageHandle,
pub format: vk::Format,
pub extent: vk::Extent3D,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SamplerDesc {
pub mag_filter: vk::Filter,
pub min_filter: vk::Filter,
pub mipmap_mode: vk::SamplerMipmapMode,
pub address_mode_u: vk::SamplerAddressMode,
pub address_mode_v: vk::SamplerAddressMode,
pub address_mode_w: vk::SamplerAddressMode,
}
impl Default for SamplerDesc {
fn default() -> Self {
Self {
mag_filter: vk::Filter::LINEAR,
min_filter: vk::Filter::LINEAR,
mipmap_mode: vk::SamplerMipmapMode::LINEAR,
address_mode_u: vk::SamplerAddressMode::REPEAT,
address_mode_v: vk::SamplerAddressMode::REPEAT,
address_mode_w: vk::SamplerAddressMode::REPEAT,
}
}
}
#[derive(Debug, Clone)]
pub struct Material {
pub name: String,
pub base_color_texture: Option<Arc<Texture>>,
pub base_color_sampler: Option<SamplerHandle>,
pub base_color_factor: [f32; 4],
pub metallic_factor: f32,
pub roughness_factor: f32,
// TODO: Add other PBR properties:
// pub metallic_roughness_texture: Option<Arc<Texture>>,
// pub metallic_roughness_sampler: Option<SamplerHandle>,
// pub normal_texture: Option<Arc<Texture>>,
// pub normal_sampler: Option<SamplerHandle>,
// pub occlusion_texture: Option<Arc<Texture>>,
// pub occlusion_sampler: Option<SamplerHandle>,
// pub emissive_texture: Option<Arc<Texture>>,
// pub emissive_sampler: Option<SamplerHandle>,
// pub emissive_factor: [f32; 3],
// pub alpha_mode: gltf::material::AlphaMode,
// pub alpha_cutoff: f32,
// pub double_sided: bool,
}