GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 5
100.0%
Branches:
2 / 2
100.0%
Functions:
1 / 1
100.0%

util/glm.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file glm.h
3 /// @brief glm as Ernie's public headers use it, with its layout checked.
4 ///
5 /// Public headers include glm through here. A consumer may build with its own glm, but libernie was
6 /// built with these layouts: a glm configured otherwise (`GLM_FORCE_DEFAULT_ALIGNED_GENTYPES`, say)
7 /// fails here instead of corrupting values across the library boundary.
8 #pragma once
9
10 #include <glm/glm.hpp>
11
12 #include <array>
13 #include <cstddef>
14
15 static_assert(sizeof(glm::vec2) == 8 && sizeof(glm::vec3) == 12 && sizeof(glm::vec4) == 16,
16 "Ernie needs glm's packed float vectors");
17 static_assert(sizeof(glm::dvec2) == 16 && sizeof(glm::dvec3) == 24 && sizeof(glm::dvec4) == 32,
18 "Ernie needs glm's packed double vectors");
19 static_assert(sizeof(glm::uvec2) == 8 && sizeof(glm::ivec3) == 12,
20 "Ernie needs glm's packed integer vectors");
21 static_assert(sizeof(glm::mat4) == 64 && sizeof(glm::dmat4) == 128 && sizeof(glm::dmat3) == 72,
22 "Ernie needs glm's packed matrices");
23
24 namespace ernie {
25
26 /// @return An affine transform's top three rows in float, as GPUs read 3x4 transforms.
27 49 inline std::array<glm::vec4, 3> ToAffineRows(const glm::dmat4& m) {
28 49 std::array<glm::vec4, 3> rows{};
29
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 49 times.
196 for (int r = 0; r < 3; ++r) {
30 147 rows[static_cast<std::size_t>(r)] = glm::vec4(m[0][r], m[1][r], m[2][r], m[3][r]);
31 }
32 49 return rows;
33 }
34
35 } // namespace ernie
36