mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-14 11:28:42 -06:00
shader macro code
This commit is contained in:
parent
88a767368b
commit
ae58706f10
1
kubi/shaders/colored.wgsl
Normal file
1
kubi/shaders/colored.wgsl
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//TODO migrate
|
|
@ -4,34 +4,37 @@ use super::Renderer;
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct Shaders {
|
pub struct Shaders {
|
||||||
pub world: wgpu::ShaderModule
|
pub world: wgpu::ShaderModule,
|
||||||
|
pub colored: wgpu::ShaderModule
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! shaders {
|
macro_rules! upload_shaders {
|
||||||
{($renderer: expr, $dir: literal), $($name: ident : $path: literal),*} => {
|
{$container: ident [$renderer: expr, $dir: literal] { $($name: ident : $path: literal $(,)*),* } } => {{
|
||||||
{
|
//ensure types
|
||||||
use super::Renderer;
|
let _: &super::Renderer = $renderer;
|
||||||
let renderer: &Renderer = $renderer;
|
let _: &str = $dir;
|
||||||
$(
|
$( let _: &str = $path; )*
|
||||||
let $name = {
|
$container {
|
||||||
let _is_string_literal: &str = $path;
|
$($name: {
|
||||||
let shader_descriptor = wgpu::include_wgsl!(concat!($dir, "/", $path));
|
let source = include_str!(concat!($dir, "/", $path)).into();
|
||||||
renderer.device.create_shader_module(shader_descriptor)
|
let descriptor = wgpu::ShaderModuleDescriptor {
|
||||||
|
label: Some(stringify!($name)),
|
||||||
|
source: wgpu::ShaderSource::Wgsl(source),
|
||||||
};
|
};
|
||||||
)*
|
$renderer.device.create_shader_module(descriptor)
|
||||||
Shaders {
|
},)*
|
||||||
$($name,)*
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_shaders(
|
pub fn compile_shaders(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
) {
|
) {
|
||||||
let renderer = &storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
let renderer = &storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
||||||
shaders! {
|
let shaders = upload_shaders! {
|
||||||
(renderer, "../../shaders"),
|
Shaders [renderer, "../../shaders"] {
|
||||||
world: "world.wgsl"
|
world: "world.wgsl",
|
||||||
|
colored: "colored.wgsl"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue