Developer Documentation
DepthPeeling.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 #pragma once
45 
46 
47 #include <QObject>
48 #include <QAction>
49 
53 
54 
55 #include <ACG/GL/IRenderer.hh>
56 #include <ACG/GL/FBO.hh>
57 
59 {
60  Q_OBJECT
61  Q_INTERFACES(BaseInterface)
62  Q_INTERFACES(RenderInterface)
63  Q_INTERFACES(LoggingInterface)
64 
65  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Render-DepthPeeling")
66 
67 signals:
68  // LoggingInterface
69  void log(Logtype _type, QString _message);
70  void log(QString _message);
71 
72 
73 public:
74  DepthPeeling();
75  ~DepthPeeling();
76 
77  QString name() { return (QString("DepthPeeling Plugin")); };
78  QString description( ) { return (QString(tr("DepthPeeling Rendering Pipeline (Alpha Version!)"))); };
79 
80 
82  void addRenderObject(ACG::RenderObject* _renderObject);
83 
84 
85 public slots:
86  QString version() { return QString("1.0"); };
87 
88  QString renderObjectsInfo(bool _outputShaderInfo);
89 
90  QAction* optionsAction();
91 
92 private slots:
93 
94  //BaseInterface
95  void initializePlugin();
96  void exit();
97 
98  // RenderInterface
99  void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
100  QString rendererName() {return QString("Alpha_Version_DepthPeeling");}
101  void supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode) {_mode = ACG::SceneGraph::DrawModes::DEFAULT;}
102 
103  QString checkOpenGL();
104 
105  void slotModeChanged( QAction * );
106 
107 
108 private:
109 
110 
112  void renderFrontPeeling(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
113 
115  void renderDualPeeling(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
116 
119 
120  bool copyFrontDepth_;
121 
124 
127 
130 
132  GLuint peelQueryID_;
133 
134 
137  GLSL::Program* peelFinalDual_;
138 
139 
142  {
143  ViewerResources();
144  ~ViewerResources();
145 
146  // resize textures
147  void resize(bool _dualPeeling, unsigned int _width, unsigned int _height);
148 
150  unsigned int width_;
151 
153  unsigned int height_;
154 
155 
156  // single layer depth peeling textures (front to back peeling)
157  // ping-pong buffer for (depth, front) targets
158  GLuint singleDepthTex_[2]; // float1: minDepth
159  GLuint singleFrontTex_[2]; // rgba: color of front-peeled layer
160  GLuint singleBlendTex_; // rgba: color accumulation buffer
161 
162  ACG::FBO* singleFbo_; // targets: {depth0, front0, depth1, front1, blend}
163 
164 
165 
166 
167  // dual depth peeling textures
168  // ping-pong buffer for (depth, front, back) targets
169  GLuint dualDepthTex_[2]; // float2: (-minDepth, maxDepth)
170  GLuint dualFrontTex_[2]; // rgba: color of front-peeled layer
171  GLuint dualBackTex_[2]; // rgba: color of back-peeled layer
172  GLuint dualBlendTex_; // rgb: color accumulation buffer
173 
174  ACG::FBO* dualFbo_; // targets: {depth0, front0, back0, depth1, front1, back1, blend}
175  };
176 
178  void initDepthPeeling();
179 
181  void initDualDepthPeeling();
182 
187  std::map<int, ViewerResources> viewerRes_;
188 
189 
190 
191 
192  // debug functions
193 // GLSL::Program* dbgProg_;
194 //
195 // void dbgDrawTex(GLuint _texID);
196 };
QString name()
Return a name for the plugin.
Definition: DepthPeeling.hh:77
unsigned int width_
viewer window width
int maxPeelCount_
max peel count
std::map< int, ViewerResources > viewerRes_
Logtype
Log types for Message Window.
QString renderObjectsInfo(bool _outputShaderInfo)
Return a qstring of the current render objects.
unsigned int height_
viewer window height
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
Interface for all Plugins which do logging to the logging window of the framework.
GLSL program class.
Definition: GLSLShader.hh:211
DrawMode DEFAULT
use the default (global) draw mode and not the node&#39;s own.
Definition: DrawModes.cc:72
void initDepthPeeling()
Allocate framebuffers and load shaders for depth-peeling.
void renderFrontPeeling(ACG::GLState *_glState, Viewer::ViewerProperties &_properties)
peel the scene from front to back, one layer per pass
void initDualDepthPeeling()
Allocate framebuffers and load shaders for dual-depth-peeling.
Interface class from which all plugins have to be created.
Interface to add additional rendering functions from within plugins.
Definition: FBO.hh:71
Collection of framebuffers for each viewport.
QAction * optionsAction()
Return options menu.
void addRenderObject(ACG::RenderObject *_renderObject)
overide addRenderObject function to include OIT check
GLuint peelQueryID_
occlusion query determining end of peeling (last layer)
GLSL::Program * peelFinal_
final copy into back-buffer
int peelMode_
mode: 0 -> front to back peeling, 1 -> dual peeling
void renderDualPeeling(ACG::GLState *_glState, Viewer::ViewerProperties &_properties)
peel the scene with dual depth peeling, two layers per pass
GLSL::Program * peelBlendDual_
dual depth peeling shaders
GLSL::Program * peelBlend_
blends one depth-layer into the current scene target
QString description()
Return a description of what the plugin is doing.
Definition: DepthPeeling.hh:78