19#ifndef vtkWebGPURenderWindow_h
20#define vtkWebGPURenderWindow_h
24#include "vtkRenderingWebGPUModule.h"
33VTK_ABI_NAMESPACE_BEGIN
38class vtkWebGPUTextureCache;
40class vtkTypeUInt32Array;
128 unsigned char*
GetPixelData(
int x,
int y,
int x2,
int y2,
int front,
int right)
override;
132 int x,
int y,
int x2,
int y2,
unsigned char* data,
int front,
int right)
override;
143 int x,
int y,
int x2,
int y2,
int front,
vtkFloatArray* data,
int right = 0)
override;
145 int x,
int y,
int x2,
int y2,
float* data,
int front,
int blend = 0,
int right = 0)
override;
147 int right = 0)
override;
150 int x,
int y,
int x2,
int y2,
int front,
int right = 0)
override;
154 int blend = 0,
int right = 0)
override;
156 int blend = 0,
int right = 0)
override;
176 void GetIdsData(
int x1,
int y1,
int x2,
int y2, vtkTypeUInt32Array* data);
254 wgpu::RenderPassEncoder
NewRenderPass(wgpu::RenderPassDescriptor& descriptor);
334 std::function<
void(const
void* mappedData,
int bytesPerRow,
void* userdata)>;
401 void InitializeRendererComputePipelines();
407 void SubmitCommandBuffer(
int count, wgpu::CommandBuffer* commandBuffer);
412 void PostRenderComputePipelines();
418 void PostRasterizationRender();
420 struct ComponentMapping
443 ComponentMapping GetComponentMapping(wgpu::TextureFormat format,
int desiredOutComponents);
445 template <
typename TOutput,
typename TInput>
446 struct PixelReadbackCallbackData
448 TOutput* OutputValues;
449 uint32_t Width, Height;
450 ComponentMapping Mapping;
451 std::function<TOutput(TInput)> Converter;
468 template <
typename TOutput,
typename TInput>
469 TOutput* GetTextureDataInternal(wgpu::Texture texture, wgpu::TextureFormat format,
int x1,
int y1,
470 int x2,
int y2,
const ComponentMapping& componentMapping,
471 std::function<TOutput(TInput)> converter =
nullptr);
478 std::uint32_t FlipY(std::uint32_t y);
489 void ReadTextureFromGPU(wgpu::Texture& wgpuTexture, wgpu::TextureFormat format,
490 std::size_t mipLevel, wgpu::TextureAspect aspect, wgpu::Origin3D offsets,
491 wgpu::Extent3D extents, TextureMapCallback callback,
void* userData);
498 void ReadTextureFromGPU(wgpu::Texture& wgpuTexture, wgpu::TextureFormat format,
499 std::size_t mipLevel, wgpu::TextureAspect aspect, TextureMapCallback callback,
void* userData);
522 void CreateSurface();
523 wgpu::Surface CreateSurfaceFromHardwareWindow(wgpu::Instance instance);
528 void ConfigureSurface();
535 void UnconfigureSurface();
543 void CreateOffscreenColorAttachment();
544 void DestroyOffscreenColorAttachment();
553 void CreateIdsAttachment();
554 void DestroyIdsAttachment();
563 void CreateDepthStencilAttachment();
564 void DestroyDepthStencilAttachment();
572 void CreateColorCopyPipeline();
573 void DestroyColorCopyPipeline();
581 void RecreateComputeRenderTextures();
589 void RenderOffscreenTexture();
595 virtual void SyncWithHardware();
597 bool RenderTexturesSetup =
false;
599 wgpu::Surface Surface;
600 wgpu::CommandEncoder CommandEncoder;
601 int SurfaceConfiguredSize[2];
602 wgpu::TextureFormat PreferredSurfaceTextureFormat = wgpu::TextureFormat::BGRA8Unorm;
603 wgpu::TextureFormat PreferredSelectorIdsTextureFormat = wgpu::TextureFormat::RGBA32Uint;
604 struct vtkWGPUDepthStencil
606 wgpu::Texture Texture;
607 wgpu::TextureView View;
608 wgpu::TextureFormat Format;
611 vtkWGPUDepthStencil DepthStencilAttachment;
613 struct vtkWGPUAttachment
615 wgpu::Texture Texture;
616 wgpu::TextureView View;
617 wgpu::TextureFormat Format;
619 vtkWGPUAttachment ColorAttachment;
620 vtkWGPUAttachment IdsAttachment;
622 struct vtkWGPUUserStagingPixelData
624 wgpu::Origin3D Origin;
625 wgpu::Extent3D Extent;
626 wgpu::TexelCopyBufferLayout Layout;
629 vtkWGPUUserStagingPixelData StagingPixelData;
631 struct vtkWGPUFullScreenQuad
634 wgpu::BindGroup BindGroup;
636 vtkWGPUFullScreenQuad ColorCopyRenderPipeline;
638 vtkSmartPointer<vtkWebGPUConfiguration> WGPUConfiguration;
639 vtkNew<vtkWebGPUShaderDatabase> WGPUShaderDatabase;
640 vtkNew<vtkWebGPURenderPipelineCache> WGPUPipelineCache;
641 vtkNew<vtkWebGPURenderTextureCache> WGPUTextureCache;
643 const wgpu::SurfaceDescriptor* CustomSurfaceDescriptor =
nullptr;
645 vtkSmartPointer<vtkWebGPUComputePipeline> DepthCopyPipeline;
646 vtkSmartPointer<vtkWebGPUComputePass> DepthCopyPass;
647 int DepthCopyBufferIndex = 0;
648 int DepthCopyTextureIndex = 0;
655 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderTexture>> ComputeRenderTextures;
658#define vtkWebGPURenderWindow_OVERRIDE_ATTRIBUTES vtkWebGPURenderWindow::CreateOverrideAttributes()
dynamic, self-adjusting array of float
topologically and geometrically regular array of data
a simple class to control print indentation
Attribute for vtkObjectFactory overrides.
platform-independent render window interaction including picking and frame rate control.
Hold a reference to a vtkObjectBase instance.
dynamic, self-adjusting array of unsigned char
This culler does both frustum culling and occlusion culling.
Render textures are returned by calls to vtkWebGPUPolyDataMapper::AcquireXXXXRenderTexture() and repr...
Create a webgpu device for use in rendering and compute pipelines.
Class to create and retrieve render pipelines based on a given key.
Class to create and retrieve render Textures based on a given key.
static vtkOverrideAttribute * CreateOverrideAttributes()
virtual void DestroyWindow()
Destroy a not-off-screen window.
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::TextureFormat GetPreferredSurfaceTextureFormat()
Get the texture format preferred for the surface.
wgpu::TextureFormat GetPreferredSelectorIdsTextureFormat()
Get the texture format preferred for selector IDs.
wgpu::TextureFormat GetDepthStencilFormat()
Get the texture format of the depth-stencil attachment.
bool EnsureDisplay() override
Ensure RenderWindow's display is opened.
std::string PreprocessShaderSource(const std::string &source) const
Replaces all include statements in the given source code with source code corresponding to the includ...
void End() override
Update the system, if needed, at end of render process.
vtkSmartPointer< vtkImageData > SaveAttachmentToVTI(AttachmentTypeForVTISnapshot type)
int SupportsOpenGL() override
Does this render window support OpenGL?
int SetZbufferData(int x1, int y1, int x2, int y2, float *buffer) override
Set/Get the zbuffer data from an image.
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.
vtkTypeUInt32 * GetIdsData(int x1, int y1, int x2, int y2)
Get the Ids data from the last render.
void SetInteractor(vtkRenderWindowInteractor *) override
Set the interactor for the window.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
wgpu::Adapter GetAdapter()
Get the webgpu adapter.
void Finalize() override
Call DestroyWindow.
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...
friend class vtkWebGPUComputeOcclusionCuller
wgpu::TextureView GetHardwareSelectorAttachmentView()
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.
static vtkWebGPURenderWindow * New()
Instantiate the class.
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 * GetGenericDisplayId() override
Get the generic display id for the window.
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.
VTK_MAYSUSPEND void SetWGPUConfiguration(vtkWebGPUConfiguration *config)
Set/Get the webgpu configuration instance.
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...
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...
vtkGetNewMacro(WGPUShaderDatabase, vtkWebGPUShaderDatabase)
Get a database of all WebGPU shader source codes in VTK.
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.
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...
wgpu::RenderBundleEncoder NewRenderBundleEncoder(wgpu::RenderBundleEncoderDescriptor &descriptor)
Create a new render bundle encoder on the webgpu device.
void SetCustomSurfaceDescriptor(const wgpu::SurfaceDescriptor *descriptor)
Set/Get a custom surface descriptor to use when creating the WebGPU surface.
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...
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...
AttachmentTypeForVTISnapshot
std::function< void(const void *mappedData, int bytesPerRow, void *userdata)> TextureMapCallback
VTK_MAYSUSPEND void GetIdsData(int x1, int y1, int x2, int y2, vtkTypeUInt32Array *data)
Get the Ids data from the last render.
void * GetGenericContext() override
Get the generic context pointer.
const wgpu::SurfaceDescriptor * GetCustomSurfaceDescriptor() const
Set/Get a custom surface descriptor to use when creating the WebGPU surface.
virtual std::string MakeDefaultWindowNameWithBackend()
Construct the window title as "Visualization Toolkit - <WindowSystem> <GraphicsBackend>" Ex: "Visuali...
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.
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...
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
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...
virtual void CreateAWindow()
Create a not-off-screen window.
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...
Class to add and retrieve source code for shader files for a specified key.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
@ Valid
Cell is in a good state.
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALEXCLUDE(reason)