VTK  9.7.1
vtkDualDepthPeelingPass.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
39 #ifndef vtkDualDepthPeelingPass_h
40 #define vtkDualDepthPeelingPass_h
41 
42 #include "vtkDepthPeelingPass.h"
43 #include "vtkRenderingOpenGL2Module.h" // For export macro
44 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
45 
46 #include <array> // For std::array!
47 
48 VTK_ABI_NAMESPACE_BEGIN
52 class vtkRenderTimerLog;
53 class vtkShaderProgram;
54 class vtkTextureObject;
55 
56 class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkDualDepthPeelingPass
57  : public vtkDepthPeelingPass
58 {
59 public:
60  static vtkDualDepthPeelingPass* New();
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
64  void Render(const vtkRenderState* s) override;
65  void ReleaseGraphicsResources(vtkWindow* w) override;
66 
68 
73  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
74  virtual void SetVolumetricPass(vtkRenderPass* volumetricPass);
76 
77  // vtkOpenGLRenderPass virtuals:
78  bool PreReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
79  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
80  bool PostReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
81  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
82  bool SetShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper, vtkProp* prop,
83  vtkOpenGLVertexArrayObject* VAO = nullptr) override;
84  vtkMTimeType GetShaderStageMTime() override;
85 
86 protected:
87  bool PostReplaceTranslucentShaderValues(std::string& vertexShader, std::string& geometryShader,
88  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
89  bool PreReplaceVolumetricShaderValues(std::string& vertexShader, std::string& geometryShader,
90  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
91  bool SetTranslucentShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
93  bool SetVolumetricShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
95 
96  // Name the textures used by this render pass. These are indexes into
97  // this->Textures
99  {
100  BackTemp = 0, // RGBA8 back-to-front peeling buffer
101  Back, // RGBA8 back-to-front accumulation buffer
102  FrontA, // RGBA8 front-to-back accumulation buffer
103  FrontB, // RGBA8 front-to-back accumulation buffer
104  DepthA, // RG32F min-max depth buffer
105  DepthB, // RG32F min-max depth buffer
106  OpaqueDepth, // Stores the depth map from the opaque passes
107 
108  NumberOfTextures
109  };
110 
111  // The stages of this multipass render pass:
113  {
114  InitializingDepth = 0,
115  Peeling = 1,
116  AlphaBlending = 2,
117 
118  NumberOfPasses = 3,
119  Inactive = -1,
120  };
121 
122  enum PeelType
123  {
125  VolumetricPeel
126  };
127 
129  ~vtkDualDepthPeelingPass() override;
130 
131  void SetCurrentStage(ShaderStage stage);
132  vtkSetMacro(CurrentPeelType, PeelType);
133 
137  void FreeGLObjects();
138 
142  void RenderTranslucentPass();
143 
147  void RenderVolumetricPass();
148 
149  bool IsRenderingVolumes();
150 
154  void Initialize(const vtkRenderState* state);
155 
157 
160  void InitColorTexture(vtkTextureObject* tex, const vtkRenderState* s);
161  void InitDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
162  void InitOpaqueDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
163  void InitFramebuffer(const vtkRenderState* s);
165 
170  void ActivateDrawBuffer(TextureName id) { this->ActivateDrawBuffers(&id, 1); }
171  template <size_t NumTextures>
172  void ActivateDrawBuffers(const std::array<TextureName, NumTextures>& a)
173  {
174  this->ActivateDrawBuffers(a.data(), a.size());
175  }
176  void ActivateDrawBuffers(const TextureName* ids, size_t numTextures);
182  void Prepare();
183 
184  void InitializeOcclusionQuery();
185  void CopyOpaqueDepthBuffer();
186  void InitializeDepth();
187 
188  void PeelVolumesOutsideTranslucentRange();
189 
190  bool PeelingDone();
191 
195  void Peel();
196 
197  // Depending on whether we're handling volumes or not, we'll initialize the
198  // front destination buffer by either clearing it or copying the last peel's
199  // output into it.
200  void PrepareFrontDestination();
201  void ClearFrontDestination();
202  void CopyFrontSourceToFrontDestination();
203 
204  void InitializeTargetsForTranslucentPass();
205  void InitializeTargetsForVolumetricPass();
206 
207  void PeelTranslucentGeometry();
208  void PeelVolumetricGeometry();
209 
210  void BlendBackBuffer();
211 
212  void StartTranslucentOcclusionQuery();
213  void EndTranslucentOcclusionQuery();
214 
215  void StartVolumetricOcclusionQuery();
216  void EndVolumetricOcclusionQuery();
217 
221  void SwapFrontBufferSourceDest();
222  void SwapDepthBufferSourceDest();
223 
224  void Finalize();
225 
226  void AlphaBlendRender();
227 
228  void BlendFinalImage();
229  void DeleteOcclusionQueryIds();
230 
234 
239 
240  vtkTextureObject* Textures[NumberOfTextures];
241 
242  TextureName FrontSource; // The current front source buffer
243  TextureName FrontDestination; // The current front destination buffer
244  TextureName DepthSource; // The current depth source buffer
245  TextureName DepthDestination; // The current depth destination buffer
246 
250 
257  unsigned int OcclusionThreshold;
258 
259  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
260  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
261 
262  // Cached state:
267 
268 private:
270  void operator=(const vtkDualDepthPeelingPass&) = delete;
271 };
272 
273 VTK_ABI_NAMESPACE_END
274 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
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:318
vtkOpenGLQuadHelper * BackBlendHelper
vtkOpenGLQuadHelper * CopyDepthHelper
record modification and/or execution time
Definition: vtkTimeStamp.h:24
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:41
Context in which a vtkRenderPass will render.
a simple class to control print indentation
Definition: vtkIndent.h:28
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.
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
vtkOpenGLQuadHelper * BlendHelper
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.
#define VTK_MARSHALAUTO
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:49
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.