VTK  9.3.20240908
vtkWebGPUActor.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#ifndef vtkWebGPUActor_h
4#define vtkWebGPUActor_h
5
6#include "vtkActor.h"
7
8#include "vtkRenderingWebGPUModule.h" // for export macro
9#include "vtkTypeUInt32Array.h" // for ivar
10#include "vtk_wgpu.h" // for return
11
12VTK_ABI_NAMESPACE_BEGIN
13class vtkMatrix3x3;
14
15class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUActor : public vtkActor
16{
17public:
19 vtkTypeMacro(vtkWebGPUActor, vtkActor);
20 void PrintSelf(ostream& os, vtkIndent indent) override;
21
25 inline const void* GetCachedActorInformation() { return &(this->CachedActorInfo); }
26 static std::size_t GetCacheSizeBytes() { return sizeof(ActorBlock); }
27
31 void Render(vtkRenderer* ren, vtkMapper* mapper) override;
32 wgpu::RenderBundle RenderToBundle(vtkRenderer* ren, vtkMapper* mapper);
40
46 int Update(vtkRenderer* renderer, vtkMapper* mapper);
47
49
57
58 virtual bool UpdateKeyMatrices();
59
60 // Which stage is the mapper render being called from?
61 // vtkWebGPUActor::Update vs vtkWebGPUActor::Render
63 {
64 None = 0,
65 UpdateBuffers,
66 RenderPassEncode,
67 RenderBundleEncode,
68 RenderPostRasterization
69 };
70
71 // mapper figures this out when updating mesh geometry.
72 // if there are point scalars and we're coloring by point scalars mapped colors,
73 // this variable is assigned a value of ShadingTypeEnum::Smooth.
74 // if there are cell scalars and we're coloring by cell scalar mapped colors,
75 // this variable is assigned a value of ShadingTypeEnum::Flat.
76 enum ShadingTypeEnum : vtkTypeUInt32
77 {
78 Global = 0,
80 Flat
81 };
82
83 // What directional vectors are available to use for lighting?
84 // mapper figures this out when updating mesh geometry. mappers should report
85 // whether a combination of these are available by bitwise or'ing the flags.
86 enum DirectionalMaskEnum : vtkTypeUInt32
87 {
88 NoNormals = 1 << 0,
89 PointNormals = 1 << 1,
90 PointTangents = 1 << 2,
91 CellNormals = 1 << 3
92 };
93
95 void SetDirectionalMaskType(vtkTypeUInt32 directionalMask);
96 inline void SetMapperRenderPipelineOutdated(bool value)
97 {
98 this->MapperRenderPipelineOutdated = value;
99 }
100
101 inline MapperRenderType GetMapperRenderType() { return this->CurrentMapperRenderType; }
103 {
104 this->CurrentMapperRenderType = mapperRenderType;
105 }
106 inline wgpu::RenderBundleEncoder GetRenderBundleEncoder() { return this->CurrentBundler; }
108 {
109 this->DynamicOffsets = offsets;
110 }
111
112protected:
114 ~vtkWebGPUActor() override;
115
116 bool CachedMapperHasOpaqueGeometry = false;
117 bool CachedMapperHasTranslucentPolygonalGeometry = false;
118
119 MapperRenderType CurrentMapperRenderType = MapperRenderType::None;
120
122 {
124 {
125 vtkTypeFloat32 World[4][4] = {};
126 vtkTypeFloat32 Normal[3][4] = {};
127 } Transform;
128
130 {
131 // Representation - 0 : VTK_POINTS, 1 : VTK_WIREFRAME, 2 : VTK_SURFACE
132 vtkTypeUInt32 Representation = 0;
133 // Point size in pixels - applicable when points are visible.
134 vtkTypeFloat32 PointSize = 0;
135 // Line width in pixels - applicable when edges are visible.
136 vtkTypeFloat32 LineWidth = 0;
137 // Edge visibility - applicable for Representation = VTK_SURFACE.
138 vtkTypeUInt32 EdgeVisibility = 0;
139 } RenderOpts;
140
142 {
143 // Material ambient color intensity.
144 vtkTypeFloat32 AmbientIntensity = 0;
145 // Material diffuse color intensity.
146 vtkTypeFloat32 DiffuseIntensity = 0;
147 // Material specular color intensity.
148 vtkTypeFloat32 SpecularIntensity = 0;
149 // Material specular power.
150 vtkTypeFloat32 SpecularPower = 0;
151 // Opacity level
152 vtkTypeFloat32 Opacity = 0;
153 // Shading type
154 // 0: Global shading - Use global color for all primitives.
155 // 1: Smooth shading - Use point based colors which will be smoothly interpolated for
156 // in-between fragments. 2: Flat shading - Use cell based colors Material ambient color
157 vtkTypeUInt32 ShadingType = 0;
158 // What kind of normals to use for lighting? 0 - No normals, 1 - point normals, 1 - cell
159 // normals
160 vtkTypeUInt32 DirectionalMaskType = 0;
161 // so that AmbientColor starts at 16-byte boundary.
162 vtkTypeUInt8 Pad1[4] = {};
163 // Material ambient color - applicable when shading type is global.
164 vtkTypeFloat32 AmbientColor[4] = {};
165 // Material diffuse color - applicable when shading type is global.
166 vtkTypeFloat32 DiffuseColor[4] = {};
167 // Material specular color - applicable when shading type is global.
168 vtkTypeFloat32 SpecularColor[4] = {};
169 // Edge color
170 vtkTypeFloat32 EdgeColor[4] = {};
171 // use this padding to make wgsl spec validator happy if needed or at least 32 bytes.
172 } ShadeOpts;
173 };
174
176
180
184
185 bool MapperRenderPipelineOutdated = false;
186 wgpu::RenderBundleEncoder CurrentBundler;
188
189private:
190 vtkWebGPUActor(const vtkWebGPUActor&) = delete;
191 void operator=(const vtkWebGPUActor&) = delete;
192};
193
194VTK_ABI_NAMESPACE_END
195#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
a simple class to control print indentation
Definition vtkIndent.h:108
abstract class specifies interface to map data to graphics primitives
Definition vtkMapper.h:137
represent and manipulate 3x3 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:167
abstract specification for renderers
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
vtkNew< vtkTransform > NormalTransform
void SetMapperRenderPipelineOutdated(bool value)
wgpu::RenderBundleEncoder GetRenderBundleEncoder()
void SetMapperRenderType(MapperRenderType mapperRenderType)
vtkTimeStamp ShadingOptionsBuildTimestamp
vtkTimeStamp ModelTransformsBuildTimestamp
void SetShadingType(ShadingTypeEnum shadeType)
void CacheActorRenderOptions()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Update(vtkRenderer *renderer, vtkMapper *mapper)
Request mapper to run the vtkAlgorithm pipeline (if needed) and consequently update device buffers co...
virtual bool UpdateKeyMatrices()
vtkTypeBool HasTranslucentPolygonalGeometry() override
Re-use cached values in between consecutive buffer update stages.
MapperRenderType GetMapperRenderType()
const void * GetCachedActorInformation()
wgpu::RenderBundle RenderToBundle(vtkRenderer *ren, vtkMapper *mapper)
~vtkWebGPUActor() override
vtkSmartPointer< vtkTypeUInt32Array > DynamicOffsets
void CacheActorTransforms()
vtkNew< vtkMatrix3x3 > NormalMatrix
void SetDirectionalMaskType(vtkTypeUInt32 directionalMask)
wgpu::RenderBundleEncoder CurrentBundler
void SetDynamicOffsets(vtkSmartPointer< vtkTypeUInt32Array > offsets)
vtkTimeStamp RenderOptionsBuildTimestamp
void CacheActorShadeOptions()
bool SupportRenderBundles()
Returns true if the actor supports rendering with render bundles, false otherwise.
static vtkWebGPUActor * New()
ActorBlock CachedActorInfo
static std::size_t GetCacheSizeBytes()
vtkNew< vtkMatrix4x4 > MCWCMatrix
vtkTypeBool HasOpaqueGeometry() override
Re-use cached values in between consecutive buffer update stages.
void Render(vtkRenderer *ren, vtkMapper *mapper) override
Actual actor render method.
int vtkTypeBool
Definition vtkABI.h:64