Jump to content


Management of Render States & Materials


3 replies to this topic

#1 Enlight

    New Member

  • Members
  • PipPip
  • 26 posts

Posted 11 July 2007 - 02:13 PM

I'm working on my 3d engine, and right now I'm at the render states & material management.

I have a Material class that manage texture samplers, pixel, vertex shaders and material properties.

Also I have another class named RenderState that manages fillmodes, z compare function, etc.

I was wondering if the Material class should include ALL render states INSIDE and remove completely the RenderState class.

After all, the material class should manage how the objects are rendered and how they look like, and the RenderState class is taking a big part on the render output.

What do you think? it is convenient ?

#2 Dim_Yimma_H

    Member

  • Members
  • PipPip
  • 49 posts

Posted 11 July 2007 - 04:20 PM

That sounds a bit like merging two classes into one. My opinion is that merging classes usually results in more complex code, unless their previous design was rushed and seriously flawy of course. Separating classes into smaller parts might be useful on the other hand as the engine is growing, to keep the code in overviewable blocks.

RenderState seems like a separate module to me, it contains how the material is rendered, the state that should do the rendering. Your Material class contains what the material is, though it can be discussed whether shaders are part of the material or if they specify how the material properties are rendered.

If I were you (which I'm not, of course), I would let the rendering module take both the Material and RenderState, to keep the code reasonably modularized and avoid refactoring bugs. That's just my opinion though.

Out of curiosity, do you have a separate renderer or do you let the Material class do the rendering of itself?

#3 Enlight

    New Member

  • Members
  • PipPip
  • 26 posts

Posted 11 July 2007 - 07:04 PM

Dim_Yimma_H said:

Out of curiosity, do you have a separate renderer or do you let the Material class do the rendering of itself?

No, the Material class does not perform any draw calls, just configure the rendering pipeline for the draw calls that will follow the material activation.

I've got your point, but, my confusion begins when, FXs, like (cgFX) or HLSL .fx files already configure the render states of the device for multi-pass materials. So, in that case, who is responsible for setting render states?, the material (by using an FX file) and/or the RenderState class?. It looks like both classes responsibilities are mixed up.

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 12 July 2007 - 02:50 AM

Where I work, we have an engine architecture where render states and CgFX shaders are combined. There are a set of defined defaults for render states and each shader is responsible for setting whatever states it needs (that are different from default) before drawing, then resetting them back to default after drawing.

Basically, it makes sense for all the state changes required for drawing a particular material - render state changes, vertex/fragment programs and VP/FP constants - all to be in the same place.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users