• Advertisement
Sign in to follow this  

State changes

This topic is 4523 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

Hello all. I'm busy making a small simple OO 3d rendering engine using OGL and D3D. I use a singeton class called 'Renderer' that can be either the D3D renderer of the OGL renderer, so my other classes don't have to worry about that. I'd like to make this Renderer as high level as possible, but still flexible enough to do lots of different things. I've started giving the Renderer class some high level functions. Two of them are: 'bindMaterial' that binds textures and lightning parameters (maybe vertex and fragment programs later. ...and 'drawMesh' that draws a mesh defined by faces (with indexed verts and a material per face). My problem is that all faces can have different materials which would cause a lot of state changes and burn up CPU in drawMesh when it has to check every face for the material and then change it all te time for different materials. It sounds like a good idear to sort all the faces to be redered by material, but that would break up my Mesh structure. Has anyone got some good suggestions? Thanx a lot! Marty

Share this post


Link to post
Share on other sites
Advertisement
Marty,

You're absolutely correct in your assessment. What you're referring to is often referred to as either segments or clusters in modeling packages. Most packages put all of their vertices into a single large vertex buffer and then break up the actual triangles into index lists, 1 list for each material on the model. So each face on your mesh would go into one of the index lists, depending on which material it had.

With that being said, depending on the changes within your material, you might actually need multiple vertex buffers, one per segment. For example, if one of your materials has two UV coordinate pairs or is skinned, its going to need different data than the rest of the materials, which may only have a single UV coordinate and no skinning.

Ideally, you dont want to create unneeded vertex buffers, so use index lists whenever possible to render faces with the same material. Ultimately, however, you must do something. DrawPrimitive calls on DirectX is one of the most expensive calls you can make, and changing render or texture stage states is almost as expensive. Batch whenever possible.

Cheers!
Jeromy

Share this post


Link to post
Share on other sites
Thanx!

So it would be a good idear to have the renderer not render all the objects one by one, but all the materials one by one.
Then i'd have to load the models and materials, determine which models are to be rendered and then push the faces to the renderer class to different lists (one list for each material).
Finally render one list at a time to minimize state changes.

I load .3ds models and they just have a large array of vertexes and faces for each object in the model. Then there is a list with materials and one with the faces that have this material assigned to them.
What I have to send to the renderer class must then be face list from the different materials...

Does this sound right?

Thanx again,
Marty

Share this post


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

  • Advertisement