mesh data structures
So I've begun working with loading in meshes from .x files, and drawing a whole
bunch of mesh objects to the screen at once. The simple--and, from an
optimization standpoint, terrible--system that I've cobbled together to do this
is a linked list of objects, where each object can load in, render, and destroy
a mesh. My render routine then just loops through this list of objects and
calls each object's personal render subroutine.
The trouble is, because each object sets its own device state, I have no way to
batch my data. I've been told that the best way to manage this is to use a tree,
rather than a linked list, but I don't see how to implement this. I could
organize the data within each object into a tree structure, but this would still
mean completely reconfiguring the device for each object I render. I can't
create a tree of objects because each object itself may consist of many
textures/parameters etc. I could store all my information about every object
into one, giant tree of data points, but this eliminates the boundary between
objects; I don't see how I would then be able to modify an object once I had
loaded it into the tree (all of its data would get spread out throughout the tree,
becoming effectively irrecoverable for modification).
Am I missing something obvious? Thanks in advance for any advice you can
give me.
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?
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?
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.
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.
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:
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement