Developer Documentation
ClassicDepthPeeling.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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include <QObject>
51 
55 
57 
58 #include <map>
59 
60 
62 {
63  Q_OBJECT
64  Q_INTERFACES(BaseInterface)
65  Q_INTERFACES(RenderInterface)
66  Q_INTERFACES(LoggingInterface)
67 
68 #if QT_VERSION >= 0x050000
69  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Render-Old-DepthPeeling")
70 #endif
71 
72 signals:
73  // LoggingInterface
74  void log(Logtype _type, QString _message);
75  void log(QString _message);
76 
77 
78 public :
79 
82 
83  QString name() { return (QString("Dual Depth Peeling Plugin using classic rendering pipeling")); };
84  QString description( ) { return (QString(tr("Order independent transparency renderer (classic pipeline)"))); };
85 
86 public slots:
87  QString version() { return QString("1.0"); };
88 
89 private slots:
90 
91  //BaseInterface
92  void initializePlugin();
93  void exit();
94 
95  // RenderInterface
96  void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
97  QString rendererName();
98  void supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode);
99  QString checkOpenGL();
100 
101 private:
102 
104  void destroyResources();
105 
107  void destroyResources(int _viewerId);
108 
110  void reloadResources(int _viewerId);
111 
113  void drawQuadProj(float _x0 = -1.0f, float _y0 = 1.0f,
114  float _w = 2.0f, float _h = 2.0f);
115 
117  void traverseLightNodes(BaseNode* _node);
118 
120  void generatePeelingShaders(GLSL::StringList* _strVertexShaderOut,
121  GLSL::StringList* _strFragmentShaderOut,
122  GLSL::StringList* _strGeometryShaderOut,
123  bool _textured, bool _flatShaded, bool _phong, bool _vertexColor, bool _wireFrame);
124 
126  void updatePeelingShaderSet();
127 
129  void drawScenePass(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode* _sceneGraphRoot);
130 
131  void drawScenePeelPass(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode* _sceneGraphRoot, int _peelPass);
132 
133  template <class Action>
134  void traverseDraw(BaseNode* _node, Action& _action, ACG::SceneGraph::DrawModes::DrawMode _globalDrawMode, int _pass, int _peelPass);
135 
136  template <class Action>
137  bool traverseDrawApplyAction(BaseNode* _node, Action& _action, ACG::SceneGraph::DrawModes::DrawMode _globalDrawMode, int _pass, int _peelPass);
138 
141 
142 private:
143 
145  {
146  ViewerResources();
147 
149  unsigned int glWidth_;
150 
152  unsigned int glHeight_;
153 
155  unsigned int rtWidth_;
157  unsigned int rtHeight_;
158 
163  };
164 
165  std::map<int, ViewerResources> viewerRes_;
166 
169 
172 
173  // note that shader flags are only good easy shader indexing
174  // some combinations like phong + flat make no sense
175  enum
176  {
177  PEEL_SHADER_WIREFRAME = 0, // wireframe is a special case here, not combinable with others
178  PEEL_SHADER_HIDDENLINE = 1, // hiddenline is another special case, it renders geometry in background color
179  PEEL_SHADER_TEXTURED = 0x1,
180  PEEL_SHADER_PHONG = 0x2,
181  PEEL_SHADER_GOURAUD = 0x4,
182  PEEL_SHADER_FLAT = 0x8,
183  PEEL_SHADER_VERTEXCOLORS = 0x10,
184  PEEL_NUM_COMBINATIONS = 0x20,
185  PEEL_SHADER_NUM_FLAGS = 5
186  };
188  GLSL::Shader* peelShaders_[PEEL_NUM_COMBINATIONS*3]; // interleaved: vertex, geometry, fragment
189 
191  GLSL::Program* peelProgs_[PEEL_NUM_COMBINATIONS];
192 
195 
198 
200  GLuint numLights_;
201 
204  {
205  LIGHTTYPE_DIRECTIONAL = 0,
206  LIGHTTYPE_POINT,
207  LIGHTTYPE_SPOT
208  };
209 
213  GLuint glLightIDs_[16];
214 };
Logtype
Log types for Message Window.
A generic shader base class.
Definition: GLSLShader.hh:77
QString description()
Return a description of what the plugin is doing.
unsigned int rtWidth_
render target width
GLuint blendDualPeelTexID_[7]
render target textures: {depth0, depth1, front_blend0, front_blend1, back_temp0, back_temp1, back_blend}
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, GLSL::StringList *_strGeometryShaderOut, bool _textured, bool _flatShaded, bool _phong, bool _vertexColor, bool _wireFrame)
peel shader generator based on lights and texture mode
Interface class from which all plugins have to be created.
void destroyResources()
free all gl resources
ACG::GLState * glStateTmp_
current glState ptr for hiddenline rendering
Interface for all Plugins which do logging to the logging window of the framework.
Interface to add additional rendering functions from within plugins.
void updatePeelingShaderSet()
regenerates peeling shaders based on light nodes in scenegraph
GLuint blendQueryID_
fragment query
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
GLSL::Shader * peelShaders_[PEEL_NUM_COMBINATIONS *3]
generated shader set
void drawScenePass(ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode *_sceneGraphRoot)
draw the current scene
unsigned int getPeelShaderIndex(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
converts a drawmode to the correct shading program index
unsigned int rtHeight_
render target height
void drawQuadProj(float _x0=-1.0f, float _y0=1.0f, float _w=2.0f, float _h=2.0f)
draw a quad in projection space (only positions)
QString name()
Return a name for the plugin.
void reloadResources(int _viewerId)
reload gl resources
GLSL::Shader * blendShaders_[8]
shader resources
GLSL::Program * peelProgs_[PEEL_NUM_COMBINATIONS]
generates shader programs
GLuint blendDualPeelFbo_
depth peeling fbo
unsigned int glWidth_
viewer window width
LightType lightTypes_[16]
registered lights in the scene
LightType
light type enumeration
GLuint glLightIDs_[16]
matching GL light id
GLSL::Program * blendDualPeelProg_[4]
depth peeling programs
GLuint numLights_
number of used lights in the scene
GLSL program class.
Definition: GLSLShader.hh:217
unsigned int glHeight_
viewer window height