diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 6ab13f2d0cb345795f761181a06777ade61ff09c (patch) | |
tree | 42007acef9846d5e79f1bf418a96647f34b530d1 /stockton-render/src/draw/texture/resolver.rs | |
parent | ccf0074b08ce835cf22e7d46153d1cb3f3d06d32 (diff) |
refactor(all): separate rendering from framework
stockton-passes is mostly just a stand-in until this is
properly separated
Diffstat (limited to 'stockton-render/src/draw/texture/resolver.rs')
-rw-r--r-- | stockton-render/src/draw/texture/resolver.rs | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/stockton-render/src/draw/texture/resolver.rs b/stockton-render/src/draw/texture/resolver.rs deleted file mode 100644 index 4b61c41..0000000 --- a/stockton-render/src/draw/texture/resolver.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Resolves a texture in a BSP File to an image - -use crate::draw::texture::image::LoadableImage; -use stockton_levels::{parts::IsTexture, prelude::HasTextures}; - -use std::{ - path::Path, - sync::{Arc, RwLock}, -}; - -use image::{io::Reader, RgbaImage}; - -/// An object that can be used to resolve a texture from a BSP File -pub trait TextureResolver { - type Image: LoadableImage; - - /// Get the given texture, or None if it's corrupt/not there. - fn resolve(&mut self, texture_id: u32) -> Option<Self::Image>; -} - -/// A basic filesystem resolver which gets the texture name from any HasTextures Object. -pub struct FsResolver<'a, T: HasTextures> { - path: &'a Path, - map_lock: Arc<RwLock<T>>, -} - -impl<'a, T: HasTextures> FsResolver<'a, T> { - pub fn new(path: &'a Path, map_lock: Arc<RwLock<T>>) -> Self { - FsResolver { path, map_lock } - } -} - -impl<'a, T: HasTextures> TextureResolver for FsResolver<'a, T> { - type Image = RgbaImage; - - fn resolve(&mut self, tex: u32) -> Option<Self::Image> { - let map = self.map_lock.read().unwrap(); - let tex = map.get_texture(tex)?; - let path = self.path.join(&tex.name()); - - // drop(tex); - // drop(map); - - if let Ok(file) = Reader::open(path) { - if let Ok(guessed) = file.with_guessed_format() { - if let Ok(decoded) = guessed.decode() { - return Some(decoded.into_rgba8()); - } - } - } - - log::warn!("Couldn't resolve texture {:?}", tex.name()); - None - } -} |