37 constexpr Color() noexcept :
43 constexpr explicit Color(SDL_Color
const& sdlColor) noexcept :
49 constexpr explicit Color(VkClearColorValue
const& clearColorValue) noexcept :
50 _r(
static_cast<uint8_t
>(clearColorValue.float32[0] * 255.0f)),
51 _g(
static_cast<uint8_t
>(clearColorValue.float32[1] * 255.0f)),
52 _b(
static_cast<uint8_t
>(clearColorValue.float32[2] * 255.0f)),
53 _a(
static_cast<uint8_t
>(clearColorValue.float32[3] * 255.0f))
55 constexpr explicit Color(glm::vec4
const& vec4) noexcept :
56 _r(
static_cast<uint8_t
>(vec4.r * 255.0f)),
57 _g(
static_cast<uint8_t
>(vec4.g * 255.0f)),
58 _b(
static_cast<uint8_t
>(vec4.b * 255.0f)),
59 _a(
static_cast<uint8_t
>(vec4.a * 255.0f))
61 constexpr Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) noexcept :
67 constexpr explicit Color(uint32_t color) noexcept :
68 _r(
static_cast<uint8_t
>((color & 0xFF000000) >> 24)),
69 _g(
static_cast<uint8_t
>((color & 0x00FF0000) >> 16)),
70 _b(
static_cast<uint8_t
>((color & 0x0000FF00) >> 8)),
71 _a(
static_cast<uint8_t
>(color & 0x000000FF))
74 constexpr operator SDL_Color()
const
76 return SDL_Color{.r = this->_r, .g = this->_g, .b = this->_b, .a = this->_a};
78 constexpr operator VkClearColorValue()
const
80 return {{
static_cast<float>(this->_r) / 255.0f,
static_cast<float>(this->_g) / 255.0f,
81 static_cast<float>(this->_b) / 255.0f,
static_cast<float>(this->_a) / 255.0f}};
83 constexpr operator glm::vec4()
const
85 return {
static_cast<float>(this->_r) / 255.0f,
static_cast<float>(this->_g) / 255.0f,
86 static_cast<float>(this->_b) / 255.0f,
static_cast<float>(this->_a) / 255.0f};
88 constexpr operator glm::uvec4()
const {
return {this->_r, this->_g, this->_b, this->_a}; }
89 constexpr operator uint32_t()
const {
return this->toInteger(); }
91 [[nodiscard]]
constexpr uint32_t toInteger()
const
93 return (
static_cast<uint32_t
>(this->_r) << 24) | (
static_cast<uint32_t
>(this->_g) << 16) |
94 (
static_cast<uint32_t
>(this->_b) << 8) |
static_cast<uint32_t
>(this->_a);
97 constexpr bool operator==(Color
const& right)
const
99 return this->_r == right._r && this->_g == right._g && this->_b == right._b && this->_a == right._a;
101 constexpr bool operator!=(Color
const& right)
const {
return !this->operator==(right); }
103 constexpr Color operator+(Color
const& right)
const
105 uint16_t
const red =
static_cast<uint16_t
>(this->_r) + right._r;
106 uint16_t
const green =
static_cast<uint16_t
>(this->_g) + right._g;
107 uint16_t
const blue =
static_cast<uint16_t
>(this->_b) + right._b;
108 uint16_t
const alpha =
static_cast<uint16_t
>(this->_a) + right._a;
109 return {red > 255 ? uint8_t(255) :
static_cast<uint8_t
>(red),
110 green > 255 ? uint8_t(255) :
static_cast<uint8_t
>(green),
111 blue > 255 ? uint8_t(255) :
static_cast<uint8_t
>(blue),
112 alpha > 255 ? uint8_t(255) :
static_cast<uint8_t
>(alpha)};
114 constexpr Color operator-(Color
const& right)
const
116 auto const red =
static_cast<int16_t
>(this->_r - right._r);
117 auto const green =
static_cast<int16_t
>(this->_g - right._g);
118 auto const blue =
static_cast<int16_t
>(this->_b - right._b);
119 auto const alpha =
static_cast<int16_t
>(this->_a - right._a);
120 return {red < 0 ? uint8_t(0) : static_cast<uint8_t>(red), green < 0 ? uint8_t(0) : static_cast<uint8_t>(green),
121 blue < 0 ? uint8_t(0) : static_cast<uint8_t>(blue),
122 alpha < 0 ? uint8_t(0) : static_cast<uint8_t>(alpha)};
124 constexpr Color operator*(Color
const& right)
const
126 uint16_t
const red =
static_cast<uint16_t
>(this->_r) * right._r;
127 uint16_t
const green =
static_cast<uint16_t
>(this->_g) * right._g;
128 uint16_t
const blue =
static_cast<uint16_t
>(this->_b) * right._b;
129 uint16_t
const alpha =
static_cast<uint16_t
>(this->_a) * right._a;
130 return {
static_cast<uint8_t
>(red / 255),
static_cast<uint8_t
>(green / 255),
static_cast<uint8_t
>(blue / 255),
131 static_cast<uint8_t
>(alpha / 255)};
134 constexpr Color& operator+=(Color
const& right) {
return this->operator=(this->
operator+(right)); }
135 constexpr Color& operator-=(Color
const& right) {
return this->operator=(this->
operator-(right)); }
136 constexpr Color& operator*=(Color
const& right) {
return this->operator=(this->
operator*(right)); }
138 [[nodiscard]]
constexpr Color setAlpha(uint8_t alpha)
const
144 [[nodiscard]]
constexpr Color setRed(uint8_t red)
const
150 [[nodiscard]]
constexpr Color setGreen(uint8_t green)
const
156 [[nodiscard]]
constexpr Color setBlue(uint8_t blue)
const