HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
unorm_a2bgr10_pack.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "numeric_array.hpp"
8#include <algorithm>
9
10namespace hi::inline v1 {
11
12[[nodiscard]] constexpr uint32_t make_unorm_a2bgr10_pack_value(f32x4 const &rhs) noexcept
13{
14 hilet r = static_cast<uint32_t>(std::clamp(rhs.r, 0.0f, 1.0f) * 1023.0f);
15 hilet g = static_cast<uint32_t>(std::clamp(rhs.g, 0.0f, 1.0f) * 1023.0f);
16 hilet b = static_cast<uint32_t>(std::clamp(rhs.b, 0.0f, 1.0f) * 1023.0f);
17 hilet a = static_cast<uint32_t>(std::clamp(rhs.a, 0.0f, 1.0f) * 3.0f);
18 return (a << 30) | (b << 20) | (g << 10) | r;
19}
20
22 uint32_t value;
23
24 unorm_a2bgr10_pack() = default;
25 unorm_a2bgr10_pack(unorm_a2bgr10_pack const &rhs) noexcept = default;
26 unorm_a2bgr10_pack(unorm_a2bgr10_pack &&rhs) noexcept = default;
27 unorm_a2bgr10_pack &operator=(unorm_a2bgr10_pack const &rhs) noexcept = default;
28 unorm_a2bgr10_pack &operator=(unorm_a2bgr10_pack &&rhs) noexcept = default;
29 ~unorm_a2bgr10_pack() = default;
30
31 explicit unorm_a2bgr10_pack(f32x4 const &rhs) noexcept : value(make_unorm_a2bgr10_pack_value(rhs)) {}
32
33 unorm_a2bgr10_pack &operator=(f32x4 const &rhs) noexcept
34 {
35 value = make_unorm_a2bgr10_pack_value(rhs);
36 return *this;
37 }
38
39 explicit operator f32x4() const noexcept
40 {
41 return f32x4{
42 static_cast<float>((value >> 20) & 0x3ff) / 1023.0f,
43 static_cast<float>((value >> 10) & 0x3ff) / 1023.0f,
44 static_cast<float>(value & 0x3ff) / 1023.0f,
45 static_cast<float>(value >> 30) / 3.0f};
46 }
47};
48
49} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
Definition unorm_a2bgr10_pack.hpp:21