blade_graphics/
derive.rs

1use std::mem;
2
3use super::{ResourceIndex, ShaderBinding, VertexFormat};
4
5pub trait HasShaderBinding {
6    const TYPE: ShaderBinding;
7}
8impl<T: bytemuck::Pod> HasShaderBinding for T {
9    const TYPE: ShaderBinding = ShaderBinding::Plain {
10        size: mem::size_of::<T>() as u32,
11    };
12}
13impl HasShaderBinding for super::TextureView {
14    const TYPE: ShaderBinding = ShaderBinding::Texture;
15}
16impl HasShaderBinding for super::Sampler {
17    const TYPE: ShaderBinding = ShaderBinding::Sampler;
18}
19impl HasShaderBinding for super::BufferPiece {
20    const TYPE: ShaderBinding = ShaderBinding::Buffer;
21}
22impl<'a, const N: ResourceIndex> HasShaderBinding for &'a super::BufferArray<N> {
23    const TYPE: ShaderBinding = ShaderBinding::BufferArray { count: N };
24}
25impl<'a, const N: ResourceIndex> HasShaderBinding for &'a super::TextureArray<N> {
26    const TYPE: ShaderBinding = ShaderBinding::TextureArray { count: N };
27}
28impl HasShaderBinding for super::AccelerationStructure {
29    const TYPE: ShaderBinding = ShaderBinding::AccelerationStructure;
30}
31
32pub trait HasVertexAttribute {
33    const FORMAT: VertexFormat;
34}
35
36impl HasVertexAttribute for f32 {
37    const FORMAT: VertexFormat = VertexFormat::F32;
38}
39impl HasVertexAttribute for [f32; 2] {
40    const FORMAT: VertexFormat = VertexFormat::F32Vec2;
41}
42impl HasVertexAttribute for [f32; 3] {
43    const FORMAT: VertexFormat = VertexFormat::F32Vec3;
44}
45impl HasVertexAttribute for [f32; 4] {
46    const FORMAT: VertexFormat = VertexFormat::F32Vec4;
47}
48impl HasVertexAttribute for u32 {
49    const FORMAT: VertexFormat = VertexFormat::U32;
50}
51impl HasVertexAttribute for [u32; 2] {
52    const FORMAT: VertexFormat = VertexFormat::U32Vec2;
53}
54impl HasVertexAttribute for [u32; 3] {
55    const FORMAT: VertexFormat = VertexFormat::U32Vec3;
56}
57impl HasVertexAttribute for [u32; 4] {
58    const FORMAT: VertexFormat = VertexFormat::U32Vec4;
59}
60impl HasVertexAttribute for i32 {
61    const FORMAT: VertexFormat = VertexFormat::I32;
62}
63impl HasVertexAttribute for [i32; 2] {
64    const FORMAT: VertexFormat = VertexFormat::I32Vec2;
65}
66impl HasVertexAttribute for [i32; 3] {
67    const FORMAT: VertexFormat = VertexFormat::I32Vec3;
68}
69impl HasVertexAttribute for [i32; 4] {
70    const FORMAT: VertexFormat = VertexFormat::I32Vec4;
71}
72
73impl HasVertexAttribute for mint::Vector2<f32> {
74    const FORMAT: VertexFormat = VertexFormat::F32Vec2;
75}
76impl HasVertexAttribute for mint::Vector3<f32> {
77    const FORMAT: VertexFormat = VertexFormat::F32Vec3;
78}
79impl HasVertexAttribute for mint::Vector4<f32> {
80    const FORMAT: VertexFormat = VertexFormat::F32Vec4;
81}
82impl HasVertexAttribute for mint::Vector2<u32> {
83    const FORMAT: VertexFormat = VertexFormat::U32Vec2;
84}
85impl HasVertexAttribute for mint::Vector3<u32> {
86    const FORMAT: VertexFormat = VertexFormat::U32Vec3;
87}
88impl HasVertexAttribute for mint::Vector4<u32> {
89    const FORMAT: VertexFormat = VertexFormat::U32Vec4;
90}
91impl HasVertexAttribute for mint::Vector2<i32> {
92    const FORMAT: VertexFormat = VertexFormat::I32Vec2;
93}
94impl HasVertexAttribute for mint::Vector3<i32> {
95    const FORMAT: VertexFormat = VertexFormat::I32Vec3;
96}
97impl HasVertexAttribute for mint::Vector4<i32> {
98    const FORMAT: VertexFormat = VertexFormat::I32Vec4;
99}