diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-27 20:28:24 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-27 20:46:16 +0200 |
| commit | ee6e010611433f0aad53e3c99571b8a8c6ca13f4 (patch) | |
| tree | 06ff656f764114361ae07f42d4be208d42d5c1c1 /engine/src/rendering | |
| parent | 749303f2bab1b2b374f7b837cc75acf65067699e (diff) | |
refactor(engine): make asset importers per asset type
Diffstat (limited to 'engine/src/rendering')
| -rw-r--r-- | engine/src/rendering/shader.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs index 085773b..061d9ac 100644 --- a/engine/src/rendering/shader.rs +++ b/engine/src/rendering/shader.rs @@ -22,6 +22,7 @@ use shader_slang::{ }; use crate::asset::{ + Asset, Assets, Event as AssetEvent, Handle as AssetHandle, @@ -53,6 +54,8 @@ pub struct ModuleSource pub link_entrypoints: EntrypointFlags, } +impl Asset for ModuleSource {} + bitflags! { #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub struct EntrypointFlags: usize @@ -1262,12 +1265,16 @@ struct VarInput<'a> index: usize, } -fn import_slang_asset( +fn import( asset_submitter: &mut AssetSubmitter<'_>, file_path: &Path, settings: Option<&'_ Settings>, ) -> Result<(), ImportError> { + if file_path.extension().is_none_or(|ext| ext != "slang") { + return Err(ImportError::UnsupportedFileType); + } + let file_name = file_path .file_name() .ok_or(ImportError::NoPathFileName)? @@ -1295,6 +1302,9 @@ fn import_slang_asset( #[derive(Debug, thiserror::Error)] enum ImportError { + #[error("File type is unsupported")] + UnsupportedFileType, + #[error("Failed to read file")] ReadFileFailed(#[source] std::io::Error), @@ -1362,7 +1372,7 @@ fn initialize(mut assets: Single<Assets>) -> Result<(), crate::Error> { let assets = assets.get_mut()?; - assets.set_importer::<_, _>(["slang"], import_slang_asset); + assets.set_importer::<ModuleSource, Settings, ImportError>(import); Ok(()) } |
