VTK  9.6.20260112
vtkWebGPUPolyDataMapper2DInternals.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 vtkWebGPUPolyDataMapper2DInternals_h
5#define vtkWebGPUPolyDataMapper2DInternals_h
6
7#include "vtkNew.h"
8#include "vtkRenderingWebGPUModule.h"
9#include "vtkSmartPointer.h"
10#include "vtkTimeStamp.h"
12
13#include "vtk_wgpu.h"
14
15VTK_ABI_NAMESPACE_BEGIN
16
17class vtkPoints;
18class vtkMatrix4x4;
19class vtkViewport;
20class vtkActor2D;
24
28class VTKRENDERINGWEBGPU_NO_EXPORT vtkWebGPUPolyDataMapper2DInternals
29{
35 enum GraphicsPipeline2DType : int
36 {
37 // Pipeline that renders points
38 GFX_PIPELINE_2D_POINTS = 0,
39 GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
40 // Pipeline that renders lines
41 GFX_PIPELINE_2D_LINES,
42 GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
43 // Pipeline that renders triangles
44 GFX_PIPELINE_2D_TRIANGLES,
45 GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
46 NUM_GFX_PIPELINE_2D_NB_TYPES
47 };
48
49 struct Mapper2DState
50 {
51 vtkTypeFloat32 WCVCMatrix[4][4];
52 vtkTypeFloat32 Color[4];
53 vtkTypeFloat32 PointSize;
54 vtkTypeFloat32 LineWidth;
55 vtkTypeUInt32 Flags;
56 vtkTypeUInt32 Padding;
57 };
58 static constexpr int BIT_POSITION_USE_CELL_COLOR = 0;
59 static constexpr int BIT_POSITION_USE_POINT_COLOR = 1;
60
61 struct MeshAttributeArrayDescriptor
62 {
63 vtkTypeUInt32 Start = 0;
64 vtkTypeUInt32 NumTuples = 0;
65 vtkTypeUInt32 NumComponents = 0;
66 };
67
68 struct MeshDescriptor
69 {
70 MeshAttributeArrayDescriptor Positions;
71 MeshAttributeArrayDescriptor UVs;
72 MeshAttributeArrayDescriptor Colors;
73 };
74
75 struct ShaderSSBO
76 {
77 wgpu::Buffer Buffer;
78 std::size_t Size;
79 vtkTimeStamp BuildTimeStamp;
80 };
81
82 struct TopologyBindGroupInfo
83 {
84 // buffer for the connectivity
85 wgpu::Buffer ConnectivityBuffer;
86 // buffer for the cell id
87 wgpu::Buffer CellIdBuffer;
88 // uniform buffer for the cell id offset
89 wgpu::Buffer CellIdOffsetUniformBuffer;
90 // bind group for the primitive size uniform.
91 wgpu::BindGroup BindGroup;
92 // vertexCount for draw call.
93 vtkTypeUInt32 VertexCount = 0;
94 };
95
96 bool RebuildGraphicsPipelines = false;
97 bool UseCellScalarMapping = false;
98 bool UsePointScalarMapping = false;
99
100 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
101 PipelineBindGroupCombos = {
103 { GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
106 { GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
109 { GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
111 };
112
113 const std::array<wgpu::PrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
114 GraphicsPipeline2DPrimitiveTypes = { wgpu::PrimitiveTopology::TriangleStrip,
115 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleStrip,
116 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleList,
117 wgpu::PrimitiveTopology::TriangleList };
118
119 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
120
121 vtkSmartPointer<vtkPoints> TransformedPoints;
122
123 vtkNew<vtkMatrix4x4> WCVCMatrix;
124 Mapper2DState State;
125 MeshDescriptor MeshArraysDescriptor;
126
127 ShaderSSBO Mapper2DStateData;
128 ShaderSSBO AttributeDescriptorData;
129 ShaderSSBO MeshData;
130
131 TopologyBindGroupInfo
133
134 wgpu::BindGroup MeshAttributeBindGroup;
135 vtkTimeStamp TextureBindTime;
136 int ActorTextureUnit = -1;
137 wgpu::BindGroupLayout MeshAttributeBindGroupLayout;
138
140
144 static wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(const wgpu::Device& device,
145 const std::string& label, vtkWebGPURenderTextureDeviceResource* textureDevRc = nullptr);
146
150 static wgpu::BindGroupLayout CreateTopologyBindGroupLayout(
151 const wgpu::Device& device, const std::string& label, bool homogeneousCellSize);
152
156 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
157
158 static bool IsPipelineForHomogeneousCellSize(GraphicsPipeline2DType graphicsPipelineType);
159
160 void ApplyShaderReplacements(GraphicsPipeline2DType pipelineType, std::string& vss,
161 std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
162
163 void ReplaceShaderVertexOutputDef(std::string& vss, std::string& fss);
164 void ReplaceShaderMapperBindings(
165 std::string& vss, std::string& fss, vtkWebGPURenderWindow* wgpuRenderWindow, vtkActor2D* actor);
166
167 void ReplaceVertexShaderConstantsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
168 void ReplaceVertexShaderMapper2DStateDef(std::string& vss);
169 void ReplaceVertexShaderMeshArraysDescriptorDef(std::string& vss);
170 void ReplaceVertexShaderTopologyBindings(std::string& vss);
171 void ReplaceVertexShaderVertexInputDef(std::string& vss);
172 void ReplaceVertexShaderUtilityMethodsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
173 void ReplaceVertexShaderVertexMainStart(std::string& vss);
174 void ReplaceVertexShaderVertexIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
175 void ReplaceVertexShaderPrimitiveIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
176 void ReplaceVertexShaderCellIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
177 void ReplaceVertexShaderPositionImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
178 void ReplaceVertexShaderPickingImpl(std::string& vss);
179 void ReplaceVertexShaderColorsImpl(std::string& vss);
180 void ReplaceVertexShaderUVsImpl(std::string& vss);
181 void ReplaceVertexShaderVertexMainEnd(std::string& vss);
182
183 void ReplaceFragmentShaderFragmentOutputDef(std::string& fss);
184 void ReplaceFragmentShaderFragmentMainStart(std::string& fss);
185 void ReplaceFragmentShaderPickingImpl(std::string& fss);
186 void ReplaceFragmentShaderColorImpl(std::string& fss);
187 void ReplaceFragmentShaderFragmentMainEnd(std::string& fss);
188
189public:
192
199
205
210 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderPassEncoder& encoder);
211 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderBundleEncoder& encoder);
212};
213
214VTK_ABI_NAMESPACE_END
215
216#endif
217// VTK-HeaderTest-Exclude: vtkWebGPUPolyDataMapper2DInternals.h
a actor that draws 2D data
Definition vtkActor2D.h:145
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:167
represent and manipulate 3D points
Definition vtkPoints.h:139
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:66
void RecordDrawCommands(vtkViewport *viewport, const wgpu::RenderBundleEncoder &encoder)
void UpdateBuffers(vtkViewport *viewport, vtkActor2D *actor, vtkWebGPUPolyDataMapper2D *mapper)
Convert cells to primitives, update topology and mesh data in webgpu buffers used by shader program.
void RecordDrawCommands(vtkViewport *viewport, const wgpu::RenderPassEncoder &encoder)
Record draw calls in the render pass encoder.
void ReleaseGraphicsResources(vtkWindow *w)
Release any graphics resources that are being consumed by this mapper.
2D PolyData support for WebGPU
WebGPU rendering window.
window superclass for vtkRenderWindow
Definition vtkWindow.h:48