# mesh data structures

## Recommended Posts

##### Share on other sites
To avoid changing device state with every object you need to sort your list by the state changes they need performed. You usually want to sort by shader (if you use any) and texture at least, so if you have some sort of abstracted material class for your objects you can probably just sort by material.

I'm guessing you'll need to refactor your code a fair bit to make this possible if the object's render method just sets state using DX calls.
I'm dont really know much details on how to do things in DirectX though (I'v pledged my soul to OpenGL), but I know it has some sort of state blocks you can use to set multiple states at once. Is it possible to just add a query function to your object's interface that will get its device state, and then use that to sort?

##### Share on other sites
The trouble is, an object doesn't necessarily have just one device state: it
may use multiple textures etc. otherwise sorting objects into a tree of device
states would be simple. I can't imagine that the solution to this problem is
to confine an object to a single device state--this would severely limit the
complexity of 3d models I could use (the most obvious limit being that each model
could consist of only one texture.

##### Share on other sites
The easy way around this is to just sort on the object's entire set of textures, not each individual texture. Also, you can do the same for constants.

I have found that the easiest way to do this is to make a scenegraph that has a tree-like structure, categorizing each entity based on its material. For clarification, a material consists of shaders, constants, and textures. So, you organize everything in a tree like this:

                     Shader1                            Shader2               |--------|--------|                 |--------|--------|           TextureSet1      TextureSet2       TextureSet3        TextureSet4       |--------|--------|      ...               ...               ...   ConstantSet1      ConstantSet2       |                 |     Entity1          Entity5     Entity2          Entity6     Entity3     Entity4

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628400
• Total Posts
2982449

• 9
• 10
• 9
• 19
• 24