سؤال

I would like to render a hierarchical model in DirectX11 for a Windows Phone app and am not sure about how to render a tree-based hierarchical model.

In OpenGL, the general flow appeared to look like: 1. Push matrix 2. Put down vertices intended for that node (through glVertex calls) 3. Recurse on the node's children 4. Pop matrix

However, I am unsure how this would look in DirectX, where it appears that it is recommended that you first copy all of your vertices and vertex indices into a large buffer and then render them using a DrawIndexed call.

This seems kind of inconvenient for a traditional hierarchical model because it would mean that I would need to perform two iterations of the same tree in order to load and display the hierarchical model. Like so: 1. Iterate through tree-structure and flatten the vertices and vertex indices into one dimensional arrays. 2. Push matrix 3. Put down vertices intended for that node (through DrawIndexed calls) 4. Recurse on the node's children (step 2) 5. Pop matrix

This feels sort of messy and I'm not sure if it's meant to be like this.

I know this is a general question but an explanation or correction would do wonders for my understanding of DX.

Thanks for your time.

هل كانت مفيدة؟

المحلول

You can use the same approach you described for OpenGL with Direct3D. Iterate the tree and for each node bind its vertex and index buffers and draw immediately.

Performance wise it may be better, as you suggested, to iterate the tree first without drawing anything and only writing the vertex and index data into two large buffers. Then for every frame set the buffers and iterate the tree, just as you would do in OpenGL. For every node bind the transformation and draw the associated primitive range from the already bound buffers.

If the geometry is static at the vertex level (no individual vertices have to be modified / added / deleted) you can reuse the buffers as often as you like.

Depending on your requirements and hardware you would have to do some profiling to find the best method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top