37 enum GraphicsPipeline2DType :
int
40 GFX_PIPELINE_2D_POINTS = 0,
41 GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
43 GFX_PIPELINE_2D_LINES,
44 GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
46 GFX_PIPELINE_2D_TRIANGLES,
47 GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
48 NUM_GFX_PIPELINE_2D_NB_TYPES
53 vtkTypeFloat32 WCVCMatrix[4][4];
54 vtkTypeFloat32 Color[4];
55 vtkTypeFloat32 PointSize;
56 vtkTypeFloat32 LineWidth;
58 vtkTypeUInt32 Padding;
60 static constexpr int BIT_POSITION_USE_CELL_COLOR = 0;
61 static constexpr int BIT_POSITION_USE_POINT_COLOR = 1;
63 struct MeshAttributeArrayDescriptor
65 vtkTypeUInt32 Start = 0;
66 vtkTypeUInt32 NumTuples = 0;
67 vtkTypeUInt32 NumComponents = 0;
72 MeshAttributeArrayDescriptor Positions;
73 MeshAttributeArrayDescriptor UVs;
74 MeshAttributeArrayDescriptor Colors;
84 struct TopologyBindGroupInfo
87 wgpu::Buffer ConnectivityBuffer;
89 wgpu::Buffer CellIdBuffer;
91 wgpu::Buffer CellIdOffsetUniformBuffer;
93 wgpu::BindGroup BindGroup;
95 vtkTypeUInt32 VertexCount = 0;
98 bool RebuildGraphicsPipelines =
false;
99 bool UseCellScalarMapping =
false;
100 bool UsePointScalarMapping =
false;
102 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
103 PipelineBindGroupCombos = {
105 { GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
108 { GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
111 { GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
115 const std::array<wgpu::PrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
116 GraphicsPipeline2DPrimitiveTypes = { wgpu::PrimitiveTopology::TriangleStrip,
117 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleStrip,
118 wgpu::PrimitiveTopology::TriangleStrip, wgpu::PrimitiveTopology::TriangleList,
119 wgpu::PrimitiveTopology::TriangleList };
121 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
127 MeshDescriptor MeshArraysDescriptor;
129 ShaderSSBO Mapper2DStateData;
130 ShaderSSBO AttributeDescriptorData;
133 TopologyBindGroupInfo
136 wgpu::BindGroup MeshAttributeBindGroup;
138 int ActorTextureUnit = -1;
139 wgpu::BindGroupLayout MeshAttributeBindGroupLayout;
142 std::unordered_set<vtkWebGPURenderer*> Renderers;
147 static wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(
const wgpu::Device& device,
153 static wgpu::BindGroupLayout CreateTopologyBindGroupLayout(
154 const wgpu::Device& device,
const std::string& label,
bool homogeneousCellSize);
159 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
161 static bool IsPipelineForHomogeneousCellSize(GraphicsPipeline2DType graphicsPipelineType);
163 void ApplyShaderReplacements(GraphicsPipeline2DType pipelineType, std::string& vss,
166 void ReplaceShaderVertexOutputDef(std::string& vss, std::string& fss);
167 void ReplaceShaderMapperBindings(
170 void ReplaceVertexShaderConstantsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
171 void ReplaceVertexShaderMapper2DStateDef(std::string& vss);
172 void ReplaceVertexShaderMeshArraysDescriptorDef(std::string& vss);
173 void ReplaceVertexShaderTopologyBindings(std::string& vss);
174 void ReplaceVertexShaderVertexInputDef(std::string& vss);
175 void ReplaceVertexShaderUtilityMethodsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
176 void ReplaceVertexShaderVertexMainStart(std::string& vss);
177 void ReplaceVertexShaderVertexIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
178 void ReplaceVertexShaderPrimitiveIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
179 void ReplaceVertexShaderCellIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
180 void ReplaceVertexShaderPositionImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
181 void ReplaceVertexShaderPickingImpl(std::string& vss);
182 void ReplaceVertexShaderColorsImpl(std::string& vss);
183 void ReplaceVertexShaderUVsImpl(std::string& vss);
184 void ReplaceVertexShaderVertexMainEnd(std::string& vss);
186 void ReplaceFragmentShaderFragmentOutputDef(std::string& fss);
187 void ReplaceFragmentShaderFragmentMainStart(std::string& fss);
188 void ReplaceFragmentShaderPickingImpl(std::string& fss);
189 void ReplaceFragmentShaderColorImpl(std::string& fss);
190 void ReplaceFragmentShaderFragmentMainEnd(std::string& fss);