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