3 #ifndef vtkWebGPUPolyDataMapper_h
4 #define vtkWebGPUPolyDataMapper_h
9 #include "vtkRenderingWebGPUModule.h"
16 #include <unordered_set>
18 VTK_ABI_NAMESPACE_BEGIN
71 GFX_PIPELINE_POINTS = 0,
129 int fieldAssociation,
int componentno = -1)
override;
139 int fieldAssociation,
int componentno = -1)
override;
174 PointDataAttributes attribute,
int bufferGroup,
int bufferBinding,
int uniformsGroup,
175 int uniformsBinding);
181 CellDataAttributes attribute,
int bufferGroup,
int bufferBinding,
int uniformsGroup,
182 int uniformsBinding);
199 void RecordDrawCommands(
201 void RecordDrawCommands(
208 virtual void DeducePointCellAttributeAvailability();
214 virtual std::vector<wgpu::BindGroupLayoutEntry> GetMeshBindGroupLayoutEntries();
220 virtual std::vector<wgpu::BindGroupLayoutEntry> GetTopologyBindGroupLayoutEntries(
221 bool homogeneousCellSize,
bool useEdgeArray);
227 virtual std::vector<wgpu::BindGroupEntry> GetMeshBindGroupEntries();
233 virtual std::vector<wgpu::BindGroupEntry> GetTopologyBindGroupEntries(
235 bool homogeneousCellSize,
bool useEdgeArray);
240 virtual unsigned long GetPointAttributeByteSize(
246 virtual unsigned long GetCellAttributeByteSize(
253 virtual bool ShouldReleaseGraphicsResourcesOnSync();
258 virtual void BeginUpdateMeshGeometryBuffers();
273 virtual void EndUpdateMeshGeometryBuffers();
279 virtual bool EnsureInput();
284 virtual void UpdateMeshTopologyBuffers(
290 virtual void SetVertexBuffers(
const wgpu::RenderBundleEncoder& vtkNotUsed(bundleEncoder)) {}
295 virtual void ApplyShaderReplacements(GraphicsPipelineType pipelineType,
298 virtual void ReplaceShaderConstantsDef(GraphicsPipelineType pipelineType,
300 virtual void ReplaceShaderActorDef(GraphicsPipelineType pipelineType,
vtkWebGPURenderer* renderer,
302 virtual void ReplaceShaderClippingPlanesDef(GraphicsPipelineType pipelineType,
304 virtual void ReplaceShaderCustomDef(GraphicsPipelineType pipelineType,
307 virtual void ReplaceShaderRendererBindings(GraphicsPipelineType pipelineType,
309 virtual void ReplaceShaderActorBindings(GraphicsPipelineType pipelineType,
311 virtual void ReplaceShaderClippingPlanesBindings(GraphicsPipelineType pipelineType,
313 virtual void ReplaceShaderMeshAttributeBindings(GraphicsPipelineType pipelineType,
315 virtual void ReplaceShaderCustomBindings(GraphicsPipelineType pipelineType,
317 virtual void ReplaceShaderTopologyBindings(GraphicsPipelineType pipelineType,
319 virtual void ReplaceShaderVertexOutputDef(GraphicsPipelineType pipelineType,
322 virtual void ReplaceVertexShaderInputDef(GraphicsPipelineType pipelineType,
324 virtual void ReplaceVertexShaderMainStart(GraphicsPipelineType pipelineType,
326 virtual void ReplaceVertexShaderCamera(GraphicsPipelineType pipelineType,
328 virtual void ReplaceVertexShaderNormalTransform(GraphicsPipelineType pipelineType,
330 virtual void ReplaceVertexShaderVertexId(GraphicsPipelineType pipelineType,
332 virtual void ReplaceVertexShaderPrimitiveId(GraphicsPipelineType pipelineType,
334 virtual void ReplaceVertexShaderCellId(GraphicsPipelineType pipelineType,
336 virtual void ReplaceVertexShaderPosition(GraphicsPipelineType pipelineType,
338 virtual void ReplaceVertexShaderClippingPlanes(GraphicsPipelineType pipelineType,
340 virtual void ReplaceVertexShaderPositionVC(GraphicsPipelineType pipelineType,
342 virtual void ReplaceVertexShaderPicking(GraphicsPipelineType pipelineType,
344 virtual void ReplaceVertexShaderColors(GraphicsPipelineType pipelineType,
346 virtual void ReplaceVertexShaderUVs(GraphicsPipelineType pipelineType,
348 virtual void ReplaceVertexShaderEdges(GraphicsPipelineType pipelineType,
350 virtual void ReplaceVertexShaderNormals(GraphicsPipelineType pipelineType,
352 virtual void ReplaceVertexShaderTangents(GraphicsPipelineType pipelineType,
354 virtual void ReplaceVertexShaderMainEnd(GraphicsPipelineType pipelineType,
357 virtual void ReplaceFragmentShaderOutputDef(GraphicsPipelineType pipelineType,
360 virtual void ReplaceFragmentShaderMainStart(GraphicsPipelineType pipelineType,
362 virtual void ReplaceFragmentShaderClippingPlanes(GraphicsPipelineType pipelineType,
364 virtual void ReplaceFragmentShaderColors(GraphicsPipelineType pipelineType,
366 virtual void ReplaceFragmentShaderNormals(GraphicsPipelineType pipelineType,
368 virtual void ReplaceFragmentShaderEdges(GraphicsPipelineType pipelineType,
370 virtual void ReplaceFragmentShaderLights(GraphicsPipelineType pipelineType,
372 virtual void ReplaceFragmentShaderPicking(GraphicsPipelineType pipelineType,
374 virtual void ReplaceFragmentShaderCoincidentOffset(GraphicsPipelineType pipelineType,
376 virtual void ReplaceFragmentShaderMainEnd(GraphicsPipelineType pipelineType,
388 static bool IsPipelineForHomogeneousCellSize(GraphicsPipelineType pipelineType);
393 virtual wgpu::PrimitiveTopology GetPrimitiveTopologyForPipeline(
394 GraphicsPipelineType pipelineType);
398 std::uint32_t VertexOffset = 0;
399 std::uint32_t VertexCount = 0;
400 std::uint32_t InstanceOffset = 0;
401 std::uint32_t InstanceCount = 0;
412 wgpu::BindGroup CreateMeshAttributeBindGroup(
413 const wgpu::Device& device,
const std::string& label);
420 wgpu::BindGroup CreateTopologyBindGroup(
const wgpu::Device& device,
const std::string& label,
427 uint64_t Watermark = 0;
428 bool Touched =
false;
434 vtkTypeFloat32 PlaneEquations[6][4];
435 vtkTypeUInt32 PlaneCount = 0;
436 } ClippingPlanesData;
445 bool HasPointAttributes[POINT_NB_ATTRIBUTES];
446 bool HasCellAttributes[CELL_NB_ATTRIBUTES];
447 bool RebuildGraphicsPipelines =
true;
479 vtkTypeUInt32 MaxCellSize = 0;
481 vtkTypeUInt32 VertexCount = 0;
490 GROUP_TEXTURES = GROUP_ACTOR,
495 GROUP_CLIPPING_PLANES = GROUP_MESH,
497 GROUP_NB_BINDGROUPS = 4
499 static_assert(GROUP_NB_BINDGROUPS <= 4,
500 "Number of bind groups exceeds 4! Most devices can support only up to 4 bind groups");
501 std::array<std::uint32_t, GROUP_NB_BINDGROUPS> NumberOfBindings = {};
518 return this->PointBuffers[attribute].
Buffer;
524 wgpu::Buffer GetCellDataWGPUBuffer(CellDataAttributes attribute)
526 return this->CellBuffers[attribute].
Buffer;
533 vtkDataArray* dataArray, PointDataAttributes attributeType,
float denominator = 1.0f);
535 vtkDataArray* dataArray, CellDataAttributes attributeType,
float denominator = 1.0f);
559 void ResetPointCellAttributeState();
564 wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(
565 const wgpu::Device& device,
const std::string& label);
570 wgpu::BindGroupLayout CreateTopologyBindGroupLayout(
const wgpu::Device& device,
571 const std::string& label,
bool homogeneousCellSize,
bool useEdgeArray);
577 unsigned long GetPointAttributeElementSize(
591 unsigned long GetExactPointBufferSize(PointDataAttributes attribute);
598 unsigned long GetExactCellBufferSize(CellDataAttributes attribute);
608 const char* GetGraphicsPipelineTypeAsString(GraphicsPipelineType graphicsPipelineType);
614 void SetupGraphicsPipelines(
const wgpu::Device& device,
vtkRenderer* renderer,
vtkActor* actor);
627 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> SetupComputeRenderBuffers;
632 std::unordered_set<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> NotSetupComputeRenderBuffers;
637 const PointDataAttributes PointDataAttributesOrder[PointDataAttributes::POINT_NB_ATTRIBUTES] = {
638 PointDataAttributes::POINT_POSITIONS, PointDataAttributes::POINT_COLORS,
639 PointDataAttributes::POINT_NORMALS, PointDataAttributes::POINT_TANGENTS,
640 PointDataAttributes::POINT_UVS, PointDataAttributes::POINT_COLOR_UVS
646 const CellDataAttributes CellDataAttributesOrder[CellDataAttributes::CELL_NB_ATTRIBUTES] = {
647 CellDataAttributes::CELL_COLORS, CellDataAttributes::CELL_NORMALS
652 int LastScalarMode = -1;
653 bool LastScalarVisibility =
false;
654 vtkTypeUInt32 LastNumClipPlanes = 0;
657 bool LastActorBackfaceCulling =
false;
658 bool LastActorFrontfaceCulling =
false;
659 bool LastVertexVisibility =
false;
661 bool LastHasRenderingTranslucentGeometry =
false;
662 int LastPointSize = 1;
663 int LastLineWidth = 1;
665 std::map<std::pair<vtkActor*, vtkRenderer*>, ActorState> CachedActorRendererProperties;
667 #define vtkWebGPUPolyDataMapper_OVERRIDE_ATTRIBUTES \
668 vtkWebGPUPolyDataMapper::CreateOverrideAttributes()
669 VTK_ABI_NAMESPACE_END
abstract superclass for all actors, volumes and annotations
virtual std::vector< wgpu::VertexBufferLayout > GetVertexBufferLayouts()
wgpu::BindGroup BindGroup
wgpu::BindGroup MeshAttributeBindGroup
Attribute for vtkObjectFactory overrides.
represents an object (geometry & properties) in a rendered scene
vtkSmartPointer< vtkWebGPUTexture > ColorTextureHostResource
virtual MapperHashType GenerateHash(vtkPolyData *)
This hash integer is computed by concrete graphics implementation of this class.
virtual void MapDataArrayToMultiTextureAttribute(const char *textureName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
virtual void RemoveAllVertexAttributeMappings()
Remove all vertex attributes.
virtual bool IsPipelineSupported(GraphicsPipelineType pipelineType)
Whether shaders must be built to target the specific pipeline.
represent surface properties of a geometric object
std::vector< std::pair< vtkTypeUInt32, vtkTypeUInt32 > > VertexOffsetAndCounts
wgpu::Buffer EdgeArrayBuffer
vtkWebGPUTexture is a concrete implementation of the abstract class vtkTexture for WebGPU...
record modification and/or execution time
virtual void SetVertexBuffers(const wgpu::RenderBundleEncoder &bundleEncoder)
abstract specification for renderers
wgpu::Buffer ConnectivityBuffer
GraphicsPipelineType
This mapper uses different wgpu::RenderPipeline to render a list of primitives.
virtual void RenderPiece(vtkRenderer *, vtkActor *)
Implemented by sub classes.
Hold a reference to a vtkObjectBase instance.
virtual void ProcessSelectorPixelBuffers(vtkHardwareSelector *, std::vector< unsigned int > &, vtkProp *)
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
concrete dataset represents vertices, lines, polygons, and triangle strips
wgpu::Buffer CellIdOffsetUniformBuffer
virtual void SetVertexBuffers(const wgpu::RenderPassEncoder &passEncoder)
virtual void RemoveVertexAttributeMapping(const char *vertexAttributeName)
Remove a vertex attribute mapping.
window superclass for vtkRenderWindow
vtkNew< vtkWebGPUCellToPrimitiveConverter > CellConverter
std::uintptr_t MapperHashType
a simple class to control print indentation
abstract superclass for arrays of numeric data
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ComputeBounds()
Called in GetBounds().
std::vector< std::uint32_t > MeshAttributeDynamicOffsets
Render buffers are returned by calls to vtkWebGPUPolyDataMapper::AcquirePointAttributeComputeRenderBu...
virtual void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1)
Select a data array from the point/cell data and map it to a generic vertex attribute.
map vtkPolyData to graphics primitives
object to represent cell connectivity
bool GetSupportsSelection() override
Create a webgpu device for use in rendering and compute pipelines.
static vtkPolyDataMapper * New()
PointDataAttributes
All the attributes supported by the point data buffer.
TopologySourceType
All supported types of topology.
wgpu::Buffer ClippingPlanesBuffer
vtkTimeStamp ClippingPlanesBuildTimestamp
Timestamps help reuse previous resources as much as possible.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
CellDataAttributes
All the attributes supported by the cell data buffer.
wgpu::Buffer CellIdBuffer