KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_compositor.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef RHI_COMPOSITOR_H
21#define RHI_COMPOSITOR_H
22
23#include <rhi/rhi_bind_group.h>
24#include <rhi/rhi_handle.h>
25
26#include <cstdint>
27#include <functional>
28#include <unordered_map>
29#include <vector>
30
31
32class RHI_DEVICE;
33
34
40{
42 float alpha = 1.0f;
43 float uvScale[2] = { 1.0f, 1.0f };
44 float uvOffset[2] = { 0.0f, 0.0f };
45};
46
47
52{
53 float alpha = 1.0f;
54 float _pad0 = 0.0f;
55 float uvScale[2] = { 1.0f, 1.0f };
56 float uvOffset[2] = { 0.0f, 0.0f };
57};
58
59
65{
66public:
67 RHI_COMPOSITOR( RHI_DEVICE& aDevice );
69
76 bool Initialize( RHI_BindGroupLayoutHandle aSingleTexLayout = {} );
77
81 void Destroy();
82
87
96 RHI_FramebufferHandle Composite( RHI_FramebufferHandle aAccumulationFBO, uint32_t aWidth, uint32_t aHeight,
97 const std::vector<COMPOSITOR_LAYER>& aLayers,
98 const float* aBackgroundColor = nullptr,
99 const std::function<void()>& aDrawOnTop = {} );
100
103
104 bool IsInitialized() const { return m_initialized; }
105
111
112private:
113 void compositeLayer( const COMPOSITOR_LAYER& aLayer );
114
117 uint32_t aGroupIndex );
118
120
125
127
128 bool m_initialized = false;
129
134 std::unordered_map<uint64_t, RHI_BindGroupHandle> m_fboBindGroups;
135
137};
138
139
140#endif // RHI_COMPOSITOR_H
RHI_BindGroupHandle bindFBOTexture(RHI_FramebufferHandle aFBO, RHI_BindGroupLayoutHandle aLayout, uint32_t aGroupIndex)
RHI_PipelineHandle m_compositorPipeline
RHI_BindGroupLayoutHandle m_singleTexLayout
bool IsInitialized() const
RHI_DEVICE & m_device
RHI_COMPOSITOR(RHI_DEVICE &aDevice)
void SetCompositorPipeline(RHI_PipelineHandle aPipeline)
Set the pipeline that draws each layer as an alpha-blended fullscreen quad.
std::unordered_map< uint64_t, RHI_BindGroupHandle > m_fboBindGroups
Bind groups over FBO color textures, keyed by texture and layout handles.
RHI_BufferHandle m_quadVB
bool Initialize(RHI_BindGroupLayoutHandle aSingleTexLayout={})
Create the clear pass and fullscreen quad.
RHI_BufferHandle GetQuadVB() const
void Destroy()
Release all GPU resources.
RHI_BindGroupLayoutHandle GetSingleTexLayout() const
void InvalidateCachedBindGroups()
Drop the cached bind groups over layer FBO textures.
RHI_FramebufferHandle Composite(RHI_FramebufferHandle aAccumulationFBO, uint32_t aWidth, uint32_t aHeight, const std::vector< COMPOSITOR_LAYER > &aLayers, const float *aBackgroundColor=nullptr, const std::function< void()> &aDrawOnTop={})
Blend aLayers back-to-front into aAccumulationFBO, which is cleared to aBackgroundColor first.
void compositeLayer(const COMPOSITOR_LAYER &aLayer)
RHI_RenderPassHandle m_clearRenderPass
Creates, uses and destroys GPU resources through one graphics API backend.
Definition rhi_device.h:66
RHI_HANDLE< RHI_TAG_FRAMEBUFFER > RHI_FramebufferHandle
Definition rhi_handle.h:93
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
Definition rhi_handle.h:83
RHI_HANDLE< RHI_TAG_PIPELINE > RHI_PipelineHandle
Definition rhi_handle.h:86
RHI_HANDLE< RHI_TAG_BIND_GROUP > RHI_BindGroupHandle
Definition rhi_handle.h:90
RHI_HANDLE< RHI_TAG_BIND_GROUP_LAYOUT > RHI_BindGroupLayoutHandle
Definition rhi_handle.h:89
RHI_HANDLE< RHI_TAG_RENDER_PASS > RHI_RenderPassHandle
Definition rhi_handle.h:88
One layer to composite.
RHI_FramebufferHandle fbo
Matches the PushConstants block of the compositor shader.