Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ACG::IRenderer Class Reference
Inheritance diagram for ACG::IRenderer:
DepthPeeling NormalRenderer Renderer ToonRenderer


class  DepthMapPass
struct  LightData

Public Member Functions

virtual void addRenderObject (RenderObject *_renderObject)
 Callback for the scenegraph nodes, which send new render objects via this function. More...
virtual void addLight (const LightData &_light)
 Callback for the scenegraph nodes, which send new lights to the renderer via this function. More...
void dumpRenderObjectsToFile (const char *_fileName, ACG::RenderObject **_sortedList=0) const
 Debugging function to dump list of render objects into a file. More...
virtual QString dumpCurrentRenderObjectsToString (ACG::RenderObject **_list=0, bool _outputShaders=false, std::vector< ACG::ShaderModifier * > *_modifiers=0)
 Outputs the current render objects to the string. More...
void setErrorDetectionLevel (int _level)
 Control error detection for checking render objects. More...
int getErrorDetectionLevel () const
 Get error detection level.
void setViewerID (int _viewerID)
 Set currently active viewer id. More...

Protected Member Functions

virtual void prepareRenderingPipeline (ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode *_scenegraphRoot)
 Prepares renderer and OpenGL for any draw-related calls including. More...
virtual void collectRenderObjects (ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode *_sceneGraphRoot)
 Traverse the scenegraph to collect render information. More...
void traverseRenderableNodes (ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode *_node, const ACG::SceneGraph::Material *_mat)
 Scene graph traversal for render object collection. More...
virtual void sortRenderObjects ()
 Sort the renderobjects by priority. More...
virtual void renderObject (ACG::RenderObject *_obj, GLSL::Program *_prog=0, bool _constRenderStates=false, const std::vector< unsigned int > *_shaderModifiers=0)
 Render one renderobject. More...
virtual void bindObjectVBO (ACG::RenderObject *_obj, GLSL::Program *_prog)
 Binding VBOs (First state function) More...
virtual void bindObjectUniforms (ACG::RenderObject *_obj, GLSL::Program *_prog)
 Binding Uniforms (Second state function) More...
virtual void bindObjectRenderStates (ACG::RenderObject *_obj)
 Binding Render state (Third state function) More...
virtual void drawObject (ACG::RenderObject *_obj)
 Executes the opengl draw call for one object (Fourth function) More...
virtual void finishRenderingPipeline (bool _drawOverlay=true)
 Draw overlay objects and reset OpenGL state. More...
virtual void saveInputFbo ()
 Save input Fbo configuration (fbo id + viewport)
virtual void restoreInputFbo ()
 Restore the previously saved input Fbo configuration (fbo id + viewport)
virtual void saveActiveFbo (GLint *_outFboId, GLint *_outViewport, GLint *_outDrawBuffer) const
 Save active Fbo configuration (fbo id + viewport) More...
virtual void restoreFbo (GLint _fboId, const GLint *_outViewport, GLint _drawBuffer) const
 Restore a previously saved input Fbo configuration (fbo id + viewport) More...
virtual void clearInputFbo (const ACG::Vec4f &_clearColor)
 Clear input Fbo. More...
virtual void copyDepthToBackBuffer (GLuint _depthTex, float _scale=1.0f)
 Copy texture to depth buffer. More...
virtual void renderDepthMap (int _viewerID, int _width, int _height)
 Render the depth map of the scene. More...
int getNumRenderObjects () const
 Get the number of collected render objects (not including overlay objects or gl4.2 line objects)
int getNumOverlayObjects () const
 Get the number of render objects in the overlay (for instance objects from coordsys are overlayed)
int getNumLineGL42Objects () const
 Get the number of default line objects rendered with opengl 4.2.
int getNumLights () const
 Get the number of current light sources.
ACG::RenderObjectgetRenderObject (int i)
 Get render objects in the sorted list by index (not including overlay objects)
ACG::RenderObjectgetOverlayRenderObject (int i)
 Get render objects in the sorted list by index (only overlay objects)
ACG::RenderObjectgetLineGL42RenderObject (int i)
 Get render objects in the sorted list by index (only line objects rendered with gl4.2)
