VTK  9.3.0
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);
33
39 int Update(vtkRenderer* renderer, vtkMapper* mapper);
40
42
50
51 virtual bool UpdateKeyMatrices();
52
53 // Which stage is the mapper render being called from?
54 // vtkWebGPUActor::Update vs vtkWebGPUActor::Render
56 {
57 None,
58 UpdateBuffers,
59 RenderPassEncode,
60 RenderBundleEncode
61 };
62
63 // mapper figures this out when updating mesh geometry.
64 // if there are point scalars and we're coloring by point scalars mapped colors,
65 // this variable is assigned a value of ShadingTypeEnum::Smooth.
66 // if there are cell scalars and we're coloring by cell scalar mapped colors,
67 // this variable is assigned a value of ShadingTypeEnum::Flat.
68 enum ShadingTypeEnum : vtkTypeUInt32
69 {
70 Global = 0,
72 Flat
73 };
74
75 // What directional vectors are available to use for lighting?
76 // mapper figures this out when updating mesh geometry. mappers should report
77 // whether a combination of these are available by bitwise or'ing the flags.
78 enum DirectionalMaskEnum : vtkTypeUInt32
79 {
80 NoNormals = 1 << 0,
81 PointNormals = 1 << 1,
82 PointTangents = 1 << 2,
83 CellNormals = 1 << 3
84 };
85
87 void SetDirectionalMaskType(vtkTypeUInt32 directionalMask);
88 inline void SetMapperRenderPipelineOutdated(bool value)
89 {
90 this->MapperRenderPipelineOutdated = value;
91 }
92
93 inline MapperRenderType GetMapperRenderType() { return this->CurrentMapperRenderType; }
94 inline wgpu::RenderBundleEncoder GetRenderBundleEncoder() { return this->CurrentBundler; }
96 {
97 this->DynamicOffsets = offsets;
98 }
99
100protected:
102 ~vtkWebGPUActor() override;
103
104 bool CachedMapperHasOpaqueGeometry = false;
105 bool CachedMapperHasTranslucentPolygonalGeometry = false;
106
107 MapperRenderType CurrentMapperRenderType = MapperRenderType::None;
108
110 {
112 {
113 vtkTypeFloat32 World[4][4] = {};
114 vtkTypeFloat32 Normal[3][4] = {};
115 } Transform;
116
118 {
119 // Representaion - 0 : VTK_POINTS, 1 : VTK_WIREFRAME, 2 : VTK_SURFACE
120 vtkTypeUInt32 Representation = 0;
121 // Point size in pixels - applicable when points are visible.
122 vtkTypeFloat32 PointSize = 0;
123 // Line width in pixels - applicable when edges are visible.
124 vtkTypeFloat32 LineWidth = 0;
125 // Edge visibility - applicable for Representation = VTK_SURFACE.
126 vtkTypeUInt32 EdgeVisibility = 0;
127 } RenderOpts;
128
130 {
131 // Material ambient color intensity.
132 vtkTypeFloat32 AmbientIntensity = 0;
133 // Material diffuse color intensity.
134 vtkTypeFloat32 DiffuseIntensity = 0;
135 // Material specular color intensity.
136 vtkTypeFloat32 SpecularIntensity = 0;
137 // Material specular power.
138 vtkTypeFloat32 SpecularPower = 0;
139 // Opacity level
140 vtkTypeFloat32 Opacity = 0;
141 // Shading type
142 // 0: Global shading - Use global color for all primitives.
143 // 1: Smooth shading - Use point based colors which will be smoothly interpolated for
144 // in-between fragments. 2: Flat shading - Use cell based colors Material ambient color
145 vtkTypeUInt32 ShadingType = 0;
146 // What kind of normals to use for lighting? 0 - No normals, 1 - point normals, 1 - cell
147 // normals
148 vtkTypeUInt32 DirectionalMaskType = 0;
149 // so that AmbientColor starts at 16-byte boundary.
150 vtkTypeUInt8 Pad1[4] = {};
151 // Material ambient color - applicable when shading type is global.
152 vtkTypeFloat32 AmbientColor[4] = {};
153 // Material diffuse color - applicable when shading type is global.
154 vtkTypeFloat32 DiffuseColor[4] = {};
155 // Material specular color - applicable when shading type is global.
156 vtkTypeFloat32 SpecularColor[4] = {};
157 // Edge color
158 vtkTypeFloat32 EdgeColor[4] = {};
159 // use this padding to make wgsl spec validator happy if needed or atleast 32 bytes.
160 } ShadeOpts;
161 };
162
164
168
172
173 bool MapperRenderPipelineOutdated = false;
174 wgpu::RenderBundleEncoder CurrentBundler;
176
177private:
178 vtkWebGPUActor(const vtkWebGPUActor&) = delete;
179 void operator=(const vtkWebGPUActor&) = delete;
180};
181
182VTK_ABI_NAMESPACE_END
183#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:41
a simple class to control print indentation
Definition vtkIndent.h:29
abstract class specifies interface to map data to graphics primitives
Definition vtkMapper.h:77
represent and manipulate 3x3 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:51
abstract specification for renderers
Definition vtkRenderer.h:59
Hold a reference to a vtkObjectBase instance.
record modification and/or execution time
vtkNew< vtkTransform > NormalTransform
void SetMapperRenderPipelineOutdated(bool value)
wgpu::RenderBundleEncoder GetRenderBundleEncoder()
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()
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