diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/color.h | 40 | ||||
| -rw-r--r-- | src/common/quaternion.h | 6 | ||||
| -rw-r--r-- | src/common/vector_math.h | 4 |
3 files changed, 25 insertions, 25 deletions
diff --git a/src/common/color.h b/src/common/color.h index 0379040be..3a2222077 100644 --- a/src/common/color.h +++ b/src/common/color.h | |||
| @@ -55,36 +55,36 @@ constexpr u8 Convert8To6(u8 value) { | |||
| 55 | /** | 55 | /** |
| 56 | * Decode a color stored in RGBA8 format | 56 | * Decode a color stored in RGBA8 format |
| 57 | * @param bytes Pointer to encoded source color | 57 | * @param bytes Pointer to encoded source color |
| 58 | * @return Result color decoded as Math::Vec4<u8> | 58 | * @return Result color decoded as Common::Vec4<u8> |
| 59 | */ | 59 | */ |
| 60 | inline Math::Vec4<u8> DecodeRGBA8(const u8* bytes) { | 60 | inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) { |
| 61 | return {bytes[3], bytes[2], bytes[1], bytes[0]}; | 61 | return {bytes[3], bytes[2], bytes[1], bytes[0]}; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | /** | 64 | /** |
| 65 | * Decode a color stored in RGB8 format | 65 | * Decode a color stored in RGB8 format |
| 66 | * @param bytes Pointer to encoded source color | 66 | * @param bytes Pointer to encoded source color |
| 67 | * @return Result color decoded as Math::Vec4<u8> | 67 | * @return Result color decoded as Common::Vec4<u8> |
| 68 | */ | 68 | */ |
| 69 | inline Math::Vec4<u8> DecodeRGB8(const u8* bytes) { | 69 | inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) { |
| 70 | return {bytes[2], bytes[1], bytes[0], 255}; | 70 | return {bytes[2], bytes[1], bytes[0], 255}; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | /** | 73 | /** |
| 74 | * Decode a color stored in RG8 (aka HILO8) format | 74 | * Decode a color stored in RG8 (aka HILO8) format |
| 75 | * @param bytes Pointer to encoded source color | 75 | * @param bytes Pointer to encoded source color |
| 76 | * @return Result color decoded as Math::Vec4<u8> | 76 | * @return Result color decoded as Common::Vec4<u8> |
| 77 | */ | 77 | */ |
| 78 | inline Math::Vec4<u8> DecodeRG8(const u8* bytes) { | 78 | inline Common::Vec4<u8> DecodeRG8(const u8* bytes) { |
| 79 | return {bytes[1], bytes[0], 0, 255}; | 79 | return {bytes[1], bytes[0], 0, 255}; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | /** | 82 | /** |
| 83 | * Decode a color stored in RGB565 format | 83 | * Decode a color stored in RGB565 format |
| 84 | * @param bytes Pointer to encoded source color | 84 | * @param bytes Pointer to encoded source color |
| 85 | * @return Result color decoded as Math::Vec4<u8> | 85 | * @return Result color decoded as Common::Vec4<u8> |
| 86 | */ | 86 | */ |
| 87 | inline Math::Vec4<u8> DecodeRGB565(const u8* bytes) { | 87 | inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) { |
| 88 | u16_le pixel; | 88 | u16_le pixel; |
| 89 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 89 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 90 | return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), | 90 | return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), |
| @@ -94,9 +94,9 @@ inline Math::Vec4<u8> DecodeRGB565(const u8* bytes) { | |||
| 94 | /** | 94 | /** |
| 95 | * Decode a color stored in RGB5A1 format | 95 | * Decode a color stored in RGB5A1 format |
| 96 | * @param bytes Pointer to encoded source color | 96 | * @param bytes Pointer to encoded source color |
| 97 | * @return Result color decoded as Math::Vec4<u8> | 97 | * @return Result color decoded as Common::Vec4<u8> |
| 98 | */ | 98 | */ |
| 99 | inline Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) { | 99 | inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) { |
| 100 | u16_le pixel; | 100 | u16_le pixel; |
| 101 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 101 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 102 | return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), | 102 | return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), |
| @@ -106,9 +106,9 @@ inline Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) { | |||
| 106 | /** | 106 | /** |
| 107 | * Decode a color stored in RGBA4 format | 107 | * Decode a color stored in RGBA4 format |
| 108 | * @param bytes Pointer to encoded source color | 108 | * @param bytes Pointer to encoded source color |
| 109 | * @return Result color decoded as Math::Vec4<u8> | 109 | * @return Result color decoded as Common::Vec4<u8> |
| 110 | */ | 110 | */ |
| 111 | inline Math::Vec4<u8> DecodeRGBA4(const u8* bytes) { | 111 | inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) { |
| 112 | u16_le pixel; | 112 | u16_le pixel; |
| 113 | std::memcpy(&pixel, bytes, sizeof(pixel)); | 113 | std::memcpy(&pixel, bytes, sizeof(pixel)); |
| 114 | return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), | 114 | return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), |
| @@ -138,9 +138,9 @@ inline u32 DecodeD24(const u8* bytes) { | |||
| 138 | /** | 138 | /** |
| 139 | * Decode a depth value and a stencil value stored in D24S8 format | 139 | * Decode a depth value and a stencil value stored in D24S8 format |
| 140 | * @param bytes Pointer to encoded source values | 140 | * @param bytes Pointer to encoded source values |
| 141 | * @return Resulting values stored as a Math::Vec2 | 141 | * @return Resulting values stored as a Common::Vec2 |
| 142 | */ | 142 | */ |
| 143 | inline Math::Vec2<u32> DecodeD24S8(const u8* bytes) { | 143 | inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) { |
| 144 | return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; | 144 | return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| @@ -149,7 +149,7 @@ inline Math::Vec2<u32> DecodeD24S8(const u8* bytes) { | |||
| 149 | * @param color Source color to encode | 149 | * @param color Source color to encode |
| 150 | * @param bytes Destination pointer to store encoded color | 150 | * @param bytes Destination pointer to store encoded color |
| 151 | */ | 151 | */ |
| 152 | inline void EncodeRGBA8(const Math::Vec4<u8>& color, u8* bytes) { | 152 | inline void EncodeRGBA8(const Common::Vec4<u8>& color, u8* bytes) { |
| 153 | bytes[3] = color.r(); | 153 | bytes[3] = color.r(); |
| 154 | bytes[2] = color.g(); | 154 | bytes[2] = color.g(); |
| 155 | bytes[1] = color.b(); | 155 | bytes[1] = color.b(); |
| @@ -161,7 +161,7 @@ inline void EncodeRGBA8(const Math::Vec4<u8>& color, u8* bytes) { | |||
| 161 | * @param color Source color to encode | 161 | * @param color Source color to encode |
| 162 | * @param bytes Destination pointer to store encoded color | 162 | * @param bytes Destination pointer to store encoded color |
| 163 | */ | 163 | */ |
| 164 | inline void EncodeRGB8(const Math::Vec4<u8>& color, u8* bytes) { | 164 | inline void EncodeRGB8(const Common::Vec4<u8>& color, u8* bytes) { |
| 165 | bytes[2] = color.r(); | 165 | bytes[2] = color.r(); |
| 166 | bytes[1] = color.g(); | 166 | bytes[1] = color.g(); |
| 167 | bytes[0] = color.b(); | 167 | bytes[0] = color.b(); |
| @@ -172,7 +172,7 @@ inline void EncodeRGB8(const Math::Vec4<u8>& color, u8* bytes) { | |||
| 172 | * @param color Source color to encode | 172 | * @param color Source color to encode |
| 173 | * @param bytes Destination pointer to store encoded color | 173 | * @param bytes Destination pointer to store encoded color |
| 174 | */ | 174 | */ |
| 175 | inline void EncodeRG8(const Math::Vec4<u8>& color, u8* bytes) { | 175 | inline void EncodeRG8(const Common::Vec4<u8>& color, u8* bytes) { |
| 176 | bytes[1] = color.r(); | 176 | bytes[1] = color.r(); |
| 177 | bytes[0] = color.g(); | 177 | bytes[0] = color.g(); |
| 178 | } | 178 | } |
| @@ -181,7 +181,7 @@ inline void EncodeRG8(const Math::Vec4<u8>& color, u8* bytes) { | |||
| 181 | * @param color Source color to encode | 181 | * @param color Source color to encode |
| 182 | * @param bytes Destination pointer to store encoded color | 182 | * @param bytes Destination pointer to store encoded color |
| 183 | */ | 183 | */ |
| 184 | inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) { | 184 | inline void EncodeRGB565(const Common::Vec4<u8>& color, u8* bytes) { |
| 185 | const u16_le data = | 185 | const u16_le data = |
| 186 | (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); | 186 | (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); |
| 187 | 187 | ||
| @@ -193,7 +193,7 @@ inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) { | |||
| 193 | * @param color Source color to encode | 193 | * @param color Source color to encode |
| 194 | * @param bytes Destination pointer to store encoded color | 194 | * @param bytes Destination pointer to store encoded color |
| 195 | */ | 195 | */ |
| 196 | inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) { | 196 | inline void EncodeRGB5A1(const Common::Vec4<u8>& color, u8* bytes) { |
| 197 | const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) | | 197 | const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) | |
| 198 | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); | 198 | (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); |
| 199 | 199 | ||
| @@ -205,7 +205,7 @@ inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) { | |||
| 205 | * @param color Source color to encode | 205 | * @param color Source color to encode |
| 206 | * @param bytes Destination pointer to store encoded color | 206 | * @param bytes Destination pointer to store encoded color |
| 207 | */ | 207 | */ |
| 208 | inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) { | 208 | inline void EncodeRGBA4(const Common::Vec4<u8>& color, u8* bytes) { |
| 209 | const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) | | 209 | const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) | |
| 210 | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); | 210 | (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); |
| 211 | 211 | ||
diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 1c304b048..370198ae0 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h | |||
| @@ -11,7 +11,7 @@ namespace Common { | |||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | class Quaternion { | 12 | class Quaternion { |
| 13 | public: | 13 | public: |
| 14 | Math::Vec3<T> xyz; | 14 | Vec3<T> xyz; |
| 15 | T w{}; | 15 | T w{}; |
| 16 | 16 | ||
| 17 | Quaternion<decltype(-T{})> Inverse() const { | 17 | Quaternion<decltype(-T{})> Inverse() const { |
| @@ -38,11 +38,11 @@ public: | |||
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | template <typename T> | 40 | template <typename T> |
| 41 | auto QuaternionRotate(const Quaternion<T>& q, const Math::Vec3<T>& v) { | 41 | auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) { |
| 42 | return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); | 42 | return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | inline Quaternion<float> MakeQuaternion(const Math::Vec3<float>& axis, float angle) { | 45 | inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) { |
| 46 | return {axis * std::sin(angle / 2), std::cos(angle / 2)}; | 46 | return {axis * std::sin(angle / 2), std::cos(angle / 2)}; |
| 47 | } | 47 | } |
| 48 | 48 | ||
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 8feb49941..429485329 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -33,7 +33,7 @@ | |||
| 33 | #include <cmath> | 33 | #include <cmath> |
| 34 | #include <type_traits> | 34 | #include <type_traits> |
| 35 | 35 | ||
| 36 | namespace Math { | 36 | namespace Common { |
| 37 | 37 | ||
| 38 | template <typename T> | 38 | template <typename T> |
| 39 | class Vec2; | 39 | class Vec2; |
| @@ -690,4 +690,4 @@ constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { | |||
| 690 | return MakeVec(x, yzw[0], yzw[1], yzw[2]); | 690 | return MakeVec(x, yzw[0], yzw[1], yzw[2]); |
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | } // namespace Math | 693 | } // namespace Common |