VTK  9.3.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 
45 #include <array> // For std::array!
46 
47 VTK_ABI_NAMESPACE_BEGIN
51 class vtkRenderTimerLog;
52 class vtkShaderProgram;
53 class vtkTextureObject;
54 
55 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass : public vtkDepthPeelingPass
56 {
57 public:
58  static vtkDualDepthPeelingPass* New();
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
62  void Render(const vtkRenderState* s) override;
63  void ReleaseGraphicsResources(vtkWindow* w) override;
64 
66 
71  vtkGetObjectMacro(VolumetricPass, vtkRenderPass) virtual void SetVolumetricPass(
72  vtkRenderPass* volumetricPass);
74 
75  // vtkOpenGLRenderPass virtuals:
76  bool PreReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
77  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
78  bool PostReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
79  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
80  bool SetShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper, vtkProp* prop,
81  vtkOpenGLVertexArrayObject* VAO = nullptr) override;
82  vtkMTimeType GetShaderStageMTime() override;
83 
84 protected:
85  bool PostReplaceTranslucentShaderValues(std::string& vertexShader, std::string& geometryShader,
86  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
87  bool PreReplaceVolumetricShaderValues(std::string& vertexShader, std::string& geometryShader,
88  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
89  bool SetTranslucentShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
91  bool SetVolumetricShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
93 
94  // Name the textures used by this render pass. These are indexes into
95  // this->Textures
97  {
98  BackTemp = 0, // RGBA8 back-to-front peeling buffer
99  Back, // RGBA8 back-to-front accumulation buffer
100  FrontA, // RGBA8 front-to-back accumulation buffer
101  FrontB, // RGBA8 front-to-back accumulation buffer
102  DepthA, // RG32F min-max depth buffer
103  DepthB, // RG32F min-max depth buffer
104  OpaqueDepth, // Stores the depth map from the opaque passes
105 
106  NumberOfTextures
107  };
108 
109  // The stages of this multipass render pass:
111  {
115 
117  Inactive = -1,
118  };
119 
120  enum PeelType
121  {
123  VolumetricPeel
124  };
125 
127  ~vtkDualDepthPeelingPass() override;
128 
129  void SetCurrentStage(ShaderStage stage);
130  vtkSetMacro(CurrentPeelType, PeelType);
131 
135  void FreeGLObjects();
136 
140  void RenderTranslucentPass();
141 
145  void RenderVolumetricPass();
146 
147  bool IsRenderingVolumes();
148 
152  void Initialize(const vtkRenderState* state);
153 
155 
158  void InitColorTexture(vtkTextureObject* tex, const vtkRenderState* s);
159  void InitDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
160  void InitOpaqueDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
161  void InitFramebuffer(const vtkRenderState* s);
163 
168  void ActivateDrawBuffer(TextureName id) { this->ActivateDrawBuffers(&id, 1); }
169  template <size_t NumTextures>
170  void ActivateDrawBuffers(const std::array<TextureName, NumTextures>& a)
171  {
172  this->ActivateDrawBuffers(a.data(), a.size());
173  }
174  void ActivateDrawBuffers(const TextureName* ids, size_t numTextures);
180  void Prepare();
181 
182  void InitializeOcclusionQuery();
183  void CopyOpaqueDepthBuffer();
184  void InitializeDepth();
185 
186  void PeelVolumesOutsideTranslucentRange();
187 
188  bool PeelingDone();
189 
193  void Peel();
194 
195  // Depending on whether we're handling volumes or not, we'll initialize the
196  // front destination buffer by either clearing it or copying the last peel's
197  // output into it.
198  void PrepareFrontDestination();
199  void ClearFrontDestination();
200  void CopyFrontSourceToFrontDestination();
201 
202  void InitializeTargetsForTranslucentPass();
203  void InitializeTargetsForVolumetricPass();
204 
205  void PeelTranslucentGeometry();
206  void PeelVolumetricGeometry();
207 
208  void BlendBackBuffer();
209 
210  void StartTranslucentOcclusionQuery();
211  void EndTranslucentOcclusionQuery();
212 
213  void StartVolumetricOcclusionQuery();
214  void EndVolumetricOcclusionQuery();
215 
219  void SwapFrontBufferSourceDest();
220  void SwapDepthBufferSourceDest();
221 
222  void Finalize();
223 
224  void AlphaBlendRender();
225 
226  void BlendFinalImage();
227  void DeleteOcclusionQueryIds();
228 
232 
237 
238  vtkTextureObject* Textures[NumberOfTextures];
239 
240  TextureName FrontSource; // The current front source buffer
241  TextureName FrontDestination; // The current front destination buffer
242  TextureName DepthSource; // The current depth source buffer
243  TextureName DepthDestination; // The current depth destination buffer
244 
248 
255  unsigned int OcclusionThreshold;
256 
257  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
258  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
259 
260  // Cached state:
265 
266 private:
268  void operator=(const vtkDualDepthPeelingPass&) = delete;
269 };
270 
271 VTK_ABI_NAMESPACE_END
272 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
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:270
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:27
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.
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:48
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.