VTK  9.7.1
vtkWebGPUBatchedPolyDataMapper.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 
11 #ifndef vtkWebGPUBatchedPolyDataMapper_h
12 #define vtkWebGPUBatchedPolyDataMapper_h
13 
15 
16 #include "vtkRenderingWebGPUModule.h" // for export macro
17 #include "vtkWebGPUCompositePolyDataMapperDelegator.h" // for struct BatchElement
18 
19 #include <cstdint> // for std::uintptr_t
20 #include <memory> // for unique_ptr
21 
22 VTK_ABI_NAMESPACE_BEGIN
24 class vtkPolyData;
25 
26 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUBatchedPolyDataMapper : public vtkWebGPUPolyDataMapper
27 {
28 public:
31  void PrintSelf(ostream& os, vtkIndent indent) override;
32 
34 
38  void AddBatchElement(unsigned int flatIndex, BatchElement&& batchElement);
39  BatchElement* GetBatchElement(vtkPolyData* polydata);
40  void ClearBatchElements();
42 
46  std::vector<vtkPolyData*> GetRenderedList() const;
47  void SetParent(vtkCompositePolyDataMapper* parent);
48 
52  void RenderPiece(vtkRenderer* renderer, vtkActor* actor) override;
53  void UnmarkBatchElements();
54  void ClearUnmarkedBatchElements();
55 
59  vtkMTimeType GetMTime() override;
60 
66  void ReleaseGraphicsResources(vtkWindow*) override;
67 
68 protected:
71 
76 
80  bool EnsureInput() override;
81 
86 
88 
91  void UpdateMeshGeometryBuffers(vtkWebGPUConfiguration* wgpuConfiguration) override;
93  vtkWebGPUConfiguration* wgpuConfiguration, vtkProperty* displayProperty) override;
95 
97 
101  unsigned long GetPointAttributeByteSize(
103  unsigned long GetCellAttributeByteSize(
106 
108 
111  std::vector<wgpu::BindGroupLayoutEntry> GetMeshBindGroupLayoutEntries() override;
112  std::vector<wgpu::BindGroupEntry> GetMeshBindGroupEntries() override;
114 
116 
119  std::vector<wgpu::BindGroupLayoutEntry> GetTopologyBindGroupLayoutEntries(
120  bool homogeneousCellSize, bool useEdgeArray) override;
121  std::vector<wgpu::BindGroupEntry> GetTopologyBindGroupEntries(
123  bool homogeneousCellSize, bool useEdgeArray) override;
125 
126  void ReplaceShaderCustomDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer* wgpuRenderer,
127  vtkWebGPUActor* wgpuActor, std::string& vss, std::string& fss) override;
129  vtkWebGPURenderer* wgpuRenderer, vtkWebGPUActor* wgpuActor, std::string& vss,
130  std::string& fss) override;
131 
133  vtkWebGPUActor* actor, std::string& vss) override;
135  vtkWebGPURenderer* wgpuRenderer, vtkWebGPUActor* wgpuActor, std::string& vss) override;
136 
138  vtkWebGPURenderer* wgpuRenderer, vtkWebGPUActor* wgpuActor, std::string& fss) override;
140  vtkWebGPURenderer* wgpuRenderer, vtkWebGPUActor* wgpuActor, std::string& fss) override;
141 
143 
148  vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType) override;
150  vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType) override;
152 
154 
155 private:
157  void operator=(const vtkWebGPUBatchedPolyDataMapper&) = delete;
158 
159  // Reference to CPDM
160  vtkCompositePolyDataMapper* Parent = nullptr;
161  // Maps an address of a vtkPolyData to its rendering attributes.
162  std::map<std::uintptr_t, std::unique_ptr<BatchElement>> VTKPolyDataToBatchElement;
163  std::map<unsigned int, std::uintptr_t> FlatIndexToPolyData;
164 
165  struct CompositeDataProperties
166  {
167  vtkTypeUInt32 ApplyOverrideColors = 0;
168  vtkTypeFloat32 Opacity = 0;
169  vtkTypeUInt32 CompositeId = 0;
170  vtkTypeUInt32 Pickable = 1;
171  vtkTypeFloat32 Ambient[3] = {};
172  vtkTypeUInt32 CellIdOffsetForVerts = 0;
173  vtkTypeFloat32 Diffuse[3] = {};
174  vtkTypeUInt32 CellIdOffsetForLines = 0;
175  vtkTypeUInt32 CellIdOffsetForPolys = 0;
176  vtkTypeUInt32 CellIdOffsetForSelector = 0;
177  };
178  struct StorageBuffer
179  {
180  wgpu::Buffer Buffer;
181  std::uint64_t Size = 0;
182  std::uint32_t BindingSize = 0;
183  };
184  StorageBuffer CompositeDataPropertyStorage;
185  vtkTimeStamp ResourcesSyncTimeStamp;
186 
187  std::size_t CurrentDrawMeshId = 0; // 0 <= CurrentDrawMeshId < BatchSize
188  std::uint32_t MinStorageBufferOffsetAlignment = 0;
189 
190  bool AllocateCompositeDataPropertyStorageBuffer(vtkWebGPUConfiguration* wgpuConfiguration);
191 };
192 
193 VTK_ABI_NAMESPACE_END
194 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
virtual std::vector< wgpu::BindGroupEntry > GetMeshBindGroupEntries()
Allow subclasses to customize the entries in the bind group corresponding to GROUP_MESH.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
represent surface properties of a geometric object
Definition: vtkProperty.h:59
void RenderPiece(vtkRenderer *renderer, vtkActor *act) override
Implemented by sub classes.
static vtkWebGPUPolyDataMapper * New()
virtual void ReplaceFragmentShaderColors(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
record modification and/or execution time
Definition: vtkTimeStamp.h:24
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual unsigned long GetCellAttributeByteSize(vtkWebGPUPolyDataMapper::CellDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole cell data SSBO for the given attribute...
A WebGPU mapper for batched rendering of vtkPolyData.
virtual std::vector< wgpu::BindGroupEntry > GetTopologyBindGroupEntries(vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType, bool homogeneousCellSize, bool useEdgeArray)
Allow subclasses to customize the entries in the bind group corresponding to GROUP_TOPOLOGY.
virtual void ReplaceShaderCustomDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual bool EnsureInput()
Ensures that the input data is valid and ready for processing.
virtual unsigned long GetPointAttributeByteSize(vtkWebGPUPolyDataMapper::PointDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole point data SSBO for the given attribute...
GraphicsPipelineType
This mapper uses different wgpu::RenderPipeline to render a list of primitives.
virtual void ReplaceFragmentShaderPicking(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
virtual void UpdateMeshGeometryBuffers(vtkWebGPUConfiguration *wgpuConfiguration)
Creates buffers as needed and updates them with point/cell attributes, topology, draw parameters...
virtual int CanUseTextureMapForColoring(vtkDataObject *input)
Returns if we can use texture maps for scalar coloring.
virtual void ReplaceVertexShaderCellId(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
virtual DrawCallArgs GetDrawCallArgs(GraphicsPipelineType pipelineType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType)
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void UpdateMeshTopologyBuffers(vtkWebGPUConfiguration *wgpuConfiguration, vtkProperty *displayProperty)
Updates the connectivity related buffers.
vtkCompositePolyDataMapperDelegator::BatchElement BatchElement
vtkMTimeType GetMTime() override
Overload standard modified time function.
virtual bool ShouldReleaseGraphicsResourcesOnSync()
Return true if the mapper should release graphics resources from previous render during the vtkWebGPU...
virtual void ReplaceVertexShaderPicking(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceShaderCustomBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void DeducePointCellAttributeAvailability()
Looks at the point/cell data of vtkPolyData object and determines which attributes are available...
virtual std::vector< wgpu::BindGroupLayoutEntry > GetTopologyBindGroupLayoutEntries(bool homogeneousCellSize, bool useEdgeArray)
Allow subclasses to customize the entries in the bind group layout corresponding to GROUP_TOPOLOGY...
Create a webgpu device for use in rendering and compute pipelines.
virtual DrawCallArgs GetDrawCallArgsForDrawingVertices(vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType)
PointDataAttributes
All the attributes supported by the point data buffer.
TopologySourceType
All supported types of topology.
virtual std::vector< wgpu::BindGroupLayoutEntry > GetMeshBindGroupLayoutEntries()
Allow subclasses to customize the entries in the bind group layout corresponding to GROUP_MESH...
general representation of visualization data
Definition: vtkDataObject.h:55
CellDataAttributes
All the attributes supported by the cell data buffer.
a class that renders hierarchical polygonal data