LightDatagetLight (int i)
 Get light by index.
const ACG::Vec3fgetGlobalAmbientScale () const
 Get global ambient light contribution from GL_LIGHT_MODEL_AMBIENT.
void setLineThicknessRenderingGL42 (bool _enable)

Static Protected Member Functions

static int cmpPriority (const void *, const void *)
 Compare priority of render objects. More...

Protected Attributes

int numLights_
 Number of Lights.
LightData lights_ [SG_MAX_SHADER_LIGHTS]
 Light sources ( Filled by addLight() )
ACG::Vec3f globalLightModelAmbient_
std::vector< ACG::RenderObjectrenderObjects_
 array of renderobjects, filled by addRenderObject()
std::vector< ACG::RenderObject * > sortedObjects_
 sorted list of renderobjects without overlay objects (sorted in rendering order)
std::vector< ACG::RenderObject * > overlayObjects_
 sorted list of overlay-only renderobjects (sorted in rendering order)
std::map< int, ACG::FBO * > depthMaps_
bool depthMapUsed_
 true if at least one renderobject requires a scene depthmap, false otherwise
int curViewerID_
 currently active viewer ID as specified in prepareRenderObjects()
GLMatrixf viewMatrix_
 view transform
Vec3f camPosWS_
 cam position in world-space
Vec3f camDirWS_
 direction the camera is looking to in world-space
GLint prevFbo_
 previous fbo
GLint prevDrawBuffer_
 previous drawbuffer target (ie GL_BACK, GL_COLOR_ATTACHMENTi...)
GLint prevViewport_ [4]
 previous viewport
bool prevFboSaved_
 flag indicating a that saveCurrentFbo() has been called prior restoreFbo()
 shader copies depth of the first front layer to the back buffer
int errorDetectionLevel_
 error-detection level for checking render objects

Private Member Functions

void renderLineThicknessGL42 ()

Private Attributes

bool enableLineThicknessGL42_
 Enable/disable gl4.2 based technique for rendering thick lines. More...
std::vector< RenderObject * > lineGL42Objects_
 default line render objects that are rendered with gl4.2
std::map< int, Texture * > lineColorBuffers_
 map from viewport id to line buffer

Detailed Description

Definition at line 84 of file IRenderer.hh.

Member Function Documentation

void ACG::IRenderer::addLight ( const LightData _light)

Callback for the scenegraph nodes, which send new lights to the renderer via this function.

Scenegraph nodes are able to add new light sources to the renderer with this function. To so, the node should implement getRenderObjects() and call addLight in there. LightNodes use this for example.

_lightNewly added light

Definition at line 1030 of file

void ACG::IRenderer::addRenderObject ( ACG::RenderObject _renderObject)

Callback for the scenegraph nodes, which send new render objects via this function.

AddRenderObject is typically called by a scenegraph nodes during the collection of renderable objects. A renderobject is a collection of opengl states, buffers and parameters, that correspond to exactly one draw call.

Creates another RenderObject instance internally, safe for temporary local RenderObject instances.

The VertexDeclaration address must be permanently valid.
_renderObjectNewly added render object

Reimplemented in DepthPeeling.

Definition at line 105 of file

void ACG::IRenderer::bindObjectRenderStates ( ACG::RenderObject _obj)

Binding Render state (Third state function)

This is the third function called by renderObject().

Prepare the opengl state machine for a renderobject draw call.

This includes any glEnable/glDisable states, depth-cmp functions, blend equation..

Definition at line 890 of file

