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
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
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}
bool RhiBackendNeedsYFlip(RHI_BACKEND backend)
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...
RHI_BACKEND
Identifies which graphics backend a device implements.
Definition rhi_types.h:28