KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_supersample.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_SUPERSAMPLE_H
21#define RHI_SUPERSAMPLE_H
22
23#include <rhi/frame_packet.h>
24
25#include <algorithm>
26#include <cstdint>
27
35
36namespace KIGFX
37{
38
40constexpr float RHI_SUPERSAMPLE_OFFSET = 0.5f;
41
42
44inline FRAME_UBO_DATA RhiSupersampleFrame( const FRAME_UBO_DATA& aFrame, uint32_t aFactor )
45{
46 FRAME_UBO_DATA frame = aFrame;
47
48 frame.renderScale = static_cast<float>( std::max( aFactor, 1u ) );
49
50 if( aFactor <= 1 || aFrame.viewport[0] <= 0.0f || aFrame.viewport[1] <= 0.0f )
51 return frame;
52
53 const float dx = 2.0f * RHI_SUPERSAMPLE_OFFSET / aFrame.viewport[0];
54 const float dy = 2.0f * RHI_SUPERSAMPLE_OFFSET / aFrame.viewport[1];
55
57 for( int col = 0; col < 4; ++col )
58 {
59 frame.projection[col * 4] += dx * aFrame.projection[col * 4 + 3];
60 frame.projection[col * 4 + 1] += dy * aFrame.projection[col * 4 + 3];
61 }
62
63 return frame;
64}
65
66
68inline GRID_UBO_DATA RhiSupersampleGrid( const GRID_UBO_DATA& aGrid, uint32_t aFactor )
69{
70 GRID_UBO_DATA grid = aGrid;
71
72 grid.renderScale = static_cast<float>( std::max( aFactor, 1u ) );
73
74 if( aFactor <= 1 || aGrid.viewport[0] <= 0.0f || aGrid.viewport[1] <= 0.0f )
75 return grid;
76
77 const float dx = 2.0f * RHI_SUPERSAMPLE_OFFSET / aGrid.viewport[0];
78 const float dy = 2.0f * RHI_SUPERSAMPLE_OFFSET / aGrid.viewport[1];
79
81 for( int row = 0; row < 4; ++row )
82 grid.invProjection[12 + row] -= dx * aGrid.invProjection[row] + dy * aGrid.invProjection[4 + row];
83
84 return grid;
85}
86
87} // namespace KIGFX
88
89#endif // RHI_SUPERSAMPLE_H
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
GRID_UBO_DATA RhiSupersampleGrid(const GRID_UBO_DATA &aGrid, uint32_t aFactor)
constexpr float RHI_SUPERSAMPLE_OFFSET
Offset of a supersampled target from where its frame puts the scene, in pixels.
FRAME_UBO_DATA RhiSupersampleFrame(const FRAME_UBO_DATA &aFrame, uint32_t aFactor)
Per-frame uniform block matching FrameUBO in frame_ubo.glsl (std140).
float projection[16]
column-major for GLSL
float renderScale
target texels per viewport pixel, above 1 in a supersampled target
Grid uniform block matching the GridUBO layout in grid.frag (std140).