use super::Loadable;
use crate::{
assets::{Id, loader::Loader},
context::ContextInner,
};
#[non_exhaustive]
pub struct ShaderLoader;
impl Loader<Shader> for ShaderLoader {
const EXTENSION: &'static str = "wgsl";
#[inline]
fn load(bytes: &[u8], _id: &Id) -> Shader {
let shader_source = String::from_utf8_lossy(bytes);
Shader(shader_source.to_string())
}
}
#[derive(Clone)]
pub struct Shader(String);
impl Loadable for Shader {
fn load_if_exists(id: &Id, ctx: &mut ContextInner) -> Option<Self>
where
Self: Sized,
{
let shader = ctx.asset_source.load_if_exists::<ShaderLoader, _>(id)?;
ctx.graphics.upload_shader(id, shader.0.clone());
Some(shader)
}
}