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