VTK  9.0.20200704
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>
75 
78 class vtkPolyData;
80 
81 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLInstanceCulling : public vtkObject
82 {
83 public:
84  static vtkOpenGLInstanceCulling* New();
86 
87  struct InstanceLOD
88  {
89  float Distance;
90  unsigned int Query;
95 
96  // used for sorting
97  bool operator<(const InstanceLOD& other) const { return this->Distance < other.Distance; }
98  };
99 
103  void InitLOD(vtkPolyData* pd);
104 
112  void AddLOD(float distance, float targetReduction);
113 
117  void BuildCullingShaders(vtkOpenGLShaderCache* cache, vtkIdType numInstances, bool withNormals);
118 
122  vtkOpenGLHelper& GetHelper();
123 
127  InstanceLOD& GetLOD(vtkIdType index);
128 
132  vtkIdType GetNumberOfLOD();
133 
137  vtkOpenGLBufferObject* GetLODBuffer(vtkIdType index);
138 
142  void RunCullingShaders(vtkIdType numInstances, vtkOpenGLBufferObject* matrixBuffer,
143  vtkOpenGLBufferObject* colorBuffer, vtkOpenGLBufferObject* normalBuffer);
144 
146 
149  vtkSetMacro(ColorLOD, bool);
150  vtkGetMacro(ColorLOD, bool);
152 
153 protected:
154  vtkOpenGLInstanceCulling() = default;
155  ~vtkOpenGLInstanceCulling() override;
156 
157  void DeleteLODs();
158  void UploadCurrentState(InstanceLOD& lod, vtkPolyData* pd);
159 
160 private:
162  void operator=(const vtkOpenGLInstanceCulling&) = delete;
163 
164  vtkOpenGLHelper CullingHelper;
165  std::vector<InstanceLOD> LODList;
167  bool ColorLOD = false;
168 };
169 
170 #endif // vtkOpenGLInstanceCulling_h
171 
172 // VTK-HeaderTest-Exclude: vtkOpenGLInstanceCulling.h
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkOpenGLHelper.h
vtkSmartPointer< vtkPolyData >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkOpenGLInstanceCulling::InstanceLOD
Definition: vtkOpenGLInstanceCulling.h:87
vtkOpenGLInstanceCulling::InstanceLOD::NormalVBO
vtkOpenGLBufferObject * NormalVBO
Definition: vtkOpenGLInstanceCulling.h:93
vtkOpenGLIndexBufferObject
OpenGL vertex buffer object.
Definition: vtkOpenGLIndexBufferObject.h:27
vtkOpenGLInstanceCulling
Frustum culling and LOD management.
Definition: vtkOpenGLInstanceCulling.h:81
vtkOpenGLHelper
Definition: vtkOpenGLHelper.h:30
vtkSmartPointer.h
vtkOpenGLInstanceCulling::InstanceLOD::Query
unsigned int Query
Definition: vtkOpenGLInstanceCulling.h:90
vtkOpenGLShaderCache
manage Shader Programs within a context
Definition: vtkOpenGLShaderCache.h:35
vtkOpenGLInstanceCulling::InstanceLOD::PositionVBO
vtkOpenGLBufferObject * PositionVBO
Definition: vtkOpenGLInstanceCulling.h:92
vtkObject.h
vtkOpenGLInstanceCulling::InstanceLOD::Distance
float Distance
Definition: vtkOpenGLInstanceCulling.h:89
vtkOpenGLInstanceCulling::InstanceLOD::IBO
vtkOpenGLIndexBufferObject * IBO
Definition: vtkOpenGLInstanceCulling.h:91
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkOpenGLInstanceCulling::InstanceLOD::NumberOfInstances
int NumberOfInstances
Definition: vtkOpenGLInstanceCulling.h:94
vtkOpenGLInstanceCulling::InstanceLOD::operator<
bool operator<(const InstanceLOD &other) const
Definition: vtkOpenGLInstanceCulling.h:97
vtkX3D::index
Definition: vtkX3D.h:252