forked from Hartmut/paradiso
we can see a quad
This commit is contained in:
parent
612677c52d
commit
ddc0f85805
10 changed files with 261 additions and 140 deletions
|
@ -3,61 +3,61 @@
|
|||
|
||||
#include "globals.hpp"
|
||||
|
||||
namespace paradiso
|
||||
{
|
||||
struct RGBA final
|
||||
{
|
||||
using value_type = std::uint32_t;
|
||||
value_type pixel{0x0};
|
||||
namespace paradiso {
|
||||
struct RGBA final {
|
||||
using value_type = std::uint32_t;
|
||||
value_type pixel{0x0};
|
||||
|
||||
static constexpr RGBA from_rgb(uint8_t red, uint8_t green, uint8_t blue) noexcept
|
||||
{
|
||||
return from_rgba(red, green, blue, 0xFF);
|
||||
}
|
||||
static constexpr RGBA from_rgb(uint8_t red, uint8_t green,
|
||||
uint8_t blue) noexcept {
|
||||
return from_rgba(red, green, blue, 0xFF);
|
||||
}
|
||||
|
||||
static constexpr RGBA from_rgba(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) noexcept
|
||||
{
|
||||
return {
|
||||
.pixel = (value_type)(((((red << 8) | green) << 8) | blue) << 8) | alpha};
|
||||
}
|
||||
static constexpr RGBA from_rgba(uint8_t red, uint8_t green, uint8_t blue,
|
||||
uint8_t alpha) noexcept {
|
||||
return {.pixel =
|
||||
(value_type)(((((red << 8) | green) << 8) | blue) << 8) |
|
||||
alpha};
|
||||
}
|
||||
|
||||
constexpr void to_float(float rgba_f[4]) const noexcept
|
||||
{
|
||||
rgba_f[0] = static_cast<float>(this->red()) / 0xFF;
|
||||
rgba_f[1] = static_cast<float>(this->green()) / 0xFF;
|
||||
rgba_f[2] = static_cast<float>(this->blue()) / 0xFF;
|
||||
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
|
||||
}
|
||||
constexpr void to_float(float rgba_f[4]) const noexcept {
|
||||
rgba_f[0] = static_cast<float>(this->red()) / 0xFF;
|
||||
rgba_f[1] = static_cast<float>(this->green()) / 0xFF;
|
||||
rgba_f[2] = static_cast<float>(this->blue()) / 0xFF;
|
||||
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
|
||||
}
|
||||
|
||||
constexpr uint8_t red() const noexcept { return (pixel & 0xFF000000) >> 24; }
|
||||
constexpr uint8_t green() const noexcept { return uint8_t((pixel & 0xFF0000) >> 16); }
|
||||
constexpr uint8_t blue() const noexcept { return uint8_t((pixel & 0xFF00) >> 8); }
|
||||
constexpr uint8_t alpha() const noexcept { return uint8_t(pixel & 0xFF); }
|
||||
constexpr uint8_t red() const noexcept {
|
||||
return (pixel & 0xFF000000) >> 24;
|
||||
}
|
||||
constexpr uint8_t green() const noexcept {
|
||||
return uint8_t((pixel & 0xFF0000) >> 16);
|
||||
}
|
||||
constexpr uint8_t blue() const noexcept {
|
||||
return uint8_t((pixel & 0xFF00) >> 8);
|
||||
}
|
||||
constexpr uint8_t alpha() const noexcept { return uint8_t(pixel & 0xFF); }
|
||||
|
||||
constexpr RGBA &set_red(uint8_t v) noexcept
|
||||
{
|
||||
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
||||
return *this;
|
||||
}
|
||||
constexpr RGBA& set_red(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA &set_green(uint8_t v) noexcept
|
||||
{
|
||||
pixel = (pixel & 0xFF00FFFF) | (v << 16);
|
||||
return *this;
|
||||
}
|
||||
constexpr RGBA& set_green(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFF00FFFF) | (v << 16);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA &set_blue(uint8_t v) noexcept
|
||||
{
|
||||
pixel = (pixel & 0xFFFF00FF) | (v << 8);
|
||||
return *this;
|
||||
}
|
||||
constexpr RGBA& set_blue(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFFFF00FF) | (v << 8);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RGBA &set_alpha(uint8_t v) noexcept
|
||||
{
|
||||
pixel = (pixel & 0xFFFFFF00) | v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
constexpr RGBA& set_alpha(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0xFFFFFF00) | v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
} // namespace paradiso
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue