VTK  9.3.1
vtkOpenGLInstanceCulling.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
54 #ifndef vtkOpenGLInstanceCulling_h
55 #define vtkOpenGLInstanceCulling_h
56 
57 #include "vtkObject.h"
58 #include "vtkOpenGLHelper.h" // For vtkOpenGLHelper
59 #include "vtkRenderingOpenGL2Module.h" // For export macro
60 #include "vtkSmartPointer.h" // For smart pointer
61 
62 #include <vector> // for std::vector
63 
64 VTK_ABI_NAMESPACE_BEGIN
67 class vtkPolyData;
69 
70 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLInstanceCulling : public vtkObject
71 {
72 public:
73  static vtkOpenGLInstanceCulling* New();
75  void PrintSelf(ostream& os, vtkIndent indent) override;
76 
77  struct InstanceLOD
78  {
79  float Distance;
80  unsigned int Query;
85 
86  // used for sorting
87  bool operator<(const InstanceLOD& other) const { return this->Distance < other.Distance; }
88  };
89 
93  void InitLOD(vtkPolyData* pd);
94 
102  void AddLOD(float distance, float targetReduction);
103 
107  void BuildCullingShaders(vtkOpenGLShaderCache* cache, vtkIdType numInstances, bool withNormals);
108 
112  vtkOpenGLHelper& GetHelper();
113 
117  InstanceLOD& GetLOD(vtkIdType index);
118 
122  vtkIdType GetNumberOfLOD();
123 
127  vtkOpenGLBufferObject* GetLODBuffer(vtkIdType index);
128 
132  void RunCullingShaders(vtkIdType numInstances, vtkOpenGLBufferObject* matrixBuffer,
133  vtkOpenGLBufferObject* colorBuffer, vtkOpenGLBufferObject* normalBuffer);
134 
136 
139  vtkSetMacro(ColorLOD, bool);
140  vtkGetMacro(ColorLOD, bool);
142 
143 protected:
144  vtkOpenGLInstanceCulling() = default;
145  ~vtkOpenGLInstanceCulling() override;
146 
147  void DeleteLODs();
148  void UploadCurrentState(InstanceLOD& lod, vtkPolyData* pd);
149 
150 private:
152  void operator=(const vtkOpenGLInstanceCulling&) = delete;
153 
154  vtkOpenGLHelper CullingHelper;
155  std::vector<InstanceLOD> LODList;
157  bool ColorLOD = false;
158 };
159 
160 VTK_ABI_NAMESPACE_END
161 #endif // vtkOpenGLInstanceCulling_h
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:315
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
a simple class to control print indentation
Definition: vtkIndent.h:28
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.