diff --git a/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat.fbs b/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat.fbs new file mode 100644 index 0000000..8bddeee --- /dev/null +++ b/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat.fbs @@ -0,0 +1,12 @@ +namespace Bigfoot; + +enum PixelFormat: byte +{ + Undefined, + R8G8B8A8Unorm, + R8G8B8A8Srgb, + B8G8R8A8Unorm, + B8G8R8A8Srgb, + A2B10G10R10UnormPack32, + R16G16B16A16Sfloat +} diff --git a/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat_generated.hpp b/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat_generated.hpp new file mode 100644 index 0000000..3651ab7 --- /dev/null +++ b/Bigfoot/Libs/Graphics/GraphicsInterface/Include/GraphicsInterface/PixelFormat_generated.hpp @@ -0,0 +1,95 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +#ifndef FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_ +#define FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_ + +#include "flatbuffers/flatbuffers.h" + +// Ensure the included flatbuffers.h is the same version as when this file was +// generated, otherwise it may not be compatible. +static_assert(FLATBUFFERS_VERSION_MAJOR == 25 && + FLATBUFFERS_VERSION_MINOR == 12 && + FLATBUFFERS_VERSION_REVISION == 19, + "Non-compatible flatbuffers version included"); +// Ensure the included flatbuffers.h is Bigfoot's fork - stock +// flatbuffers (or a differently versioned Bigfoot fork) is not compatible. +#ifndef FLATBUFFERS_BIGFOOT_VERSION +#error "This file requires Bigfoot's flatbuffers fork - stock flatbuffers is not compatible" +#endif +static_assert(FLATBUFFERS_BIGFOOT_VERSION == 1, + "Non-compatible Bigfoot flatbuffers fork version included"); + +#include "EASTL/unique_ptr.h" +#include "EASTL/string.h" +#include "EASTL/vector.h" + +namespace Bigfoot { + +enum class PixelFormat : int8_t { + Undefined = 0, + R8G8B8A8Unorm = 1, + R8G8B8A8Srgb = 2, + B8G8R8A8Unorm = 3, + B8G8R8A8Srgb = 4, + A2B10G10R10UnormPack32 = 5, + R16G16B16A16Sfloat = 6, + MIN = Undefined, + MAX = R16G16B16A16Sfloat +}; + +inline const PixelFormat (&EnumValuesPixelFormat())[7] { + static const PixelFormat values[] = { + PixelFormat::Undefined, + PixelFormat::R8G8B8A8Unorm, + PixelFormat::R8G8B8A8Srgb, + PixelFormat::B8G8R8A8Unorm, + PixelFormat::B8G8R8A8Srgb, + PixelFormat::A2B10G10R10UnormPack32, + PixelFormat::R16G16B16A16Sfloat + }; + return values; +} + +inline const char * const *EnumNamesPixelFormat() { + static const char * const names[8] = { + "Undefined", + "R8G8B8A8Unorm", + "R8G8B8A8Srgb", + "B8G8R8A8Unorm", + "B8G8R8A8Srgb", + "A2B10G10R10UnormPack32", + "R16G16B16A16Sfloat", + nullptr + }; + return names; +} + +inline const char *EnumNamePixelFormat(PixelFormat e) { + if (::flatbuffers::IsOutRange(e, PixelFormat::Undefined, PixelFormat::R16G16B16A16Sfloat)) return ""; + const size_t index = static_cast(e); + return EnumNamesPixelFormat()[index]; +} + +inline const ::flatbuffers::TypeTable *PixelFormatTypeTable() { + static const ::flatbuffers::TypeCode type_codes[] = { + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 }, + { ::flatbuffers::ET_CHAR, 0, 0 } + }; + static const ::flatbuffers::TypeFunction type_refs[] = { + Bigfoot::PixelFormatTypeTable + }; + static const ::flatbuffers::TypeTable tt = { + ::flatbuffers::ST_ENUM, 7, type_codes, type_refs, nullptr, nullptr, nullptr + }; + return &tt; +} + +} // namespace Bigfoot + +#endif // FLATBUFFERS_GENERATED_PIXELFORMAT_BIGFOOT_H_ diff --git a/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanPixelFormat.hpp b/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanPixelFormat.hpp new file mode 100644 index 0000000..e56e8b5 --- /dev/null +++ b/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanPixelFormat.hpp @@ -0,0 +1,34 @@ +/********************************************************************* + * \file VulkanPixelFormat.hpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANPIXELFORMAT_HPP +#define BIGFOOT_GRAPHICSVULKAN_VULKANPIXELFORMAT_HPP +#include + +#include + +namespace Bigfoot::Vulkan +{ +/** + * Convert PixelFormat to its vk::Format equivalent + * + * \param p_format The format to convert + * \return The equivalent vk::Format + */ +[[nodiscard]] +vk::Format ToVulkanFormat(PixelFormat p_format); + +/** + * Convert a vk::Format to its PixelFormat equivalent + * + * \param p_format The format to convert + * \return The equivalent PixelFormat + */ +[[nodiscard]] +PixelFormat FromVulkanFormat(vk::Format p_format); +} // namespace Bigfoot::Vulkan + +#endif diff --git a/Bigfoot/Libs/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp b/Bigfoot/Libs/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp new file mode 100644 index 0000000..eb64dfa --- /dev/null +++ b/Bigfoot/Libs/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp @@ -0,0 +1,55 @@ +/********************************************************************* + * \file VulkanPixelFormat.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +namespace Bigfoot::Vulkan +{ +vk::Format ToVulkanFormat(const PixelFormat p_format) +{ + switch (p_format) + { + case PixelFormat::R8G8B8A8Unorm: + return vk::Format::eR8G8B8A8Unorm; + case PixelFormat::R8G8B8A8Srgb: + return vk::Format::eR8G8B8A8Srgb; + case PixelFormat::B8G8R8A8Unorm: + return vk::Format::eB8G8R8A8Unorm; + case PixelFormat::B8G8R8A8Srgb: + return vk::Format::eB8G8R8A8Srgb; + case PixelFormat::A2B10G10R10UnormPack32: + return vk::Format::eA2B10G10R10UnormPack32; + case PixelFormat::R16G16B16A16Sfloat: + return vk::Format::eR16G16B16A16Sfloat; + case PixelFormat::Undefined: + default: + return vk::Format::eUndefined; + } +} + +/****************************************************************************************/ + +PixelFormat FromVulkanFormat(const vk::Format p_format) +{ + switch (p_format) + { + case vk::Format::eR8G8B8A8Unorm: + return PixelFormat::R8G8B8A8Unorm; + case vk::Format::eR8G8B8A8Srgb: + return PixelFormat::R8G8B8A8Srgb; + case vk::Format::eB8G8R8A8Unorm: + return PixelFormat::B8G8R8A8Unorm; + case vk::Format::eB8G8R8A8Srgb: + return PixelFormat::B8G8R8A8Srgb; + case vk::Format::eA2B10G10R10UnormPack32: + return PixelFormat::A2B10G10R10UnormPack32; + case vk::Format::eR16G16B16A16Sfloat: + return PixelFormat::R16G16B16A16Sfloat; + default: + return PixelFormat::Undefined; + } +} +} // namespace Bigfoot::Vulkan diff --git a/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp b/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp new file mode 100644 index 0000000..5f22823 --- /dev/null +++ b/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanPixelFormat.cpp @@ -0,0 +1,61 @@ +/********************************************************************* + * \file VulkanPixelFormat.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +#include + +namespace Bigfoot::Vulkan +{ +class VulkanPixelFormatFixture: public ::testing::Test +{ + protected: +}; + +/****************************************************************************************/ + +TEST_F(VulkanPixelFormatFixture, ToVulkanFormat_MapsUndefinedToAnUndefinedVkFormat) +{ + EXPECT_EQ(ToVulkanFormat(PixelFormat::Undefined), vk::Format::eUndefined); +} + +/****************************************************************************************/ + +TEST_F(VulkanPixelFormatFixture, ToVulkanFormat_MapsEveryOtherPixelFormatToANonUndefinedVkFormat) +{ + for (const PixelFormat format: EnumValuesPixelFormat()) + { + if (format == PixelFormat::Undefined) + { + continue; + } + + EXPECT_NE(ToVulkanFormat(format), vk::Format::eUndefined) << EnumNamePixelFormat(format); + } +} + +/****************************************************************************************/ + +TEST_F(VulkanPixelFormatFixture, ToVulkanFormat_RoundTripsThroughFromVulkanFormatForEveryPixelFormat) +{ + for (const PixelFormat format: EnumValuesPixelFormat()) + { + if (format == PixelFormat::Undefined) + { + continue; + } + + EXPECT_EQ(FromVulkanFormat(ToVulkanFormat(format)), format) << EnumNamePixelFormat(format); + } +} + +/****************************************************************************************/ + +TEST_F(VulkanPixelFormatFixture, FromVulkanFormat_ReturnsUndefinedForAnUnmappedVkFormat) +{ + EXPECT_EQ(FromVulkanFormat(vk::Format::eR32G32B32A32Sfloat), PixelFormat::Undefined); +} +} // namespace Bigfoot::Vulkan