VTK  9.0.3
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:
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 
123 
128 
133 
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:
156 
157  void DeleteLODs();
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
abstract base class for most VTK objects
Definition: vtkObject.h:63
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.
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:85
@ index
Definition: vtkX3D.h:252
bool operator<(const InstanceLOD &other) const
int vtkIdType
Definition: vtkType.h:338