Developer Documentation
ACG::IRenderer Class Reference
Inheritance diagram for ACG::IRenderer:
DepthPeeling NormalRenderer Renderer ToonRenderer

Classes

class  DepthMapPass
 
struct  LightData
 
class  RenderObjectRange
 

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...
 
virtual void addRenderObjectModifier (RenderObjectModifier *_mod)
 Callback for the scenegraph nodes, which adds a render object modifier to the renderer via this function. More...
 
virtual void removeRenderObjectModifier (RenderObjectModifier *_mod)
 Callback for the scenegraph nodes, which removes a render object modifier from the renderer. 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...
 
const RenderObjectRangegetCollectedSubtreeObjects () const
 

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 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)
 

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::vector< ACG::RenderObjectModifier * > renderObjectModifiers_
 active render object modifiers
 
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()
 
GLSL::ProgramdepthCopyShader_
 shader copies depth of the first front layer to the back buffer
 
int errorDetectionLevel_
 error-detection level for checking render objects
 
RenderObjectRange current_subtree_objects_
 

Static Protected Attributes

static int maxClipDistances_ = -1
 max number of clip distance outputs in a vertex shader
 

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)
virtual

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.

Parameters
_lightNewly added light

Definition at line 1097 of file IRenderer.cc.

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

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.

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

Reimplemented in DepthPeeling.

Definition at line 108 of file IRenderer.cc.

void ACG::IRenderer::addRenderObjectModifier ( RenderObjectModifier _mod)
virtual

Callback for the scenegraph nodes, which adds a render object modifier to the renderer via this function.

This function is needed whenever a scenegraph node wants to set certain rendering parameters for all its child nodes. A scenegraph node does not have direct access to render object created within its subtree. Instead, it can implement a render object modifier and attach it to the renderer. This modifier is applied to all render objects added to this renderer until it gets removed again.

A good place to call this function is in the derived BaseNode::enter() function.

Parameters
_modaddress of the modifier. It has to remain in memory until it gets removed from the renderer!

Definition at line 1111 of file IRenderer.cc.

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

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 943 of file IRenderer.cc.

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

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 834 of file IRenderer.cc.

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

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 807 of file IRenderer.cc.

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

Clear input Fbo.

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

Parameters
_clearColorclear color

Definition at line 769 of file IRenderer.cc.

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

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 402 of file IRenderer.cc.

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

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)
Parameters
_depthTextexture containing depth values
_scalescaling factor for the depth values from _depthTex

Definition at line 1249 of file IRenderer.cc.

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

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 996 of file IRenderer.cc.

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

Outputs the current render objects to the string.

Parameters
_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
Returns
Render object data in a QString

Definition at line 1184 of file IRenderer.cc.

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.

Parameters
_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 1165 of file IRenderer.cc.

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

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 634 of file IRenderer.cc.

const RenderObjectRange& ACG::IRenderer::getCollectedSubtreeObjects ( ) const
inline

During traversal of the scene graph this method returns the range of render objects that has been collected in the current subtree.

This method is exclusively intended to be called in the leave() function of scene graph nodes. Calling it from anywhere else will yield an undefined result with potentially invalid iterators.

Definition at line 483 of file IRenderer.hh.

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

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

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

Parameters
_glStatepointer to glstate
_drawModedefault drawmode
_scenegraphRootroot node of scenegraph

Definition at line 522 of file IRenderer.cc.

void ACG::IRenderer::removeRenderObjectModifier ( RenderObjectModifier _mod)
virtual

Callback for the scenegraph nodes, which removes a render object modifier from the renderer.

Remove a previously added modifier. RenderObjects added to the renderer afterwards will not be affected anymore.

A good place to call this function is in the derived BaseNode::leave() function.

Parameters
_modaddress of the modifier.

Definition at line 1116 of file IRenderer.cc.

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

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.

Parameters
_viewerIDid of viewport,
_widthviewport width
_heightviewport height

Definition at line 1324 of file IRenderer.cc.

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

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 1053 of file IRenderer.cc.

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

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

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

Definition at line 762 of file IRenderer.cc.

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

Save active Fbo configuration (fbo id + viewport)

Parameters
_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 754 of file IRenderer.cc.

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

Parameters
_leveldetection level

Definition at line 1593 of file IRenderer.cc.

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

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.

Parameters
_enableenable/disable

Definition at line 1587 of file IRenderer.cc.

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.

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

Definition at line 1412 of file IRenderer.cc.

void ACG::IRenderer::sortRenderObjects ( )
protectedvirtual

Sort the renderobjects by priority.

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

Definition at line 799 of file IRenderer.cc.

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

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 447 of file IRenderer.cc.

Member Data Documentation

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

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 516 of file IRenderer.hh.

bool ACG::IRenderer::enableLineThicknessGL42_
private

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 566 of file IRenderer.hh.

ACG::Vec3f ACG::IRenderer::globalLightModelAmbient_
protected

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

Definition at line 496 of file IRenderer.hh.


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