VTK
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 "vtkRenderingOpenGL2Module.h" // For export macro
55 #include "vtkDepthPeelingPass.h"
56 
57 #include <array> // For std::array!
58 
62 class vtkRenderTimerLog;
63 class vtkShaderProgram;
64 class vtkTextureObject;
65 
66 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass:
67  public vtkDepthPeelingPass
68 {
69 public:
72  void PrintSelf(ostream &os, vtkIndent indent) override;
73 
74  void Render(const vtkRenderState *s) override;
75  void ReleaseGraphicsResources(vtkWindow *w) override;
76 
78 
83  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
84  virtual void SetVolumetricPass(vtkRenderPass *volumetricPass);
86 
87  // vtkOpenGLRenderPass virtuals:
88  bool PreReplaceShaderValues(std::string &vertexShader,
89  std::string &geometryShader,
90  std::string &fragmentShader,
91  vtkAbstractMapper *mapper,
92  vtkProp *prop) override;
93  bool PostReplaceShaderValues(std::string &vertexShader,
94  std::string &geometryShader,
95  std::string &fragmentShader,
96  vtkAbstractMapper *mapper,
97  vtkProp *prop) override;
98  bool SetShaderParameters(vtkShaderProgram *program,
99  vtkAbstractMapper *mapper,
100  vtkProp *prop,
101  vtkOpenGLVertexArrayObject *VAO = nullptr) override;
102  vtkMTimeType GetShaderStageMTime() override;
103 
104 protected:
105 
106  bool PostReplaceTranslucentShaderValues(std::string &vertexShader,
107  std::string &geometryShader,
108  std::string &fragmentShader,
109  vtkAbstractMapper *mapper,
110  vtkProp *prop);
111  bool PreReplaceVolumetricShaderValues(std::string &vertexShader,
112  std::string &geometryShader,
113  std::string &fragmentShader,
114  vtkAbstractMapper *mapper,
115  vtkProp *prop);
116  bool SetTranslucentShaderParameters(vtkShaderProgram *program,
117  vtkAbstractMapper *mapper, vtkProp *prop,
119  bool SetVolumetricShaderParameters(vtkShaderProgram *program,
120  vtkAbstractMapper *mapper, vtkProp *prop,
122 
123 
124  // Name the textures used by this render pass. These are indexes into
125  // this->Textures
127  {
128  BackTemp = 0, // RGBA8 back-to-front peeling buffer
129  Back, // RGBA8 back-to-front accumulation buffer
130  FrontA, // RGBA8 front-to-back accumulation buffer
131  FrontB, // RGBA8 front-to-back accumulation buffer
132  DepthA, // RG32F min-max depth buffer
133  DepthB, // RG32F min-max depth buffer
134  OpaqueDepth, // Stores the depth map from the opaque passes
135 
136  NumberOfTextures
137  };
138 
139  // The stages of this multipass render pass:
141  {
145 
147  Inactive = -1,
148  };
149 
150  enum PeelType
151  {
153  VolumetricPeel
154  };
155 
158 
160  vtkSetMacro(CurrentPeelType, PeelType)
161 
162 
165  void FreeGLObjects();
166 
170  void RenderTranslucentPass();
171 
175  void RenderVolumetricPass();
176 
177  bool IsRenderingVolumes();
178 
182  void Initialize(const vtkRenderState *state);
183 
185 
188  void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s);
189  void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
190  void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
191  void InitFramebuffer(const vtkRenderState *s);
193 
198  void ActivateDrawBuffer(TextureName id)
199  { this->ActivateDrawBuffers(&id, 1); }
200  template <size_t NumTextures>
201  void ActivateDrawBuffers(const std::array<TextureName, NumTextures> &a)
202  { this->ActivateDrawBuffers(a.data(), a.size()); }
203  void ActivateDrawBuffers(const TextureName *ids, size_t numTextures);
209  void Prepare();
210 
214 
216 
217  bool PeelingDone();
218 
222  void Peel();
223 
224  // Depending on whether we're handling volumes or not, we'll initialize the
225  // front destination buffer by either clearing it or copying the last peel's
226  // output into it.
230 
233 
236 
238 
241 
244 
250 
251  void Finalize();
252 
254 
257 
261 
266 
267  vtkTextureObject *Textures[NumberOfTextures];
268 
269  TextureName FrontSource; // The current front source buffer
270  TextureName FrontDestination; // The current front destination buffer
271  TextureName DepthSource; // The current depth source buffer
272  TextureName DepthDestination; // The current depth destination buffer
273 
277 
284  unsigned int OcclusionThreshold;
285 
286  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
287  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
288 
289  // Cached state:
294 
295 private:
297  void operator=(const vtkDualDepthPeelingPass&) = delete;
298 };
299 
300 #endif // vtkDualDepthPeelingPass_h
vtkDualDepthPeelingPass::AlphaBlendRender
void AlphaBlendRender()
vtkDualDepthPeelingPass::PeelType
PeelType
Definition: vtkDualDepthPeelingPass.h:151
vtkDualDepthPeelingPass::FrontDestination
TextureName FrontDestination
Definition: vtkDualDepthPeelingPass.h:270
vtkDualDepthPeelingPass::SaveScissorTestState
bool SaveScissorTestState
Definition: vtkDualDepthPeelingPass.h:290
vtkDualDepthPeelingPass::TranslucentOcclusionQueryId
unsigned int TranslucentOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:280
vtkDualDepthPeelingPass
Implements the dual depth peeling algorithm.
Definition: vtkDualDepthPeelingPass.h:68
vtkDualDepthPeelingPass::ActivateDrawBuffers
void ActivateDrawBuffers(const std::array< TextureName, NumTextures > &a)
Bind and activate draw buffers.
Definition: vtkDualDepthPeelingPass.h:201
vtkDepthPeelingPass
Implement Depth Peeling for use within a framebuffer pass.
Definition: vtkDepthPeelingPass.h:68
vtkDualDepthPeelingPass::TranslucentPeel
@ TranslucentPeel
Definition: vtkDualDepthPeelingPass.h:152
vtkDualDepthPeelingPass::DepthB
@ DepthB
Definition: vtkDualDepthPeelingPass.h:133
vtkDualDepthPeelingPass::RenderState
const vtkRenderState * RenderState
Definition: vtkDualDepthPeelingPass.h:260
vtkDualDepthPeelingPass::BackBlendHelper
vtkOpenGLQuadHelper * BackBlendHelper
Definition: vtkDualDepthPeelingPass.h:264
vtkDualDepthPeelingPass::CopyDepthHelper
vtkOpenGLQuadHelper * CopyDepthHelper
Definition: vtkDualDepthPeelingPass.h:263
vtkDualDepthPeelingPass::StartVolumetricOcclusionQuery
void StartVolumetricOcclusionQuery()
vtkDualDepthPeelingPass::InitializeTargetsForVolumetricPass
void InitializeTargetsForVolumetricPass()
vtkDualDepthPeelingPass::InitializeOcclusionQuery
void InitializeOcclusionQuery()
vtkDualDepthPeelingPass::InitializingDepth
@ InitializingDepth
Definition: vtkDualDepthPeelingPass.h:142
vtkDualDepthPeelingPass::PeelVolumesOutsideTranslucentRange
void PeelVolumesOutsideTranslucentRange()
vtkDualDepthPeelingPass::VolumetricWrittenPixels
unsigned int VolumetricWrittenPixels
Definition: vtkDualDepthPeelingPass.h:283
vtkDualDepthPeelingPass::TextureName
TextureName
Definition: vtkDualDepthPeelingPass.h:127
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:36
vtkDualDepthPeelingPass::CurrentStageTimeStamp
vtkTimeStamp CurrentStageTimeStamp
Definition: vtkDualDepthPeelingPass.h:276
vtkOpenGLFramebufferObject
Internal class which encapsulates OpenGL FramebufferObject.
Definition: vtkOpenGLFramebufferObject.h:183
vtkDualDepthPeelingPass::CurrentPeelType
PeelType CurrentPeelType
Definition: vtkDualDepthPeelingPass.h:275
vtkDualDepthPeelingPass::PeelTranslucentGeometry
void PeelTranslucentGeometry()
vtkOpenGLQuadHelper
Class to make rendering a full screen quad easier.
Definition: vtkOpenGLQuadHelper.h:55
vtkDualDepthPeelingPass::NumberOfPasses
@ NumberOfPasses
Definition: vtkDualDepthPeelingPass.h:146
vtkDualDepthPeelingPass::CopyFrontSourceToFrontDestination
void CopyFrontSourceToFrontDestination()
vtkDualDepthPeelingPass::CopyOpaqueDepthBuffer
void CopyOpaqueDepthBuffer()
vtkDualDepthPeelingPass::FrontA
@ FrontA
Definition: vtkDualDepthPeelingPass.h:130
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkDualDepthPeelingPass::BlendFinalImage
void BlendFinalImage()
vtkDualDepthPeelingPass::DepthDestination
TextureName DepthDestination
Definition: vtkDualDepthPeelingPass.h:272
vtkDualDepthPeelingPass::Back
@ Back
Definition: vtkDualDepthPeelingPass.h:129
vtkDepthPeelingPass.h
vtkDualDepthPeelingPass::Finalize
void Finalize()
vtkDualDepthPeelingPass::StartTranslucentOcclusionQuery
void StartTranslucentOcclusionQuery()
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:284
vtkDualDepthPeelingPass::CurrentStage
ShaderStage CurrentStage
Definition: vtkDualDepthPeelingPass.h:274
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:48
vtkDualDepthPeelingPass::LastPeelHadVolumes
bool LastPeelHadVolumes
Definition: vtkDualDepthPeelingPass.h:278
vtkDualDepthPeelingPass::EndVolumetricOcclusionQuery
void EndVolumetricOcclusionQuery()
vtkDualDepthPeelingPass::PeelVolumetricGeometry
void PeelVolumetricGeometry()
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:40
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:45
vtkDualDepthPeelingPass::SwapDepthBufferSourceDest
void SwapDepthBufferSourceDest()
vtkDualDepthPeelingPass::CullFaceEnabled
bool CullFaceEnabled
Definition: vtkDualDepthPeelingPass.h:292
vtkDualDepthPeelingPass::ClearFrontDestination
void ClearFrontDestination()
vtkDualDepthPeelingPass::DepthA
@ DepthA
Definition: vtkDualDepthPeelingPass.h:132
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:287
vtkRenderTimerLog
Asynchronously measures GPU execution times for a series of events.
Definition: vtkRenderTimerLog.h:82
vtkDualDepthPeelingPass::CopyColorHelper
vtkOpenGLQuadHelper * CopyColorHelper
Definition: vtkDualDepthPeelingPass.h:262
vtkDualDepthPeelingPass::TranslucentRenderCount
int TranslucentRenderCount
Definition: vtkDualDepthPeelingPass.h:286
vtkDualDepthPeelingPass::SetCurrentStage
void SetCurrentStage(ShaderStage stage)
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:53
vtkDualDepthPeelingPass::Prepare
void Prepare()
Fill textures with initial values, bind the framebuffer.
vtkDualDepthPeelingPass::EndTranslucentOcclusionQuery
void EndTranslucentOcclusionQuery()
vtkDualDepthPeelingPass::Timer
vtkRenderTimerLog * Timer
Definition: vtkDualDepthPeelingPass.h:258
vtkDualDepthPeelingPass::VolumetricPass
vtkRenderPass * VolumetricPass
Definition: vtkDualDepthPeelingPass.h:259
vtkDualDepthPeelingPass::BlendHelper
vtkOpenGLQuadHelper * BlendHelper
Definition: vtkDualDepthPeelingPass.h:265
vtkDualDepthPeelingPass::PrepareFrontDestination
void PrepareFrontDestination()
vtkDualDepthPeelingPass::AlphaBlending
@ AlphaBlending
Definition: vtkDualDepthPeelingPass.h:144
vtkDualDepthPeelingPass::FrontSource
TextureName FrontSource
Definition: vtkDualDepthPeelingPass.h:269
vtkDualDepthPeelingPass::Peeling
@ Peeling
Definition: vtkDualDepthPeelingPass.h:143
vtkDualDepthPeelingPass::OpaqueDepth
@ OpaqueDepth
Definition: vtkDualDepthPeelingPass.h:134
vtkDualDepthPeelingPass::CurrentPeel
int CurrentPeel
Definition: vtkDualDepthPeelingPass.h:279
vtkDualDepthPeelingPass::InitializeTargetsForTranslucentPass
void InitializeTargetsForTranslucentPass()
vtkDualDepthPeelingPass::FrontB
@ FrontB
Definition: vtkDualDepthPeelingPass.h:131
vtkDualDepthPeelingPass::~vtkDualDepthPeelingPass
~vtkDualDepthPeelingPass() override
vtkDualDepthPeelingPass::DepthSource
TextureName DepthSource
Definition: vtkDualDepthPeelingPass.h:271
vtkDualDepthPeelingPass::New
static vtkDualDepthPeelingPass * New()
vtkDualDepthPeelingPass::CullFaceMode
int CullFaceMode
Definition: vtkDualDepthPeelingPass.h:291
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::TranslucentWrittenPixels
unsigned int TranslucentWrittenPixels
Definition: vtkDualDepthPeelingPass.h:281
vtkDualDepthPeelingPass::VolumetricOcclusionQueryId
unsigned int VolumetricOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:282
vtkDualDepthPeelingPass::PeelingDone
bool PeelingDone()
vtkAbstractMapper
abstract class specifies interface to map data
Definition: vtkAbstractMapper.h:56
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
vtkDualDepthPeelingPass::ShaderStage
ShaderStage
Definition: vtkDualDepthPeelingPass.h:141
vtkDualDepthPeelingPass::vtkDualDepthPeelingPass
vtkDualDepthPeelingPass()
vtkRenderPass
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:59
vtkDualDepthPeelingPass::DepthTestEnabled
bool DepthTestEnabled
Definition: vtkDualDepthPeelingPass.h:293