VTK  9.1.0
vtkOpenGLInstanceCulling.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLInstanceCulling.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 
66 #ifndef vtkOpenGLInstanceCulling_h
67 #define vtkOpenGLInstanceCulling_h
68 
69 #include "vtkObject.h"
70 #include "vtkOpenGLHelper.h" // For vtkOpenGLHelper
71 #include "vtkRenderingOpenGL2Module.h" // For export macro
72 #include "vtkSmartPointer.h" // For smart pointer
73 
74 #include <vector> // for std::vector
75 
78 class vtkPolyData;
80 
81 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLInstanceCulling : public vtkObject
82 {
83 public:
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
88  struct InstanceLOD
89  {
90  float Distance;
91  unsigned int Query;
96 
97  // used for sorting
98  bool operator<(const InstanceLOD& other) const { return this->Distance < other.Distance; }
99  };
100 
104  void InitLOD(vtkPolyData* pd);
105 
113  void AddLOD(float distance, float targetReduction);
114 
118  void BuildCullingShaders(vtkOpenGLShaderCache* cache, vtkIdType numInstances, bool withNormals);
119 
124 
129 
134 
139 
143  void RunCullingShaders(vtkIdType numInstances, vtkOpenGLBufferObject* matrixBuffer,
144  vtkOpenGLBufferObject* colorBuffer, vtkOpenGLBufferObject* normalBuffer);
145 
147 
150  vtkSetMacro(ColorLOD, bool);
151  vtkGetMacro(ColorLOD, bool);
153 
154 protected:
157 
158  void DeleteLODs();
160 
161 private:
163  void operator=(const vtkOpenGLInstanceCulling&) = delete;
164 
165  vtkOpenGLHelper CullingHelper;
166  std::vector<InstanceLOD> LODList;
168  bool ColorLOD = false;
169 };
170 
171 #endif // vtkOpenGLInstanceCulling_h
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
OpenGL buffer object.
OpenGL vertex buffer object.
Frustum culling and LOD management.
vtkOpenGLHelper & GetHelper()
Get helper structure.
~vtkOpenGLInstanceCulling() override
void AddLOD(float distance, float targetReduction)
Add a level of detail.
void BuildCullingShaders(vtkOpenGLShaderCache *cache, vtkIdType numInstances, bool withNormals)
Build culling shader program (if not created yet) and binds it.
void InitLOD(vtkPolyData *pd)
Initialize LOD with a polydata.
vtkIdType GetNumberOfLOD()
Get number of LOD currently declared.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
InstanceLOD & GetLOD(vtkIdType index)
Get LOD structure.
void RunCullingShaders(vtkIdType numInstances, vtkOpenGLBufferObject *matrixBuffer, vtkOpenGLBufferObject *colorBuffer, vtkOpenGLBufferObject *normalBuffer)
Run the culling program and generate LOD buffers.
static vtkOpenGLInstanceCulling * New()
void UploadCurrentState(InstanceLOD &lod, vtkPolyData *pd)
vtkOpenGLInstanceCulling()=default
vtkOpenGLBufferObject * GetLODBuffer(vtkIdType index)
Get the transform feedback buffer generated by the culling program.
manage Shader Programs within a context
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
@ index
Definition: vtkX3D.h:252
bool operator<(const InstanceLOD &other) const
int vtkIdType
Definition: vtkType.h:332