3#ifndef vtkWebGPUPolyDataMapper_h
4#define vtkWebGPUPolyDataMapper_h
9#include "vtkRenderingWebGPUModule.h"
16#include <unordered_set>
18VTK_ABI_NAMESPACE_BEGIN
126 int fieldAssociation,
int componentno = -1)
override;
136 int fieldAssociation,
int componentno = -1)
override;
172 int uniformsBinding);
179 int uniformsBinding);
230 const wgpu::Device& device,
const std::string& label);
236 const std::string& label,
bool homogeneousCellSize,
bool useEdgeArray);
256 const wgpu::Device& device,
const std::string& label);
468 } ClippingPlanesData;
530 static_assert(GROUP_NB_BINDGROUPS <= 4,
531 "Number of bind groups exceeds 4! Most devices can support only up to 4 bind groups");
563 return this->PointBuffers[attribute].
Buffer;
569 wgpu::Buffer GetCellDataWGPUBuffer(CellDataAttributes attribute)
571 return this->CellBuffers[attribute].
Buffer;
580 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> SetupComputeRenderBuffers;
585 std::unordered_set<vtkSmartPointer<vtkWebGPUComputeRenderBuffer>> NotSetupComputeRenderBuffers;
590 const PointDataAttributes PointDataAttributesOrder[PointDataAttributes::POINT_NB_ATTRIBUTES] = {
591 PointDataAttributes::POINT_POSITIONS, PointDataAttributes::POINT_COLORS,
592 PointDataAttributes::POINT_NORMALS, PointDataAttributes::POINT_TANGENTS,
593 PointDataAttributes::POINT_UVS, PointDataAttributes::POINT_COLOR_UVS
599 const CellDataAttributes CellDataAttributesOrder[CellDataAttributes::CELL_NB_ATTRIBUTES] = {
600 CellDataAttributes::CELL_COLORS, CellDataAttributes::CELL_NORMALS
603 std::map<std::pair<vtkActor*, vtkRenderer*>, ActorState> CachedActorRendererProperties;
605 vtkWebGPUPolyDataMapper(
const vtkWebGPUPolyDataMapper&) =
delete;
606 void operator=(
const vtkWebGPUPolyDataMapper&) =
delete;
represents an object (geometry & properties) in a rendered scene
object to represent cell connectivity
a simple class to control print indentation
Allocate and hold a VTK object.
std::uintptr_t MapperHashType
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
abstract specification for renderers
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
TopologySourceType
All supported types of topology.
@ NUM_TOPOLOGY_SOURCE_TYPES
Render buffers are returned by calls to vtkWebGPUPolyDataMapper::AcquirePointAttributeComputeRenderBu...
Create a webgpu device for use in rendering and compute pipelines.
vtkTimeStamp PointAttributesBuildTimestamp[POINT_NB_ATTRIBUTES]
Timestamps help reuse previous resources as much as possible.
PointDataAttributes
All the attributes supported by the point data buffer.
unsigned long GetPointAttributeByteSize(vtkWebGPUPolyDataMapper::PointDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole point data SSBO for the given attribute.
void ProcessSelectorPixelBuffers(vtkHardwareSelector *sel, std::vector< unsigned int > &pixeloffsets, vtkProp *prop) override
allows a mapper to update a selections color buffers Called from a prop which in turn is called from ...
virtual void ReplaceShaderCustomDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceVertexShaderMainEnd(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
bool GetSupportsSelection() override
virtual void ReplaceShaderMeshAttributeBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
wgpu::BindGroup MeshAttributeBindGroup
virtual void ReplaceVertexShaderPositionVC(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceShaderVertexOutputDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceVertexShaderNormalTransform(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceFragmentShaderMainEnd(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
virtual void ReplaceFragmentShaderMainStart(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
virtual void ReplaceFragmentShaderClippingPlanes(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
bool RebuildGraphicsPipelines
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
unsigned long GetExactCellBufferSize(CellDataAttributes attribute)
Calculates the size of a buffer that is large enough to contain all the values from the cell attribut...
vtkTypeFloat32 PlaneEquations[6][4]
std::array< std::uint32_t, GROUP_NB_BINDGROUPS > NumberOfBindings
virtual void ReplaceVertexShaderPicking(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
vtkTimeStamp ClippingPlanesBuildTimestamp
Timestamps help reuse previous resources as much as possible.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned long GetCellAttributeElementSize(vtkWebGPUPolyDataMapper::CellDataAttributes attribute)
Returns the size in bytes of one element of the given attribute.
bool HasCellAttributes[CELL_NB_ATTRIBUTES]
friend class vtkWebGPURenderer
void MapDataArrayToVertexAttribute(const char *vertexAttributeName, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
Select a data array from the point/cell data and map it to a generic vertex attribute.
virtual void ReplaceShaderClippingPlanesBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
void RemoveAllVertexAttributeMappings() override
Remove all vertex attributes.
wgpu::BindGroupLayout CreateTopologyBindGroupLayout(const wgpu::Device &device, const std::string &label, bool homogeneousCellSize, bool useEdgeArray)
Create a bind group layout for the TopologyRenderInfo::BindGroup
vtkTypeUInt32 LastNumClipPlanes
void DeducePointCellAttributeAvailability(vtkPolyData *mesh)
Looks at the point/cell data of vtkPolyData object and determines which attributes are available.
AttributeBuffer CellBuffers[CELL_NB_ATTRIBUTES]
vtkPolyDataMapper::MapperHashType GenerateHash(vtkPolyData *polydata) override
This hash integer is computed by concrete graphics implementation of this class.
vtkSmartPointer< vtkWebGPUTexture > ColorTextureHostResource
virtual std::vector< wgpu::BindGroupEntry > GetMeshBindGroupEntries()
virtual void ReplaceShaderRendererBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
void ResetPointCellAttributeState()
Reset the internal Has{Point,Cell}Attribute booleans to false.
vtkTimeStamp CellAttributesBuildTimestamp[CELL_NB_ATTRIBUTES]
Timestamps help reuse previous resources as much as possible.
vtkSmartPointer< vtkWebGPUComputeRenderBuffer > AcquirePointAttributeComputeRenderBuffer(PointDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup, int uniformsBinding)
Returns an already configured (ready to be added to a vtkWebGPUComputePipeline) buffer bound to the g...
virtual void ReplaceFragmentShaderOutputDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
wgpu::BindGroupLayout CreateMeshAttributeBindGroupLayout(const wgpu::Device &device, const std::string &label)
Create a bind group layout for the mesh attribute bind group.
vtkSmartPointer< vtkWebGPUComputeRenderBuffer > AcquireCellAttributeComputeRenderBuffer(CellDataAttributes attribute, int bufferGroup, int bufferBinding, int uniformsGroup, int uniformsBinding)
Same as AcquirePointAttributeComputeRenderBuffer but for cell data attributes.
virtual void ReplaceShaderActorBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceVertexShaderClippingPlanes(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
AttributeBuffer PointBuffers[POINT_NB_ATTRIBUTES]
virtual std::vector< wgpu::BindGroupLayoutEntry > GetMeshBindGroupLayoutEntries()
virtual void ReplaceFragmentShaderColors(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
TopologyBindGroupInfo TopologyBindGroupInfos[vtkWebGPUCellToPrimitiveConverter::NUM_TOPOLOGY_SOURCE_TYPES]
virtual void ReplaceVertexShaderEdges(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceVertexShaderPrimitiveId(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
vtkPolyData * CurrentInput
unsigned long GetExactPointBufferSize(PointDataAttributes attribute)
Calculates the size of a buffer that is large enough to contain all the values from the point attribu...
wgpu::BindGroup CreateTopologyBindGroup(const wgpu::Device &device, const std::string &label, vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType)
Create a bind group for the primitives of a mesh.
void SetupGraphicsPipelines(const wgpu::Device &device, vtkRenderer *renderer, vtkActor *actor)
Creates the graphics pipeline.
vtkWebGPUPolyDataMapper()
std::string GraphicsPipelineKeys[GFX_PIPELINE_NB_TYPES]
void RecordDrawCommands(vtkRenderer *renderer, vtkActor *actor, const wgpu::RenderPassEncoder &passEncoder)
Record draw calls in the render pass encoder.
virtual void ReplaceVertexShaderPosition(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
void RemoveVertexAttributeMapping(const char *vertexAttributeName) override
Remove a vertex attribute mapping.
virtual bool IsPipelineSupported(GraphicsPipelineType pipelineType)
Whether shaders must be built to target the specific pipeline.
static vtkWebGPUPolyDataMapper * New()
virtual void ReplaceVertexShaderMainStart(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceFragmentShaderNormals(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
~vtkWebGPUPolyDataMapper() override
virtual void ReplaceFragmentShaderEdges(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
virtual DrawCallArgs GetDrawCallArgsForDrawingVertices(vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType)
virtual wgpu::PrimitiveTopology GetPrimitiveTopologyForPipeline(GraphicsPipelineType pipelineType)
Get the primitive topology type that should be used for the given pipeline.
void RecordDrawCommands(vtkRenderer *renderer, vtkActor *actor, const wgpu::RenderBundleEncoder &bundleEncoder)
virtual DrawCallArgs GetDrawCallArgs(GraphicsPipelineType pipelineType, vtkWebGPUCellToPrimitiveConverter::TopologySourceType topologySourceType)
const char * GetGraphicsPipelineTypeAsString(GraphicsPipelineType graphicsPipelineType)
Get the name of the graphics pipeline type as a string.
vtkNew< vtkWebGPUCellToPrimitiveConverter > CellConverter
void MapDataArrayToMultiTextureAttribute(const char *tname, const char *dataArrayName, int fieldAssociation, int componentno=-1) override
This method will Map the specified data array for use as a texture coordinate for texture tname.
virtual void ReplaceFragmentShaderLights(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
void UpdateClippingPlanesBuffer(vtkWebGPUConfiguration *wgpuConfiguration, vtkActor *actor)
Updates the clipping planes buffer with the current clipping planes data.
unsigned long GetCellAttributeByteSize(vtkWebGPUPolyDataMapper::CellDataAttributes attribute)
Returns the size of the 'sub-buffer' within the whole cell data SSBO for the given attribute.
bool LastScalarVisibility
vtkTimeStamp IndirectDrawBufferUploadTimeStamp[vtkWebGPUCellToPrimitiveConverter::NUM_TOPOLOGY_SOURCE_TYPES]
Timestamps help reuse previous resources as much as possible.
virtual void ReplaceShaderConstantsDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceShaderClippingPlanesDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceShaderActorDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
void RenderPiece(vtkRenderer *renderer, vtkActor *act) override
Implemented by sub classes.
virtual void ReplaceVertexShaderTangents(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceVertexShaderInputDef(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceFragmentShaderPicking(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &fss)
vtkPolyData * CachedInput
friend class vtkWebGPUComputeRenderBuffer
GraphicsPipelineType
This mapper uses different wgpu::RenderPipeline to render a list of primitives.
@ GFX_PIPELINE_POINTS_SHAPED
@ GFX_PIPELINE_LINES_ROUND_CAP_ROUND_JOIN
@ GFX_PIPELINE_POINTS_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_LINES_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_LINES_MITER_JOIN
@ GFX_PIPELINE_LINES_THICK_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_LINES_THICK
@ GFX_PIPELINE_LINES_ROUND_CAP_ROUND_JOIN_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_POINTS_SHAPED_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_TRIANGLES_HOMOGENEOUS_CELL_SIZE
@ GFX_PIPELINE_LINES_MITER_JOIN_HOMOGENEOUS_CELL_SIZE
virtual void ReplaceShaderCustomBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
static bool IsPipelineForHomogeneousCellSize(GraphicsPipelineType pipelineType)
virtual void ReplaceVertexShaderUVs(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
wgpu::Buffer ClippingPlanesBuffer
void UpdateMeshGeometryBuffers(vtkWebGPURenderWindow *wgpuRenderWindow)
Creates buffers as needed and updates them with point/cell attributes, topology, draw parameters.
virtual void ReplaceVertexShaderCamera(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
bool GetNeedToRebuildGraphicsPipelines(vtkActor *actor, vtkRenderer *renderer)
Get whether the graphics pipeline needs rebuilt.
virtual void ReplaceVertexShaderCellId(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ApplyShaderReplacements(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
Generates vertex and fragment shader code.
unsigned long GetPointAttributeElementSize(vtkWebGPUPolyDataMapper::PointDataAttributes attribute)
Returns the size in bytes of one element of the given attribute.
bool HasPointAttributes[POINT_NB_ATTRIBUTES]
wgpu::BindGroup CreateMeshAttributeBindGroup(const wgpu::Device &device, const std::string &label)
Create a bind group for the point and cell attributes of a mesh.
bool CacheActorRendererProperties(vtkActor *actor, vtkRenderer *renderer)
This method keeps track of few properties of the actor which when changed, require rebuilding a rende...
virtual void ReplaceVertexShaderNormals(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
CellDataAttributes
All the attributes supported by the cell data buffer.
void ComputeBounds() override
Called in GetBounds().
virtual void ReplaceVertexShaderVertexId(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
virtual void ReplaceShaderTopologyBindings(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss, std::string &fss)
virtual void ReplaceVertexShaderColors(GraphicsPipelineType pipelineType, vtkWebGPURenderer *renderer, vtkWebGPUActor *actor, std::string &vss)
vtkWebGPUTexture is a concrete implementation of the abstract class vtkTexture for WebGPU.
window superclass for vtkRenderWindow
bool LastHasRenderingTranslucentGeometry
bool LastActorFrontfaceCulling
bool LastVertexVisibility
bool LastActorBackfaceCulling
std::uint32_t VertexCount
std::uint32_t InstanceCount
wgpu::Buffer CellIdOffsetUniformBuffer
wgpu::BindGroup BindGroup
vtkTypeUInt32 VertexCount
wgpu::Buffer EdgeArrayBuffer
vtkTypeUInt32 MaxCellSize
wgpu::Buffer CellIdBuffer
wgpu::Buffer ConnectivityBuffer