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, uint32_t 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 WGPUDevice device = {};
34 WGPUSurface surface = {};
35 WGPUSwapChain swapChain = {};
36
37 WGPUTexture colorBufferTexture = {};
38 WGPUTextureView colorBufferView = {};
39
40 WGPUTexture depthBufferTexture = {};
41 WGPUTextureView depthBufferView = {};
42
43#ifndef EMSCRIPTEN
44 WGPUTexture resolveTexture = {};
45#endif
46 WGPUTextureView resolveView = {};
47
48 int set_width = 1920;
49 int set_height = 1080;
50 int samples = 4;
51 bool resize = false;
52
53#ifdef EMSCRIPTEN
54 WGPUTextureFormat swap_chain_format = WGPUTextureFormat_BGRA8Unorm;
55 WGPUTextureFormat color_format = WGPUTextureFormat_BGRA8Unorm;
56 WGPUTextureFormat depth_format = WGPUTextureFormat_Depth32Float;
57#else
58 WGPUTextureFormat swap_chain_format = WGPUTextureFormat_BGRA8Unorm;
59 WGPUTextureFormat color_format = WGPUTextureFormat_BGRA8UnormSrgb;
60 WGPUTextureFormat depth_format = WGPUTextureFormat_Depth32Float;
61#endif
62 };
63}
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 void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None) override
Signal the end of a frame to the graphics device.
virtual int getSamples() const override
Returns the number of samples this swap chain has.
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
@ None
No flags.
Definition: Common.h:177