KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_projection.cpp
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
#include <
rhi/rhi_projection.h
>
21
22
23
bool
RhiBackendNeedsYFlip
(
RHI_BACKEND
backend )
24
{
25
// Vulkan and Metal present to top-down framebuffers, so GAL's OpenGL Y-up clip space
26
// must be flipped to land right-side up on screen
27
return
backend ==
RHI_BACKEND::VULKAN
|| backend ==
RHI_BACKEND::METAL
;
28
}
29
30
31
void
RhiAdjustProjectionForBackend
(
float
* m,
RHI_BACKEND
backend )
32
{
33
if
( !m )
34
return
;
35
36
if
( backend ==
RHI_BACKEND::NONE
)
37
return
;
38
39
// Column-major layout, m[col*4 + row]
40
if
(
RhiBackendNeedsYFlip
( backend ) )
41
{
42
m[1] = -m[1];
43
m[5] = -m[5];
44
m[9] = -m[9];
45
m[13] = -m[13];
46
}
47
48
// Remap Z from [-1,1] to [0,1]
49
for
(
int
col = 0; col < 4; col++ )
50
{
51
int
idx2 = col * 4 + 2;
52
int
idx3 = col * 4 + 3;
53
m[idx2] = 0.5f * m[idx2] + 0.5f * m[idx3];
54
}
55
}
RhiBackendNeedsYFlip
bool RhiBackendNeedsYFlip(RHI_BACKEND backend)
Definition
rhi_projection.cpp:23
RhiAdjustProjectionForBackend
void RhiAdjustProjectionForBackend(float *m, RHI_BACKEND backend)
Convert a column-major OpenGL projection, with NDC Z in [-1, 1] and Y up, in place to the backend's c...
Definition
rhi_projection.cpp:31
rhi_projection.h
RHI_BACKEND
RHI_BACKEND
Identifies which graphics backend a device implements.
Definition
rhi_types.h:28
RHI_BACKEND::METAL
@ METAL
Definition
rhi_types.h:31
RHI_BACKEND::NONE
@ NONE
Definition
rhi_types.h:29
RHI_BACKEND::VULKAN
@ VULKAN
Definition
rhi_types.h:30
src
common
rhi
rhi_projection.cpp
Generated on Thu Oct 22 2026 00:06:34 for KiCad PCB EDA Suite by
1.13.2