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 
57 #include <array> // For std::array!
58 
62 class vtkRenderTimerLog;
63 class vtkShaderProgram;
64 class vtkTextureObject;
65 
66 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass:
67  public vtkDepthPeelingPass
68 {
69 public:
70  static vtkDualDepthPeelingPass* New();
72  void PrintSelf(ostream &os, vtkIndent indent) override;
73 
74  void Render(const vtkRenderState *s) override;
75  void ReleaseGraphicsResources(vtkWindow *w) override;
76 
78 
83  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
84  virtual void SetVolumetricPass(vtkRenderPass *volumetricPass);
86 
87  // vtkOpenGLRenderPass virtuals:
88  bool PreReplaceShaderValues(std::string &vertexShader,
89  std::string &geometryShader,
90  std::string &fragmentShader,
91  vtkAbstractMapper *mapper,
92  vtkProp *prop) override;
93  bool PostReplaceShaderValues(std::string &vertexShader,
94  std::string &geometryShader,
95  std::string &fragmentShader,
96  vtkAbstractMapper *mapper,
97  vtkProp *prop) override;
98  bool SetShaderParameters(vtkShaderProgram *program,
99  vtkAbstractMapper *mapper,
100  vtkProp *prop,
101  vtkOpenGLVertexArrayObject *VAO = nullptr) override;
102  vtkMTimeType GetShaderStageMTime() override;
103 
104 protected:
105 
106  bool PostReplaceTranslucentShaderValues(std::string &vertexShader,
107  std::string &geometryShader,
108  std::string &fragmentShader,
109  vtkAbstractMapper *mapper,
110  vtkProp *prop);
111  bool PreReplaceVolumetricShaderValues(std::string &vertexShader,
112  std::string &geometryShader,
113  std::string &fragmentShader,
114  vtkAbstractMapper *mapper,
115  vtkProp *prop);
116  bool SetTranslucentShaderParameters(vtkShaderProgram *program,
117  vtkAbstractMapper *mapper, vtkProp *prop,
119  bool SetVolumetricShaderParameters(vtkShaderProgram *program,
120  vtkAbstractMapper *mapper, vtkProp *prop,
122 
123 
124  // Name the textures used by this render pass. These are indexes into
125  // this->Textures
127  {
128  BackTemp = 0, // RGBA8 back-to-front peeling buffer
129  Back, // RGBA8 back-to-front accumulation buffer
130  FrontA, // RGBA8 front-to-back accumulation buffer
131  FrontB, // RGBA8 front-to-back accumulation buffer
132  DepthA, // RG32F min-max depth buffer
133  DepthB, // RG32F min-max depth buffer
134  OpaqueDepth, // Stores the depth map from the opaque passes
135 
136  NumberOfTextures
137  };
138 
139  // The stages of this multipass render pass:
141  {
145 
147  Inactive = -1,
148  };
149 
150  enum PeelType
151  {
153  VolumetricPeel
154  };
155 
157  ~vtkDualDepthPeelingPass() override;
158 
159  void SetCurrentStage(ShaderStage stage);
160  vtkSetMacro(CurrentPeelType, PeelType)
161 
162 
165  void FreeGLObjects();
166 
170  void RenderTranslucentPass();
171 
175  void RenderVolumetricPass();
176 
177  bool IsRenderingVolumes();
178 
182  void Initialize(const vtkRenderState *state);
183 
185 
188  void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s);
189  void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
190  void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
191  void InitFramebuffer(const vtkRenderState *s);
193 
198  void ActivateDrawBuffer(TextureName id)
199  { this->ActivateDrawBuffers(&id, 1); }
200  template <size_t NumTextures>
201  void ActivateDrawBuffers(const std::array<TextureName, NumTextures> &a)
202  { this->ActivateDrawBuffers(a.data(), a.size()); }
203  void ActivateDrawBuffers(const TextureName *ids, size_t numTextures);
209  void Prepare();
210 
211  void InitializeOcclusionQuery();
212  void CopyOpaqueDepthBuffer();
213  void InitializeDepth();
214 
215  void PeelVolumesOutsideTranslucentRange();
216 
217  bool PeelingDone();
218 
222  void Peel();
223 
224  // Depending on whether we're handling volumes or not, we'll initialize the
225  // front destination buffer by either clearing it or copying the last peel's
226  // output into it.
227  void PrepareFrontDestination();
228  void ClearFrontDestination();
229  void CopyFrontSourceToFrontDestination();
230 
231  void InitializeTargetsForTranslucentPass();
232  void InitializeTargetsForVolumetricPass();
233 
234  void PeelTranslucentGeometry();
235  void PeelVolumetricGeometry();
236 
237  void BlendBackBuffer();
238 
239  void StartTranslucentOcclusionQuery();
240  void EndTranslucentOcclusionQuery();
241 
242  void StartVolumetricOcclusionQuery();
243  void EndVolumetricOcclusionQuery();
244 
248  void SwapFrontBufferSourceDest();
249  void SwapDepthBufferSourceDest();
250 
251  void Finalize();
252 
253  void AlphaBlendRender();
254 
255  void BlendFinalImage();
256  void DeleteOcclusionQueryIds();
257 
261 
266 
267  vtkTextureObject *Textures[NumberOfTextures];
268 
269  TextureName FrontSource; // The current front source buffer
270  TextureName FrontDestination; // The current front destination buffer
271  TextureName DepthSource; // The current depth source buffer
272  TextureName DepthDestination; // The current depth destination buffer
273 
277 
284  unsigned int OcclusionThreshold;
285 
286  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
287  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
288 
289  // Cached state:
294 
295 private:
297  void operator=(const vtkDualDepthPeelingPass&) = delete;
298 };
299 
300 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:52
void ActivateDrawBuffers(const std::array< TextureName, NumTextures > &a)
Bind and activate draw buffers.
Implement Depth Peeling for use within a framebuffer pass.
const vtkRenderState * RenderState
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
vtkOpenGLQuadHelper * BackBlendHelper
vtkOpenGLQuadHelper * CopyDepthHelper
record modification and/or execution time
Definition: vtkTimeStamp.h:35
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
Context in which a vtkRenderPass will render.
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
Internal class which encapsulates OpenGL FramebufferObject.
vtkOpenGLQuadHelper * CopyColorHelper
static vtkDepthPeelingPass * New()
abstract class specifies interface to map data
abstracts an OpenGL texture object.
vtkOpenGLQuadHelper * BlendHelper
Implements the dual depth peeling algorithm.
Class to make rendering a full screen quad easier.
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:58
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.