VTK: Rendering/OpenGL2/vtkOpenGLInstanceCulling.h Source File

| 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
65 class vtkOpenGLIndexBufferObject;
66 class vtkOpenGLBufferObject;
67 class vtkPolyData;
68 class vtkOpenGLShaderCache;
69
70 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLInstanceCulling : public vtkObject
71 {
72 public:
73 static vtkOpenGLInstanceCulling* New();
74 vtkTypeMacro(vtkOpenGLInstanceCulling, vtkObject);
75 void PrintSelf(ostream& os, vtkIndent indent) override;
76
77 struct InstanceLOD
78 {
79 float Distance;
80 unsigned int Query;
81 vtkOpenGLIndexBufferObject* IBO;
82 vtkOpenGLBufferObject* PositionVBO;
83 vtkOpenGLBufferObject* NormalVBO;
84 int NumberOfInstances;
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:
151 vtkOpenGLInstanceCulling(const vtkOpenGLInstanceCulling&) = delete;
152 void operator=(const vtkOpenGLInstanceCulling&) = delete;
153
154 vtkOpenGLHelper CullingHelper;
155 std::vector<InstanceLOD> LODList;
156 vtkSmartPointer<vtkPolyData> PolyData;
157 bool ColorLOD = false;
158 };
159
160 VTK_ABI_NAMESPACE_END
161 #endif // vtkOpenGLInstanceCulling_h
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:24
vtkOpenGLHelper
Definition: vtkOpenGLHelper.h:21
vtkOpenGLIndexBufferObject
OpenGL vertex buffer object.
Definition: vtkOpenGLIndexBufferObject.h:18
vtkOpenGLInstanceCulling
Frustum culling and LOD management.
Definition: vtkOpenGLInstanceCulling.h:71
vtkOpenGLInstanceCulling::GetHelper
vtkOpenGLHelper & GetHelper()
Get helper structure.
vtkOpenGLInstanceCulling::~vtkOpenGLInstanceCulling
~vtkOpenGLInstanceCulling() override
vtkOpenGLInstanceCulling::AddLOD
void AddLOD(float distance, float targetReduction)
Add a level of detail.
vtkOpenGLInstanceCulling::DeleteLODs
void DeleteLODs()
vtkOpenGLInstanceCulling::BuildCullingShaders
void BuildCullingShaders(vtkOpenGLShaderCache *cache, vtkIdType numInstances, bool withNormals)
Build culling shader program (if not created yet) and binds it.
vtkOpenGLInstanceCulling::InitLOD
void InitLOD(vtkPolyData *pd)
Initialize LOD with a polydata.
vtkOpenGLInstanceCulling::GetNumberOfLOD
vtkIdType GetNumberOfLOD()
Get number of LOD currently declared.
vtkOpenGLInstanceCulling::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkOpenGLInstanceCulling::GetLOD
InstanceLOD & GetLOD(vtkIdType index)
Get LOD structure.
vtkOpenGLInstanceCulling::RunCullingShaders
void RunCullingShaders(vtkIdType numInstances, vtkOpenGLBufferObject *matrixBuffer, vtkOpenGLBufferObject *colorBuffer, vtkOpenGLBufferObject *normalBuffer)
Run the culling program and generate LOD buffers.
vtkOpenGLInstanceCulling::New
static vtkOpenGLInstanceCulling * New()
vtkOpenGLInstanceCulling::UploadCurrentState
void UploadCurrentState(InstanceLOD &lod, vtkPolyData *pd)
vtkOpenGLInstanceCulling::vtkOpenGLInstanceCulling
vtkOpenGLInstanceCulling()=default
vtkOpenGLInstanceCulling::GetLODBuffer
vtkOpenGLBufferObject * GetLODBuffer(vtkIdType index)
Get the transform feedback buffer generated by the culling program.
vtkOpenGLShaderCache
manage Shader Programs within a context
Definition: vtkOpenGLShaderCache.h:25
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:89
vtkSmartPointer< vtkPolyData >
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkOpenGLInstanceCulling::InstanceLOD
Definition: vtkOpenGLInstanceCulling.h:78
vtkOpenGLInstanceCulling::InstanceLOD::Query
unsigned int Query
Definition: vtkOpenGLInstanceCulling.h:80
vtkOpenGLInstanceCulling::InstanceLOD::NumberOfInstances
int NumberOfInstances
Definition: vtkOpenGLInstanceCulling.h:84
vtkOpenGLInstanceCulling::InstanceLOD::operator<
bool operator<(const InstanceLOD &other) const
Definition: vtkOpenGLInstanceCulling.h:87
vtkOpenGLInstanceCulling::InstanceLOD::PositionVBO
vtkOpenGLBufferObject * PositionVBO
Definition: vtkOpenGLInstanceCulling.h:82
vtkOpenGLInstanceCulling::InstanceLOD::Distance
float Distance
Definition: vtkOpenGLInstanceCulling.h:79
vtkOpenGLInstanceCulling::InstanceLOD::NormalVBO
vtkOpenGLBufferObject * NormalVBO
Definition: vtkOpenGLInstanceCulling.h:83
vtkOpenGLInstanceCulling::InstanceLOD::IBO
vtkOpenGLIndexBufferObject * IBO
Definition: vtkOpenGLInstanceCulling.h:81
vtkObject.h
vtkOpenGLHelper.h
vtkSmartPointer.h
vtkIdType
int vtkIdType
Definition: vtkType.h:315