VTK  9.2.6
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:
84  static vtkOpenGLInstanceCulling* New();
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 
123  vtkOpenGLHelper& GetHelper();
124 
128  InstanceLOD& GetLOD(vtkIdType index);
129 
133  vtkIdType GetNumberOfLOD();
134 
138  vtkOpenGLBufferObject* GetLODBuffer(vtkIdType index);
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:
155  vtkOpenGLInstanceCulling() = default;
156  ~vtkOpenGLInstanceCulling() override;
157 
158  void DeleteLODs();
159  void UploadCurrentState(InstanceLOD& lod, vtkPolyData* pd);
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
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
manage Shader Programs within a context
int vtkIdType
Definition: vtkType.h:332
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
a simple class to control print indentation
Definition: vtkIndent.h:39
bool operator<(const InstanceLOD &other) const
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.