VTK  9.4.20241103
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 "vtkWebGPUComputePipeline.h" // for the compute pipelines of this render window
11#include "vtkWebGPUComputeRenderTexture.h" // for compute render textures
12#include "vtk_wgpu.h" // for webgpu
13
14VTK_ABI_NAMESPACE_BEGIN
15
18
19class VTKRENDERINGWEBGPU_EXPORT vtkWebGPURenderWindow : public vtkRenderWindow
20{
21public:
23 void PrintSelf(ostream& os, vtkIndent indent) override;
24
29 virtual bool WindowSetup() = 0;
30
34 virtual void CreateAWindow() = 0;
35
39 virtual void DestroyWindow() = 0;
40
53 void Initialize() override;
54
55 void Start() override;
56
60 void End() override;
61
65 void Render() override;
66
71 void StereoMidpoint() override;
72 void Frame() override;
73
74 const char* GetRenderingBackend() override;
75
79 void ReadPixels();
80
82
87 unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
89 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
91 int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
93 int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
95
97
100 float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
102 int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
104 int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
105 int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
106 int right = 0) override;
107 void ReleaseRGBAPixelData(float* data) override;
108 unsigned char* GetRGBACharPixelData(
109 int x, int y, int x2, int y2, int front, int right = 0) override;
111 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
112 int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
113 int blend = 0, int right = 0) override;
114 int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
115 int blend = 0, int right = 0) override;
117
119
122 float* GetZbufferData(int x1, int y1, int x2, int y2) override;
123 int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
124 int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
125 int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
126 int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
128
133 int GetColorBufferSizes(int* rgba) override;
137 void WaitForCompletion() override;
138
142 int SupportsOpenGL() override;
143
147 const char* ReportCapabilities() override;
148
154
160
163
167 wgpu::RenderPassEncoder NewRenderPass(wgpu::RenderPassDescriptor& descriptor);
168
173 wgpu::RenderBundleEncoder NewRenderBundleEncoder(wgpu::RenderBundleEncoderDescriptor& descriptor);
174
179 wgpu::CommandEncoder GetCommandEncoder();
180
185
189 void FlushCommandBuffers(vtkTypeUInt32 count, wgpu::CommandBuffer* buffers);
190
195
199 wgpu::TextureView GetDepthStencilView();
200
204 wgpu::TextureFormat GetDepthStencilFormat();
205
210
214 wgpu::Device GetDevice();
215
219 wgpu::Adapter GetAdapter();
220
225
227
237
240
244 wgpu::Buffer CreateDeviceBuffer(wgpu::BufferDescriptor& bufferDescriptor);
245
246protected:
249
258 virtual std::string MakeDefaultWindowNameWithBackend() = 0;
259
260 bool WGPUInit();
262
265
268
271
274
276
278
279 bool RenderTexturesSetup = false;
280
281 wgpu::Surface Surface;
282 wgpu::CommandEncoder CommandEncoder;
283
285 {
286 wgpu::SwapChain Instance;
287 wgpu::TextureView Framebuffer;
288 wgpu::TextureFormat TexFormat;
289 wgpu::PresentMode PresentMode;
290 int Width = 0;
291 int Height = 0;
292 };
294
296 {
297 wgpu::Texture Texture;
298 wgpu::TextureView View;
299 wgpu::TextureFormat Format;
301 };
303
305 {
306 wgpu::Texture Texture;
307 wgpu::TextureView View;
308 wgpu::TextureFormat Format;
309 wgpu::Buffer OffscreenBuffer;
310 };
312
314 {
315 wgpu::Origin3D Origin;
316 wgpu::Extent3D Extent;
317 wgpu::TextureDataLayout Layout;
318 wgpu::Buffer Buffer; // for SetPixelData
319 };
321
323 {
324 wgpu::RenderPipeline Pipeline;
325 wgpu::BindGroup BindGroup;
326 };
327
329
331 {
333 wgpu::Buffer src;
334 unsigned long size;
336 } BufferMapReadContext;
337
340
341 int ScreenSize[2];
342
343private:
344 // For accessing SubmitCommandBuffer to submit custom prop render work
346
348 void operator=(const vtkWebGPURenderWindow&) = delete;
349
354 void InitializeRendererComputePipelines();
355
360 void SubmitCommandBuffer(int count, wgpu::CommandBuffer* commandBuffer);
361
365 void PostRenderComputePipelines();
366
371 void PostRasterizationRender();
372
377 void CopyFramebufferToOffscreenBuffer();
378
379 // Render textures acquired by the user on this render window. They are kept here in case the
380 // render window is resized, in which case, we'll need to resize the render textures --> We need
381 // access to the textures
382 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderTexture>> ComputeRenderTextures;
383};
384
385VTK_ABI_NAMESPACE_END
386#endif
dynamic, self-adjusting array of float
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
create a window for renderers to draw into
Hold a reference to a vtkObjectBase instance.
dynamic, self-adjusting array of unsigned char
This culler does both frustum culling and occlusion culling.
Create a webgpu device for use in rendering and compute pipelines.
void DestroyDepthStencilTexture()
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
void CreateCommandEncoder()
Initializes a new command encoder.
wgpu::Buffer CreateDeviceBuffer(wgpu::BufferDescriptor &bufferDescriptor)
Creates a wgpu buffer with the device of this render window.
void RecreateComputeRenderTextures()
wgpu::TextureFormat GetDepthStencilFormat()
Get the texture format of the depth-stencil attachment.
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()
Get the currently used command encoder.
vtkGetSmartPointerMacro(WGPUConfiguration, vtkWebGPUConfiguration)
void SetWGPUConfiguration(vtkWebGPUConfiguration *config)
void CreateOffscreenColorAttachments()
vtkWGPUColorAttachment ColorAttachment
const char * ReportCapabilities() override
Get report of capabilities for the render window.
wgpu::Adapter GetAdapter()
Get the webgpu adapter.
bool HasStencil()
Whether the offscreen render target has stencil capabilities.
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.
vtkSmartPointer< vtkWebGPUConfiguration > WGPUConfiguration
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...
void Initialize() override
Creates the WebGPU context, swapchain, depth buffer, color attachment, ...
wgpu::TextureView GetDepthStencilView()
Get a view of the depth-stencil attachment used in the offscreen render target.
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()
Get the texture format preferred for the swapchain presentation.
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...
virtual std::string MakeDefaultWindowNameWithBackend()=0
Construct the window title as "Visualization Toolkit - <WindowSystem> <GraphicsBackend>" Ex: "Visuali...
vtkNew< vtkTypeUInt8Array > CachedPixelBytes
wgpu::RenderBundleEncoder NewRenderBundleEncoder(wgpu::RenderBundleEncoderDescriptor &descriptor)
Create a new render bundle encoder on the webgpu device.
vtkSmartPointer< vtkWebGPUComputeRenderTexture > AcquireDepthBufferRenderTexture()
Returns a vtkWebGPUComputeRenderTexture ready to be added to a compute pipeline using vtkWebGPUComput...
void FlushCommandBuffers(vtkTypeUInt32 count, wgpu::CommandBuffer *buffers)
Sends a given command buffer to the device queue.
void Start() override
Start the rendering process for a frame.
const char * GetRenderingBackend() override
What rendering backend has the user requested.
vtkSmartPointer< vtkWebGPUComputeRenderTexture > AcquireFramebufferRenderTexture()
Returns a vtkWebGPUComputeRenderTexture ready to be added to a compute pipeline using vtkWebGPUComput...
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
wgpu::RenderPassEncoder NewRenderPass(wgpu::RenderPassDescriptor &descriptor)
Create a new render pass encoder on the webgpu device.
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()
virtual bool WindowSetup()=0
Concrete render windows must create a platform window and initialize this->WindowId.
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
Set/Get the zbuffer data from an image.
wgpu::TextureView GetOffscreenColorAttachmentView()
Get a view of the color attachment used in the offscreen render target.
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.
wgpu::Device GetDevice()
Get the webgpu device.
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:48
vtkSmartPointer< vtkTypeUInt8Array > dst