VTK  9.7.1
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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
13 
14 VTK_ABI_NAMESPACE_BEGIN
15 
33 class VTKRENDERINGWEBGPU_EXPORT VTK_MARSHALAUTO vtkWebGPUComputeFrustumCuller : public vtkCuller
34 {
35 public:
38 
39  virtual double Cull(
40  vtkRenderer* renderer, vtkProp** propList, int& listLength, int& initialized) override;
41 
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
44 protected:
47 
48 private:
50  void operator=(const vtkWebGPUComputeFrustumCuller&) = delete;
51 
55  void CreateInputBoundsBuffer(vtkProp** propList, unsigned int nbProps);
56 
60  void CreateOutputIndicesBuffer(int nbProps);
61 
69  void CreateViewProjMatrixBuffer(const std::vector<float>& matrixData);
70 
77  void ResizeCuller(vtkProp** propList, int propsCount);
78 
83  void ResizeBoundsBuffer(vtkProp** propList, int newPropsCount);
84 
88  void ResizeOutputIndicesBuffer(int newPropsCount);
89 
94  void ResizeScratchList(vtkProp** propList, int listLength);
95 
104  void TriggerBoundsRecomputation(vtkProp** propList, int listLength);
105 
109  void UpdateBoundsBuffer(vtkProp** propList, int listLength);
110 
114  void UpdateCamera(vtkRenderer* renderer);
115 
120  static void OutputObjectCountMapCallback(const void* mappedData, void* userdata);
121 
127  static void OutputObjectIndicesMapCallback(const void* mappedData, void* userdata);
128 
143  struct OutputIndicesCallbackData
144  {
145  // The list of props. This should be the same list as passed in parameter to the Cull() method
146  vtkProp** propList = nullptr;
147  // How many props passed the culling test? This should be the value contained in the OutputCount
148  // WebGPU buffer
149  int* indicesCount = nullptr;
150 
151  // The scratch list is a pointer on the pre-allocated vector stored in this compute culler
152  std::vector<vtkProp*>* scratchList = nullptr;
153  };
154 
155  // How many props was the culler last configured for. This variable is used to determine if the
156  // number of props to be culled has changed since last time, meaning that we have to recreate a
157  // new bounds buffer, a new PropsBounds cache std::vector etc...
158  int PreviousPropsCount = -1;
159 
160  // Compute pipeline used for the frustum culling compute shader
162 
163  // Frustum culling compute shader pass
164  vtkSmartPointer<vtkWebGPUComputePass> FrustumCullingPass;
165 
166  // Scratch list used by the OutputObjectIndicesMapCallback
167  std::vector<vtkProp*> CallbackScratchList;
168 
169  // Index of the input bounds buffer in the compute pipeline
170  int InputBoundsBufferIndex = -1;
171  // Index of the buffer that contains the view-projection matrix of the camera
172  int CameraViewProjMatrixBufferIndex = -1;
173  // Buffer that will contain the indices of the objects that were not culled.
174  // This buffer will need to be initialized when the cull method is called because we don't know
175  // how many actor we're going to cull yet (and thus we cannot initialize the size of this buffer)
176  int OutputIndicesBufferIndex = -1;
177  // Index of the buffer that contains the number of actors that were not culled
178  int OutputObjectCountBufferIndex = -1;
179 };
180 
181 VTK_ABI_NAMESPACE_END
182 
183 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
This culler culls props to the camera view frustum using WebGPU compute shaders.
abstract specification for renderers
Definition: vtkRenderer.h:63
a superclass for prop cullers
Definition: vtkCuller.h:30
a simple class to control print indentation
Definition: vtkIndent.h:28
#define VTK_MARSHALAUTO
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual double Cull(vtkRenderer *ren, vtkProp **propList, int &listLength, int &initialized)=0
This is called outside the render loop by vtkRenderer.