#include <sglStatelet.hpp>
Inheritance diagram for sglStatelet::
Public Types | |
enum | StateEnum { eALPHA_TEST, eANTI_ALIAS_LINE, eANTI_ALIAS_POINT, eANTI_ALIAS_POLYGON, eBLENDING, eCOLOR_MASK, eCULL_MODE, eDEPTH_MASK, eDEPTH_RANGE, eDEPTH_TEST, eDITHERING, eFOG, eFRONT_FACE, eHIGHLIGHT, eLIGHTING, eLINE_STIPPLE, eLINE_WIDTH, eLOGIC_OP, eMATERIAL, eOCCLUSION_CULL, ePOINT_SIZE, ePOINT_PARAMETERS, ePOLY_BACK_STYLE, ePOLY_FRONT_STYLE, ePOLYGON_OFFSET, ePOLYGON_STIPPLE, eSHADE_MODEL, eTRANSFORM_MATRIX, eTRANSPARENCY, eTEX_ENV, eTEX_GEN, eTEXTURE, eTEXTURE_MATRIX, eNUM_BASIC_STATES } |
Public Methods | |
virtual | ~sglStatelet () |
virtual unsigned int | getType () const |
virtual void | apply (sglCurrState *curr_state) const=0 |
virtual bool | getSorted () const |
const void* | getSortKey () const |
unsigned int | getIndex () const |
bool | operator== (const sglStatelet &rhs) const |
virtual void | printInfo (ostream &ostrm, const char *indent_string) const |
Protected Methods | |
sglStatelet (StateEnum type) | |
Protected Attributes | |
unsigned int | m_index |
sglCullf trav_state; : vector<sglStatelet::StateEnum> sort_order; sort_order.push_back(sglStatelet::eTEXTURE); sort_order.push_back(sglStatelet::eMATERIAL); trav_state.setSortOrder(sort_order);
Note, there is no "best" sort order. The best sort order is dependent on the graphics hardware/driver and the contents of your scene. See the testTraversal program for examples of two scene graphs that work best with completely different sort orders.
Arbitrarily long sort orders can be specified but longer sort orders require more computation and quickly suffer from diminishing returns after the first two or three. Also note that some sorts are more expensive than others. Obviously, the more attributes that you sort on the more time it is going to take. You should also be aware that statelets that can take on an unlimited number of values (e.g. material, texture, etc) have a worst case O(n*logn) sort time. Statelets with a fixed number of values (e.g., any boolean statelets, polygon style, etc.) have a worst case O(n) sort time.
Implementation Notes:
This base class implements a number of the functions that the internal state sorting mechanism uses: getSorted, getSortKey, and getIndex. Each subclass is responsible for setting the m_index member variable in the sglStatelet base class. If the statelet can only take on a few distinct modes (e.g. disable or enable line anti-aliasing) then m_index should be set to a unique small unsigned integer corresponding to each unique mode. This value should start at zero and cover a contiguous set of values. If the statelet can take on a nearly infinite number of modes (e.g. RGB floating point color value), then m_index should be set to UINT_MAX. The state sorting algorithm calls the getIndex() member function to get this index, and if it is set to UINT_MAX it will sort this particular statelet by its pointer rather than the index number.
The default implementation of getSorted() is to return false indicating that the statelet should be sorted by using m_index to index into an array of possible statelets (which take on the state corresponding to that index). If m_index can be set to UINT_MAX, then that subclass must override the getSorted() function to return true. In this case the state sorting mechanism will call the getSortKey() function and sort on its return value.
Note that a given subclass can set m_index to small unsigned integers for a subset of its more common states and UINT_MAX for other states (see sglAlphaTest for an example). In this case the getSorted() function should return true and the getSortKey() will return a pointer to the statelet if m_index is UINT_MAX or a pseudo-pointer equal to m_index otherwise to make it appear that statelets of this type with the same m_index will be treated as the same state for sorting purposes.
Subclassing sglStatelet:
The following is the procedure for creating new subclasses of sglStatelet:
Add sglNormalsDisplay statelet (a la Performer) where normals are rendered along with the geometry.
Definition at line 177 of file sglStatelet.hpp.
|
The complete list of state enums in alphabetical order with the exception that all texture/multitexture states must come last. These enum values will be used as indexes into arrays of statelets (sglFullState). Definition at line 185 of file sglStatelet.hpp. |
|
virtual destructor Definition at line 238 of file sglStatelet.hpp. |
|
Get an identifier for the type of this statelet.
Reimplemented in sglMultiTextureStatelet. Definition at line 245 of file sglStatelet.hpp. |
|
Apply this state change to the current rendering state.
Reimplemented in sglFog, sglMaterial, sglAlphaTest, sglAntiAliasLine, sglAntiAliasPoint, sglAntiAliasPolygon, sglBlending, sglColorMask, sglCullMode, sglDepthMask, sglDepthRange, sglDepthTest, sglDithering, sglFrontFace, sglHighlight, sglLighting, sglLineStipple, sglLineWidth, sglLogicOp, sglOcclusionCull, sglPointSize, sglPointParameters, sglPolyBackStyle, sglPolyFrontStyle, sglPolygonOffset, sglPolygonStipple, sglShadeModel, sglTexturingStatelet, sglMultiTextureStatelet, and sglTransparency. |
|
Query the sorting mode for this statelet.
Reimplemented in sglFog, sglMaterial, sglAlphaTest, sglBlending, sglDepthRange, sglLineStipple, sglLineWidth, sglPointSize, sglPointParameters, sglPolygonOffset, sglPolygonStipple, sglMultiTextureStatelet, sglTextureMatrix, sglTexEnv, sglTexGen, and sglTexture. Definition at line 262 of file sglStatelet.hpp. Referenced by sglMultiTextureStatelet::getSorted(). |
|
If getSorted() returns true, then this function is used to retrieve the key (pointer) to sort with. This function is non-virtual so that access to it can be inlined in the cull traversal for speed.
Definition at line 269 of file sglStatelet.hpp. |
|
If getSorted() returns false, then this function is used to retrieve an index that can be used as a lookup key in a table for state sorting. This function is non-virtual so that access to it can be inlined in the cull traversal for speed.
Definition at line 283 of file sglStatelet.hpp. |
|
The equality operator
Definition at line 289 of file sglStatelet.hpp. |
|
Output the state of this node to the specified ostream.
Reimplemented from sglObject. Reimplemented in sglFog, sglMaterial, sglBooleanStatelet, sglAlphaTest, sglBlending, sglColorMask, sglCullMode, sglDepthRange, sglDepthTest, sglFrontFace, sglLineStipple, sglLineWidth, sglLogicOp, sglOcclusionCull, sglPointSize, sglPointParameters, sglPolyStyle, sglPolygonOffset, sglPolygonStipple, sglShadeModel, sglTextureMatrix, sglTexEnv, sglTexGen, sglTexture, sglTexture1D, and sglTexture2D. |