VTK  9.3.20240329
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:
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
62  void Render(const vtkRenderState* s) override;
64 
66 
71  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
72  virtual void SetVolumetricPass(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 
128 
130  vtkSetMacro(CurrentPeelType, PeelType);
131 
136 
141 
146 
148 
152  void Initialize(const vtkRenderState* state);
153 
155 
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 
185 
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.
201 
204 
207 
209 
212 
215 
221 
222  void Finalize();
223 
225 
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 class specifies interface to map data
Implement Depth Peeling for use within a framebuffer pass.
Implements the dual depth peeling algorithm.
void ActivateDrawBuffers(const std::array< TextureName, NumTextures > &a)
Bind and activate draw buffers.
void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s)
Initialize helpers.
void PeelVolumesOutsideTranslucentRange()
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
void RenderVolumetricPass()
Render any volumetric geometry.
void Prepare()
Fill textures with initial values, bind the framebuffer.
void ActivateDrawBuffer(TextureName id)
Bind and activate draw buffers.
void StartTranslucentOcclusionQuery()
~vtkDualDepthPeelingPass() override
void InitializeTargetsForVolumetricPass()
void Initialize(const vtkRenderState *state)
Allocate and configure FBOs and textures.
vtkOpenGLQuadHelper * BlendHelper
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetCurrentStage(ShaderStage stage)
void SwapFrontBufferSourceDest()
Swap the src/dest render targets:
vtkOpenGLQuadHelper * CopyDepthHelper
void InitializeTargetsForTranslucentPass()
void FreeGLObjects()
Release all FBOs and textures.
void Peel()
Render the scene to produce the next set of peels.
vtkOpenGLQuadHelper * BackBlendHelper
static vtkDualDepthPeelingPass * New()
void RenderTranslucentPass()
Render the translucent pass geometry, counting number of render calls.
void Render(const vtkRenderState *s) override
Perform rendering according to a render state s.
void ActivateDrawBuffers(const TextureName *ids, size_t numTextures)
Bind and activate draw buffers.
void StartVolumetricOcclusionQuery()
void CopyFrontSourceToFrontDestination()
vtkOpenGLQuadHelper * CopyColorHelper
const vtkRenderState * RenderState
void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s)
Initialize helpers.
void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s)
Initialize helpers.
void InitFramebuffer(const vtkRenderState *s)
Initialize helpers.
a simple class to control print indentation
Definition: vtkIndent.h:108
Internal class which encapsulates OpenGL FramebufferObject.
Class to make rendering a full screen quad easier.
The VertexArrayObject class uses, or emulates, vertex array objects.
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:66
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:49
Context in which a vtkRenderPass will render.
Asynchronously measures GPU execution times for a series of events.
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
record modification and/or execution time
Definition: vtkTimeStamp.h:44
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270