void ACG::IRenderer::bindObjectUniforms ( ACG::RenderObject _obj,
GLSL::Program _prog 

Binding Uniforms (Second state function)

This is the second function called by renderObject().

Set common shader constants like model-view-projection matrix, material colors and light params.

Definition at line 781 of file

void ACG::IRenderer::bindObjectVBO ( ACG::RenderObject _obj,
GLSL::Program _prog 

Binding VBOs (First state function)

This is the first function called by renderObject().

It binds vertex, index buffer and vertex format of a render object.

Definition at line 754 of file

void ACG::IRenderer::clearInputFbo ( const ACG::Vec4f _clearColor)

Clear input Fbo.

Clears color and depth buffer of input Fbo (using a scissor test to only clear viewport area).

_clearColorclear color

Definition at line 721 of file

int ACG::IRenderer::cmpPriority ( const void *  _a,
const void *  _b 

Compare priority of render objects.

compare function for qsort. This is required to compare render objects based on their prioerity and render them in the right order

Definition at line 477 of file

void ACG::IRenderer::collectRenderObjects ( ACG::GLState _glState,
ACG::SceneGraph::DrawModes::DrawMode  _drawMode,
ACG::SceneGraph::BaseNode _sceneGraphRoot 

Traverse the scenegraph to collect render information.

Traverses the scenegraph and calls the getRenderObject function of each node. Each node can then add multiple renderobjects via addRenderObject to this renderer.

Also collects all light sources in the scenegraph. The currently active list of renderobjects is invalidated too.

Definition at line 391 of file

void ACG::IRenderer::copyDepthToBackBuffer ( GLuint  _depthTex,
float  _scale = 1.0f 

Copy texture to depth buffer.

Copies depth values from a texture to the input depth buffer. These are the changes made to the OpenGL state, which are not restored upon return:

  • active texture stage is 0 with _depthTex bound
  • internal shader program active
  • internal screen quad vbo active
  • filling mode is set to glPolygonMode(GL_FRONT, GL_FILL)
_depthTextexture containing depth values
_scalescaling factor for the depth values from _depthTex

Definition at line 1200 of file

void ACG::IRenderer::drawObject ( ACG::RenderObject _obj)

Executes the opengl draw call for one object (Fourth function)

This is the fourth function called by renderObject().

Executes one draw call for the given render object

Definition at line 929 of file

QString ACG::IRenderer::dumpCurrentRenderObjectsToString ( ACG::RenderObject **  _list = 0,
bool  _outputShaders = false,
std::vector< ACG::ShaderModifier * > *  _modifiers = 0 

Outputs the current render objects to the string.

_listPointer to a list of render objects used for output (defaults to unsorted internal list)
_outputShadersOutput the shaders used for the objects?
_modifiersPointer to vector of registered ShaderModifier
Render object data in a QString

Definition at line 1135 of file

void ACG::IRenderer::dumpRenderObjectsToFile ( const char *  _fileName,
ACG::RenderObject **  _sortedList = 0 
) const

Debugging function to dump list of render objects into a file.

Dump list of render objects to text file.

_fileNamename of text file to write to
_sortedListdump sorted render objects in order, may be 0 to use the unsorted list instead

Definition at line 1116 of file

void ACG::IRenderer::finishRenderingPipeline ( bool  _drawOverlay = true)

Draw overlay objects and reset OpenGL state.

Optionally renders overlay objects. Resets critical OpenGL states to default to prevent crashes.

  • deactivate framebuffer
  • disable shaders
  • disable vbo

Definition at line 589 of file

void ACG::IRenderer::prepareRenderingPipeline ( ACG::GLState _glState,
ACG::SceneGraph::DrawModes::DrawMode  _drawMode,
ACG::SceneGraph::BaseNode _scenegraphRoot 

Prepares renderer and OpenGL for any draw-related calls including.

Prepares renderer and OpenGL for any draw-related calls including:

_glStatepointer to glstate
_drawModedefault drawmode
_scenegraphRootroot node of scenegraph

Definition at line 486 of file

void ACG::IRenderer::renderDepthMap ( int  _viewerID,
int  _width,
int  _height 

Render the depth map of the scene.

When setting up a shader of a render-object, a scenegraph node can use the depth map for custom rendering techniques. If at least one render object calls this function, the depth map is later rendered before the scene pass. and bound to the shader of an renderobject in bindObjectUniforms according to the provided "depthMapUniformName". Depth Map format: GL_TEXTURE_2D, GL_R32F, depth value = gl_FragCoord.z This function is automatically called in prepareRenderingPipeline() when required.

_viewerIDid of viewport,
_widthviewport width
_heightviewport height

Definition at line 1275 of file

void ACG::IRenderer::renderObject ( ACG::RenderObject _obj,
GLSL::Program _prog = 0,
bool  _constRenderStates = false,
const std::vector< unsigned int > *  _shaderModifiers = 0 

Render one renderobject.

Fully prepares opengl for a renderobject and executes the draw call. This combines bindObjectVBO, bindObjectUniforms...

Optionally render-states may not be changed, in case depth-peeling or similar global shader operations may require a fixed state setting.

Shader modifiers can be combined and applied to this pass.

Definition at line 986 of file

void ACG::IRenderer::restoreFbo ( GLint  _fboId,
const GLint *  _outViewport,
GLint  _drawBuffer 
) const

Restore a previously saved input Fbo configuration (fbo id + viewport)

_fboIdfbo id
_outViewport[in] pointer to address of 4 GLint values receiving the currently active viewport
_drawBufferdraw-buffer target of fbo

Definition at line 714 of file

void ACG::IRenderer::saveActiveFbo ( GLint *  _outFboId,
GLint *  _outViewport,
GLint *  _outDrawBuffer 
) const

Save active Fbo configuration (fbo id + viewport)

_outFboId[out] pointer to address receiving the currently active fbo id
_outViewport[out] pointer to address of 4 GLint values receiving the currently active viewport
_outDrawBuffer[out] pointer to address receiving the currently active drawbuffer target (ie GL_BACK, GL_COLOR_ATTACHMENTi ..)

Definition at line 706 of file

void ACG::IRenderer::setErrorDetectionLevel ( int  _level)

Control error detection for checking render objects.

Levels: 0 - disable error detection 1 - fast check (obvious stuff that does not require much time to check) 2 - intensive check (do additional check, possibly false positives and impact on performance)

Default level is 1

_leveldetection level

Definition at line 1544 of file

void ACG::IRenderer::setLineThicknessRenderingGL42 ( bool  _enable)

Enable/disable line thickness rendering with opengl4.2

Instead of quad extrusion in a geometry shader, thick lines are manually rasterized in a load/store image. This image is then composited with the back buffer. If the gpu does not support image load/store, the default quad extrusion is used anyway and this function has no effect.


Definition at line 1538 of file

void ACG::IRenderer::setViewerID ( int  _viewerID)

Set currently active viewer id.

If the scenegraph makes use of the z-prepass feature and the application uses multiple viewports, the currently active viewport should be set prior rendering. Otherwise, this function can be ignored.

_viewerIDunique id of the current viewport (i.e. ViewerProperties::viewerID() )

Definition at line 1363 of file

void ACG::IRenderer::sortRenderObjects ( )

Sort the renderobjects by priority.

Sort array of renderobjects by priority and store the result in sortedObjects_.

Definition at line 744 of file

void ACG::IRenderer::traverseRenderableNodes ( ACG::GLState _glState,
ACG::SceneGraph::DrawModes::DrawMode  _drawMode,
ACG::SceneGraph::BaseNode _node,
const ACG::SceneGraph::Material _mat 

Scene graph traversal for render object collection.

Calls getRenderObjects on each node of the scenegraph recursively.Calls getRenderObjects on each node of the scenegraph recursively. Each node then triggers the callbacks.

Definition at line 422 of file

Member Data Documentation

std::map<int, ACG::FBO*> ACG::IRenderer::depthMaps_

Stores fbo containing a depth map for each viewport. The depth map is computed in a z-prepass if at least one RenderObject makes use of the scene depth map. (optional convenience feature)

Definition at line 473 of file IRenderer.hh.

bool ACG::IRenderer::enableLineThicknessGL42_

Enable/disable gl4.2 based technique for rendering thick lines.

If enabled, default line objects are not returned via getRenderObject(), but are rendered in finishRenderingPipeline() just before drawing overlays.

Definition at line 519 of file IRenderer.hh.

ACG::Vec3f ACG::IRenderer::globalLightModelAmbient_

ambient color scale for global light: this is set via glLightModel(GL_LIGHT_MODEL_AMBIENT, scale)

Definition at line 456 of file IRenderer.hh.

The documentation for this class was generated from the following files: