I've been writing Direct3D11 code using a vertex shader and pixel shader, a vertex buffer, an index buffer, an instance buffer, and a constant buffer. At one point I had everything working, but I didn't commit my code then and I was trying out other stuff.
I've recently been having problems transferring the instance data to the vertex shader.
Using the Visual Studio Graphics Debugger, which is awesome, I've figured out that even though I'm calling this:
D3DDeviceContext->DrawIndexedInstanced(12U, 8U, 0U, 0U, 0U);
the instance data floats in the vertex shader are all 0.0f's...
Here's the thing though: it was working before, without an index buffer. Now, with the index buffer, no instance data is copied???
Do you know what could cause this?
I figured out what the problem was, finally, and I will tell it here. Thanks to MooseBoys for pointing out why!
My problem was here:
unsigned int strides[] = { sizeof(Vertex), sizeof(Instance) };
unsigned int offsets[] = { 0U, 0U };
D3DDeviceContext->IASetVertexBuffers(0U, 2U, &VertexBuffer, strides, offsets);
I should have done:
unsigned int strides[] = { sizeof(Vertex), sizeof(Instance) };
unsigned int offsets[] = { 0U, 0U };
ID3D11Buffer* VertexBuffers[] = { VertexBuffer, InstanceBuffer };
D3DDeviceContext->IASetVertexBuffers(0U, 2U, VertexBuffers, strides, offsets);
Lesson learned: thoroughly look at the documentation for the function on whatever line the code breaks on...