8个版本 (1个稳定版)
1.0.0 | 2022年9月8日 |
---|---|
0.21.31 |
|
0.3.0 | 2022年8月30日 |
0.2.2 | 2022年8月28日 |
0.1.2 | 2022年8月20日 |
在 图形API 中排名第 580
42KB
437 代码行
WRLD (Wgpu Rust语言描述符)
WRLD是一组derive宏,使得编写wgpu代码变得简单、愉快且更安全。
WRLD的描述基于Learn wgpu教程。
动机
创建wrld的主要原因是使用一个宏来创建VertexBufferLayout,该宏支持所有wgpu原生支持的类型。
然而,随着我对其的开发,我越来越看到可以实施但wgpu不支持的功能。
入门
要开始使用wrld,只需在cargo.toml依赖中添加wrld
wrld = "Your version"
就是这样。
示例
基本的Rust结构。
struct Test {
position: [f32; 2],
color: [f32; 4]
}
使用WRLD
use wrld::Desc;
#[repr(C)]
#[derive(Desc)]
struct Test {
#[f32x2(0)] position: [f32; 2],
#[f32x4(1)] color: [f32; 4]
}
// or
#[repr(transparent)]
#[derive(Desc)]
struct TestTransparent {
#[f32x2(0)] position: f32,
#[f32x4(1)] color: f32
}
将生成
impl Test {
pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
wgpu::VertexBufferLayout {
// let size_f32 = size_of::<f32>() = 4
// let f32x2 = size_f32 * 2 = 8;
// let f32x4 = size_f32 * 4 = 16;
// let array_stride = 8 + 16 = 24;
array_stride: 24 as wgpu::BufferAddress // array_stride variable,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
wgpu::VertexAttribute {
offset: 0u64,
format: wgpu::VertexFormat::Float32x2,
shader_location: 0u32,
},
wgpu::VertexAttribute {
offset: 8u64,
format: wgpu::VertexFormat::Float32x4,
shader_location: 1u32,
},
],
}
}
}
更新日志
依赖项
~5–18MB
~243K SLoC