VTK  9.0.1
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 "vtkDepthPeelingPass.h"
55 #include "vtkRenderingOpenGL2Module.h" // For export macro
56 
57 #include <array> // For std::array!
58 
62 class vtkRenderTimerLog;
63 class vtkShaderProgram;
64 class vtkTextureObject;
65 
66 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass : public vtkDepthPeelingPass
67 {
68 public:
69  static vtkDualDepthPeelingPass* New();
71  void PrintSelf(ostream& os, vtkIndent indent) override;
72 
73  void Render(const vtkRenderState* s) override;
74  void ReleaseGraphicsResources(vtkWindow* w) override;
75 
77 
82  vtkGetObjectMacro(VolumetricPass, vtkRenderPass) virtual void SetVolumetricPass(
83  vtkRenderPass* volumetricPass);
85 
86  // vtkOpenGLRenderPass virtuals:
87  bool PreReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
88  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
89  bool PostReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
90  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
91  bool SetShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper, vtkProp* prop,
92  vtkOpenGLVertexArrayObject* VAO = nullptr) override;
94 
95 protected:
96  bool PostReplaceTranslucentShaderValues(std::string& vertexShader, std::string& geometryShader,
97  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
98  bool PreReplaceVolumetricShaderValues(std::string& vertexShader, std::string& geometryShader,
99  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
100  bool SetTranslucentShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
101  vtkProp* prop, vtkOpenGLVertexArrayObject* VAO);
102  bool SetVolumetricShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
103  vtkProp* prop, vtkOpenGLVertexArrayObject* VAO);
104 
105  // Name the textures used by this render pass. These are indexes into
106  // this->Textures
108  {
109  BackTemp = 0, // RGBA8 back-to-front peeling buffer
110  Back, // RGBA8 back-to-front accumulation buffer
111  FrontA, // RGBA8 front-to-back accumulation buffer
112  FrontB, // RGBA8 front-to-back accumulation buffer
113  DepthA, // RG32F min-max depth buffer
114  DepthB, // RG32F min-max depth buffer
115  OpaqueDepth, // Stores the depth map from the opaque passes
116 
117  NumberOfTextures
118  };
119 
120  // The stages of this multipass render pass:
122  {
126 
128  Inactive = -1,
129  };
130 
131  enum PeelType
132  {
134  VolumetricPeel
135  };
136 
138  ~vtkDualDepthPeelingPass() override;
139 
140  void SetCurrentStage(ShaderStage stage);
141  vtkSetMacro(CurrentPeelType, PeelType);
142 
146  void FreeGLObjects();
147 
151  void RenderTranslucentPass();
152 
156  void RenderVolumetricPass();
157 
158  bool IsRenderingVolumes();
159 
163  void Initialize(const vtkRenderState* state);
164 
166 
169  void InitColorTexture(vtkTextureObject* tex, const vtkRenderState* s);
170  void InitDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
171  void InitOpaqueDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
172  void InitFramebuffer(const vtkRenderState* s);
174 
179  void ActivateDrawBuffer(TextureName id) { this->ActivateDrawBuffers(&id, 1); }
180  template <size_t NumTextures>
181  void ActivateDrawBuffers(const std::array<TextureName, NumTextures>& a)
182  {
183  this->ActivateDrawBuffers(a.data(), a.size());
184  }
185  void ActivateDrawBuffers(const TextureName* ids, size_t numTextures);
191  void Prepare();
192 
193  void InitializeOcclusionQuery();
194  void CopyOpaqueDepthBuffer();
195  void InitializeDepth();
196 
197  void PeelVolumesOutsideTranslucentRange();
198 
199  bool PeelingDone();
200 
204  void Peel();
205 
206  // Depending on whether we're handling volumes or not, we'll initialize the
207  // front destination buffer by either clearing it or copying the last peel's
208  // output into it.
209  void PrepareFrontDestination();
210  void ClearFrontDestination();
211  void CopyFrontSourceToFrontDestination();
212 
213  void InitializeTargetsForTranslucentPass();
214  void InitializeTargetsForVolumetricPass();
215 
216  void PeelTranslucentGeometry();
217  void PeelVolumetricGeometry();
218 
219  void BlendBackBuffer();
220 
221  void StartTranslucentOcclusionQuery();
222  void EndTranslucentOcclusionQuery();
223 
224  void StartVolumetricOcclusionQuery();
225  void EndVolumetricOcclusionQuery();
226 
230  void SwapFrontBufferSourceDest();
231  void SwapDepthBufferSourceDest();
232 
233  void Finalize();
234 
235  void AlphaBlendRender();
236 
237  void BlendFinalImage();
238  void DeleteOcclusionQueryIds();
239 
243 
248 
249  vtkTextureObject* Textures[NumberOfTextures];
250 
251  TextureName FrontSource; // The current front source buffer
252  TextureName FrontDestination; // The current front destination buffer
253  TextureName DepthSource; // The current depth source buffer
254  TextureName DepthDestination; // The current depth destination buffer
255 
259 
266  unsigned int OcclusionThreshold;
267 
268  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
269  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
270 
271  // Cached state:
276 
277 private:
279  void operator=(const vtkDualDepthPeelingPass&) = delete;
280 };
281 
282 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:53
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:293
vtkOpenGLQuadHelper * BackBlendHelper
vtkOpenGLQuadHelper * CopyDepthHelper
record modification and/or execution time
Definition: vtkTimeStamp.h:32
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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:33
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
virtual bool PreReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop)
Use vtkShaderProgram::Substitute to replace //VTK::XXX:YYY declarations in the shader sources...
abstracts an OpenGL texture object.
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
vtkOpenGLQuadHelper * BlendHelper
virtual vtkMTimeType GetShaderStageMTime()
For multi-stage render passes that need to change shader code during a single pass, use this method to notify a mapper that the shader needs to be rebuilt (rather than reuse the last cached shader.
Implements the dual depth peeling algorithm.
void Render(const vtkRenderState *s) override
Perform rendering according to a render state s.
Class to make rendering a full screen quad easier.
void ActivateDrawBuffer(TextureName id)
Bind and activate draw buffers.
bool PostReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop) override
Use vtkShaderProgram::Substitute to replace //VTK::XXX:YYY declarations in the shader sources...
bool SetShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO=nullptr) override
Update the uniforms of the shader program.
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:56
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.