VTK
vtkDualDepthPeelingPass.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDualDepthPeelingPass.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
51 #ifndef vtkDualDepthPeelingPass_h
52 #define vtkDualDepthPeelingPass_h
53 
54 #include "vtkRenderingOpenGL2Module.h" // For export macro
55 #include "vtkDepthPeelingPass.h"
56 
60 class vtkRenderTimerLog;
61 class vtkShaderProgram;
62 class vtkTextureObject;
63 
64 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass:
65  public vtkDepthPeelingPass
66 {
67 public:
68  static vtkDualDepthPeelingPass* New();
70  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
71 
72  void Render(const vtkRenderState *s) VTK_OVERRIDE;
73  void ReleaseGraphicsResources(vtkWindow *w) VTK_OVERRIDE;
74 
76 
81  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
82  virtual void SetVolumetricPass(vtkRenderPass *volumetricPass);
84 
85  // vtkOpenGLRenderPass virtuals:
86  bool PreReplaceShaderValues(std::string &vertexShader,
87  std::string &geometryShader,
88  std::string &fragmentShader,
89  vtkAbstractMapper *mapper,
90  vtkProp *prop) VTK_OVERRIDE;
91  bool PostReplaceShaderValues(std::string &vertexShader,
92  std::string &geometryShader,
93  std::string &fragmentShader,
94  vtkAbstractMapper *mapper,
95  vtkProp *prop) VTK_OVERRIDE;
96  bool SetShaderParameters(vtkShaderProgram *program,
97  vtkAbstractMapper *mapper,
98  vtkProp *prop,
99  vtkOpenGLVertexArrayObject *VAO = NULL) VTK_OVERRIDE;
100  virtual vtkMTimeType GetShaderStageMTime() VTK_OVERRIDE;
101 
102 protected:
103 
104  bool PostReplaceTranslucentShaderValues(std::string &vertexShader,
105  std::string &geometryShader,
106  std::string &fragmentShader,
107  vtkAbstractMapper *mapper,
108  vtkProp *prop);
109  bool PreReplaceVolumetricShaderValues(std::string &vertexShader,
110  std::string &geometryShader,
111  std::string &fragmentShader,
112  vtkAbstractMapper *mapper,
113  vtkProp *prop);
114  bool SetTranslucentShaderParameters(vtkShaderProgram *program,
115  vtkAbstractMapper *mapper, vtkProp *prop,
117  bool SetVolumetricShaderParameters(vtkShaderProgram *program,
118  vtkAbstractMapper *mapper, vtkProp *prop,
120 
121 
122  // Name the textures used by this render pass. These are indexes into
123  // this->Textures
125  {
126  BackTemp = 0, // RGBA8 back-to-front peeling buffer
127  Back, // RGBA8 back-to-front accumulation buffer
128  FrontA, // RGBA8 front-to-back accumulation buffer
129  FrontB, // RGBA8 front-to-back accumulation buffer
130  DepthA, // RG32F min-max depth buffer
131  DepthB, // RG32F min-max depth buffer
132  OpaqueDepth, // Stores the depth map from the opaque passes
133 
134  NumberOfTextures
135  };
136 
137  // The stages of this multipass render pass:
139  {
143 
145  Inactive = -1,
146  };
147 
148  enum PeelType
149  {
151  VolumetricPeel
152  };
153 
155  ~vtkDualDepthPeelingPass() VTK_OVERRIDE;
156 
157  void SetCurrentStage(ShaderStage stage);
158  vtkSetMacro(CurrentPeelType, PeelType)
159 
163  void FreeGLObjects();
164 
168  void RenderTranslucentPass();
169 
173  void RenderVolumetricPass();
174 
175  bool IsRenderingVolumes();
176 
180  void Initialize(const vtkRenderState *state);
181 
183 
186  void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s);
187  void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
188  void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
189  void InitFramebuffer(const vtkRenderState *s);
191 
195  void Prepare();
196 
197  void InitializeOcclusionQuery();
198  void CopyOpaqueDepthBuffer();
199  void InitializeDepth();
200 
201  void PeelVolumesOutsideTranslucentRange();
202 
203  bool PeelingDone();
204 
208  void Peel();
209 
210  // Depending on whether we're handling volumes or not, we'll initialize the
211  // front destination buffer by either clearing it or copying the last peel's
212  // output into it.
213  void PrepareFrontDestination();
214  void ClearFrontDestination();
215  void CopyFrontSourceToFrontDestination();
216 
217  void InitializeTargetsForTranslucentPass();
218  void InitializeTargetsForVolumetricPass();
219 
220  void PeelTranslucentGeometry();
221  void PeelVolumetricGeometry();
222 
223  void BlendBackBuffer();
224 
225  void StartTranslucentOcclusionQuery();
226  void EndTranslucentOcclusionQuery();
227 
228  void StartVolumetricOcclusionQuery();
229  void EndVolumetricOcclusionQuery();
230 
234  void SwapFrontBufferSourceDest();
235  void SwapDepthBufferSourceDest();
236 
237  void Finalize();
238 
239  void AlphaBlendRender();
240 
241  void BlendFinalImage();
242  void DeleteOcclusionQueryIds();
243 
245  vtkRenderPass *VolumetricPass;
246  const vtkRenderState *RenderState;
247 
248  vtkShaderProgram *CopyColorProgram;
250  vtkOpenGLBufferObject *CopyColorVBO;
251 
252  vtkShaderProgram *CopyDepthProgram;
254  vtkOpenGLBufferObject *CopyDepthVBO;
255 
256  vtkShaderProgram *BackBlendProgram;
258  vtkOpenGLBufferObject *BackBlendVBO;
259 
260  vtkShaderProgram *BlendProgram;
263 
265  vtkTextureObject *Textures[NumberOfTextures];
266 
267  TextureName FrontSource; // The current front source buffer
268  TextureName FrontDestination; // The current front destination buffer
269  TextureName DepthSource; // The current depth source buffer
270  TextureName DepthDestination; // The current depth destination buffer
271 
272  ShaderStage CurrentStage;
273  PeelType CurrentPeelType;
274  vtkTimeStamp CurrentStageTimeStamp;
275 
276  bool LastPeelHadVolumes;
277  int CurrentPeel;
278  unsigned int TranslucentOcclusionQueryId;
279  unsigned int TranslucentWrittenPixels;
280  unsigned int VolumetricOcclusionQueryId;
281  unsigned int VolumetricWrittenPixels;
282  unsigned int OcclusionThreshold;
283 
284  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
285  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
286 
287  // Cached state:
288  bool SaveScissorTestState;
289  int CullFaceMode;
290  bool CullFaceEnabled;
291 
292 private:
293  vtkDualDepthPeelingPass(const vtkDualDepthPeelingPass&) VTK_DELETE_FUNCTION;
294  void operator=(const vtkDualDepthPeelingPass&) VTK_DELETE_FUNCTION;
295 };
296 
297 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:44
Implement an Order Independent Transparency render pass.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
record modification and/or execution time
Definition: vtkTimeStamp.h:32
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
Context in which a vtkRenderPass will render.
a simple class to control print indentation
Definition: vtkIndent.h:33
The VertexArrayObject class uses, or emulates, vertex array objects.
Internal class which encapsulates OpenGL FramebufferObject.
static vtkDepthPeelingPass * New()
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstract class specifies interface to map data
abstracts an OpenGL texture object.
Implements the dual depth peeling algorithm.
OpenGL buffer object.
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:55
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.