Jump to content
  • Advertisement
Sign in to follow this  

Update instance data

This topic is 2075 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 am looking for feedback and information on how one should handle instance data. I am using DirectX 11, but it's the theory I'm interesting in and not the actual implementation.


This is my current setup:


  1. Game class with Update() and Draw() methods.'
  2. An array with GameObjects
  3. GameObject has Update() to recalculate a transform matrix and Draw() to pass the matrix and a mesh name to a RenderManager
  4. RenderManager has a list of mesh names, each name has its own list of transform matrices (one matrix per instance to draw)
  5. For each name I loop through all matrices and copy their data to an array of type InstanceData
  6. This InstanceData array is a subresource of an ID3D11Buffer
  7. After all copying is done the buffer is updated with Map/Unmap and memcpy
  8. I then DrawIndexedInstanced() using the mesh VertexBuffer, IndexBuffer and the InstanceDataBuffer 


This is what I came up with on my own using the knowledge I already had on the subject and looking up things when I needed to. Now I'm interested in hearing what I've done wrong and how to improve it. I'm interested in your opinions and any recommended reading on the subject.


I am mostly concerned with point number 5, which at the moment is a constant reorganizing of an array. How should I go about in improving this?


Thanks for reading

Share this post

Link to post
Share on other sites

it sounds ok'ish, there is nothing particularly bad.


some improvements:

-instead of having a temporary copy of the transform matrices, you could rather group your game objects already by the render mesh name. then you'd process those in one go, fill immediately the InstanceData and when you're done with them, you'd invoke the drawcall.

-it's common in games to have most of the data unchanged, just some objects are dynamic, if you could figure out which objects don't change, you could just re-use the instancedata buffer from the last frame with no update etc. needed

Share this post

Link to post
Share on other sites

Thanks a lot for your input, I will definitely try your suggestion of processing objects based on mesh or in other groups that makes sense. It's good to know I'm not completely off the mark so I will build on what I have for now.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!