VTK: Rendering/WebGPU/vtkWebGPURenderWindow.h Source File

| VTK 9.3.1

vtkWebGPURenderWindow.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 vtkWebGPURenderWindow_h
4 #define vtkWebGPURenderWindow_h
5
6 #include "vtkRenderWindow.h"
7
8 #include "vtkRenderingWebGPUModule.h" // for export macro
9 #include "vtkTypeUInt8Array.h" // for ivar
10 #include "vtk_wgpu.h" // for webgpu
11
12 VTK_ABI_NAMESPACE_BEGIN
13
14 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPURenderWindow : public vtkRenderWindow
15 {
16 public:
17 vtkTypeMacro(vtkWebGPURenderWindow, vtkRenderWindow);
18 void PrintSelf(ostream& os, vtkIndent indent) override;
19
20 // for high power preference, we shall request discrete GPU instead of integrated GPU or the CPU.
21 void SetPowerPreference(bool high = true)
22 {
23 this->PowerPreference =
24 high ? wgpu::PowerPreference::HighPerformance : wgpu::PowerPreference::LowPower;
25 this->Modified();
26 }
27
32 virtual bool Initialize() = 0;
33
37 virtual void CreateAWindow() = 0;
38
42 virtual void DestroyWindow() = 0;
43
44 void Start() override;
45
49 void End() override;
50
54 void Render() override;
55
60 void StereoMidpoint() override;
61 void Frame() override;
62
63 const char* GetRenderingBackend() override;
64
68 void ReadPixels();
69
71
76 unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
77 int GetPixelData(
78 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
79 int SetPixelData(
80 int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
81 int SetPixelData(
82 int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
84
86
89 float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
90 int GetRGBAPixelData(
91 int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
92 int SetRGBAPixelData(
93 int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
94 int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
95 int right = 0) override;
96 void ReleaseRGBAPixelData(float* data) override;
97 unsigned char* GetRGBACharPixelData(
98 int x, int y, int x2, int y2, int front, int right = 0) override;
99 int GetRGBACharPixelData(
100 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
101 int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
102 int blend = 0, int right = 0) override;
103 int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
104 int blend = 0, int right = 0) override;
106
108
111 float* GetZbufferData(int x1, int y1, int x2, int y2) override;
112 int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
113 int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
114 int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
115 int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
117
122 int GetColorBufferSizes(int* rgba) override;
126 void WaitForCompletion() override;
127
131 int SupportsOpenGL() override;
132
136 const char* ReportCapabilities() override;
137
142 bool InitializeFromCurrentContext() override;
143
148 void ReleaseGraphicsResources(vtkWindow*) override;
149
150 inline wgpu::RenderPassEncoder NewRenderPass(wgpu::RenderPassDescriptor& descriptor)
151 {
152 return this->CommandEncoder.BeginRenderPass(&descriptor);
153 }
154
155 inline wgpu::RenderBundleEncoder NewRenderBundleEncoder(
156 wgpu::RenderBundleEncoderDescriptor& descriptor)
157 {
158 return this->Device.CreateRenderBundleEncoder(&descriptor);
159 }
160
161 inline wgpu::CommandEncoder GetCommandEncoder() { return this->CommandEncoder; }
162 inline wgpu::TextureView GetOffscreenColorAttachmentView() { return this->ColorAttachment.View; }
163 inline wgpu::TextureView GetDepthStencilView() { return this->DepthStencil.View; }
164 inline wgpu::TextureFormat GetDepthStencilFormat() { return this->DepthStencil.Format; }
165 inline bool HasStencil() { return this->DepthStencil.HasStencil; }
166 inline wgpu::Device GetDevice() { return this->Device; }
167
168 wgpu::TextureFormat GetPreferredSwapChainTextureFormat();
169
170 protected:
171 vtkWebGPURenderWindow();
172 ~vtkWebGPURenderWindow() override;
173
174 bool WGPUInit();
175 void WGPUFinalize();
176
177 void CreateSwapChain();
178 void DestroySwapChain();
179
180 void CreateOffscreenColorAttachments();
181 void DestroyOffscreenColorAttachments();
182
183 void CreateDepthStencilTexture();
184 void DestroyDepthStencilTexture();
185
186 void CreateFSQGraphicsPipeline();
187 void DestroyFSQGraphicsPipeline();
188
189 void RenderOffscreenTexture();
190
191 void FlushCommandBuffers(vtkTypeUInt32 count, wgpu::CommandBuffer* buffers);
192
193 bool WGPUInitialized = false;
194 wgpu::PowerPreference PowerPreference = wgpu::PowerPreference::HighPerformance;
195 wgpu::Adapter Adapter;
196 wgpu::Device Device;
197 wgpu::Surface Surface;
198 wgpu::CommandEncoder CommandEncoder;
199
200 struct vtkWGPUSwapChain
201 {
202 wgpu::SwapChain Instance;
203 wgpu::TextureView Framebuffer;
204 wgpu::TextureFormat TexFormat;
205 wgpu::PresentMode PresentMode;
206 int Width = 0;
207 int Height = 0;
208 };
209 vtkWGPUSwapChain SwapChain;
210
211 struct vtkWGPUDeptStencil
212 {
213 wgpu::Texture Texture;
214 wgpu::TextureView View;
215 wgpu::TextureFormat Format;
216 bool HasStencil;
217 };
218 vtkWGPUDeptStencil DepthStencil;
219
220 struct vtkWGPUColorAttachment
221 {
222 wgpu::Texture Texture;
223 wgpu::TextureView View;
224 wgpu::TextureFormat Format;
225 wgpu::Buffer OffscreenBuffer;
226 };
227 vtkWGPUColorAttachment ColorAttachment;
228
229 struct vtkWGPUUserStagingPixelData
230 {
231 wgpu::Origin3D Origin;
232 wgpu::Extent3D Extent;
233 wgpu::TextureDataLayout Layout;
234 wgpu::Buffer Buffer; // for SetPixelData
235 };
236 vtkWGPUUserStagingPixelData StagingPixelData;
237
238 struct vtkWGPUFullScreenQuad
239 {
240 wgpu::RenderPipeline Pipeline;
241 wgpu::BindGroup BindGroup;
242 };
243 vtkWGPUFullScreenQuad FSQ;
244
245 struct MappingContext
246 {
247 vtkSmartPointer<vtkTypeUInt8Array> dst;
248 wgpu::Buffer src;
249 unsigned long size;
250 } BufferMapReadContext;
251
252 vtkNew<vtkTypeUInt8Array> CachedPixelBytes;
253
254 private:
255 vtkWebGPURenderWindow(const vtkWebGPURenderWindow&) = delete;
256 void operator=(const vtkWebGPURenderWindow&) = delete;
257 };
258
259 VTK_ABI_NAMESPACE_END
260 #endif
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:40
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkNew< vtkTypeUInt8Array >
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:95
vtkSmartPointer< vtkTypeUInt8Array >
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:40
vtkWebGPURenderWindow
Definition: vtkWebGPURenderWindow.h:15
vtkWebGPURenderWindow::DestroyDepthStencilTexture
void DestroyDepthStencilTexture()
vtkWebGPURenderWindow::Initialize
virtual bool Initialize()=0
Concrete render windows must create a platform window and initialize this->WindowId.
vtkWebGPURenderWindow::ReportCapabilities
const char * ReportCapabilities() override
Get report of capabilities for the render window.
vtkWebGPURenderWindow::Frame
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
vtkWebGPURenderWindow::CreateSwapChain
void CreateSwapChain()
vtkWebGPURenderWindow::DestroySwapChain
void DestroySwapChain()
vtkWebGPURenderWindow::GetDepthStencilFormat
wgpu::TextureFormat GetDepthStencilFormat()
Definition: vtkWebGPURenderWindow.h:164
vtkWebGPURenderWindow::Adapter
wgpu::Adapter Adapter
Definition: vtkWebGPURenderWindow.h:195
vtkWebGPURenderWindow::SwapChain
vtkWGPUSwapChain SwapChain
Definition: vtkWebGPURenderWindow.h:209
vtkWebGPURenderWindow::End
void End() override
Update the system, if needed, at end of render process.
vtkWebGPURenderWindow::SupportsOpenGL
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
vtkWebGPURenderWindow::SetZbufferData
int SetZbufferData(int x1, int y1, int x2, int y2, float *buffer) override
Set/Get the zbuffer data from an image.
vtkWebGPURenderWindow::ReadPixels
void ReadPixels()
Reads pixels into the CachedPixelBytes variable.
vtkWebGPURenderWindow::GetCommandEncoder
wgpu::CommandEncoder GetCommandEncoder()
Definition: vtkWebGPURenderWindow.h:161
vtkWebGPURenderWindow::CreateOffscreenColorAttachments
void CreateOffscreenColorAttachments()
vtkWebGPURenderWindow::ColorAttachment
vtkWGPUColorAttachment ColorAttachment
Definition: vtkWebGPURenderWindow.h:227
vtkWebGPURenderWindow::HasStencil
bool HasStencil()
Definition: vtkWebGPURenderWindow.h:165
vtkWebGPURenderWindow::GetPixelData
int GetPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
vtkWebGPURenderWindow::CreateAWindow
virtual void CreateAWindow()=0
Create a not-off-screen window.
vtkWebGPURenderWindow::GetPixelData
unsigned char * GetPixelData(int x, int y, int x2, int y2, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
vtkWebGPURenderWindow::SetPowerPreference
void SetPowerPreference(bool high=true)
Definition: vtkWebGPURenderWindow.h:21
vtkWebGPURenderWindow::GetRGBAPixelData
int GetRGBAPixelData(int x, int y, int x2, int y2, int front, vtkFloatArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::Device
wgpu::Device Device
Definition: vtkWebGPURenderWindow.h:196
vtkWebGPURenderWindow::ReleaseRGBAPixelData
void ReleaseRGBAPixelData(float *data) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWebGPURenderWindow::GetRGBACharPixelData
unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::GetRGBACharPixelData
int GetRGBACharPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::GetZbufferData
float * GetZbufferData(int x1, int y1, int x2, int y2) override
Set/Get the zbuffer data from an image.
vtkWebGPURenderWindow::DestroyOffscreenColorAttachments
void DestroyOffscreenColorAttachments()
vtkWebGPURenderWindow::SetPixelData
int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
vtkWebGPURenderWindow::GetRenderingBackend
const char * GetRenderingBackend() override
What rendering backend has the user requested.
vtkWebGPURenderWindow::GetRGBAPixelData
float * GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::DestroyFSQGraphicsPipeline
void DestroyFSQGraphicsPipeline()
vtkWebGPURenderWindow::WaitForCompletion
void WaitForCompletion() override
Block the thread until work queue completes all submitted work.
vtkWebGPURenderWindow::SetPixelData
int SetPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
vtkWebGPURenderWindow::CommandEncoder
wgpu::CommandEncoder CommandEncoder
Definition: vtkWebGPURenderWindow.h:198
vtkWebGPURenderWindow::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
vtkWebGPURenderWindow::InitializeFromCurrentContext
bool InitializeFromCurrentContext() override
Initialize the render window from the information associated with the currently activated OpenGL cont...
vtkWebGPURenderWindow::Surface
wgpu::Surface Surface
Definition: vtkWebGPURenderWindow.h:197
vtkWebGPURenderWindow::GetDepthStencilView
wgpu::TextureView GetDepthStencilView()
Definition: vtkWebGPURenderWindow.h:163
vtkWebGPURenderWindow::SetZbufferData
int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
vtkWebGPURenderWindow::GetZbufferData
int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
vtkWebGPURenderWindow::Render
void Render() override
Handle opengl specific code and calls superclass.
vtkWebGPURenderWindow::GetPreferredSwapChainTextureFormat
wgpu::TextureFormat GetPreferredSwapChainTextureFormat()
vtkWebGPURenderWindow::SetRGBAPixelData
int SetRGBAPixelData(int x, int y, int x2, int y2, float *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::WGPUFinalize
void WGPUFinalize()
vtkWebGPURenderWindow::CachedPixelBytes
vtkNew< vtkTypeUInt8Array > CachedPixelBytes
Definition: vtkWebGPURenderWindow.h:252
vtkWebGPURenderWindow::NewRenderBundleEncoder
wgpu::RenderBundleEncoder NewRenderBundleEncoder(wgpu::RenderBundleEncoderDescriptor &descriptor)
Definition: vtkWebGPURenderWindow.h:155
vtkWebGPURenderWindow::RenderOffscreenTexture
void RenderOffscreenTexture()
vtkWebGPURenderWindow::FlushCommandBuffers
void FlushCommandBuffers(vtkTypeUInt32 count, wgpu::CommandBuffer *buffers)
vtkWebGPURenderWindow::Start
void Start() override
Start the rendering process for a frame.
vtkWebGPURenderWindow::DestroyWindow
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
vtkWebGPURenderWindow::NewRenderPass
wgpu::RenderPassEncoder NewRenderPass(wgpu::RenderPassDescriptor &descriptor)
Definition: vtkWebGPURenderWindow.h:150
vtkWebGPURenderWindow::SetRGBACharPixelData
int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::CreateFSQGraphicsPipeline
void CreateFSQGraphicsPipeline()
vtkWebGPURenderWindow::WGPUInit
bool WGPUInit()
vtkWebGPURenderWindow::~vtkWebGPURenderWindow
~vtkWebGPURenderWindow() override
vtkWebGPURenderWindow::CreateDepthStencilTexture
void CreateDepthStencilTexture()
vtkWebGPURenderWindow::vtkWebGPURenderWindow
vtkWebGPURenderWindow()
vtkWebGPURenderWindow::GetZbufferData
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
Set/Get the zbuffer data from an image.
vtkWebGPURenderWindow::GetOffscreenColorAttachmentView
wgpu::TextureView GetOffscreenColorAttachmentView()
Definition: vtkWebGPURenderWindow.h:162
vtkWebGPURenderWindow::StagingPixelData
vtkWGPUUserStagingPixelData StagingPixelData
Definition: vtkWebGPURenderWindow.h:236
vtkWebGPURenderWindow::SetRGBAPixelData
int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWebGPURenderWindow::FSQ
vtkWGPUFullScreenQuad FSQ
Definition: vtkWebGPURenderWindow.h:243
vtkWebGPURenderWindow::StereoMidpoint
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkWebGPURenderWindow::DepthStencil
vtkWGPUDeptStencil DepthStencil
Definition: vtkWebGPURenderWindow.h:218
vtkWebGPURenderWindow::GetColorBufferSizes
int GetColorBufferSizes(int *rgba) override
Get the size of the color buffer.
vtkWebGPURenderWindow::GetDevice
wgpu::Device GetDevice()
Definition: vtkWebGPURenderWindow.h:166
vtkWebGPURenderWindow::SetRGBACharPixelData
int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkX3D::data
@ data
Definition: vtkX3D.h:315
vtkWebGPURenderWindow::MappingContext
Definition: vtkWebGPURenderWindow.h:246
vtkWebGPURenderWindow::MappingContext::dst
vtkSmartPointer< vtkTypeUInt8Array > dst
Definition: vtkWebGPURenderWindow.h:247
vtkWebGPURenderWindow::MappingContext::src
wgpu::Buffer src
Definition: vtkWebGPURenderWindow.h:248
vtkWebGPURenderWindow::MappingContext::size
unsigned long size
Definition: vtkWebGPURenderWindow.h:249
vtkWebGPURenderWindow::vtkWGPUColorAttachment
Definition: vtkWebGPURenderWindow.h:221
vtkWebGPURenderWindow::vtkWGPUColorAttachment::Format
wgpu::TextureFormat Format
Definition: vtkWebGPURenderWindow.h:224
vtkWebGPURenderWindow::vtkWGPUColorAttachment::Texture
wgpu::Texture Texture
Definition: vtkWebGPURenderWindow.h:222
vtkWebGPURenderWindow::vtkWGPUColorAttachment::OffscreenBuffer
wgpu::Buffer OffscreenBuffer
Definition: vtkWebGPURenderWindow.h:225
vtkWebGPURenderWindow::vtkWGPUColorAttachment::View
wgpu::TextureView View
Definition: vtkWebGPURenderWindow.h:223
vtkWebGPURenderWindow::vtkWGPUDeptStencil
Definition: vtkWebGPURenderWindow.h:212
vtkWebGPURenderWindow::vtkWGPUDeptStencil::HasStencil
bool HasStencil
Definition: vtkWebGPURenderWindow.h:216
vtkWebGPURenderWindow::vtkWGPUDeptStencil::Texture
wgpu::Texture Texture
Definition: vtkWebGPURenderWindow.h:213
vtkWebGPURenderWindow::vtkWGPUDeptStencil::View
wgpu::TextureView View
Definition: vtkWebGPURenderWindow.h:214
vtkWebGPURenderWindow::vtkWGPUDeptStencil::Format
wgpu::TextureFormat Format
Definition: vtkWebGPURenderWindow.h:215
vtkWebGPURenderWindow::vtkWGPUFullScreenQuad
Definition: vtkWebGPURenderWindow.h:239
vtkWebGPURenderWindow::vtkWGPUFullScreenQuad::BindGroup
wgpu::BindGroup BindGroup
Definition: vtkWebGPURenderWindow.h:241
vtkWebGPURenderWindow::vtkWGPUFullScreenQuad::Pipeline
wgpu::RenderPipeline Pipeline
Definition: vtkWebGPURenderWindow.h:240
vtkWebGPURenderWindow::vtkWGPUSwapChain
Definition: vtkWebGPURenderWindow.h:201
vtkWebGPURenderWindow::vtkWGPUSwapChain::Instance
wgpu::SwapChain Instance
Definition: vtkWebGPURenderWindow.h:202
vtkWebGPURenderWindow::vtkWGPUSwapChain::PresentMode
wgpu::PresentMode PresentMode
Definition: vtkWebGPURenderWindow.h:205
vtkWebGPURenderWindow::vtkWGPUSwapChain::Framebuffer
wgpu::TextureView Framebuffer
Definition: vtkWebGPURenderWindow.h:203
vtkWebGPURenderWindow::vtkWGPUSwapChain::TexFormat
wgpu::TextureFormat TexFormat
Definition: vtkWebGPURenderWindow.h:204
vtkWebGPURenderWindow::vtkWGPUUserStagingPixelData
Definition: vtkWebGPURenderWindow.h:230
vtkWebGPURenderWindow::vtkWGPUUserStagingPixelData::Buffer
wgpu::Buffer Buffer
Definition: vtkWebGPURenderWindow.h:234
vtkWebGPURenderWindow::vtkWGPUUserStagingPixelData::Origin
wgpu::Origin3D Origin
Definition: vtkWebGPURenderWindow.h:231
vtkWebGPURenderWindow::vtkWGPUUserStagingPixelData::Layout
wgpu::TextureDataLayout Layout
Definition: vtkWebGPURenderWindow.h:233
vtkWebGPURenderWindow::vtkWGPUUserStagingPixelData::Extent
wgpu::Extent3D Extent
Definition: vtkWebGPURenderWindow.h:232
vtkRenderWindow.h
vtk_wgpu.h