encase
encase copied to clipboard
Vertex buffers
I am currently trying to use encase
with wgpu
, but got a bit confused when I tried to use it for vertex buffers.
As far as I could tell, the only difference between StorageBuffer
and UniformBuffer
is that UniformBuffer
calls assert_uniform_compat
.
So if I need to make a vertex buffer, am I supposed to just use StorageBuffer
?
(worked fine so far by the way)
Vertex buffers are a bit tricky to fit into the current design since they have a couple more limitations but also offer more flexibility at the same time. Only scalars and vectors should be allowed and there are also 8 bit and 16 bit variants that get mapped automatically to 32 bit ones in the shader.
I experimented with adding support for them a while ago but don't have anything concrete yet.
Do note that using the existing uniform/storage buffer warpers for this might not always work since vertex buffer items are tightly packed.
I'd personally use bytemuck (for vertex buffers) for now since there is no extra padding needed for them.
Thanks for the explanation, will do.
I'd personally use bytemuck (for vertex buffers) for now since there is no extra padding needed for them.
Sorry for necrobump, but is there currently a solution for index buffers? As far as I know, if you have index buffer of u16 values for example, you need to pad them correctly. Casting arbitrarily sized index array through bytemuck can fail unlike vertex buffer.
Edit: Well I scrapped something for this case and it seems to work:
pub fn pad_index_buffer(buffer: &[u16]) -> Vec<u16> {
let s = buffer.len() % 4;
let mut gg = buffer.to_vec();
if s > 0 {
for _ in 0..s {
gg.push(0);
}
}
gg
}
@kaphula &[u16]
to &[u8]
via bytemuck should work, the reverse might not (if the size is odd).