VTK  9.3.0
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:
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 
113 
118 
123 
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:
146 
147  void DeleteLODs();
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
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
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:89
@ index
Definition: vtkX3D.h:246
bool operator<(const InstanceLOD &other) const
int vtkIdType
Definition: vtkType.h:315