pebble/wgpu/
material_instance.rs1use crate::{assets::storage::RawAssetHandle, wgpu::samplers::SamplerKind};
2
3pub enum ParamValue {
8 Texture(RawAssetHandle),
9 TextureArray(RawAssetHandle),
12 Cubemap(RawAssetHandle),
13 Sampler(SamplerKind),
14 Float(f32),
15 Vec4([f32; 4]),
16 Bytes(Vec<u8>),
19}
20
21pub struct MaterialInstanceDescriptor {
25 pub material: RawAssetHandle,
26 pub params: Vec<(&'static str, ParamValue)>,
27}
28
29impl MaterialInstanceDescriptor {
30 pub fn new(material: RawAssetHandle) -> Self {
31 Self {
32 material,
33 params: Vec::new(),
34 }
35 }
36
37 pub fn with_texture(mut self, name: &'static str, handle: RawAssetHandle) -> Self {
38 self.params.push((name, ParamValue::Texture(handle)));
39 self
40 }
41 pub fn with_texture_array(mut self, name: &'static str, handle: RawAssetHandle) -> Self {
42 self.params.push((name, ParamValue::TextureArray(handle)));
43 self
44 }
45 pub fn with_cubemap(mut self, name: &'static str, handle: RawAssetHandle) -> Self {
46 self.params.push((name, ParamValue::Cubemap(handle)));
47 self
48 }
49 pub fn with_sampler(mut self, name: &'static str, kind: SamplerKind) -> Self {
50 self.params.push((name, ParamValue::Sampler(kind)));
51 self
52 }
53 pub fn with_float(mut self, name: &'static str, value: f32) -> Self {
54 self.params.push((name, ParamValue::Float(value)));
55 self
56 }
57 pub fn with_vec4(mut self, name: &'static str, value: [f32; 4]) -> Self {
58 self.params.push((name, ParamValue::Vec4(value)));
59 self
60 }
61
62 pub fn with_bytes(mut self, name: &'static str, bytes: Vec<u8>) -> Self {
63 self.params.push((name, ParamValue::Bytes(bytes)));
64 self
65 }
66}