Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ACG::SceneGraph::ACG::IRenderer Class Reference

Classes

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()
 
GLSL::ProgramdepthCopyShader_
 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 MeshNode2T.cc.

Member Function Documentation

virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::ACG::IRenderer::addRenderObject ( 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
virtual void ACG::SceneGraph::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..

virtual void ACG::SceneGraph::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.

virtual void ACG::SceneGraph::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.

virtual void ACG::SceneGraph::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
static int ACG::SceneGraph::ACG::IRenderer::cmpPriority ( const void *  ,
const void *   
)
staticprotected

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

virtual void ACG::SceneGraph::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.

virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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

virtual QString ACG::SceneGraph::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
void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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.

virtual void ACG::SceneGraph::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
virtual void ACG::SceneGraph::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 ..)
void ACG::SceneGraph::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
void ACG::SceneGraph::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
void ACG::SceneGraph::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() )
virtual void ACG::SceneGraph::ACG::IRenderer::sortRenderObjects ( )
protectedvirtual

Sort the renderobjects by priority.

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

void ACG::SceneGraph::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.

Member Data Documentation

std::map<int, ACG::FBO*> ACG::SceneGraph::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 473 of file MeshNode2T.cc.

bool ACG::SceneGraph::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 519 of file MeshNode2T.cc.

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

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

Definition at line 456 of file MeshNode2T.cc.


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