Jump to content
  • Advertisement
Sign in to follow this  
DXnut

Drawing instanced meshes

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried to create hardware instancing, where the stream 1 data contains the instancing data, but when I draw the mesh (pMesh->DrawSubset(i)) it is drawn all over the screen. I am doing this for the draw:
pDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | numInstances);
pDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul);

// set declaration to include mesh vertex + stream 1 data
pDevice->SetVertexDeclaration(mHW_STREAM_Stream1.mVDecl);

for all subsets
pMesh->DrawSubset(i);


I suspect that this is not possible for a mesh object, since it will do an internal SetVertexDeclaration() call, and my stream 1 buffer will never make it to the shader (so the shader is getting zeroes or garbage for the SRT matrix data). So, I will have to revert to drawing it manually with DrawIndexedPrimitive for all of my subsets using the attribute buffer to draw each subset. Is this true? It will be a more work to draw the subsets manually this way, but at least I am optimizing the mesh first to make it easier. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Have you checked the instancing demo/sample in the SDK? That should probably be your text-book example of what can/can't be done. If it avoids ID3DXMesh then, yeah, probably not compatible.

Also, re-implementing DrawSubset() isn't actually that difficult. In all truth, re-implementing much of ID3DXMesh wouldn't take more than a couple of days provided you were happy with some simple limitations (and/or knew what you wanted to use it for). Even the nice tricks like cloning and optimizing can be done via other D3DX calls ....

hth
Jack

Share this post


Link to post
Share on other sites
Thanks. I am basing my changes on that SDK sample. Since they just create a simple 8 vertex box manually, I did not know if it would work with a mesh, but since I am adding this functionality to my mesh modeling program I figured I would try it. I got it to work with the Constants technique now, which has no changes to the vertex buffer. But for the Hardware and Stream techniques, that use stream 1 data, I think I am going to have to do it manually. Actually, it won't take me more than an hour or two to do it. I just wanted to know if it was possible to just use the DrawSubset functionality of the ID3DXMesh interface to do it, and I was missing something.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!