Cogs.Core
SwapChainWebGPU.h
1#pragma once
2
3#include "CommonWebGPU.h"
4
5#include "../ISwapChain.h"
6
7namespace Cogs {
8 class SwapChainWebGPU : public ISwapChain {
9 public:
12
13 void initialize(WGPUDevice device, WGPUSurface surface);
14 void destroy();
15
16 void create();
17
18 virtual void beginFrame() override;
19 virtual void endFrame(uint32_t syncInterval = 0, PresentFlags presentFlags = PresentFlags::None) override;
20
21 virtual void setSize(int newWidth, int newHeight, bool forceIt = false) override;
22 virtual void setFullscreen(bool enabled) override;
23
24 virtual bool isFullscreen() override;
25
26 virtual int getWidth() const override { return set_width; }
27 virtual int getHeight() const override { return set_height; }
28 virtual int getSamples() const override { return samples; }
29
30 virtual const RenderTargetHandle& getRenderTarget() const;
31 virtual const DepthStencilHandle& getDepthStencil() const;
32
33 WGPUSurfaceTexture getTextureData();
34
35 WGPUDevice device = {};
36 WGPUSurface surface = {};
37
38 WGPUTexture colorBufferTexture = {};
39 WGPUTextureView colorBufferView = {};
40
41 WGPUTexture depthBufferTexture = {};
42 WGPUTextureView depthBufferView = {};
43
44#ifndef EMSCRIPTEN
45 WGPUTexture resolveTexture = {};
46#endif
47 WGPUTextureView resolveView = {};
48
49 int set_width = 1920;
50 int set_height = 1080;
51 int samples = 4;
52 bool resize = false;
53
54 WGPUTextureFormat swap_chain_format = WGPUTextureFormat_BGRA8Unorm;
55 WGPUTextureFormat color_format = WGPUTextureFormat_BGRA8UnormSrgb;
56 WGPUTextureFormat depth_format = WGPUTextureFormat_Depth32Float;
57 };
58}
virtual bool isFullscreen() override
Test whether the current swap chain is fullscreen.
virtual const DepthStencilHandle & getDepthStencil() const
Returns the depth stencil managed by this swap chain.
virtual void beginFrame() override
Signal the beginning of a new frame to the graphics device.
virtual int getWidth() const override
Returns the pixel width of this swap chain.
virtual void setFullscreen(bool enabled) override
Switch this swap chain to fullscreen or windowed depending on the parameter.
virtual int getHeight() const override
Returns the pixel height of this swap chain.
virtual int getSamples() const override
Returns the number of samples this swap chain has.
virtual void endFrame(uint32_t syncInterval=0, PresentFlags presentFlags=PresentFlags::None) override
Signal the end of a frame to the graphics device.
virtual const RenderTargetHandle & getRenderTarget() const
Returns the render target managed by this swap chain.
virtual void setSize(int newWidth, int newHeight, bool forceIt=false) override
Set the size of the main drawing buffer used by the graphics device in pixels.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
PresentFlags
Flags controlling presentation.
Definition: Common.h:166