State system

The original ssg state system was relying on an abstract base class named ssgState with two realizations : ssgSimpleState and ssgStateSelector. The OpenGL states managed by ssgSimpleState were fixed and limited to a simple set available in early OpenGL : material colors, single texturing, alpha test, blending and lighting. Moreover, parameters for some were fixed and couldn't be changed.

The new scheme relies on the concept of state attributes and is borrowed from the OpenSceneGraph project. ssgState is now an instanciable class and hold collections of ssgStateAttribute(s) and ssgTextureStateAttribute(s). The difference between these two classes is that the same kind of texture attribute can be set to different texture units. State attribute classes hold specific parameter for that state and the system is now easily expandable. With a small change to it, we could even support user-provided state attributes.

The new classes are summarized below :

Parent class Class Kind Parameters
ssgStateAttribute ssgAlphaFunc SSG_STATE_ALPHA_FUNC function
value
ssgBlendFunc SSG_STATE_BLEND_FUNC source function
destination function
ssgCullFace SSG_STATE_CULL_FACE which face
ssgLighting SSG_STATE_LIGHTING none
ssgColorMaterial SSG_STATE_COLOR_MATERIAL which
for back and front
ssgMaterial SSG_STATE_MATERIAL ambient color
diffuse color
emissive color
specular color

for back and front
ssgShadeModel SSG_STATE_SHADE_MODEL flat or smooth
ssgDepth SSG_STATE_DEPTH function
ssgTextureStateAttribute ssgTexture2D SSG_TEXSTATE_TEXTURE2D texture
wrap
ssgTextureCubeMap SSG_TEXSTATE_TEXTURECUBEMAP texture
wrap
ssgTexEnv SSG_TEXSTATE_TEXENV function
color
ssgTexEnvCombine SSG_TEXSTATE_TEXENVCOMBINE function
source0
source1
source2
operand0
operand1
operand2
scale

for rgb and alpha
ssgTexGenS SSG_TEXSTATE_TEXGENS function
plane
ssgTexGenT SSG_TEXSTATE_TEXGENT function
plane
ssgTexGenR SSG_TEXSTATE_TEXGENR function
plane
ssgTexGenQ SSG_TEXSTATE_TEXGENQ function
plane

The class ssgState has a new set of methods that manage attributes. They are :

void setAttribute( ssgStateAttribute *attrib )
Add the new attribute to the list of enabled states and unref the previous one of the same kind.
void clrAttribute( int kind )
Unref the attribute of that kind. If it has a mode, it will be disabled when the state will be applied.
ssgStateAttribute *getAttribute( int kind )
Return the current attribute of that kind or NULL if it is disabled.
void setTextureAttribute( int tex_unit, ssgTextureStateAttribute *attrib )
Add the new attribute to the list of enabled states for that texture unit and unref the previous one of the same kind and the same unit.
void clrTextureAttribute( int tex_unit, int kind )
Unref the attribute of that kind for the texture unit. If it has a mode, it will be disabled when the state will be applied.
ssgTextureStateAttribute *getTextureAttribute( int tex_unit, int kind )
Return the current attribute of that kind for that texture unit or NULL if it is disabled.

In order to preserve source compatibility, ssgSimpleState is now a ssgState with the old set of supported opengl states already initialized.

New Scene Graph Leaves

New capabilities supported by current OpenGL includes :

In a first phase, only the first two constraints are addressed but the two last are kept in mind in the design choices. The first choice is to create generic 2D, 3D and 4D arrays ( called ssgVec2Array, ssgVec3Array and ssgVec4Array ). Old ssgVertexArray, ssgNormalArray and ssgColourArray are derived from these generic classes, but ssgTexCoordArray ( a 2D array ) is only kept for compatibility reason. The new interfaces accept any 2D, 3D or 4D arrays.

Next is to extend ssgVtxTable and ssgVtxArray classes. For the moment, two new classes are created, ssgVtxTableEx and ssgVtxArrayEx, but their vocation is to replace their old counterpart. They support multiple set of coordinates and ssgVtxArrayEx, used to draw indexed elements, support multiple primitives with their own type and set of indices. Indeed, their is no point of using indexed primitive if we must provide a new set of vertices and vertices attributes every time. The new ssgVtxArrayEx enables to provide only one set of attributes for multiple primitives and thus, will ease the use of VBO.

New or changed methods for class ssgVtxTableEx vs ssgVtxTable :

Constructor : ssgVtxTableEx( GLenum ty, ssgVertexArray *vl, ssgNormalArray *nl, ssgSimpleListArray *tl, ssgColourArray *cl )
tl is now a list of arrays. One can simply pass NULL, then call void setTexCoords ( ssgVecXArray *tl, int tu )
void setTexCoords ( ssgVecXArray *tl, int tu )
Coordinate set for texture unit tu.
void setTexCoords ( ssgVecXArray *tl )
Coordinate set for texture unit 0.

New or changed methods for class ssgVtxArrayEx vs ssgVtxArray :

Constructor : ssgVtxArrayEx ( GLenum ty, ssgVertexArray *vl, ssgNormalArray *nl, ssgSimpleListArray *tl, ssgColourArray *cl, ssgIndexArray *il )
tl is now a list of arrays. One can simply pass NULL, then call void ssgVtxTableEx::setTexCoords ( ssgVecXArray *tl, int tu )
void addPrimitive( GLenum ty, ssgIndexArray *il )
Add a new primitive with a new set of indices but sharing vertices and vertices attributes with the initial primitive set up by the constructor.