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