VTK  9.4.20241112
vtkWebGPUComputeFrustumCuller.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
4#ifndef vtkWebGPUComputeFrustumCuller_h
5#define vtkWebGPUComputeFrustumCuller_h
6
7#include "vtkCuller.h"
8#include "vtkNew.h" // for new macro
9#include "vtkRenderingWebGPUModule.h" // For export macro
10#include "vtkSmartPointer.h" // for the pipeline smart pointer
11#include "vtkWebGPUComputePipeline.h" // for the member compute pipeline
12
13VTK_ABI_NAMESPACE_BEGIN
14
32class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUComputeFrustumCuller : public vtkCuller
33{
34public:
37
38 virtual double Cull(
39 vtkRenderer* renderer, vtkProp** propList, int& listLength, int& initialized) override;
40
41 void PrintSelf(ostream& os, vtkIndent indent) override;
42
43protected:
46
47private:
49 void operator=(const vtkWebGPUComputeFrustumCuller&) = delete;
50
54 void CreateInputBoundsBuffer(vtkProp** propList, unsigned int nbProps);
55
59 void CreateOutputIndicesBuffer(int nbProps);
60
68 void CreateViewProjMatrixBuffer(const std::vector<float>& matrixData);
69
76 void ResizeCuller(vtkProp** propList, int propsCount);
77
82 void ResizeBoundsBuffer(vtkProp** propList, int newPropsCount);
83
87 void ResizeOutputIndicesBuffer(int newPropsCount);
88
93 void ResizeScratchList(vtkProp** propList, int listLength);
94
103 void TriggerBoundsRecomputation(vtkProp** propList, int listLength);
104
108 void UpdateBoundsBuffer(vtkProp** propList, int listLength);
109
113 void UpdateCamera(vtkRenderer* renderer);
114
119 static void OutputObjectCountMapCallback(const void* mappedData, void* userdata);
120
126 static void OutputObjectIndicesMapCallback(const void* mappedData, void* userdata);
127
142 struct OutputIndicesCallbackData
143 {
144 // The list of props. This should be the same list as passed in parameter to the Cull() method
145 vtkProp** propList = nullptr;
146 // How many props passed the culling test? This should be the value contained in the OutputCount
147 // WebGPU buffer
148 int* indicesCount = nullptr;
149
150 // The scratch list is a pointer on the pre-allocated vector stored in this compute culler
151 std::vector<vtkProp*>* scratchList = nullptr;
152 };
153
154 // How many props was the culler last configured for. This variable is used to determine if the
155 // number of props to be culled has changed since last time, meaning that we have to recreate a
156 // new bounds buffer, a new PropsBounds cache std::vector etc...
157 int PreviousPropsCount = -1;
158
159 // Compute pipeline used for the frustum culling compute shader
161
162 // Frustum culling compute shader pass
163 vtkSmartPointer<vtkWebGPUComputePass> FrustumCullingPass;
164
165 // Scratch list used by the OutputObjectIndicesMapCallback
166 std::vector<vtkProp*> CallbackScratchList;
167
168 // Index of the input bounds buffer in the compute pipeline
169 int InputBoundsBufferIndex = -1;
170 // Index of the buffer that contains the view-projection matrix of the camera
171 int CameraViewProjMatrixBufferIndex = -1;
172 // Buffer that will contain the indices of the objects that were not culled.
173 // This buffer will need to be initialized when the cull method is called because we don't know
174 // how many actor we're going to cull yet (and thus we cannot initialize the size of this buffer)
175 int OutputIndicesBufferIndex = -1;
176 // Index of the buffer that contains the number of actors that were not culled
177 int OutputObjectCountBufferIndex = -1;
178};
179
180VTK_ABI_NAMESPACE_END
181
182#endif
a superclass for prop cullers
Definition vtkCuller.h:31
a simple class to control print indentation
Definition vtkIndent.h:108
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
abstract specification for renderers
Hold a reference to a vtkObjectBase instance.
This culler culls props to the camera view frustum using WebGPU compute shaders.
virtual double Cull(vtkRenderer *renderer, vtkProp **propList, int &listLength, int &initialized) override
This is called outside the render loop by vtkRenderer.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
~vtkWebGPUComputeFrustumCuller() override
static vtkWebGPUComputeFrustumCuller * New()