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-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #pragma once
51 
52 
53 #include <ACG/GL/gl.hh>
54 #include <ACG/Math/GLMatrixT.hh>
55 #include <ACG/GL/ShaderGenerator.hh>
56 #include <ACG/GL/RenderObject.hh>
57 
59 #include <ACG/Scenegraph/MaterialNode.hh>
60 
61 
62 
63 namespace GLSL{
64  class Program;
65 }
66 
67 namespace ACG
68 {
69 
70 // forward declaration
71 class VertexDeclaration;
72 class GLState;
73 class FBO;
74 class Texture;
75 class Texture2D;
76 
77 namespace SceneGraph {
78  namespace DrawModes {
79  class DrawModeProperties;
80  }
81  class Material;
82 }
83 
84 class ACGDLLEXPORT IRenderer
85 {
86 public:
87  IRenderer();
88  virtual ~IRenderer();
89 
90 
91 public:
92  //=========================================================================
93  // Callbacks for the scenegraph nodes
94  //=========================================================================
95 
108  virtual void addRenderObject(RenderObject* _renderObject);
109 
110  struct LightData
111  {
112  LightData()
113  : ltype(ACG::SG_LIGHT_DIRECTIONAL),
114  diffuse(1.0f, 1.0f, 1.0f), ambient(1.0f, 1.0f, 1.0f), specular(1.0f, 1.0f, 1.0f),
115  pos(0.0f, 0.0f, 0.0f), dir(1.0f, 0.0f, 0.0f), atten(1.0f, 0.0f, 0.0f),
116  spotCutoffExponent(0.0f, 0.0f)
117  { }
118 
119  ACG::ShaderGenLightType ltype; // directional, spot- or pointlight
120  ACG::Vec3f diffuse, ambient, specular; // light color factor
121  ACG::Vec3f pos, dir; // position, direction in view-space
122  ACG::Vec3f atten; // (constant, linear, quadratic) attenuation
123  ACG::Vec2f spotCutoffExponent; // (cutoff angle, exponent) for spotlights
124  };
125 
134  virtual void addLight(const LightData& _light);
135 
136  //=========================================================================
137  // Render object collection and OpenGL setup for shader-based rendering
138  //=========================================================================
139 protected:
151  virtual void prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot);
152 
161  virtual void collectRenderObjects(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _sceneGraphRoot);
162 
163 
171  void traverseRenderableNodes(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _node, const ACG::SceneGraph::Material* _mat);
172 
173 
174 
175  //=========================================================================
176  // Sorting
177  //=========================================================================
178 protected:
179 
185  static int cmpPriority(const void*, const void*);
186 
187 
192  virtual void sortRenderObjects();
193 
194 
195  //=========================================================================
196  // Rendering
197  //=========================================================================
198 protected:
199 
210  virtual void renderObject(ACG::RenderObject* _obj, GLSL::Program* _prog = 0, bool _constRenderStates = false, const std::vector<unsigned int>* _shaderModifiers = 0);
211 
219  virtual void bindObjectVBO(ACG::RenderObject* _obj,
220  GLSL::Program* _prog);
221 
229  virtual void bindObjectUniforms(ACG::RenderObject* _obj,
230  GLSL::Program* _prog);
231 
240  virtual void bindObjectRenderStates(ACG::RenderObject* _obj);
241 
242 
249  virtual void drawObject(ACG::RenderObject* _obj);
250 
251 
252  //=========================================================================
253  // Restore OpenGL State
254  //=========================================================================
255 
256 protected:
257 
258 
267  virtual void finishRenderingPipeline(bool _drawOverlay = true);
268 
271  virtual void saveInputFbo();
272 
275  virtual void restoreInputFbo();
276 
282  virtual void saveActiveFbo(GLint* _outFboId, GLint* _outViewport, GLint* _outDrawBuffer) const;
283 
289  virtual void restoreFbo(GLint _fboId, const GLint* _outViewport, GLint _drawBuffer) const;
290 
296  virtual void clearInputFbo(const ACG::Vec4f& _clearColor);
297 
298  //=========================================================================
299  // Other Convenience
300  //=========================================================================
301 
302 protected:
303 
316  virtual void copyDepthToBackBuffer(GLuint _depthTex, float _scale = 1.0f);
317 
318 
331  virtual void renderDepthMap(int _viewerID, int _width, int _height);
332 
333 
334  //=========================================================================
335  // Internal shader modifiers
336  //=========================================================================
337 protected:
338 
339  // depth map modifier: writes gl_FragCoord.z to red color channel
341  {
342  public:
343  void modifyFragmentEndCode(QStringList* _code);
344 
345  static DepthMapPass instance;
346  };
347 
348 
349  //=========================================================================
350  // Debugging
351  //=========================================================================
352 public:
353 
360  void dumpRenderObjectsToFile(const char* _fileName, ACG::RenderObject** _sortedList = 0) const;
361 
369  virtual QString dumpCurrentRenderObjectsToString(ACG::RenderObject** _list = 0, bool _outputShaders = false, std::vector<ACG::ShaderModifier*>* _modifiers = 0);
370 
382  void setErrorDetectionLevel(int _level);
383 
385  int getErrorDetectionLevel() const;
386 
387  //=========================================================================
388  // Variables
389  //=========================================================================
390 protected:
391 
393  int getNumRenderObjects() const;
394 
396  int getNumOverlayObjects() const;
397 
399  int getNumLineGL42Objects() const;
400 
402  int getNumLights() const;
403 
405  ACG::RenderObject* getRenderObject(int i);
406 
408  ACG::RenderObject* getOverlayRenderObject(int i);
409 
411  ACG::RenderObject* getLineGL42RenderObject(int i);
412 
414  LightData* getLight(int i);
415 
416 
418  const ACG::Vec3f& getGlobalAmbientScale() const {return globalLightModelAmbient_;}
419 
420 
429  void setLineThicknessRenderingGL42(bool _enable);
430 
431 
432  //=========================================================================
433  // Internally called by OpenFlipper core
434  //=========================================================================
435 public:
436 
445  void setViewerID(int _viewerID);
446 
447 protected:
450 
452  LightData lights_[SG_MAX_SHADER_LIGHTS];
453 
457 
459  std::vector<ACG::RenderObject> renderObjects_;
460 
461 
463  std::vector<ACG::RenderObject*> sortedObjects_;
464 
466  std::vector<ACG::RenderObject*> overlayObjects_;
467 
473  std::map<int, ACG::FBO*> depthMaps_;
474 
477 
480 
483 
486 
489 
491  GLint prevFbo_;
492 
495 
497  GLint prevViewport_[4];
498 
501 
504 
507 
508 private:
509 
510  //=========================================================================
511  // Default rendering of thick lines
512  //=========================================================================
513 
520 
522  std::vector<RenderObject*> lineGL42Objects_;
523 
525  std::map< int, Texture* > lineColorBuffers_;
526 
527  void renderLineThicknessGL42();
528 
529 
530 };
531 
532 
533 
534 //=============================================================================
535 } // namespace ACG
536 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
bool depthMapUsed_
true if at least one renderobject requires a scene depthmap, false otherwise
Definition: IRenderer.hh:476
Vec3f camDirWS_
direction the camera is looking to in world-space
Definition: IRenderer.hh:488
ACG::Vec3f globalLightModelAmbient_
Definition: IRenderer.hh:456
bool prevFboSaved_
flag indicating a that saveCurrentFbo() has been called prior restoreFbo()
Definition: IRenderer.hh:500
Interface class between scenegraph and renderer.
std::vector< ACG::RenderObject * > sortedObjects_
sorted list of renderobjects without overlay objects (sorted in rendering order)
Definition: IRenderer.hh:463
GLSL::Program * depthCopyShader_
shader copies depth of the first front layer to the back buffer
Definition: IRenderer.hh:503
GLint prevDrawBuffer_
previous drawbuffer target (ie GL_BACK, GL_COLOR_ATTACHMENTi...)
Definition: IRenderer.hh:494
int errorDetectionLevel_
error-detection level for checking render objects
Definition: IRenderer.hh:506
bool enableLineThicknessGL42_
Enable/disable gl4.2 based technique for rendering thick lines.
Definition: IRenderer.hh:519
Vec3f camPosWS_
cam position in world-space
Definition: IRenderer.hh:485
GLMatrixf viewMatrix_
view transform
Definition: IRenderer.hh:482
std::vector< RenderObject * > lineGL42Objects_
default line render objects that are rendered with gl4.2
Definition: IRenderer.hh:522
int curViewerID_
currently active viewer ID as specified in prepareRenderObjects()
Definition: IRenderer.hh:479
std::map< int, Texture * > lineColorBuffers_
map from viewport id to line buffer
Definition: IRenderer.hh:525
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:183
int numLights_
Number of Lights.
Definition: IRenderer.hh:449
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:75
std::map< int, ACG::FBO * > depthMaps_
Definition: IRenderer.hh:473
std::vector< ACG::RenderObject > renderObjects_
array of renderobjects, filled by addRenderObject()
Definition: IRenderer.hh:459
GLSL program class.
Definition: GLSLShader.hh:217
std::vector< ACG::RenderObject * > overlayObjects_
sorted list of overlay-only renderobjects (sorted in rendering order)
Definition: IRenderer.hh:466
GLint prevFbo_
previous fbo
Definition: IRenderer.hh:491
const ACG::Vec3f & getGlobalAmbientScale() const
Get global ambient light contribution from GL_LIGHT_MODEL_AMBIENT.
Definition: IRenderer.hh:418