Added code example directly

I added this in case the link breaks.
pull/305/head
sotrh 2 years ago committed by GitHub
parent 4368358033
commit ed202350b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -185,9 +185,26 @@ wgpu::VertexBufferLayout {
}
```
While this is definitely nice, because the result of `vertex_attr_array` is a temporary value, some tweak is required to return it from a function (e.g. changing the lifetime on `wgpu::VertexBufferLayout` to `'static`, or [make it `const`](https://github.com/gfx-rs/wgpu/discussions/1790#discussioncomment-1160378)).
While this is definitely nice, Rust sees the result of `vertex_attr_array` is a temporary value, so a tweak is required to return it from a function. We could change the lifetime on `wgpu::VertexBufferLayout` to `'static`, or [make it `const`](https://github.com/gfx-rs/wgpu/discussions/1790#discussioncomment-1160378). You can see an example below:
```rust
impl Vertex {
const ATTRIBS: [wgpu::VertexAttribute; 2] =
wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3];
fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
use std::mem;
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &Self::ATTRIBS,
}
}
}
```
Beyond that, I feel it's good to show how the data gets mapped, so I'll forgo using this macro for now.
Regardless I feel it's good to show how the data gets mapped, so I'll forgo using this macro for now.
</div>

Loading…
Cancel
Save