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:
71  void PrintSelf(ostream& os, vtkIndent indent) override;
72 
73  void Render(const vtkRenderState* s) 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;
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);
101  vtkProp* prop, vtkOpenGLVertexArrayObject* VAO);
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 
139 
141  vtkSetMacro(CurrentPeelType, PeelType);
142 
147 
152 
157 
159 
163  void Initialize(const vtkRenderState* state);
164 
166 
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 
196 
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.
212 
215 
218 
220 
223 
226 
232 
233  void Finalize();
234 
236 
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
vtkDualDepthPeelingPass::AlphaBlendRender
void AlphaBlendRender()
vtkDualDepthPeelingPass::PeelType
PeelType
Definition: vtkDualDepthPeelingPass.h:132
vtkDualDepthPeelingPass::FrontDestination
TextureName FrontDestination
Definition: vtkDualDepthPeelingPass.h:252
vtkDualDepthPeelingPass::SaveScissorTestState
bool SaveScissorTestState
Definition: vtkDualDepthPeelingPass.h:272
vtkDualDepthPeelingPass::TranslucentOcclusionQueryId
unsigned int TranslucentOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:262
vtkDualDepthPeelingPass
Implements the dual depth peeling algorithm.
Definition: vtkDualDepthPeelingPass.h:67
vtkDualDepthPeelingPass::ActivateDrawBuffers
void ActivateDrawBuffers(const std::array< TextureName, NumTextures > &a)
Bind and activate draw buffers.
Definition: vtkDualDepthPeelingPass.h:181
vtkDepthPeelingPass
Implement Depth Peeling for use within a framebuffer pass.
Definition: vtkDepthPeelingPass.h:64
vtkDualDepthPeelingPass::IsRenderingVolumes
bool IsRenderingVolumes()
vtkDualDepthPeelingPass::TranslucentPeel
@ TranslucentPeel
Definition: vtkDualDepthPeelingPass.h:133
vtkDualDepthPeelingPass::DepthB
@ DepthB
Definition: vtkDualDepthPeelingPass.h:114
vtkDualDepthPeelingPass::RenderState
const vtkRenderState * RenderState
Definition: vtkDualDepthPeelingPass.h:242
vtkDualDepthPeelingPass::BackBlendHelper
vtkOpenGLQuadHelper * BackBlendHelper
Definition: vtkDualDepthPeelingPass.h:246
vtkDualDepthPeelingPass::CopyDepthHelper
vtkOpenGLQuadHelper * CopyDepthHelper
Definition: vtkDualDepthPeelingPass.h:245
vtkDualDepthPeelingPass::StartVolumetricOcclusionQuery
void StartVolumetricOcclusionQuery()
vtkDualDepthPeelingPass::InitializeTargetsForVolumetricPass
void InitializeTargetsForVolumetricPass()
vtkDualDepthPeelingPass::SetTranslucentShaderParameters
bool SetTranslucentShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO)
vtkDualDepthPeelingPass::InitializeOcclusionQuery
void InitializeOcclusionQuery()
vtkDualDepthPeelingPass::InitializingDepth
@ InitializingDepth
Definition: vtkDualDepthPeelingPass.h:123
vtkDualDepthPeelingPass::PeelVolumesOutsideTranslucentRange
void PeelVolumesOutsideTranslucentRange()
vtkDualDepthPeelingPass::VolumetricWrittenPixels
unsigned int VolumetricWrittenPixels
Definition: vtkDualDepthPeelingPass.h:265
vtkDualDepthPeelingPass::TextureName
TextureName
Definition: vtkDualDepthPeelingPass.h:108
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:33
vtkDualDepthPeelingPass::CurrentStageTimeStamp
vtkTimeStamp CurrentStageTimeStamp
Definition: vtkDualDepthPeelingPass.h:258
vtkDualDepthPeelingPass::FreeGLObjects
void FreeGLObjects()
Release all FBOs and textures.
vtkOpenGLFramebufferObject
Internal class which encapsulates OpenGL FramebufferObject.
Definition: vtkOpenGLFramebufferObject.h:182
vtkDualDepthPeelingPass::CurrentPeelType
PeelType CurrentPeelType
Definition: vtkDualDepthPeelingPass.h:257
vtkDualDepthPeelingPass::PostReplaceTranslucentShaderValues
bool PostReplaceTranslucentShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop)
vtkDualDepthPeelingPass::PeelTranslucentGeometry
void PeelTranslucentGeometry()
vtkOpenGLQuadHelper
Class to make rendering a full screen quad easier.
Definition: vtkOpenGLQuadHelper.h:58
vtkDualDepthPeelingPass::NumberOfPasses
@ NumberOfPasses
Definition: vtkDualDepthPeelingPass.h:127
vtkDualDepthPeelingPass::CopyFrontSourceToFrontDestination
void CopyFrontSourceToFrontDestination()
vtkDualDepthPeelingPass::CopyOpaqueDepthBuffer
void CopyOpaqueDepthBuffer()
vtkDualDepthPeelingPass::InitColorTexture
void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s)
Initialize helpers.
vtkDualDepthPeelingPass::FrontA
@ FrontA
Definition: vtkDualDepthPeelingPass.h:111
vtkDualDepthPeelingPass::RenderTranslucentPass
void RenderTranslucentPass()
Render the translucent pass geometry, counting number of render calls.
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
vtkDualDepthPeelingPass::InitFramebuffer
void InitFramebuffer(const vtkRenderState *s)
vtkDualDepthPeelingPass::BlendFinalImage
void BlendFinalImage()
vtkDualDepthPeelingPass::DepthDestination
TextureName DepthDestination
Definition: vtkDualDepthPeelingPass.h:254
vtkDualDepthPeelingPass::InitOpaqueDepthTexture
void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s)
vtkDualDepthPeelingPass::Back
@ Back
Definition: vtkDualDepthPeelingPass.h:110
vtkDepthPeelingPass.h
vtkDualDepthPeelingPass::Finalize
void Finalize()
vtkDualDepthPeelingPass::StartTranslucentOcclusionQuery
void StartTranslucentOcclusionQuery()
vtkDualDepthPeelingPass::Render
void Render(const vtkRenderState *s) override
Perform rendering according to a render state s.
vtkDualDepthPeelingPass::Peel
void Peel()
Render the scene to produce the next set of peels.
vtkDualDepthPeelingPass::BlendBackBuffer
void BlendBackBuffer()
vtkDualDepthPeelingPass::OcclusionThreshold
unsigned int OcclusionThreshold
Definition: vtkDualDepthPeelingPass.h:266
vtkDualDepthPeelingPass::CurrentStage
ShaderStage CurrentStage
Definition: vtkDualDepthPeelingPass.h:256
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:45
vtkDualDepthPeelingPass::LastPeelHadVolumes
bool LastPeelHadVolumes
Definition: vtkDualDepthPeelingPass.h:260
vtkDualDepthPeelingPass::EndVolumetricOcclusionQuery
void EndVolumetricOcclusionQuery()
vtkDualDepthPeelingPass::PeelVolumetricGeometry
void PeelVolumetricGeometry()
vtkDualDepthPeelingPass::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDualDepthPeelingPass::SwapFrontBufferSourceDest
void SwapFrontBufferSourceDest()
Swap the src/dest render targets:
vtkDualDepthPeelingPass::DeleteOcclusionQueryIds
void DeleteOcclusionQueryIds()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:41
vtkDualDepthPeelingPass::SwapDepthBufferSourceDest
void SwapDepthBufferSourceDest()
vtkDualDepthPeelingPass::GetShaderStageMTime
vtkMTimeType GetShaderStageMTime() override
For multi-stage render passes that need to change shader code during a single pass,...
vtkDualDepthPeelingPass::CullFaceEnabled
bool CullFaceEnabled
Definition: vtkDualDepthPeelingPass.h:274
vtkDualDepthPeelingPass::ClearFrontDestination
void ClearFrontDestination()
vtkDualDepthPeelingPass::DepthA
@ DepthA
Definition: vtkDualDepthPeelingPass.h:113
vtkDualDepthPeelingPass::PostReplaceShaderValues
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.
vtkDualDepthPeelingPass::PreReplaceVolumetricShaderValues
bool PreReplaceVolumetricShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop)
vtkDualDepthPeelingPass::SetVolumetricShaderParameters
bool SetVolumetricShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO)
vtkDualDepthPeelingPass::InitializeDepth
void InitializeDepth()
vtkDualDepthPeelingPass::ActivateDrawBuffers
void ActivateDrawBuffers(const TextureName *ids, size_t numTextures)
Bind and activate draw buffers.
vtkDualDepthPeelingPass::VolumetricRenderCount
int VolumetricRenderCount
Definition: vtkDualDepthPeelingPass.h:269
vtkDualDepthPeelingPass::SetVolumetricPass
virtual void SetVolumetricPass(vtkRenderPass *volumetricPass)
vtkRenderTimerLog
Asynchronously measures GPU execution times for a series of events.
Definition: vtkRenderTimerLog.h:81
vtkDualDepthPeelingPass::InitDepthTexture
void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s)
vtkDualDepthPeelingPass::CopyColorHelper
vtkOpenGLQuadHelper * CopyColorHelper
Definition: vtkDualDepthPeelingPass.h:244
vtkDualDepthPeelingPass::TranslucentRenderCount
int TranslucentRenderCount
Definition: vtkDualDepthPeelingPass.h:268
vtkDualDepthPeelingPass::SetCurrentStage
void SetCurrentStage(ShaderStage stage)
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:48
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkDualDepthPeelingPass::Prepare
void Prepare()
Fill textures with initial values, bind the framebuffer.
vtkDualDepthPeelingPass::RenderVolumetricPass
void RenderVolumetricPass()
Render any volumetric geometry.
vtkDualDepthPeelingPass::EndTranslucentOcclusionQuery
void EndTranslucentOcclusionQuery()
vtkDualDepthPeelingPass::Timer
vtkRenderTimerLog * Timer
Definition: vtkDualDepthPeelingPass.h:240
vtkDualDepthPeelingPass::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
vtkDualDepthPeelingPass::VolumetricPass
vtkRenderPass * VolumetricPass
Definition: vtkDualDepthPeelingPass.h:241
vtkDualDepthPeelingPass::BlendHelper
vtkOpenGLQuadHelper * BlendHelper
Definition: vtkDualDepthPeelingPass.h:247
vtkDualDepthPeelingPass::PrepareFrontDestination
void PrepareFrontDestination()
vtkDualDepthPeelingPass::AlphaBlending
@ AlphaBlending
Definition: vtkDualDepthPeelingPass.h:125
vtkDualDepthPeelingPass::FrontSource
TextureName FrontSource
Definition: vtkDualDepthPeelingPass.h:251
vtkDualDepthPeelingPass::Peeling
@ Peeling
Definition: vtkDualDepthPeelingPass.h:124
vtkDualDepthPeelingPass::OpaqueDepth
@ OpaqueDepth
Definition: vtkDualDepthPeelingPass.h:115
vtkDualDepthPeelingPass::ActivateDrawBuffer
void ActivateDrawBuffer(TextureName id)
Bind and activate draw buffers.
Definition: vtkDualDepthPeelingPass.h:179
vtkDualDepthPeelingPass::CurrentPeel
int CurrentPeel
Definition: vtkDualDepthPeelingPass.h:261
vtkDualDepthPeelingPass::InitializeTargetsForTranslucentPass
void InitializeTargetsForTranslucentPass()
vtkDualDepthPeelingPass::SetShaderParameters
bool SetShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO=nullptr) override
Update the uniforms of the shader program.
vtkDualDepthPeelingPass::FrontB
@ FrontB
Definition: vtkDualDepthPeelingPass.h:112
vtkDualDepthPeelingPass::~vtkDualDepthPeelingPass
~vtkDualDepthPeelingPass() override
vtkDualDepthPeelingPass::PreReplaceShaderValues
bool PreReplaceShaderValues(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.
vtkDualDepthPeelingPass::DepthSource
TextureName DepthSource
Definition: vtkDualDepthPeelingPass.h:253
vtkDualDepthPeelingPass::New
static vtkDualDepthPeelingPass * New()
vtkDualDepthPeelingPass::CullFaceMode
int CullFaceMode
Definition: vtkDualDepthPeelingPass.h:273
vtkRenderState
Context in which a vtkRenderPass will render.
Definition: vtkRenderState.h:41
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:37
vtkDualDepthPeelingPass::Initialize
void Initialize(const vtkRenderState *state)
Allocate and configure FBOs and textures.
vtkDualDepthPeelingPass::TranslucentWrittenPixels
unsigned int TranslucentWrittenPixels
Definition: vtkDualDepthPeelingPass.h:263
vtkDualDepthPeelingPass::VolumetricOcclusionQueryId
unsigned int VolumetricOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:264
vtkDualDepthPeelingPass::PeelingDone
bool PeelingDone()
vtkAbstractMapper
abstract class specifies interface to map data
Definition: vtkAbstractMapper.h:53
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
vtkDualDepthPeelingPass::ShaderStage
ShaderStage
Definition: vtkDualDepthPeelingPass.h:122
vtkDualDepthPeelingPass::vtkDualDepthPeelingPass
vtkDualDepthPeelingPass()
vtkRenderPass
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:57
vtkDualDepthPeelingPass::DepthTestEnabled
bool DepthTestEnabled
Definition: vtkDualDepthPeelingPass.h:275