-1

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?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Andrew
  • 5,839
  • 1
  • 51
  • 72
  • Honestly, this is a fairly bad question because there's basically no useful code shown, so nobody else could even attempt to figure out the problem. – Puppy Apr 25 '15 at 10:31
  • I edited out a bunch of irrelevant stuff after the answer was pointed out. I had thought it was relevant at the time, but it wasn't. And actually, I would have to disagree: anyone who commits this same error that I have will likely find this question in the search results. – Andrew Apr 25 '15 at 10:39

1 Answers1

1

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...

Andrew
  • 5,839
  • 1
  • 51
  • 72
  • 1
    The third parameter to `IASetVertexBuffers` expects an array of `ID3D11Buffer*`s. By moving the buffers around in your class, you probably accidentally fixed the problem by making them adjacent in memory. What you should be doing is explicitly defining which buffers you want to bind, i.e. `ID3D11Buffer* vbs[] = {VertexBuffer, SomeOtherVertexBuffer}; con->IASetVertexBuffers(0, 2, vbs, ...);`. – MooseBoys Apr 24 '15 at 23:48