Cogs.Core
RenderTargetsWebGPU.h
1#pragma once
2
3#include "CommonWebGPU.h"
4
5#include "../IRenderTargets.h"
6#include "../Base/ResourceMap.h"
7
8namespace Cogs {
9 class GraphicsDeviceWebGPU;
10
12 WGPUTextureView view[8] = {};
13 TextureHandle textureHandle[8] = {};
14 WGPUTextureFormat format[8] = { WGPUTextureFormat_Undefined };
15 uint32_t count = 0;
16
17 uint32_t width = 0;
18 uint32_t height = 0;
19 uint32_t samples = 0;
20 };
22 WGPUTextureView view = {};
23 TextureHandle textureHandle = {};
24 uint32_t samples = 0;
25 WGPUTextureFormat format = WGPUTextureFormat_Undefined;
26 };
27
29 public:
30 void initialize(GraphicsDeviceWebGPU *graphicsDevice);
31
32 virtual void annotate(RenderTargetHandle /*handle*/, const StringView& /*name*/) override {}
33 virtual void annotate(DepthStencilHandle /*handle*/, const StringView& /*name*/) override {}
34
35 virtual RenderTargetHandle createRenderTarget(const RenderTargetViewDescription* renderTargetViews, const size_t numViews) override;
36 virtual void releaseRenderTarget(RenderTargetHandle handle) override;
37
39 virtual DepthStencilHandle createDepthStencilTarget(const RenderTargetHandle handle, const TextureHandle textureHandle) override;
40 virtual DepthStencilHandle createDepthStencilTarget(const RenderTargetHandle handle, const DepthStencilViewDescription& depthStencilView) override;
41 virtual void releaseDepthStencilTarget(DepthStencilHandle handle) override;
42
43 virtual DepthStencilStateHandle loadDepthStencilState(const DepthStencilState& depthStencilState) override {
44 return DepthStencilStateHandle(reinterpret_cast<int64_t>(new DepthStencilState(depthStencilState)));
45 }
46 virtual void releaseDepthStencilState(DepthStencilStateHandle depthStencilStateHandle) override {
47 delete reinterpret_cast<DepthStencilState*>(depthStencilStateHandle.handle);
48 }
49 virtual RasterizerStateHandle loadRasterizerState(const RasterizerState& rasterizerState) override {
50 return RasterizerStateHandle(reinterpret_cast<int64_t>(new RasterizerState(rasterizerState)));
51 }
52 virtual void releaseRasterizerState(RasterizerStateHandle rasterizerStateHandle) override {
53 delete reinterpret_cast<RasterizerState*>(rasterizerStateHandle.handle);
54 }
55 virtual BlendStateHandle loadBlendState(const BlendState& blendState) override {
56 return loadBlendState(blendState, blendState);
57 }
58 virtual BlendStateHandle loadBlendState(const BlendState& color, const BlendState& alpha) override {
59 return BlendStateHandle(reinterpret_cast<int64_t>(new BlendState[2] {color, alpha}));
60 }
61 virtual void releaseBlendState(BlendStateHandle blendStateHandle) override {
62 delete [] reinterpret_cast<BlendState*>(blendStateHandle.handle);
63 }
64
65 virtual void releaseResources() override {}
66
67 GraphicsDeviceWebGPU *graphicsDevice = nullptr;
68
71 };
72}
virtual void releaseRenderTarget(RenderTargetHandle handle) override
Release the render target with the given renderTargetHandle.
virtual void releaseResources() override
Release all allocated render target resources.
virtual DepthStencilHandle createDepthStencilTarget(const RenderTargetHandle handle) override
Creates a depth/stencil target to back the render target with the given handle.
virtual void releaseDepthStencilState(DepthStencilStateHandle depthStencilStateHandle) override
Release the depth stencil state with the given handle.
virtual DepthStencilStateHandle loadDepthStencilState(const DepthStencilState &depthStencilState) override
Load a depth stencil state object.
virtual BlendStateHandle loadBlendState(const BlendState &blendState) override
Load a blend state object.
virtual void releaseRasterizerState(RasterizerStateHandle rasterizerStateHandle) override
Release the rasterizer state with the given handle.
virtual RasterizerStateHandle loadRasterizerState(const RasterizerState &rasterizerState) override
Load a rasterizer state object.
virtual void releaseBlendState(BlendStateHandle blendStateHandle) override
Release the blend state with the given handle.
virtual BlendStateHandle loadBlendState(const BlendState &color, const BlendState &alpha) override
Load a blend state object with separate blending for alpha channel.
virtual void releaseDepthStencilTarget(DepthStencilHandle handle) override
Release the depth target with the given depthStencilHandle.
virtual void annotate(RenderTargetHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
virtual void annotate(DepthStencilHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
virtual RenderTargetHandle createRenderTarget(const RenderTargetViewDescription *renderTargetViews, const size_t numViews) override
Create a render target using the given view descriptions.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Encapsulates blend state for the graphics pipeline in a state object.
Definition: BlendState.h:9
Encapsulates state for depth buffer usage and stencil buffer usage in a state object.
Describes a single depth stencil view and which resources to use from the underlying texture.
handle_type handle
Internal resource handle.
Definition: Common.h:74
Provides render target management functionality.
Encapsulates state for primitive rasterization in a state object.
Describes a single render target view and which resources to use from the underlying texture.