VTK  9.3.0
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
12VTK_ABI_NAMESPACE_BEGIN
13
14class VTKRENDERINGWEBGPU_EXPORT vtkWebGPURenderWindow : public vtkRenderWindow
15{
16public:
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;
78 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
80 int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
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;
91 int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
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;
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
143
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
169
170protected:
173
174 bool WGPUInit();
176
179
182
185
188
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
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 };
210
212 {
213 wgpu::Texture Texture;
214 wgpu::TextureView View;
215 wgpu::TextureFormat Format;
217 };
219
221 {
222 wgpu::Texture Texture;
223 wgpu::TextureView View;
224 wgpu::TextureFormat Format;
225 wgpu::Buffer OffscreenBuffer;
226 };
228
230 {
231 wgpu::Origin3D Origin;
232 wgpu::Extent3D Extent;
233 wgpu::TextureDataLayout Layout;
234 wgpu::Buffer Buffer; // for SetPixelData
235 };
237
239 {
240 wgpu::RenderPipeline Pipeline;
241 wgpu::BindGroup BindGroup;
242 };
244
246 {
248 wgpu::Buffer src;
249 unsigned long size;
250 } BufferMapReadContext;
251
253
254private:
256 void operator=(const vtkWebGPURenderWindow&) = delete;
257};
258
259VTK_ABI_NAMESPACE_END
260#endif
dynamic, self-adjusting array of float
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:51
virtual void Modified()
Update the modification time for this object.
create a window for renderers to draw into
Hold a reference to a vtkObjectBase instance.
dynamic, self-adjusting array of unsigned char
void DestroyDepthStencilTexture()
virtual bool Initialize()=0
Concrete render windows must create a platform window and initialize this->WindowId.
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
wgpu::TextureFormat GetDepthStencilFormat()
void End() override
Update the system, if needed, at end of render process.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
int SetZbufferData(int x1, int y1, int x2, int y2, float *buffer) override
Set/Get the zbuffer data from an image.
void ReadPixels()
Reads pixels into the CachedPixelBytes variable.
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...
wgpu::CommandEncoder GetCommandEncoder()
void CreateOffscreenColorAttachments()
vtkWGPUColorAttachment ColorAttachment
const char * ReportCapabilities() override
Get report of capabilities for the render window.
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... front in this context indicates that the...
virtual void CreateAWindow()=0
Create a not-off-screen window.
void SetPowerPreference(bool high=true)
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...
void ReleaseRGBAPixelData(float *data) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
void DestroyOffscreenColorAttachments()
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... front in this context indicates that the...
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...
float * GetZbufferData(int x1, int y1, int x2, int y2) override
Set/Get the zbuffer data from an image.
void DestroyFSQGraphicsPipeline()
void WaitForCompletion() override
Block the thread until work queue completes all submitted work.
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... front in this context indicates that the...
wgpu::CommandEncoder CommandEncoder
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
bool InitializeFromCurrentContext() override
Initialize the render window from the information associated with the currently activated OpenGL cont...
wgpu::TextureView GetDepthStencilView()
int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
void Render() override
Handle opengl specific code and calls superclass.
wgpu::TextureFormat GetPreferredSwapChainTextureFormat()
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...
vtkNew< vtkTypeUInt8Array > CachedPixelBytes
wgpu::RenderBundleEncoder NewRenderBundleEncoder(wgpu::RenderBundleEncoderDescriptor &descriptor)
void FlushCommandBuffers(vtkTypeUInt32 count, wgpu::CommandBuffer *buffers)
void Start() override
Start the rendering process for a frame.
const char * GetRenderingBackend() override
What rendering backend has the user requested.
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
wgpu::RenderPassEncoder NewRenderPass(wgpu::RenderPassDescriptor &descriptor)
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...
void CreateFSQGraphicsPipeline()
~vtkWebGPURenderWindow() override
void CreateDepthStencilTexture()
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
Set/Get the zbuffer data from an image.
wgpu::TextureView GetOffscreenColorAttachmentView()
vtkWGPUUserStagingPixelData StagingPixelData
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...
vtkWGPUFullScreenQuad FSQ
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkWGPUDeptStencil DepthStencil
int GetColorBufferSizes(int *rgba) override
Get the size of the color buffer.
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...
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... front in this context indicates that the...
window superclass for vtkRenderWindow
Definition vtkWindow.h:25
vtkSmartPointer< vtkTypeUInt8Array > dst