From aeb003fb526a034401f1f4d40c92ae8193eebb09 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Wed, 12 Feb 2025 20:07:05 +0200 Subject: [PATCH 1/3] Fmt formatter for basic Math stuff --- openVulkanoCpp/Extensions/FmtFormatter.hpp | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/openVulkanoCpp/Extensions/FmtFormatter.hpp b/openVulkanoCpp/Extensions/FmtFormatter.hpp index 085a5bc..7041de0 100644 --- a/openVulkanoCpp/Extensions/FmtFormatter.hpp +++ b/openVulkanoCpp/Extensions/FmtFormatter.hpp @@ -14,6 +14,7 @@ #error "Failed to find fmt include" #endif #include "Math/ByteSize.hpp" +#include "Math/Math.hpp" #include template<> struct fmt::formatter @@ -42,4 +43,118 @@ template<> struct fmt::formatter : fmt::formatter::format(path.string(), ctx); } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::vec<2, T, Q>& v, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "({}, {})", v.x, v.y); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::vec<3, T, Q>& v, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::vec<4, T, Q>& v, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::mat<2, 2, T, Q>& m, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "[[{}, {}], [{}, {}]]", + m[0][0], m[0][1], + m[1][0], m[1][1]); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::mat<3, 3, T, Q>& m, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "[[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]", + m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2], + m[2][0], m[2][1], m[2][2]); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::mat<4, 4, T, Q>& m, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "[[{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}]]", + m[0][0], m[0][1], m[0][2], m[0][3], + m[1][0], m[1][1], m[1][2], m[1][3], + m[2][0], m[2][1], m[2][2], m[2][3], + m[3][0], m[3][1], m[3][2], m[3][3]); + } +}; + +template +struct fmt::formatter> +{ + template constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const glm::qua& q, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "({}, {}, {}, {})", q.w, q.x, q.y, q.z); + } }; \ No newline at end of file From 9eaecd7982d810956045ef049e334335fdfcff6d Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Wed, 12 Feb 2025 21:46:23 +0200 Subject: [PATCH 2/3] Changed to row-major matrices repr --- openVulkanoCpp/Extensions/FmtFormatter.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openVulkanoCpp/Extensions/FmtFormatter.hpp b/openVulkanoCpp/Extensions/FmtFormatter.hpp index 7041de0..0eb3276 100644 --- a/openVulkanoCpp/Extensions/FmtFormatter.hpp +++ b/openVulkanoCpp/Extensions/FmtFormatter.hpp @@ -102,8 +102,8 @@ struct fmt::formatter> auto format(const glm::mat<2, 2, T, Q>& m, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "[[{}, {}], [{}, {}]]", - m[0][0], m[0][1], - m[1][0], m[1][1]); + m[0][0], m[1][0], + m[0][1], m[1][1]); } }; @@ -119,9 +119,9 @@ struct fmt::formatter> auto format(const glm::mat<3, 3, T, Q>& m, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "[[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]", - m[0][0], m[0][1], m[0][2], - m[1][0], m[1][1], m[1][2], - m[2][0], m[2][1], m[2][2]); + m[0][0], m[1][0], m[2][0], + m[0][1], m[1][1], m[2][1], + m[0][2], m[1][2], m[2][2]); } }; @@ -137,10 +137,10 @@ struct fmt::formatter> auto format(const glm::mat<4, 4, T, Q>& m, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "[[{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}]]", - m[0][0], m[0][1], m[0][2], m[0][3], - m[1][0], m[1][1], m[1][2], m[1][3], - m[2][0], m[2][1], m[2][2], m[2][3], - m[3][0], m[3][1], m[3][2], m[3][3]); + m[0][0], m[1][0], m[2][0], m[3][0], + m[0][1], m[1][1], m[2][1], m[3][1], + m[0][2], m[1][2], m[2][2], m[3][2], + m[0][3], m[1][3], m[2][3], m[3][3]); } }; From 1c31850497004efd8fb8f6e72fddc8508a9a5d43 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 13 Feb 2025 13:11:12 +0200 Subject: [PATCH 3/3] Formatter for Base/UUID and Math/Range --- openVulkanoCpp/Extensions/FmtFormatter.hpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/openVulkanoCpp/Extensions/FmtFormatter.hpp b/openVulkanoCpp/Extensions/FmtFormatter.hpp index 0eb3276..2c3b9d2 100644 --- a/openVulkanoCpp/Extensions/FmtFormatter.hpp +++ b/openVulkanoCpp/Extensions/FmtFormatter.hpp @@ -15,6 +15,8 @@ #endif #include "Math/ByteSize.hpp" #include "Math/Math.hpp" +#include "Math/Range.hpp" +#include "Base/UUID.hpp" #include template<> struct fmt::formatter @@ -157,4 +159,36 @@ struct fmt::formatter> { return fmt::format_to(ctx.out(), "({}, {}, {}, {})", q.w, q.x, q.y, q.z); } +}; + +template +struct fmt::formatter> : fmt::formatter +{ + template + constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const OpenVulkano::Math::Range& range, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "[{}, {}]", range.min, range.max); + } +}; + +template<> +struct fmt::formatter : fmt::formatter +{ + template + constexpr auto parse(ParseContext& ctx) + { + return ctx.begin(); + } + + template + auto format(const OpenVulkano::UUID& uuid, FormatContext& ctx) const + { + return fmt::format_to(ctx.out(), "{}", uuid.string()); + } }; \ No newline at end of file