VTK  9.3.0
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
12VTK_ABI_NAMESPACE_BEGIN
13class vtkCellArray;
14class vtkTypeFloat32Array;
16
17class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUPolyDataMapper : public vtkPolyDataMapper
18{
19public:
22 void PrintSelf(ostream& os, vtkIndent indent) override;
23
27 void RenderPiece(vtkRenderer* ren, vtkActor* act) override;
29 vtkRenderer* renderer, vtkActor* act, const wgpu::RenderPassEncoder& passEncoder);
31 vtkRenderer* renderer, vtkActor* act, const wgpu::RenderBundleEncoder& bundleEncoder);
32
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
84
90 vtkHardwareSelector* sel, std::vector<unsigned int>& pixeloffsets, vtkProp* prop) override;
91
92protected:
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.
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
223private:
225 void operator=(const vtkWebGPUPolyDataMapper&) = delete;
226};
227VTK_ABI_NAMESPACE_END
228#endif
abstract class specifies interface to map data
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:41
object to represent cell connectivity
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:29
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:80
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:43
abstract specification for renderers
Definition vtkRenderer.h:59
record modification and/or execution time
wgpu::BindGroupLayout MeshAttributeBindGroupLayout
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 ...
bool GetSupportsSelection() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
void SetupBindGroups(const wgpu::Device &device, vtkRenderer *renderer)
Creates bind groups for all the buffers in the MeshGeometryBuffers struct.
PrimitiveBindGroupInfo PointPrimitiveBGInfo
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
PrimitiveBindGroupInfo TrianglePrimitiveBGInfo
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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.
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderBundleEncoder &bundleEncoder)
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
PrimitiveBindGroupInfo LinePrimitiveBGInfo
bool UpdateMeshGeometryBuffers(const wgpu::Device &device, vtkActor *actor)
void SetupPipelineLayout(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Sets up bindgroup layouts and creates a pipeline layout.
wgpu::PipelineLayout PipelineLayout
unsigned long GetExactPointBufferSize()
Enqueues a write command on the device queue for all buffers whose data is outdated.
void ShallowCopy(vtkAbstractMapper *m) override
Make a shallow copy of this mapper.
bool UpdateMeshIndexBuffers(const wgpu::Device &device)
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
static vtkWebGPUPolyDataMapper * New()
vtkTypeFloat32Array * ComputeEdgeArray(vtkCellArray *polys)
~vtkWebGPUPolyDataMapper() override
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
void EncodeRenderCommands(vtkRenderer *renderer, vtkActor *act, const wgpu::RenderPassEncoder &passEncoder)
std::vector< unsigned long > GetExactConnecitivityBufferSizes()
void SetupGraphicsPipeline(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Creates the graphics pipeline.
void RenderPiece(vtkRenderer *ren, vtkActor *act) override
Implemented by sub classes.
wgpu::BindGroupLayout PrimitiveBindGroupLayout
unsigned long GetExactCellBufferSize()
void ComputeBounds() override
Called in GetBounds().
window superclass for vtkRenderWindow
Definition vtkWindow.h:25