Scene Graph

The main purpose of RC is to encapsulate different graphics application building blocks and to provide a scene graph to ease the handling of these. The building blocks are separated in to two groups that inherit from different base classes - Node and Resource.

Nodes are scene elements like light sources and geometry, and are structured in the scene graph in a tree-like manner.

Resources hold instantiatable data such as textures, vertex arrays and shader programs. Resources are typically used by nodes and other resources.

For example, a texture may be used by many meshes (Geometry nodes) in a scene. Instead of duplicating the texture data over and over, the geometry nodes reference a common texture.

The nodes and resources cannot be created by calling a constructor. Instead these objects are spawned by using the SceneGraph::create...-functions. Similarly, you should not call delete to destroy these objects, but use SceneGraph::deleteNode() and SceneGraph::dereferenceResource() respectively. The SceneGraph-class contains many useful scene graph handling functions, so be sure to check those out.

A brief summary of the different nodes and resources follow.

Nodes

The node types that can be used to describe a scene are listen below. The nodes share functionality through inheritance. Abstract nodes are denoted with < >, and cannot be directly created.


         <Node>

            |

        /       \

    World     <Transformable>

                     |

          /       /     \      \

      Group  Camera     Light  Geometry

Node - This is the base class. All nodes inherit from this node type. It mostly contains functionality to handle graph structure, such as attaching and detaching child nodes, etc, which is common to all nodes.

World - The root object of your scene graph. Calling renderAll() on this object will begin the traversal and rendering of the whole scene graph. You can have any number of World nodes, and it is not required to have it in your scene graph structure at all (but then you have to set the renderer specifics yourself before rendering).

Transformable - Base class for nodes that can be transformed (rotated, translated and scaled). Contains many helper functions for extracting information about position, facing, etc. Transformations applied to a parent that is a Transformable will be inherited by the child nodes.

Group - Doesn't really do much. Use this to stack transformations.

Camera - A camera with orthogonal, perspective or free projection. If you have a World node at the base of your scene graph, you can set the active Camera on that for a renderAll-call. (Alternatively set Camera by calling Renderer::setMatrices() (overridden by World's camera)).

Light - Describes a simple point light with intensity, color and position. Also note that since this is a transformable, direction can also be extracted, for use in spotlights.

Geometry - Describes a mesh with acompanying shader programs. Holds a VertexArray and at least one ShaderProgram. It also has its own set of Uniform values that override those of the shader programs attached to it.

Resources

Resources are "floating around" a little more than nodes. They are not organized in the scene tree in the same manner as nodes and don't have a child parent relation. Basically, a resource is a container for a chunk of data that is used by multiple objects. Instead of creating many copies, the resource list system keeps track of all the resources and only allow one copy of each unique data set.

The available resources are;

Vertex array - A vertex array is a list of per-vertex attributes such as position, normal, color, texture coordinate, etc. These are organized in an "array of structure" manner, which means that all of the attributes for one vertex are grouped together in the list (as opposed to having one whole array for each attribute type (= non-local memory access)). However, sometimes we don't want to duplicate all of the vertex attributes for each of the triangles in a mesh. An index array can optionally be added, that points to the indices in the vertex array to use for each triangle.

ShaderProgram - A shader program is something that the Renderer interprets and applies to the Geometry nodes that are sent down for rendering. For OpenGL 2.0 this would be a vertex- and a fragment program. The ShaderProgram also has a set of values that it can relay to the Renderer on a per-geometry basis. These are handled by the enclosed Uniform member. Geometry nodes also have Uniform objects and can override values set per shader program. The ShaderProgram also holds a RenderState, which controls blending, cull mode, depth tests/write, etc.

Texture - Textures can be used for a variety of purposes. Commonly they contain information like diffuse color, normals and specularity. Textures can be added to Geometry and ShaderPrograms (because they hold Uniform objects), and are thus relayed to the Renderer upon rendering a Geometry node. Textures are also contained in RenderTargets and can be extracted and used like regular textures.

CubeMap - Similar to the Texture resouce, but has 6 images for each of the directions. Good for skyboxes and reflective effects. Can also be relayed to the Renderer through Geometry and ShaderPrograms.

RenderTarget - Sets up a number of textures that can be rendered to, and optionally a depth buffer as well. To switch render target you must explicitly call Renderer::setRenderTarget() (pass 0 as argument for screen buffer).

 All Classes Functions