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 :
In order to preserve source compatibility, ssgSimpleState is now a ssgState with the old set of supported opengl states already initialized.
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 :
New or changed methods for class ssgVtxArrayEx vs ssgVtxArray :