38 enum GraphicsPipeline2DType :
int
41 GFX_PIPELINE_2D_POINTS = 0,
42 GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
44 GFX_PIPELINE_2D_LINES,
45 GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
47 GFX_PIPELINE_2D_TRIANGLES,
48 GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
49 NUM_GFX_PIPELINE_2D_NB_TYPES
54 vtkTypeFloat32 WCVCMatrix[4][4];
55 vtkTypeFloat32 Color[4];
56 vtkTypeFloat32 PointSize;
57 vtkTypeFloat32 LineWidth;
59 vtkTypeUInt32 Padding;
61 static constexpr int BIT_POSITION_USE_CELL_COLOR = 0;
62 static constexpr int BIT_POSITION_USE_POINT_COLOR = 1;
64 struct MeshAttributeArrayDescriptor
66 vtkTypeUInt32 Start = 0;
67 vtkTypeUInt32 NumTuples = 0;
68 vtkTypeUInt32 NumComponents = 0;
73 MeshAttributeArrayDescriptor Positions;
74 MeshAttributeArrayDescriptor UVs;
75 MeshAttributeArrayDescriptor Colors;
80 vtkWebGPU::Buffer Buffer;
85 struct TopologyBindGroupInfo
88 vtkWebGPU::Buffer ConnectivityBuffer;
90 vtkWebGPU::Buffer CellIdBuffer;
92 vtkWebGPU::Buffer CellIdOffsetUniformBuffer;
94 vtkWebGPU::BindGroup BindGroup;
96 vtkTypeUInt32 VertexCount = 0;
99 bool RebuildGraphicsPipelines =
false;
100 bool UseCellScalarMapping =
false;
101 bool UsePointScalarMapping =
false;
103 std::map<GraphicsPipeline2DType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType>
104 PipelineBindGroupCombos = {
106 { GFX_PIPELINE_2D_POINTS_HOMOGENEOUS_CELL_SIZE,
109 { GFX_PIPELINE_2D_LINES_HOMOGENEOUS_CELL_SIZE,
112 { GFX_PIPELINE_2D_TRIANGLES_HOMOGENEOUS_CELL_SIZE,
116 const std::array<WGPUPrimitiveTopology, NUM_GFX_PIPELINE_2D_NB_TYPES>
117 GraphicsPipeline2DPrimitiveTypes = { WGPUPrimitiveTopology_TriangleStrip,
118 WGPUPrimitiveTopology_TriangleStrip, WGPUPrimitiveTopology_TriangleStrip,
119 WGPUPrimitiveTopology_TriangleStrip, WGPUPrimitiveTopology_TriangleList,
120 WGPUPrimitiveTopology_TriangleList };
122 std::string GraphicsPipeline2DKeys[NUM_GFX_PIPELINE_2D_NB_TYPES];
128 MeshDescriptor MeshArraysDescriptor;
130 ShaderSSBO Mapper2DStateData;
131 ShaderSSBO AttributeDescriptorData;
134 TopologyBindGroupInfo
137 vtkWebGPU::BindGroup MeshAttributeBindGroup;
139 int ActorTextureUnit = -1;
140 vtkWebGPU::BindGroupLayout MeshAttributeBindGroupLayout;
143 std::unordered_set<vtkWebGPURenderer*> Renderers;
148 static vtkWebGPU::BindGroupLayout CreateMeshAttributeBindGroupLayout(
const WGPUDevice& device,
154 static vtkWebGPU::BindGroupLayout CreateTopologyBindGroupLayout(
155 const WGPUDevice& device,
const std::string& label,
bool homogeneousCellSize);
160 static const char* GetGraphicsPipelineTypeAsString(GraphicsPipeline2DType graphicsPipelineType);
162 static bool IsPipelineForHomogeneousCellSize(GraphicsPipeline2DType graphicsPipelineType);
164 void ApplyShaderReplacements(GraphicsPipeline2DType pipelineType, std::string& vss,
167 void ReplaceShaderVertexOutputDef(std::string& vss, std::string& fss);
168 void ReplaceShaderMapperBindings(
171 void ReplaceVertexShaderConstantsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
172 void ReplaceVertexShaderMapper2DStateDef(std::string& vss);
173 void ReplaceVertexShaderMeshArraysDescriptorDef(std::string& vss);
174 void ReplaceVertexShaderTopologyBindings(std::string& vss);
175 void ReplaceVertexShaderVertexInputDef(std::string& vss);
176 void ReplaceVertexShaderUtilityMethodsDef(GraphicsPipeline2DType pipelineType, std::string& vss);
177 void ReplaceVertexShaderVertexMainStart(std::string& vss);
178 void ReplaceVertexShaderVertexIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
179 void ReplaceVertexShaderPrimitiveIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
180 void ReplaceVertexShaderCellIdImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
181 void ReplaceVertexShaderPositionImpl(GraphicsPipeline2DType pipelineType, std::string& vss);
182 void ReplaceVertexShaderPickingImpl(std::string& vss);
183 void ReplaceVertexShaderColorsImpl(std::string& vss);
184 void ReplaceVertexShaderUVsImpl(std::string& vss);
185 void ReplaceVertexShaderVertexMainEnd(std::string& vss);
187 void ReplaceFragmentShaderFragmentOutputDef(std::string& fss);
188 void ReplaceFragmentShaderFragmentMainStart(std::string& fss);
189 void ReplaceFragmentShaderPickingImpl(std::string& fss);
190 void ReplaceFragmentShaderColorImpl(std::string& fss);
191 void ReplaceFragmentShaderFragmentMainEnd(std::string& fss);