mono / VulkanSharp

Open source .NET binding for the Vulkan API
MIT License
538 stars 61 forks source link

CmdDrawIndexed not drawing as expected #74

Closed Amatsugu closed 6 years ago

Amatsugu commented 6 years ago

I've been following the Vulkan Tutorial and I implemented an index buffer and noticed that it does not draw my vertices correctly. It seems to be drawing in the reverse order. My vertices

private Vertex[] vertices = new Vertex[]
{
    new Vertex(new float[] { -0.5f, -0.5f }, new float[] { 1.0f, 1.0f , 1.0f }),
    new Vertex(new float[] {  0.5f, -0.5f }, new float[] { 255/255f, 0.0f , 100/255f }),
    new Vertex(new float[] {  0.5f,  0.5f }, new float[] { 0.0f, 1.0f , 1.0f }),
};

My indices

private readonly int[] indices = new[]
{
    0, 1, 2
};

Everything draws correctly when using CmdDraw, but it wont draw properly (with the correct front face) when I use CmdDrawIndexed unless i reverse my indices.

Here is the full code: Command Buffers Initialize Pipeline Creation Vertex/Index Buffer Creation

I'm not sure why it's not working, I couldn't find any obvious errors with my code, so I decided to post here.

TillAlex commented 6 years ago

The indices array in your post differs from that in your code. Which one are you using?

Amatsugu commented 6 years ago

The ones I posted, the ones in my code is the reversed order to try to make sense of what may be happening, but I was only able to get one triangle rendered with that method.

TillAlex commented 6 years ago

I think the problem is in this line:

commandBuffers[i].CmdBindIndexBuffer(indexBuffer, 0, IndexType.Uint16);

You are using an int array for indices. The IndexType should be Int32 in this case. You could also change the array to ushort[].

Amatsugu commented 6 years ago

Thanks. That was infact the issue. Guess a validation layer won't catch an issue like this. I'll have to be more careful.