VTK  9.4.20250130
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;
22
26class VTKRENDERINGWEBGPU_NO_EXPORT vtkWebGPUPolyDataMapper2DInternals
27{
33 enum GraphicsPipeline2DType : int
34 {
35 // Pipeline that renders points
36 GFX_PIPELINE_2D_POINTS = 0,
37 // Pipeline that renders lines
38 GFX_PIPELINE_2D_LINES,
39 // Pipeline that renders triangles
40 GFX_PIPELINE_2D_TRIANGLES,
41 NUM_GFX_PIPELINE_2D_NB_TYPES
42 };
43
44 struct Mapper2DState
45 {
46 vtkTypeFloat32 WCVCMatrix[4][4];
47 vtkTypeFloat32 Color[4];
48 vtkTypeFloat32 PointSize;
49 vtkTypeFloat32 LineWidth;
50 vtkTypeUInt32 Flags;
51 vtkTypeUInt32 Padding;
52 };
53
54 struct MeshAttributeArrayDescriptor
55 {
56 vtkTypeUInt32 Start = 0;
57 vtkTypeUInt32 NumTuples = 0;
58 vtkTypeUInt32 NumComponents = 0;
59 };
60
61 struct MeshDescriptor
62 {
63 MeshAttributeArrayDescriptor Positions;
64 MeshAttributeArrayDescriptor UVs;
65 MeshAttributeArrayDescriptor Colors;
66 };
67
68 struct ShaderSSBO
69 {
70 wgpu::Buffer Buffer;
71 std::size_t Size;
72 vtkTimeStamp BuildTimeStamp;
73 };
74
75 struct TopologyBindGroupInfo
76 {
77 // buffer for the primitive cell ids and point ids.
78 wgpu::Buffer TopologyBuffer;
79 // // buffer for indirect draw command
80 // wgpu::Buffer IndirectDrawBuffer;
81 // bind group for the primitive size uniform.
82 wgpu::BindGroup BindGroup;
83 // vertexCount for draw call.
84 vtkTypeUInt32 VertexCount = 0;
85 };
86
87 bool RebuildGraphicsPipelines = false;
88 bool UseCellScalarMapping = false;
89 bool UsePointScalarMapping = false;
90
91 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
92 PipelineBindGroupCombos = {
96 };
97
98 const std::array<wgpu::PrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
99 GraphicsPipeline2DPrimitiveTypes = { wgpu::PrimitiveTopology::TriangleStrip,
100 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleList };
101 const std::array<std::string, NUM_GFX_PIPELINE_2D_NB_TYPES> VertexShaderEntryPoints = {
102 "pointVertexMain", "lineVertexMain", "polygonVertexMain"
103 };
104
105 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
106
107 vtkSmartPointer<vtkPoints> TransformedPoints;
108
109 vtkNew<vtkMatrix4x4> WCVCMatrix;
110 Mapper2DState State;
111 MeshDescriptor MeshArraysDescriptor;
112
113 ShaderSSBO Mapper2DStateData;
114 ShaderSSBO AttributeDescriptorData;
115 ShaderSSBO MeshData;
116
117 TopologyBindGroupInfo
119
120 wgpu::BindGroup MeshAttributeBindGroup;
121
123
127 static wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(
128 const wgpu::Device& device, const std::string& label);
129
133 static wgpu::BindGroupLayout CreateTopologyBindGroupLayout(
134 const wgpu::Device& device, const std::string& label);
135
139 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
140
141public:
144
151
157
162 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderPassEncoder& encoder);
163 void RecordDrawCommands(vtkViewport* viewport, const wgpu::RenderBundleEncoder& encoder);
164};
165
166VTK_ABI_NAMESPACE_END
167
168#endif
169// 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:65
Internal implementation details of vtkWebGPUPolyDataMapper2D.
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
window superclass for vtkRenderWindow
Definition vtkWindow.h:48