VTK  9.3.1
vtkWebGPUPolyDataMapper.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 #ifndef vtkWebGPUPolyDataMapper_h
4 #define vtkWebGPUPolyDataMapper_h
5 
6 #include "vtkPolyDataMapper.h"
7 
8 #include "vtkRenderingWebGPUModule.h" // for export macro
9 #include "vtkType.h" // for types
10 #include "vtk_wgpu.h" // for webgpu
11 
12 VTK_ABI_NAMESPACE_BEGIN
13 class vtkCellArray;
14 class vtkTypeFloat32Array;
16 
17 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUPolyDataMapper : public vtkPolyDataMapper
18 {
19 public:
20  static vtkWebGPUPolyDataMapper* New();
22  void PrintSelf(ostream& os, vtkIndent indent) override;
23 
27  void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
28  void EncodeRenderCommands(
29  vtkRenderer* renderer, vtkActor* act, const wgpu::RenderPassEncoder& passEncoder);
30  void EncodeRenderCommands(
31  vtkRenderer* renderer, vtkActor* act, const wgpu::RenderBundleEncoder& bundleEncoder);
32 
38  void ReleaseGraphicsResources(vtkWindow*) override;
39 
46  bool GetSupportsSelection() override { return false; }
47 
51  void ShallowCopy(vtkAbstractMapper* m) override;
52 
64  void MapDataArrayToVertexAttribute(const char* vertexAttributeName, const char* dataArrayName,
65  int fieldAssociation, int componentno = -1) override;
66 
67  // This method will Map the specified data array for use as
68  // a texture coordinate for texture tname. The actual
69  // attribute will be named tname_coord so as to not
70  // conflict with the texture sampler definition which will
71  // be tname.
72  void MapDataArrayToMultiTextureAttribute(const char* tname, const char* dataArrayName,
73  int fieldAssociation, int componentno = -1) override;
74 
78  void RemoveVertexAttributeMapping(const char* vertexAttributeName) override;
79 
83  void RemoveAllVertexAttributeMappings() override;
84 
90  vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
91 
92 protected:
94  ~vtkWebGPUPolyDataMapper() override;
95 
101  void ComputeBounds() override;
102 
106  void SetupPipelineLayout(const wgpu::Device& device, vtkRenderer* renderer, vtkActor* actor);
107 
112  void SetupBindGroups(const wgpu::Device& device, vtkRenderer* renderer);
113 
119  unsigned long GetExactPointBufferSize();
120  unsigned long GetExactCellBufferSize();
121  std::vector<unsigned long> GetExactConnecitivityBufferSizes();
122  bool UpdateMeshGeometryBuffers(const wgpu::Device& device, vtkActor* actor);
123  bool UpdateMeshIndexBuffers(const wgpu::Device& device);
124  vtkTypeFloat32Array* ComputeEdgeArray(vtkCellArray* polys);
125 
129  void SetupGraphicsPipeline(const wgpu::Device& device, vtkRenderer* renderer, vtkActor* actor);
130 
131  wgpu::PipelineLayout PipelineLayout;
132  wgpu::ShaderModule Shader;
133 
135  {
136  struct
137  {
138  // point attributes.
139  wgpu::Buffer Buffer;
140  } Point;
141 
142  struct
143  {
144  // cell attributes.
145  wgpu::Buffer Buffer;
146  } Cell;
147  };
149 
151  {
152  vtkTypeUInt32 Start = 0;
153  vtkTypeUInt32 NumTuples = 0;
154  vtkTypeUInt32 NumComponents = 0;
155  vtkTypeUInt32 Pad = 0; // for 16-byte alignment in MeshAttributeDescriptor
156  };
158  {
167  };
169 
172 
173  bool InitializedPipeline = false;
174  bool UpdatedPrimitiveSizes = false;
175  bool HasPointColors = false;
176  bool HasPointNormals = false;
177  bool HasPointTangents = false;
178  bool HasPointUVs = false;
179  bool HasCellColors = false;
180  bool HasCellNormals = false;
181  // used by RenderPiece and functions it calls to reduce
182  // calls to get the input and allow for rendering of
183  // other polydata (not the input)
184  vtkPolyData* CurrentInput = nullptr;
185  // vtkRenderer culls props to frustum. At that point, it requests
186  // mappers for bounds of the geometry. We cache the vtkAlgorithm output
187  // so that `UpdateMeshGeometryBuffers` can reuse it without climbing up
188  // vtkAlgorithm pipeline.
189  vtkPolyData* CachedInput = nullptr;
190 
191  // 1 bind group for this polydata mesh
192  wgpu::BindGroup MeshAttributeBindGroup;
193  // 1 bind group layout for the above bindgroup
194  wgpu::BindGroupLayout MeshAttributeBindGroupLayout;
195 
197  {
198  // 1 uniform buffer for the primitive size.
199  wgpu::Buffer PrimitiveSizeBuffer;
200  // 1 buffer for the primitive cell ids and point ids.
201  wgpu::Buffer Buffer;
202  // 1 bind group for the primitive size uniform.
203  wgpu::BindGroup BindGroup;
204  // each primitive-type gets a pipeline.
205  wgpu::RenderPipeline Pipeline;
206  // vertexCount for draw call.
207  vtkTypeUInt32 VertexCount = 0;
208  };
209  // 1 bind group layout for the above bindgroups.
210  wgpu::BindGroupLayout PrimitiveBindGroupLayout;
211 
215  unsigned long EdgeArrayCount = 0;
216 
217  // Cache these so that subsequent arrivals to UpdateMeshGeometry do not unnecessarily invoke
218  // MapScalars().
221  vtkDataArray* LastColors = nullptr;
222 
223 private:
225  void operator=(const vtkWebGPUPolyDataMapper&) = delete;
226 };
227 VTK_ABI_NAMESPACE_END
228 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:40
virtual void MapDataArrayToMultiTextureAttribute(const char *textureName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
vtkTimeStamp PointCellAttributesBuildTimestamp
virtual void RemoveAllVertexAttributeMappings()
Remove all vertex attributes.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
abstract specification for renderers
Definition: vtkRenderer.h:61
virtual void RenderPiece(vtkRenderer *, vtkActor *)
Implemented by sub classes.
virtual void ProcessSelectorPixelBuffers(vtkHardwareSelector *, std::vector< unsigned int > &, vtkProp *)
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
Definition: vtkMapper.h:466
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
virtual void RemoveVertexAttributeMapping(const char *vertexAttributeName)
Remove a vertex attribute mapping.
wgpu::BindGroupLayout PrimitiveBindGroupLayout
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
wgpu::BindGroupLayout MeshAttributeBindGroupLayout
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
PrimitiveBindGroupInfo TrianglePrimitiveBGInfo
virtual void ComputeBounds()
Called in GetBounds().
PrimitiveBindGroupInfo PointPrimitiveBGInfo
abstract class specifies interface to map data
virtual void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
Select a data array from the point/cell data and map it to a generic vertex attribute.
map vtkPolyData to graphics primitives
object to represent cell connectivity
Definition: vtkCellArray.h:175
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
static vtkPolyDataMapper * New()
PrimitiveBindGroupInfo LinePrimitiveBGInfo
wgpu::PipelineLayout PipelineLayout
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
Definition: vtkMapper.h:104