Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IRenderer.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 19916 $ *
38  * $Author: tenter $ *
39  * $Date: 2014-11-27 14:17:45 +0100 (Thu, 27 Nov 2014) $ *
40  * *
41 \*===========================================================================*/
42 
43 #pragma once
44 
45 
46 #include <ACG/GL/gl.hh>
47 #include <ACG/Math/GLMatrixT.hh>
48 #include <ACG/GL/ShaderGenerator.hh>
49 #include <ACG/GL/RenderObject.hh>
50 
52 #include <ACG/Scenegraph/MaterialNode.hh>
53 
54 
55 
56 namespace GLSL{
57  class Program;
58 }
59 
60 namespace ACG
61 {
62 
63 // forward declaration
64 class VertexDeclaration;
65 class GLState;
66 class FBO;
67 class Texture;
68 class Texture2D;
69 
70 namespace SceneGraph {
71  namespace DrawModes {
72  class DrawModeProperties;
73  }
74  class Material;
75 }
76 
77 class ACGDLLEXPORT IRenderer
78 {
79 public:
80  IRenderer();
81  virtual ~IRenderer();
82 
83 
84 public:
85  //=========================================================================
86  // Callbacks for the scenegraph nodes
87  //=========================================================================
88 
101  virtual void addRenderObject(RenderObject* _renderObject);
102 
103  struct LightData
104  {
105  LightData()
106  : ltype(ACG::SG_LIGHT_DIRECTIONAL),
107  diffuse(1.0f, 1.0f, 1.0f), ambient(1.0f, 1.0f, 1.0f), specular(1.0f, 1.0f, 1.0f),
108  pos(0.0f, 0.0f, 0.0f), dir(1.0f, 0.0f, 0.0f), atten(1.0f, 0.0f, 0.0f),
109  spotCutoffExponent(0.0f, 0.0f)
110  { }
111 
112  ACG::ShaderGenLightType ltype; // directional, spot- or pointlight
113  ACG::Vec3f diffuse, ambient, specular; // light color factor
114  ACG::Vec3f pos, dir; // position, direction in view-space
115  ACG::Vec3f atten; // (constant, linear, quadratic) attenuation
116  ACG::Vec2f spotCutoffExponent; // (cutoff angle, exponent) for spotlights
117  };
118 
127  virtual void addLight(const LightData& _light);
128 
129  //=========================================================================
130  // Render object collection and OpenGL setup for shader-based rendering
131  //=========================================================================
132 protected:
144  virtual void prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot);
145 
154  virtual void collectRenderObjects(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _sceneGraphRoot);
155 
156 
164  void traverseRenderableNodes(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _node, const ACG::SceneGraph::Material* _mat);
165 
166 
167 
168  //=========================================================================
169  // Sorting
170  //=========================================================================
171 protected:
172 
178  static int cmpPriority(const void*, const void*);
179 
180 
185  virtual void sortRenderObjects();
186 
187 
188  //=========================================================================
189  // Rendering
190  //=========================================================================
191 protected:
192 
203  virtual void renderObject(ACG::RenderObject* _obj, GLSL::Program* _prog = 0, bool _constRenderStates = false, const std::vector<unsigned int>* _shaderModifiers = 0);
204 
212  virtual void bindObjectVBO(ACG::RenderObject* _obj,
213  GLSL::Program* _prog);
214 
222  virtual void bindObjectUniforms(ACG::RenderObject* _obj,
223  GLSL::Program* _prog);
224 
233  virtual void bindObjectRenderStates(ACG::RenderObject* _obj);
234 
235 
242  virtual void drawObject(ACG::RenderObject* _obj);
243 
244 
245  //=========================================================================
246  // Restore OpenGL State
247  //=========================================================================
248 
249 protected:
250 
251 
260  virtual void finishRenderingPipeline(bool _drawOverlay = true);
261 
264  virtual void saveInputFbo();
265 
268  virtual void restoreInputFbo();
269 
275  virtual void saveActiveFbo(GLint* _outFboId, GLint* _outViewport, GLint* _outDrawBuffer) const;
276 
282  virtual void restoreFbo(GLint _fboId, const GLint* _outViewport, GLint _drawBuffer) const;
283 
289  virtual void clearInputFbo(const ACG::Vec4f& _clearColor);
290 
291  //=========================================================================
292  // Other Convenience
293  //=========================================================================
294 
295 protected:
296 
309  virtual void copyDepthToBackBuffer(GLuint _depthTex, float _scale = 1.0f);
310 
311 
324  virtual void renderDepthMap(int _viewerID, int _width, int _height);
325 
326 
327  //=========================================================================
328  // Internal shader modifiers
329  //=========================================================================
330 protected:
331 
332  // depth map modifier: writes gl_FragCoord.z to red color channel
334  {
335  public:
336  void modifyFragmentEndCode(QStringList* _code);
337 
338  static DepthMapPass instance;
339  };
340 
341 
342  //=========================================================================
343  // Debugging
344  //=========================================================================
345 public:
346 
353  void dumpRenderObjectsToFile(const char* _fileName, ACG::RenderObject** _sortedList = 0) const;
354 
362  virtual QString dumpCurrentRenderObjectsToString(ACG::RenderObject** _list = 0, bool _outputShaders = false, std::vector<ACG::ShaderModifier*>* _modifiers = 0);
363 
375  void setErrorDetectionLevel(int _level);
376 
378  int getErrorDetectionLevel() const;
379 
380  //=========================================================================
381  // Variables
382  //=========================================================================
383 protected:
384 
386  int getNumRenderObjects() const;
387 
389  int getNumOverlayObjects() const;
390 
392  int getNumLineGL42Objects() const;
393 
395  int getNumLights() const;
396 
398  ACG::RenderObject* getRenderObject(int i);
399 
401  ACG::RenderObject* getOverlayRenderObject(int i);
402 
404  ACG::RenderObject* getLineGL42RenderObject(int i);
405 
407  LightData* getLight(int i);
408 
409 
411  const ACG::Vec3f& getGlobalAmbientScale() const {return globalLightModelAmbient_;}
412 
413 
422  void setLineThicknessRenderingGL42(bool _enable);
423 
424 
425  //=========================================================================
426  // Internally called by OpenFlipper core
427  //=========================================================================
428 public:
429 
438  void setViewerID(int _viewerID);
439 
440 protected:
443 
445  LightData lights_[SG_MAX_SHADER_LIGHTS];
446 
450 
452  std::vector<ACG::RenderObject> renderObjects_;
453 
454 
456  std::vector<ACG::RenderObject*> sortedObjects_;
457 
459  std::vector<ACG::RenderObject*> overlayObjects_;
460 
466  std::map<int, ACG::FBO*> depthMaps_;
467 
470 
473 
476 
479 
482 
484  GLint prevFbo_;
485 
488 
490  GLint prevViewport_[4];
491 
494 
497 
500 
501 private:
502 
503  //=========================================================================
504  // Default rendering of thick lines
505  //=========================================================================
506 
513 
515  std::vector<RenderObject*> lineGL42Objects_;
516 
518  std::map< int, Texture* > lineColorBuffers_;
519 
520  void renderLineThicknessGL42();
521 
522 
523 };
524 
525 
526 
527 //=============================================================================
528 } // namespace ACG
529 //=============================================================================
bool prevFboSaved_
flag indicating a that saveCurrentFbo() has been called prior restoreFbo()
Definition: IRenderer.hh:493
std::vector< ACG::RenderObject > renderObjects_
array of renderobjects, filled by addRenderObject()
Definition: IRenderer.hh:452
bool depthMapUsed_
true if at least one renderobject requires a scene depthmap, false otherwise
Definition: IRenderer.hh:469
GLint prevFbo_
previous fbo
Definition: IRenderer.hh:484
VectorT< float, 2 > Vec2f
Definition: VectorT.hh:101
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:118
std::map< int, ACG::FBO * > depthMaps_
Definition: IRenderer.hh:466
int curViewerID_
currently active viewer ID as specified in prepareRenderObjects()
Definition: IRenderer.hh:472
Vec3f camPosWS_
cam position in world-space
Definition: IRenderer.hh:478
GLSL::Program * depthCopyShader_
shader copies depth of the first front layer to the back buffer
Definition: IRenderer.hh:496
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:175
int numLights_
Number of Lights.
Definition: IRenderer.hh:442
const ACG::Vec3f & getGlobalAmbientScale() const
Get global ambient light contribution from GL_LIGHT_MODEL_AMBIENT.
Definition: IRenderer.hh:411
GLSL program class.
Definition: GLSLShader.hh:210
std::map< int, Texture * > lineColorBuffers_
map from viewport id to line buffer
Definition: IRenderer.hh:518
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:68
ACG::Vec3f globalLightModelAmbient_
Definition: IRenderer.hh:449
GLMatrixf viewMatrix_
view transform
Definition: IRenderer.hh:475
GLint prevDrawBuffer_
previous drawbuffer target (ie GL_BACK, GL_COLOR_ATTACHMENTi...)
Definition: IRenderer.hh:487
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:10
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:137
bool enableLineThicknessGL42_
Enable/disable gl4.2 based technique for rendering thick lines.
Definition: IRenderer.hh:512
int errorDetectionLevel_
error-detection level for checking render objects
Definition: IRenderer.hh:499
std::vector< ACG::RenderObject * > overlayObjects_
sorted list of overlay-only renderobjects (sorted in rendering order)
Definition: IRenderer.hh:459
std::vector< ACG::RenderObject * > sortedObjects_
sorted list of renderobjects without overlay objects (sorted in rendering order)
Definition: IRenderer.hh:456
std::vector< RenderObject * > lineGL42Objects_
default line render objects that are rendered with gl4.2
Definition: IRenderer.hh:515
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
Vec3f camDirWS_
direction the camera is looking to in world-space
Definition: IRenderer.hh:481