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 
60 class vtkShaderProgram;
61 class vtkTextureObject;
62 
63 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass:
64  public vtkDepthPeelingPass
65 {
66 public:
67  static vtkDualDepthPeelingPass* New();
69  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
70 
71  void Render(const vtkRenderState *s) VTK_OVERRIDE;
72  void ReleaseGraphicsResources(vtkWindow *w) VTK_OVERRIDE;
73 
75 
80  vtkGetObjectMacro(VolumetricPass, vtkRenderPass)
81  virtual void SetVolumetricPass(vtkRenderPass *volumetricPass);
83 
84  // vtkOpenGLRenderPass virtuals:
85  bool PreReplaceShaderValues(std::string &vertexShader,
86  std::string &geometryShader,
87  std::string &fragmentShader,
88  vtkAbstractMapper *mapper,
89  vtkProp *prop) VTK_OVERRIDE;
90  bool PostReplaceShaderValues(std::string &vertexShader,
91  std::string &geometryShader,
92  std::string &fragmentShader,
93  vtkAbstractMapper *mapper,
94  vtkProp *prop) VTK_OVERRIDE;
96  vtkAbstractMapper *mapper,
97  vtkProp *prop,
98  vtkOpenGLVertexArrayObject *VAO = NULL) VTK_OVERRIDE;
99  virtual vtkMTimeType GetShaderStageMTime() VTK_OVERRIDE;
100 
101 protected:
102 
103  bool PostReplaceTranslucentShaderValues(std::string &vertexShader,
104  std::string &geometryShader,
105  std::string &fragmentShader,
106  vtkAbstractMapper *mapper,
107  vtkProp *prop);
108  bool PreReplaceVolumetricShaderValues(std::string &vertexShader,
109  std::string &geometryShader,
110  std::string &fragmentShader,
111  vtkAbstractMapper *mapper,
112  vtkProp *prop);
113  bool SetTranslucentShaderParameters(vtkShaderProgram *program,
114  vtkAbstractMapper *mapper, vtkProp *prop,
116  bool SetVolumetricShaderParameters(vtkShaderProgram *program,
117  vtkAbstractMapper *mapper, vtkProp *prop,
119 
120 
121  // Name the textures used by this render pass. These are indexes into
122  // this->Textures
124  {
125  BackTemp = 0, // RGBA8 back-to-front peeling buffer
126  Back, // RGBA8 back-to-front accumulation buffer
127  FrontA, // RGBA8 front-to-back accumulation buffer
128  FrontB, // RGBA8 front-to-back accumulation buffer
129  DepthA, // RG32F min-max depth buffer
130  DepthB, // RG32F min-max depth buffer
131  OpaqueDepth, // Stores the depth map from the opaque passes
132 
133  NumberOfTextures
134  };
135 
136  // The stages of this multipass render pass:
138  {
142 
144  Inactive = -1,
145  };
146 
147  enum PeelType
148  {
150  VolumetricPeel
151  };
152 
154  ~vtkDualDepthPeelingPass() VTK_OVERRIDE;
155 
156  void SetCurrentStage(ShaderStage stage);
157  vtkSetMacro(CurrentPeelType, PeelType)
158 
162  void FreeGLObjects();
163 
167  void RenderTranslucentPass();
168 
172  void RenderVolumetricPass();
173 
174  bool IsRenderingVolumes();
175 
179  void Initialize(const vtkRenderState *state);
180 
182 
185  void InitColorTexture(vtkTextureObject *tex, const vtkRenderState *s);
186  void InitDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
187  void InitOpaqueDepthTexture(vtkTextureObject *tex, const vtkRenderState *s);
188  void InitFramebuffer(const vtkRenderState *s);
190 
194  void Prepare();
195 
196  void InitializeOcclusionQuery();
197  void CopyOpaqueDepthBuffer();
198  void InitializeDepth();
199 
200  void PeelVolumesOutsideTranslucentRange();
201 
202  bool PeelingDone();
203 
207  void Peel();
208 
209  // Depending on whether we're handling volumes or not, we'll initialize the
210  // front destination buffer by either clearing it or copying the last peel's
211  // output into it.
212  void PrepareFrontDestination();
213  void ClearFrontDestination();
214  void CopyFrontSourceToFrontDestination();
215 
216  void InitializeTargetsForTranslucentPass();
217  void InitializeTargetsForVolumetricPass();
218 
219  void PeelTranslucentGeometry();
220  void PeelVolumetricGeometry();
221 
222  void BlendBackBuffer();
223 
224  void StartTranslucentOcclusionQuery();
225  void EndTranslucentOcclusionQuery();
226 
227  void StartVolumetricOcclusionQuery();
228  void EndVolumetricOcclusionQuery();
229 
233  void SwapFrontBufferSourceDest();
234  void SwapDepthBufferSourceDest();
235 
236  void Finalize();
237 
238  void AlphaBlendRender();
239 
240  void BlendFinalImage();
241  void DeleteOcclusionQueryIds();
242 
243  vtkRenderPass *VolumetricPass;
244  const vtkRenderState *RenderState;
245 
246  vtkShaderProgram *CopyColorProgram;
248  vtkOpenGLBufferObject *CopyColorVBO;
249 
250  vtkShaderProgram *CopyDepthProgram;
252  vtkOpenGLBufferObject *CopyDepthVBO;
253 
254  vtkShaderProgram *BackBlendProgram;
256  vtkOpenGLBufferObject *BackBlendVBO;
257 
258  vtkShaderProgram *BlendProgram;
261 
263  vtkTextureObject *Textures[NumberOfTextures];
264 
265  TextureName FrontSource; // The current front source buffer
266  TextureName FrontDestination; // The current front destination buffer
267  TextureName DepthSource; // The current depth source buffer
268  TextureName DepthDestination; // The current depth destination buffer
269 
270  ShaderStage CurrentStage;
271  PeelType CurrentPeelType;
272  vtkTimeStamp CurrentStageTimeStamp;
273 
274  bool LastPeelHadVolumes;
275  int CurrentPeel;
276  unsigned int TranslucentOcclusionQueryId;
277  unsigned int TranslucentWrittenPixels;
278  unsigned int VolumetricOcclusionQueryId;
279  unsigned int VolumetricWrittenPixels;
280  unsigned int OcclusionThreshold;
281 
282  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
283  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
284 
285  // Cached state:
286  bool SaveScissorTestState;
287  int CullFaceMode;
288  bool CullFaceEnabled;
289 
290 private:
291  vtkDualDepthPeelingPass(const vtkDualDepthPeelingPass&) VTK_DELETE_FUNCTION;
292  void operator=(const vtkDualDepthPeelingPass&) VTK_DELETE_FUNCTION;
293 };
294 
295 #endif // vtkDualDepthPeelingPass_h
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:50
Implement an Order Independent Transparency render pass.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
record modification and/or execution time
Definition: vtkTimeStamp.h:35
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:37
Context in which a vtkRenderPass will render.
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
Internal class which encapsulates OpenGL FramebufferObject.
static vtkDepthPeelingPass * New()
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstract class specifies interface to map data
virtual bool PreReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop)
Use vtkShaderProgram::Substitute to replace //VTK::XXX:YYY declarations in the shader sources...
abstracts an OpenGL texture object.
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
virtual vtkMTimeType GetShaderStageMTime()
For multi-stage render passes that need to change shader code during a single pass, use this method to notify a mapper that the shader needs to be rebuilt (rather than reuse the last cached shader.
Implements the dual depth peeling algorithm.
void Render(const vtkRenderState *s) override
Perform rendering according to a render state s.
bool PostReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop) override
Is rendering at translucent geometry stage using depth peeling and rendering a layer other than the f...
bool SetShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO=NULL) override
Update the uniforms of the shader program.
OpenGL buffer object.
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:58
The ShaderProgram uses one or more Shader objects.