VTK: Rendering/WebGPU/vtkWebGPUPolyDataMapper.h Source File

| 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;
15 class vtkWebGPURenderWindow;
16
17 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUPolyDataMapper : public vtkPolyDataMapper
18 {
19 public:
20 static vtkWebGPUPolyDataMapper* New();
21 vtkTypeMacro(vtkWebGPUPolyDataMapper, vtkPolyDataMapper);
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
89 void ProcessSelectorPixelBuffers(
90 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
91
92 protected:
93 vtkWebGPUPolyDataMapper();
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
134 struct MeshAttributeBuffers
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 };
148 MeshAttributeBuffers MeshSSBO;
149
150 struct AttributeDescriptor
151 {
152 vtkTypeUInt32 Start = 0;
153 vtkTypeUInt32 NumTuples = 0;
154 vtkTypeUInt32 NumComponents = 0;
155 vtkTypeUInt32 Pad = 0; // for 16-byte alignment in MeshAttributeDescriptor
156 };
157 struct MeshAttributeDescriptor
158 {
159 AttributeDescriptor Positions;
160 AttributeDescriptor Colors;
161 AttributeDescriptor Normals;
162 AttributeDescriptor Tangents;
163 AttributeDescriptor UVs;
164 AttributeDescriptor CellColors;
165 AttributeDescriptor CellNormals;
166 AttributeDescriptor CellEdgeArray;
167 };
168 wgpu::Buffer AttributeDescriptorBuffer;
169
170 vtkTimeStamp PointCellAttributesBuildTimestamp;
171 vtkTimeStamp Primitive2CellIDsBuildTimestamp;
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
196 struct PrimitiveBindGroupInfo
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
212 PrimitiveBindGroupInfo PointPrimitiveBGInfo;
213 PrimitiveBindGroupInfo LinePrimitiveBGInfo;
214 PrimitiveBindGroupInfo TrianglePrimitiveBGInfo;
215 unsigned long EdgeArrayCount = 0;
216
217 // Cache these so that subsequent arrivals to UpdateMeshGeometry do not unnecessarily invoke
218 // MapScalars().
219 int LastScalarMode;
220 bool LastScalarVisibility;
221 vtkDataArray* LastColors = nullptr;
222
223 private:
224 vtkWebGPUPolyDataMapper(const vtkWebGPUPolyDataMapper&) = delete;
225 void operator=(const vtkWebGPUPolyDataMapper&) = delete;
226 };
227 VTK_ABI_NAMESPACE_END
228 #endif
vtkAbstractMapper
abstract class specifies interface to map data
Definition: vtkAbstractMapper.h:46
vtkActor
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:185
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkHardwareSelector
Definition: vtkHardwareSelector.h:125
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkPolyDataMapper
map vtkPolyData to graphics primitives
Definition: vtkPolyDataMapper.h:42
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:89
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:55
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:71
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:34
vtkWebGPUPolyDataMapper
Definition: vtkWebGPUPolyDataMapper.h:18
vtkWebGPUPolyDataMapper::MeshAttributeBindGroupLayout
wgpu::BindGroupLayout MeshAttributeBindGroupLayout
Definition: vtkWebGPUPolyDataMapper.h:194
vtkWebGPUPolyDataMapper::PointCellAttributesBuildTimestamp
vtkTimeStamp PointCellAttributesBuildTimestamp
Definition: vtkWebGPUPolyDataMapper.h:170
vtkWebGPUPolyDataMapper::ProcessSelectorPixelBuffers
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
vtkWebGPUPolyDataMapper::GetSupportsSelection
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
Definition: vtkWebGPUPolyDataMapper.h:46
vtkWebGPUPolyDataMapper::SetupBindGroups
void SetupBindGroups(const wgpu::Device &device, vtkRenderer *renderer)
Creates bind groups for all the buffers in the MeshGeometryBuffers struct.
vtkWebGPUPolyDataMapper::PointPrimitiveBGInfo
PrimitiveBindGroupInfo PointPrimitiveBGInfo
Definition: vtkWebGPUPolyDataMapper.h:212
vtkWebGPUPolyDataMapper::MeshAttributeBindGroup
wgpu::BindGroup MeshAttributeBindGroup
Definition: vtkWebGPUPolyDataMapper.h:192
vtkWebGPUPolyDataMapper::LastScalarMode
int LastScalarMode
Definition: vtkWebGPUPolyDataMapper.h:219
vtkWebGPUPolyDataMapper::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
vtkWebGPUPolyDataMapper::TrianglePrimitiveBGInfo
PrimitiveBindGroupInfo TrianglePrimitiveBGInfo
Definition: vtkWebGPUPolyDataMapper.h:214
vtkWebGPUPolyDataMapper::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWebGPUPolyDataMapper::MapDataArrayToVertexAttribute
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
vtkWebGPUPolyDataMapper::EncodeRenderCommands
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderBundleEncoder &bundleEncoder)
vtkWebGPUPolyDataMapper::RemoveAllVertexAttributeMappings
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
vtkWebGPUPolyDataMapper::Shader
wgpu::ShaderModule Shader
Definition: vtkWebGPUPolyDataMapper.h:132
vtkWebGPUPolyDataMapper::LinePrimitiveBGInfo
PrimitiveBindGroupInfo LinePrimitiveBGInfo
Definition: vtkWebGPUPolyDataMapper.h:213
vtkWebGPUPolyDataMapper::MeshSSBO
MeshAttributeBuffers MeshSSBO
Definition: vtkWebGPUPolyDataMapper.h:148
vtkWebGPUPolyDataMapper::UpdateMeshGeometryBuffers
bool UpdateMeshGeometryBuffers(const wgpu::Device &device, vtkActor *actor)
vtkWebGPUPolyDataMapper::GetExactConnecitivityBufferSizes
std::vector< unsigned long > GetExactConnecitivityBufferSizes()
vtkWebGPUPolyDataMapper::SetupPipelineLayout
void SetupPipelineLayout(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Sets up bindgroup layouts and creates a pipeline layout.
vtkWebGPUPolyDataMapper::PipelineLayout
wgpu::PipelineLayout PipelineLayout
Definition: vtkWebGPUPolyDataMapper.h:131
vtkWebGPUPolyDataMapper::GetExactPointBufferSize
unsigned long GetExactPointBufferSize()
Enqueues a write command on the device queue for all buffers whose data is outdated.
vtkWebGPUPolyDataMapper::ShallowCopy
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
vtkWebGPUPolyDataMapper::vtkWebGPUPolyDataMapper
vtkWebGPUPolyDataMapper()
vtkWebGPUPolyDataMapper::UpdateMeshIndexBuffers
bool UpdateMeshIndexBuffers(const wgpu::Device &device)
vtkWebGPUPolyDataMapper::RemoveVertexAttributeMapping
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
vtkWebGPUPolyDataMapper::~vtkWebGPUPolyDataMapper
~vtkWebGPUPolyDataMapper() override
vtkWebGPUPolyDataMapper::MapDataArrayToMultiTextureAttribute
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
vtkWebGPUPolyDataMapper::EncodeRenderCommands
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderPassEncoder &passEncoder)
vtkWebGPUPolyDataMapper::LastScalarVisibility
bool LastScalarVisibility
Definition: vtkWebGPUPolyDataMapper.h:220
vtkWebGPUPolyDataMapper::SetupGraphicsPipeline
void SetupGraphicsPipeline(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Creates the graphics pipeline.
vtkWebGPUPolyDataMapper::RenderPiece
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
vtkWebGPUPolyDataMapper::PrimitiveBindGroupLayout
wgpu::BindGroupLayout PrimitiveBindGroupLayout
Definition: vtkWebGPUPolyDataMapper.h:210
vtkWebGPUPolyDataMapper::New
static vtkWebGPUPolyDataMapper * New()
vtkWebGPUPolyDataMapper::Primitive2CellIDsBuildTimestamp
vtkTimeStamp Primitive2CellIDsBuildTimestamp
Definition: vtkWebGPUPolyDataMapper.h:171
vtkWebGPUPolyDataMapper::ComputeEdgeArray
vtkTypeFloat32Array * ComputeEdgeArray(vtkCellArray *polys)
vtkWebGPUPolyDataMapper::GetExactCellBufferSize
unsigned long GetExactCellBufferSize()
vtkWebGPUPolyDataMapper::AttributeDescriptorBuffer
wgpu::Buffer AttributeDescriptorBuffer
Definition: vtkWebGPUPolyDataMapper.h:168
vtkWebGPUPolyDataMapper::ComputeBounds
void ComputeBounds() override
Called in GetBounds().
vtkWebGPURenderWindow
Definition: vtkWebGPURenderWindow.h:15
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkWebGPUPolyDataMapper::AttributeDescriptor
Definition: vtkWebGPUPolyDataMapper.h:151
vtkWebGPUPolyDataMapper::MeshAttributeBuffers
Definition: vtkWebGPUPolyDataMapper.h:135
vtkWebGPUPolyDataMapper::MeshAttributeBuffers::Buffer
wgpu::Buffer Buffer
Definition: vtkWebGPUPolyDataMapper.h:139
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor
Definition: vtkWebGPUPolyDataMapper.h:158
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::Positions
AttributeDescriptor Positions
Definition: vtkWebGPUPolyDataMapper.h:159
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::UVs
AttributeDescriptor UVs
Definition: vtkWebGPUPolyDataMapper.h:163
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::CellColors
AttributeDescriptor CellColors
Definition: vtkWebGPUPolyDataMapper.h:164
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::CellNormals
AttributeDescriptor CellNormals
Definition: vtkWebGPUPolyDataMapper.h:165
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::Normals
AttributeDescriptor Normals
Definition: vtkWebGPUPolyDataMapper.h:161
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::CellEdgeArray
AttributeDescriptor CellEdgeArray
Definition: vtkWebGPUPolyDataMapper.h:166
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::Colors
AttributeDescriptor Colors
Definition: vtkWebGPUPolyDataMapper.h:160
vtkWebGPUPolyDataMapper::MeshAttributeDescriptor::Tangents
AttributeDescriptor Tangents
Definition: vtkWebGPUPolyDataMapper.h:162
vtkWebGPUPolyDataMapper::PrimitiveBindGroupInfo
Definition: vtkWebGPUPolyDataMapper.h:197
vtkWebGPUPolyDataMapper::PrimitiveBindGroupInfo::Buffer
wgpu::Buffer Buffer
Definition: vtkWebGPUPolyDataMapper.h:201
vtkWebGPUPolyDataMapper::PrimitiveBindGroupInfo::BindGroup
wgpu::BindGroup BindGroup
Definition: vtkWebGPUPolyDataMapper.h:203
vtkWebGPUPolyDataMapper::PrimitiveBindGroupInfo::PrimitiveSizeBuffer
wgpu::Buffer PrimitiveSizeBuffer
Definition: vtkWebGPUPolyDataMapper.h:199
vtkWebGPUPolyDataMapper::PrimitiveBindGroupInfo::Pipeline
wgpu::RenderPipeline Pipeline
Definition: vtkWebGPUPolyDataMapper.h:205
vtkPolyDataMapper.h
vtkType.h
vtk_wgpu.h