VTK
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
98  {
99  return this->Distance < other.Distance;
100  }
101  };
102 
106  void InitLOD(vtkPolyData* pd);
107 
115  void AddLOD(float distance, float targetReduction);
116 
120  void BuildCullingShaders(vtkOpenGLShaderCache* cache, vtkIdType numInstances, bool withNormals);
121 
125  vtkOpenGLHelper& GetHelper();
126 
130  InstanceLOD& GetLOD(vtkIdType index);
131 
135  vtkIdType GetNumberOfLOD();
136 
140  vtkOpenGLBufferObject* GetLODBuffer(vtkIdType index);
141 
145  void RunCullingShaders(vtkIdType numInstances,
146  vtkOpenGLBufferObject* matrixBuffer,
147  vtkOpenGLBufferObject* colorBuffer,
148  vtkOpenGLBufferObject* normalBuffer);
149 
151 
154  vtkSetMacro(ColorLOD, bool);
155  vtkGetMacro(ColorLOD, bool);
157 
158 protected:
159  vtkOpenGLInstanceCulling() = default;
160  ~vtkOpenGLInstanceCulling() override;
161 
162  void DeleteLODs();
163  void UploadCurrentState(InstanceLOD& lod, vtkPolyData* pd);
164 
165 private:
167  void operator=(const vtkOpenGLInstanceCulling &) = delete;
168 
169  vtkOpenGLHelper CullingHelper;
170  std::vector<InstanceLOD> LODList;
172  bool ColorLOD = false;
173 };
174 
175 #endif // vtkOpenGLInstanceCulling_h
176 
177 // VTK-HeaderTest-Exclude: vtkOpenGLInstanceCulling.h
abstract base class for most VTK objects
Definition: vtkObject.h:59
manage Shader Programs within a context
int vtkIdType
Definition: vtkType.h:347
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
Frustum culling and LOD management.
OpenGL buffer object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
OpenGL vertex buffer object.