Reputation: 4429
Suppose I have a single buffer of instance data for 2 different groups of instances (ie, I want to draw them in separate draw calls because they use different textures). How do I set up the offsets to accomplish this? IASetVertexBuffers
and DrawIndexedInstanced
both have offset parameters and its not clear to me which ones I need to use. Also, DrawIndexedInstanced
isn't exactly clear if the offset value is in bytes or not.
Upvotes: 2
Views: 2262
Reputation: 13003
Those offsets works independently. You can offset either in ID3D11DeviceContext::IASetVertexBuffers or in ID3D11DeviceContext::DrawIndexedInstanced or in both (then they will combine).
ID3D11DeviceContext::IASetVertexBuffers accepts offset in bytes:
bindedData = (uint8_t*)data + sizeof(uint8_t) * offset
ID3D11DeviceContext::DrawIndexedInstanced accepts all offsets in elements (indices, vertices, instances). They are just values added to indices. Vertex and instance offsets works independently. Index offset also offsets vertices and instances (obviously):
index = indexBuffer[i] + StartIndexLocation
indexVert = index + BaseVertexLocation
indexInst = index + StartInstanceLocation
I prefer offsetting in draw call:
Instead of splitting rendering to two draw calls, you can merge your texture resources and draw all in one draw call:
Hope it helps!
Upvotes: 2