HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
A2B10G10R10UNormPack32.hpp
1// Copyright 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Foundation/vec.hpp"
7#include <algorithm>
8
9namespace tt {
10
11[[nodiscard]] constexpr uint32_t make_A2B10G10R10UNormPack32_value(vec const &rhs) noexcept
12{
13 ttlet r = static_cast<uint32_t>(std::clamp(rhs.r, 0.0f, 1.0f) * 1023.0f);
14 ttlet g = static_cast<uint32_t>(std::clamp(rhs.g, 0.0f, 1.0f) * 1023.0f);
15 ttlet b = static_cast<uint32_t>(std::clamp(rhs.b, 0.0f, 1.0f) * 1023.0f);
16 ttlet a = static_cast<uint32_t>(std::clamp(rhs.a, 0.0f, 1.0f) * 3.0f);
17 return (a << 30) | (b << 20) | (g << 10) | r;
18}
19
21 uint32_t value;
22
23 A2B10G10R10UNormPack32() = default;
24 A2B10G10R10UNormPack32(A2B10G10R10UNormPack32 const &rhs) noexcept = default;
25 A2B10G10R10UNormPack32(A2B10G10R10UNormPack32 &&rhs) noexcept = default;
26 A2B10G10R10UNormPack32 &operator=(A2B10G10R10UNormPack32 const &rhs) noexcept = default;
27 A2B10G10R10UNormPack32 &operator=(A2B10G10R10UNormPack32 &&rhs) noexcept = default;
28 ~A2B10G10R10UNormPack32() = default;
29
30 explicit A2B10G10R10UNormPack32(vec const &rhs) noexcept :
31 value(make_A2B10G10R10UNormPack32_value(rhs)) {}
32
33 A2B10G10R10UNormPack32 &operator=(vec const &rhs) noexcept {
34 value = make_A2B10G10R10UNormPack32_value(rhs);
35 return *this;
36 }
37
38 explicit operator vec () const noexcept {
39 return vec{
40 static_cast<float>((value >> 20) & 0x3ff) / 1023.0f,
41 static_cast<float>((value >> 10) & 0x3ff) / 1023.0f,
42 static_cast<float>(value & 0x3ff) / 1023.0f,
43 static_cast<float>(value >> 30) / 3.0f
44 };
45 }
46};
47
48}
Definition A2B10G10R10UNormPack32.hpp:20
A 4D vector.
Definition vec.hpp:37