-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Managed to make the derive macro work not required const ATTRIBUTES def.
- Loading branch information
1 parent
f1c819c
commit e4ac6c9
Showing
8 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "internals" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wgpu = "22.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
pub trait ConstFormat { | ||
const FORMAT: wgpu::VertexFormat; | ||
} | ||
|
||
pub const fn format_of<T: ConstFormat>() -> wgpu::VertexFormat { | ||
T::FORMAT | ||
} | ||
/// Defines the default VertexFormat of a particular type. | ||
/// By defining it using | ||
/// `````` | ||
/// const_format_of!(MyVec3 => VertexFormat::Float32x3) | ||
/// ``` | ||
/// | ||
/// You can then use its format with the following call | ||
/// ``` | ||
/// let vertex_format: wgpu::VertexFormat = format_of::<MyVec3>(); | ||
/// ``` | ||
/// | ||
/// And use this in conjunction with VertexAttributeArray macro | ||
/// ``` | ||
/// #[derive(VertexAttributeArray)] | ||
/// struct MyVertexBuffer{ | ||
/// pos: MyVec3, | ||
/// } | ||
macro_rules! const_format_of { | ||
($T:ty => $format:expr) => { | ||
impl ConstFormat for $T { | ||
const FORMAT: wgpu::VertexFormat = $format; | ||
} | ||
}; | ||
} | ||
|
||
const_format_of!(f32 => wgpu::VertexFormat::Float32); | ||
const_format_of!([f32; 2] => wgpu::VertexFormat::Float32x2); | ||
const_format_of!([f32; 3] => wgpu::VertexFormat::Float32x3); | ||
const_format_of!([f32; 4] => wgpu::VertexFormat::Float32x4); | ||
const_format_of!(u32 => wgpu::VertexFormat::Uint32); | ||
const_format_of!([u32; 2] => wgpu::VertexFormat::Uint32x2); | ||
const_format_of!([u32; 3] => wgpu::VertexFormat::Uint32x3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters