VTK  9.7.1
vtkWebGPUSkybox.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
16 #ifndef vtkWebGPUSkybox_h
17 #define vtkWebGPUSkybox_h
18 
19 #include "vtkSkybox.h"
20 
21 #include "vtkNew.h" // for ivars
22 #include "vtkRenderingWebGPUModule.h" // For export macro
23 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
24 #include "vtk_wgpu.h" // for webgpu
25 
26 VTK_ABI_NAMESPACE_BEGIN
27 class vtkMatrix3x3;
31 class vtkWebGPURenderer;
32 
33 class VTKRENDERINGWEBGPU_EXPORT VTK_MARSHALAUTO vtkWebGPUSkybox : public vtkSkybox
34 {
35 public:
36  static vtkWebGPUSkybox* New();
38  static vtkOverrideAttribute* CreateOverrideAttributes();
39  vtkTypeMacro(vtkWebGPUSkybox, vtkSkybox);
40  void PrintSelf(ostream& os, vtkIndent indent) override;
41 
45  void Render(vtkRenderer* ren, vtkMapper* mapper) override;
46 
50  void ReleaseGraphicsResources(vtkWindow* window) override;
51 
52 protected:
54  ~vtkWebGPUSkybox() override;
55 
56 private:
57  vtkWebGPUSkybox(const vtkWebGPUSkybox&) = delete;
58  void operator=(const vtkWebGPUSkybox&) = delete;
59 
63  std::string BuildShaderSource();
64 
68  void CreatePipeline(vtkWebGPURenderWindow* wgpuRenderWindow);
69 
73  void CreateBindGroup(vtkWebGPUConfiguration* wgpuConfiguration);
74 
78  void UpdateUniformBuffer(vtkWebGPUConfiguration* wgpuConfiguration, vtkRenderer* ren);
79 
80  // Uniform block matching the WGSL struct layout
81  struct SkyboxUniforms
82  {
83  float CameraPosition[4]; // vec4 (padded from vec3)
84  float FloorPlane[4]; // vec4
85  float FloorRight[4]; // vec4 (padded from vec3)
86  float FloorFront[4]; // vec4 (padded from vec3)
87  float FloorTexCoordScale[2]; // vec2
88  float LeftEye; // f32
89  float ProjectionMode; // f32: 0=Cube, 1=Sphere, 2=StereoSphere, 3=Floor
90  alignas(16) float RotationMatrix[12]; // mat3x3 in WGSL = 3 x vec4 (each row padded to vec4)
91  };
92 
93  int LastProjection = -1;
94  bool LastGammaCorrect = false;
95 
96  wgpu::RenderPipeline Pipeline;
97  wgpu::BindGroupLayout BindGroupLayout;
98  wgpu::BindGroup BindGroup;
99  wgpu::Buffer UniformBuffer;
100  wgpu::Buffer MatrixBuffer;
101  wgpu::BindGroupLayout MatrixBindGroupLayout;
102  wgpu::BindGroup MatrixBindGroup;
103  std::string PipelineKey;
104 
105  vtkNew<vtkMatrix3x3> RotationMatrix;
106 
107  vtkMTimeType TextureBuildTime = 0;
108 };
109 
110 #define vtkWebGPUSkybox_OVERRIDE_ATTRIBUTES vtkWebGPUSkybox::CreateOverrideAttributes()
111 VTK_ABI_NAMESPACE_END
112 #endif
Attribute for vtkObjectFactory overrides.
virtual void Render(vtkRenderer *, vtkMapper *)
This causes the actor to be rendered.
Definition: vtkActor.h:83
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
abstract specification for renderers
Definition: vtkRenderer.h:63
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
a simple class to control print indentation
Definition: vtkIndent.h:28
WebGPU Skybox.
Renders a skybox environment.
Definition: vtkSkybox.h:21
int CreatePipeline(int argc, char *argv[], vtkProp *textActor, vtkTextProperty *textProperty, bool depthPeeling)
#define VTK_NEWINSTANCE
abstract class specifies interface to map data to graphics primitives
Definition: vtkMapper.h:77
static vtkSkybox * New()
Create a webgpu device for use in rendering and compute pipelines.
#define VTK_MARSHALAUTO
WebGPU rendering window.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:26