DynamicIndexBuffer stride should be 4 but is 2

(Abovegame) #1

Since i’ve asked on the discord and got no response i think i should probably do it here now.

I have a terrain mesh render plugin which uses a vertex and an index buffer. The index buffer holds u16 type values. Now just out of curiosity i tried making a bigger terrain so i had to switch to u32 and for some reason i don’t even get the terrain rendered correctly. So what’s up with that ?

I asked around on the Rust Community discord and a few guys helped me out and we concluded that the index buffer is read by 2 bytes meaning u16. What it would do is after each element of the index buffer add a zero ( which is probably the other 2bytes ). This doesn’t make my terrain render correctly. For those who have used renderdoc this is called a stride in there, which in my case is 2 but should be 4.

Now they’ve pointed out to me there’s like a setter function which is used directly when creating the pipeline with the wgpu, and it is this.

As far as rendy goes i’m using the DynamicIndexBuffer. This is a wrapper two to types of which the second is called IndexData<B,T>. Now there are two methods corresponding to this ( actually the same method for different types ) and that is bind. These two exist for IndexData<B,u16> and IndexData<B,u32> (notice that the u16 takes 3 arguments and u32 takes 4).

Now i assume rustc is smart enough to infer the type hence the method, and it won’t let me call the u32 method for some reason even if i explicitly declare the index buffer as DynamicIndexBuffer<B, u32>.

This is too much text and honestly i don’t think i should write a paragraph for this, basically i need my stride to be 4 and that’s all. If there’s another method similar to the wgpu’s please let me know.

Just to make this perfectly clear my index buffer is flawless so don’t dig around it.