From 1ebe1a80911a66f5b64b3c0f3716ed9e076f9883 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 17 May 2016 14:23:45 +0200 Subject: [PATCH] Utility: Rework PixelFormat (WIP) Former-commit-id: 1ab609e753783d9767ba23fd4cab9390453bf729 --- include/Nazara/Utility/Enums.hpp | 34 +- include/Nazara/Utility/PixelFormat.hpp | 64 +-- include/Nazara/Utility/PixelFormat.inl | 642 ++++++----------------- src/Nazara/Renderer/RenderBuffer.cpp | 2 +- src/Nazara/Renderer/RenderTexture.cpp | 27 +- src/Nazara/Renderer/Texture.cpp | 6 +- src/Nazara/Utility/Formats/DDSLoader.cpp | 2 +- src/Nazara/Utility/Image.cpp | 8 +- src/Nazara/Utility/PixelFormat.cpp | 82 ++- 9 files changed, 306 insertions(+), 561 deletions(-) diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 143390906..3f32945c2 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -142,6 +142,17 @@ namespace Nz NodeType_Max = NodeType_Skeletal }; + enum PixelFormatContent + { + PixelFormatContent_Undefined = -1, + + PixelFormatContent_ColorRGBA, + PixelFormatContent_DepthStencil, + PixelFormatContent_Stencil, + + PixelFormatContent_Max = PixelFormatContent_Stencil + }; + enum PixelFormatType { PixelFormatType_Undefined = -1, @@ -204,27 +215,16 @@ namespace Nz enum PixelFormatSubType { - PixelFormatSubType_Double, // F64 - PixelFormatSubType_Float, // F32 - PixelFormatSubType_Half, // F16 - PixelFormatSubType_Int, // I32 - PixelFormatSubType_Unsigned, // U32 + PixelFormatSubType_Compressed, // Opaque + PixelFormatSubType_Double, // F64 + PixelFormatSubType_Float, // F32 + PixelFormatSubType_Half, // F16 + PixelFormatSubType_Int, // Signed integer + PixelFormatSubType_Unsigned, // Unsigned integer PixelFormatSubType_Max = PixelFormatSubType_Unsigned }; - enum PixelFormatTypeType - { - PixelFormatTypeType_Undefined = -1, - - PixelFormatTypeType_Color, - PixelFormatTypeType_Depth, - PixelFormatTypeType_DepthStencil, - PixelFormatTypeType_Stencil, - - PixelFormatTypeType_Max = PixelFormatTypeType_Stencil - }; - enum PixelFlipping { PixelFlipping_Horizontally, diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 6844162d5..92eecb7f4 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -23,33 +23,36 @@ namespace Nz { struct PixelFormatInfo { - PixelFormatInfo() : - bitsPerPixel(0) - { - } + inline PixelFormatInfo(); + inline PixelFormatInfo(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); + inline PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); + inline PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType); + inline PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0); - PixelFormatInfo(UInt8 bpp, PixelFormatSubType subType) : - bitsPerPixel(bpp), - redType(subType), - greenType(subType), - blueType(subType), - alphaType(subType) - { - } + inline void Clear(); - // Warning: Bit Endian + inline bool IsCompressed() const; + inline bool IsValid() const; + + inline void RecomputeBitsPerPixel(); + + inline bool Validate() const; + + // Warning: Masks bit order is reversed Bitset<> redMask; Bitset<> greenMask; Bitset<> blueMask; Bitset<> alphaMask; + PixelFormatContent content; PixelFormatSubType redType; PixelFormatSubType greenType; PixelFormatSubType blueType; PixelFormatSubType alphaType; + String name; UInt8 bitsPerPixel; }; - class PixelFormat + class NAZARA_UTILITY_API PixelFormat { friend class Utility; @@ -59,34 +62,35 @@ namespace Nz static inline std::size_t ComputeSize(PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth); - static bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst); - static bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* start, const void* end, void* dst); + static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst); + static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* start, const void* end, void* dst); - static bool Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); + static inline bool Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); - static UInt8 GetBitsPerPixel(PixelFormatType format); - static UInt8 GetBytesPerPixel(PixelFormatType format); - static PixelFormatTypeType GetType(PixelFormatType format); + static inline UInt8 GetBitsPerPixel(PixelFormatType format); + static inline PixelFormatContent GetContent(PixelFormatType format); + static inline UInt8 GetBytesPerPixel(PixelFormatType format); + static inline const PixelFormatInfo& GetInfo(PixelFormatType format); + static inline const String& GetName(PixelFormatType format); - static bool HasAlpha(PixelFormatType format); + static inline bool HasAlpha(PixelFormatType format); static PixelFormatType IdentifyFormat(const PixelFormatInfo& info); - static bool IsCompressed(PixelFormatType format); - static bool IsConversionSupported(PixelFormatType srcFormat, PixelFormatType dstFormat); - static bool IsValid(PixelFormatType format); + static inline bool IsCompressed(PixelFormatType format); + static inline bool IsConversionSupported(PixelFormatType srcFormat, PixelFormatType dstFormat); + static inline bool IsValid(PixelFormatType format); - static void SetConvertFunction(PixelFormatType srcFormat, PixelFormatType dstFormat, ConvertFunction func); - static void SetFlipFunction(PixelFlipping flipping, PixelFormatType format, FlipFunction func); - - static String ToString(PixelFormatType format); + static inline void SetConvertFunction(PixelFormatType srcFormat, PixelFormatType dstFormat, ConvertFunction func); + static inline void SetFlipFunction(PixelFlipping flipping, PixelFormatType format, FlipFunction func); private: static bool Initialize(); static void Uninitialize(); - static NAZARA_UTILITY_API ConvertFunction s_convertFunctions[PixelFormatType_Max+1][PixelFormatType_Max+1]; - static NAZARA_UTILITY_API std::map s_flipFunctions[PixelFlipping_Max+1]; + static PixelFormatInfo s_pixelFormatInfos[PixelFormatType_Max + 1]; + static ConvertFunction s_convertFunctions[PixelFormatType_Max+1][PixelFormatType_Max+1]; + static std::map s_flipFunctions[PixelFlipping_Max+1]; }; } diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 2d09273b9..7b05ec8fb 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -2,13 +2,151 @@ // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include +#include #include #include namespace Nz { + inline PixelFormatInfo::PixelFormatInfo() : + bitsPerPixel(0), + content(PixelFormatContent_Undefined) + { + } + + inline PixelFormatInfo::PixelFormatInfo(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : + bitsPerPixel(bpp), + content(formatContent), + redType(subType), + greenType(subType), + blueType(subType), + alphaType(subType) + { + } + + inline PixelFormatInfo::PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : + bitsPerPixel(bpp), + content(formatContent), + redType(subType), + greenType(subType), + blueType(subType), + alphaType(subType), + name(formatName) + { + } + + inline PixelFormatInfo::PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) : + redMask(rMask), + greenMask(gMask), + blueMask(bMask), + alphaMask(aMask), + content(formatContent), + redType(subType), + greenType(subType), + blueType(subType), + alphaType(subType), + name(formatName) + { + RecomputeBitsPerPixel(); + } + + inline PixelFormatInfo::PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) : + redMask(rMask), + greenMask(gMask), + blueMask(bMask), + alphaMask(aMask), + content(formatContent), + redType(rType), + greenType(gType), + blueType(bType), + alphaType(aType), + name(formatName) + { + if (bpp == 0) + RecomputeBitsPerPixel(); + } + + inline void PixelFormatInfo::Clear() + { + bitsPerPixel = 0; + alphaMask.Clear(); + blueMask.Clear(); + greenMask.Clear(); + redMask.Clear(); + name.Clear(); + } + + inline bool PixelFormatInfo::IsCompressed() const + { + return redType == PixelFormatSubType_Compressed || + greenType == PixelFormatSubType_Compressed || + blueType == PixelFormatSubType_Compressed || + alphaType == PixelFormatSubType_Compressed; + } + + inline bool PixelFormatInfo::IsValid() const + { + return bitsPerPixel != 0; + } + + inline void PixelFormatInfo::RecomputeBitsPerPixel() + { + Bitset<> counter; + counter |= redMask; + counter |= greenMask; + counter |= blueMask; + counter |= alphaMask; + + bitsPerPixel = counter.Count(); + } + + inline bool PixelFormatInfo::Validate() const + { + if (!IsValid()) + return false; + + if (content <= PixelFormatContent_Undefined || content > PixelFormatContent_Max) + return false; + + std::array*, 4> masks = {&redMask, &greenMask, &blueMask, &alphaMask}; + std::array types = {redType, greenType, blueType, alphaType}; + + for (unsigned int i = 0; i < 4; ++i) + { + unsigned int usedBits = masks[i]->Count(); + if (usedBits == 0) + continue; + + if (usedBits > bitsPerPixel) + return false; + + switch (types[i]) + { + case PixelFormatSubType_Half: + if (usedBits != 16) + return false; + + break; + + case PixelFormatSubType_Float: + if (usedBits != 32) + return false; + + break; + + default: + break; + } + } + + return true; + } + + + inline std::size_t PixelFormat::ComputeSize(PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth) { if (IsCompressed(format)) @@ -54,13 +192,13 @@ namespace Nz ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; if (!func) { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported"); return false; } if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBytesPerPixel(srcFormat), reinterpret_cast(dst))) { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " failed"); return false; } @@ -78,13 +216,13 @@ namespace Nz ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; if (!func) { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported"); return false; } if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " failed"); return false; } @@ -189,126 +327,7 @@ namespace Nz inline UInt8 PixelFormat::GetBitsPerPixel(PixelFormatType format) { - switch (format) - { - case PixelFormatType_A8: - return 8; - - case PixelFormatType_BGR8: - return 24; - - case PixelFormatType_BGRA8: - return 32; - - case PixelFormatType_DXT1: - return 8; - - case PixelFormatType_DXT3: - return 16; - - case PixelFormatType_DXT5: - return 16; - - case PixelFormatType_L8: - return 8; - - case PixelFormatType_LA8: - return 16; - - case PixelFormatType_R8: - case PixelFormatType_R8I: - case PixelFormatType_R8UI: - return 8; - - case PixelFormatType_R16: - case PixelFormatType_R16F: - case PixelFormatType_R16I: - case PixelFormatType_R16UI: - return 16; - - case PixelFormatType_R32F: - case PixelFormatType_R32I: - case PixelFormatType_R32UI: - return 32; - - case PixelFormatType_RG8: - case PixelFormatType_RG8I: - case PixelFormatType_RG8UI: - return 16; - - case PixelFormatType_RG16: - case PixelFormatType_RG16F: - case PixelFormatType_RG16I: - case PixelFormatType_RG16UI: - return 32; - - case PixelFormatType_RG32F: - case PixelFormatType_RG32I: - case PixelFormatType_RG32UI: - return 64; - - case PixelFormatType_RGB16F: - case PixelFormatType_RGB16I: - case PixelFormatType_RGB16UI: - return 48; - - case PixelFormatType_RGB32F: - case PixelFormatType_RGB32I: - case PixelFormatType_RGB32UI: - return 96; - - case PixelFormatType_RGBA16F: - case PixelFormatType_RGBA16I: - case PixelFormatType_RGBA16UI: - return 64; - - case PixelFormatType_RGBA32F: - case PixelFormatType_RGBA32I: - case PixelFormatType_RGBA32UI: - return 128; - - case PixelFormatType_RGBA4: - return 16; - - case PixelFormatType_RGB5A1: - return 16; - - case PixelFormatType_RGB8: - return 24; - - case PixelFormatType_RGBA8: - return 32; - - case PixelFormatType_Depth16: - return 16; - - case PixelFormatType_Depth24: - return 24; - - case PixelFormatType_Depth24Stencil8: - return 32; - - case PixelFormatType_Depth32: - return 32; - - case PixelFormatType_Stencil1: - return 1; - - case PixelFormatType_Stencil4: - return 2; - - case PixelFormatType_Stencil8: - return 8; - - case PixelFormatType_Stencil16: - return 16; - - case PixelFormatType_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return 0; + return s_pixelFormatInfos[format].bitsPerPixel; } inline UInt8 PixelFormat::GetBytesPerPixel(PixelFormatType format) @@ -316,212 +335,29 @@ namespace Nz return GetBitsPerPixel(format)/8; } - inline PixelFormatTypeType PixelFormat::GetType(PixelFormatType format) + inline PixelFormatContent PixelFormat::GetContent(PixelFormatType format) { - switch (format) - { - case PixelFormatType_A8: - case PixelFormatType_BGR8: - case PixelFormatType_BGRA8: - case PixelFormatType_DXT1: - case PixelFormatType_DXT3: - case PixelFormatType_DXT5: - case PixelFormatType_L8: - case PixelFormatType_LA8: - case PixelFormatType_R8: - case PixelFormatType_R8I: - case PixelFormatType_R8UI: - case PixelFormatType_R16: - case PixelFormatType_R16F: - case PixelFormatType_R16I: - case PixelFormatType_R16UI: - case PixelFormatType_R32F: - case PixelFormatType_R32I: - case PixelFormatType_R32UI: - case PixelFormatType_RG8: - case PixelFormatType_RG8I: - case PixelFormatType_RG8UI: - case PixelFormatType_RG16: - case PixelFormatType_RG16F: - case PixelFormatType_RG16I: - case PixelFormatType_RG16UI: - case PixelFormatType_RG32F: - case PixelFormatType_RG32I: - case PixelFormatType_RG32UI: - case PixelFormatType_RGB5A1: - case PixelFormatType_RGB8: - case PixelFormatType_RGB16F: - case PixelFormatType_RGB16I: - case PixelFormatType_RGB16UI: - case PixelFormatType_RGB32F: - case PixelFormatType_RGB32I: - case PixelFormatType_RGB32UI: - case PixelFormatType_RGBA4: - case PixelFormatType_RGBA8: - case PixelFormatType_RGBA16F: - case PixelFormatType_RGBA16I: - case PixelFormatType_RGBA16UI: - case PixelFormatType_RGBA32F: - case PixelFormatType_RGBA32I: - case PixelFormatType_RGBA32UI: - return PixelFormatTypeType_Color; + return s_pixelFormatInfos[format].content; + } - case PixelFormatType_Depth16: - case PixelFormatType_Depth24: - case PixelFormatType_Depth32: - return PixelFormatTypeType_Depth; + inline const PixelFormatInfo& PixelFormat::GetInfo(PixelFormatType format) + { + return s_pixelFormatInfos[format]; + } - case PixelFormatType_Depth24Stencil8: - return PixelFormatTypeType_DepthStencil; - - case PixelFormatType_Stencil1: - case PixelFormatType_Stencil4: - case PixelFormatType_Stencil8: - case PixelFormatType_Stencil16: - return PixelFormatTypeType_Stencil; - - case PixelFormatType_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return PixelFormatTypeType_Undefined; + inline const String& PixelFormat::GetName(PixelFormatType format) + { + return s_pixelFormatInfos[format].name; } inline bool PixelFormat::HasAlpha(PixelFormatType format) { - switch (format) - { - case PixelFormatType_A8: - case PixelFormatType_BGRA8: - case PixelFormatType_DXT3: - case PixelFormatType_DXT5: - case PixelFormatType_LA8: - case PixelFormatType_RGB5A1: - case PixelFormatType_RGBA16F: - case PixelFormatType_RGBA16I: - case PixelFormatType_RGBA16UI: - case PixelFormatType_RGBA32F: - case PixelFormatType_RGBA32I: - case PixelFormatType_RGBA32UI: - case PixelFormatType_RGBA4: - case PixelFormatType_RGBA8: - return true; - - case PixelFormatType_BGR8: - case PixelFormatType_DXT1: - case PixelFormatType_L8: - case PixelFormatType_R8: - case PixelFormatType_R8I: - case PixelFormatType_R8UI: - case PixelFormatType_R16: - case PixelFormatType_R16F: - case PixelFormatType_R16I: - case PixelFormatType_R16UI: - case PixelFormatType_R32F: - case PixelFormatType_R32I: - case PixelFormatType_R32UI: - case PixelFormatType_RG8: - case PixelFormatType_RG8I: - case PixelFormatType_RG8UI: - case PixelFormatType_RG16: - case PixelFormatType_RG16F: - case PixelFormatType_RG16I: - case PixelFormatType_RG16UI: - case PixelFormatType_RG32F: - case PixelFormatType_RG32I: - case PixelFormatType_RG32UI: - case PixelFormatType_RGB8: - case PixelFormatType_RGB16F: - case PixelFormatType_RGB16I: - case PixelFormatType_RGB16UI: - case PixelFormatType_RGB32F: - case PixelFormatType_RGB32I: - case PixelFormatType_RGB32UI: - case PixelFormatType_Depth16: - case PixelFormatType_Depth24: - case PixelFormatType_Depth24Stencil8: - case PixelFormatType_Depth32: - case PixelFormatType_Stencil1: - case PixelFormatType_Stencil4: - case PixelFormatType_Stencil8: - case PixelFormatType_Stencil16: - return false; - - case PixelFormatType_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; + return s_pixelFormatInfos[format].alphaMask.TestAny(); } inline bool PixelFormat::IsCompressed(PixelFormatType format) { - switch (format) - { - case PixelFormatType_DXT1: - case PixelFormatType_DXT3: - case PixelFormatType_DXT5: - return true; - - case PixelFormatType_A8: - case PixelFormatType_BGR8: - case PixelFormatType_BGRA8: - case PixelFormatType_L8: - case PixelFormatType_LA8: - case PixelFormatType_R8: - case PixelFormatType_R8I: - case PixelFormatType_R8UI: - case PixelFormatType_R16: - case PixelFormatType_R16F: - case PixelFormatType_R16I: - case PixelFormatType_R16UI: - case PixelFormatType_R32F: - case PixelFormatType_R32I: - case PixelFormatType_R32UI: - case PixelFormatType_RG8: - case PixelFormatType_RG8I: - case PixelFormatType_RG8UI: - case PixelFormatType_RG16: - case PixelFormatType_RG16F: - case PixelFormatType_RG16I: - case PixelFormatType_RG16UI: - case PixelFormatType_RG32F: - case PixelFormatType_RG32I: - case PixelFormatType_RG32UI: - case PixelFormatType_RGB5A1: - case PixelFormatType_RGB8: - case PixelFormatType_RGB16F: - case PixelFormatType_RGB16I: - case PixelFormatType_RGB16UI: - case PixelFormatType_RGB32F: - case PixelFormatType_RGB32I: - case PixelFormatType_RGB32UI: - case PixelFormatType_RGBA4: - case PixelFormatType_RGBA8: - case PixelFormatType_RGBA16F: - case PixelFormatType_RGBA16I: - case PixelFormatType_RGBA16UI: - case PixelFormatType_RGBA32F: - case PixelFormatType_RGBA32I: - case PixelFormatType_RGBA32UI: - case PixelFormatType_Depth16: - case PixelFormatType_Depth24: - case PixelFormatType_Depth24Stencil8: - case PixelFormatType_Depth32: - case PixelFormatType_Stencil1: - case PixelFormatType_Stencil4: - case PixelFormatType_Stencil8: - case PixelFormatType_Stencil16: - return false; - - case PixelFormatType_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; + return s_pixelFormatInfos[format].IsCompressed(); } inline bool PixelFormat::IsConversionSupported(PixelFormatType srcFormat, PixelFormatType dstFormat) @@ -546,174 +382,6 @@ namespace Nz { s_flipFunctions[flipping][format] = func; } - - inline String PixelFormat::ToString(PixelFormatType format) - { - switch (format) - { - case PixelFormatType_A8: - return "A8"; - - case PixelFormatType_BGR8: - return "BGR8"; - - case PixelFormatType_BGRA8: - return "BGRA8"; - - case PixelFormatType_DXT1: - return "DXT1"; - - case PixelFormatType_DXT3: - return "DXT3"; - - case PixelFormatType_DXT5: - return "DXT5"; - - case PixelFormatType_L8: - return "L8"; - - case PixelFormatType_LA8: - return "LA8"; - - case PixelFormatType_R8: - return "R8"; - - case PixelFormatType_R8I: - return "R8I"; - - case PixelFormatType_R8UI: - return "R8UI"; - - case PixelFormatType_R16: - return "R16"; - - case PixelFormatType_R16F: - return "R16F"; - - case PixelFormatType_R16I: - return "R16I"; - - case PixelFormatType_R16UI: - return "R16UI"; - - case PixelFormatType_R32F: - return "R32F"; - - case PixelFormatType_R32I: - return "R32I"; - - case PixelFormatType_R32UI: - return "R32UI"; - - case PixelFormatType_RG8: - return "RG8"; - - case PixelFormatType_RG8I: - return "RG8I"; - - case PixelFormatType_RG8UI: - return "RG8UI"; - - case PixelFormatType_RG16: - return "RG16"; - - case PixelFormatType_RG16F: - return "RG16F"; - - case PixelFormatType_RG16I: - return "RG16I"; - - case PixelFormatType_RG16UI: - return "RG16UI"; - - case PixelFormatType_RG32F: - return "RG32F"; - - case PixelFormatType_RG32I: - return "RG32I"; - - case PixelFormatType_RG32UI: - return "RG32UI"; - - case PixelFormatType_RGB5A1: - return "RGB5A1"; - - case PixelFormatType_RGB8: - return "RGB8"; - - case PixelFormatType_RGB16F: - return "RGB16F"; - - case PixelFormatType_RGB16I: - return "RGB16I"; - - case PixelFormatType_RGB16UI: - return "RGB16UI"; - - case PixelFormatType_RGB32F: - return "RGB32F"; - - case PixelFormatType_RGB32I: - return "RGB32I"; - - case PixelFormatType_RGB32UI: - return "RGB32UI"; - - case PixelFormatType_RGBA4: - return "RGBA4"; - - case PixelFormatType_RGBA8: - return "RGBA8"; - - case PixelFormatType_RGBA16F: - return "RGBA16F"; - - case PixelFormatType_RGBA16I: - return "RGBA16I"; - - case PixelFormatType_RGBA16UI: - return "RGBA16UI"; - - case PixelFormatType_RGBA32F: - return "RGBA32F"; - - case PixelFormatType_RGBA32I: - return "RGBA32I"; - - case PixelFormatType_RGBA32UI: - return "RGBA32UI"; - - case PixelFormatType_Depth16: - return "Depth16"; - - case PixelFormatType_Depth24: - return "Depth24"; - - case PixelFormatType_Depth24Stencil8: - return "Depth24Stencil8"; - - case PixelFormatType_Depth32: - return "Depth32"; - - case PixelFormatType_Stencil1: - return "Stencil1"; - - case PixelFormatType_Stencil4: - return "Stencil4"; - - case PixelFormatType_Stencil8: - return "Stencil8"; - - case PixelFormatType_Stencil16: - return "Stencil16"; - - case PixelFormatType_Undefined: - return "Undefined"; - } - - NazaraError("Invalid pixel format"); - return "Invalid format"; - } } #include diff --git a/src/Nazara/Renderer/RenderBuffer.cpp b/src/Nazara/Renderer/RenderBuffer.cpp index b1316f4c3..b6b182ab8 100644 --- a/src/Nazara/Renderer/RenderBuffer.cpp +++ b/src/Nazara/Renderer/RenderBuffer.cpp @@ -44,7 +44,7 @@ namespace Nz OpenGL::Format openglFormat; if (!OpenGL::TranslateFormat(format, &openglFormat, OpenGL::FormatType_RenderBuffer)) { - NazaraError("Failed to translate pixel format \"" + PixelFormat::ToString(format) + "\" into OpenGL format"); + NazaraError("Failed to translate pixel format \"" + PixelFormat::GetName(format) + "\" into OpenGL format"); return false; } diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp index 37b45c46a..0ae0d97bf 100644 --- a/src/Nazara/Renderer/RenderTexture.cpp +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -44,12 +44,23 @@ namespace Nz 2 // AttachmentPoint_Stencil }; - AttachmentPoint formatTypeToAttachment[PixelFormatTypeType_Max+1] = + AttachmentPoint FormatTypeToAttachment(PixelFormatType format) { - AttachmentPoint_Color, // PixelFormatTypeType_Color - AttachmentPoint_Depth, // PixelFormatTypeType_Depth - AttachmentPoint_DepthStencil, // PixelFormatTypeType_DepthStencil - AttachmentPoint_Stencil // PixelFormatTypeType_Stencil + const PixelFormatInfo& info = PixelFormat::GetInfo(format); + switch (info.content) + { + case PixelFormatContent_ColorRGBA: + return AttachmentPoint_Color; + + case PixelFormatContent_DepthStencil: + return (!info.greenMask.TestAny()) ? AttachmentPoint_Depth : AttachmentPoint_DepthStencil; + + case PixelFormatContent_Stencil: + return AttachmentPoint_Stencil; + } + + NazaraInternalError("Unexpected pixel format content: 0x" + String::Number(info.content, 16)); + return AttachmentPoint_Max; }; GLuint lockedPrevious = 0; @@ -118,9 +129,9 @@ namespace Nz } } - AttachmentPoint targetAttachmentPoint = formatTypeToAttachment[PixelFormat::GetType(buffer->GetFormat())]; + AttachmentPoint targetAttachmentPoint = FormatTypeToAttachment(buffer->GetFormat()); if (targetAttachmentPoint != attachmentPoint && targetAttachmentPoint != AttachmentPoint_DepthStencil && - attachmentPoint != AttachmentPoint_Depth && attachmentPoint != AttachmentPoint_Stencil) + attachmentPoint != AttachmentPoint_Depth && attachmentPoint != AttachmentPoint_Stencil) { NazaraError("Pixel format type does not match attachment point type"); return false; @@ -230,7 +241,7 @@ namespace Nz return false; } - AttachmentPoint targetAttachmentPoint = formatTypeToAttachment[PixelFormat::GetType(texture->GetFormat())]; + AttachmentPoint targetAttachmentPoint = FormatTypeToAttachment(texture->GetFormat()); if (targetAttachmentPoint != attachmentPoint && targetAttachmentPoint != AttachmentPoint_DepthStencil && attachmentPoint != AttachmentPoint_Depth && attachmentPoint != AttachmentPoint_Stencil) { diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index e4382cfc5..835dce85e 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -521,7 +521,7 @@ namespace Nz { ///TODO: Sélectionner le format le plus adapté selon les composantes présentes dans le premier format PixelFormatType newFormat = (PixelFormat::HasAlpha(format)) ? PixelFormatType_BGRA8 : PixelFormatType_BGR8; - NazaraWarning("Format " + PixelFormat::ToString(format) + " not supported, trying to convert it to " + PixelFormat::ToString(newFormat) + "..."); + NazaraWarning("Format " + PixelFormat::GetName(format) + " not supported, trying to convert it to " + PixelFormat::GetName(newFormat) + "..."); if (PixelFormat::IsConversionSupported(format, newFormat)) { @@ -1197,7 +1197,7 @@ namespace Nz OpenGL::Format openGLFormat; if (!OpenGL::TranslateFormat(m_impl->format, &openGLFormat, OpenGL::FormatType_Texture)) { - NazaraError("Format " + PixelFormat::ToString(m_impl->format) + " not supported by OpenGL"); + NazaraError("Format " + PixelFormat::GetName(m_impl->format) + " not supported by OpenGL"); return false; } @@ -1306,7 +1306,7 @@ namespace Nz glTexParameteri(target, GL_TEXTURE_SWIZZLE_A, openGLFormat.swizzle[3]); } - if (!proxy && PixelFormat::GetType(m_impl->format) == PixelFormatTypeType_Depth) + if (!proxy && PixelFormat::GetContent(m_impl->format) == PixelFormatContent_DepthStencil) { glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); diff --git a/src/Nazara/Utility/Formats/DDSLoader.cpp b/src/Nazara/Utility/Formats/DDSLoader.cpp index baa2657b3..fe775d97a 100644 --- a/src/Nazara/Utility/Formats/DDSLoader.cpp +++ b/src/Nazara/Utility/Formats/DDSLoader.cpp @@ -169,7 +169,7 @@ namespace Nz { if (header.format.flags & (DDPF_RGB | DDPF_ALPHA | DDPF_ALPHAPIXELS | DDPF_LUMINANCE)) { - PixelFormatInfo info(header.format.bpp, PixelFormatSubType_Unsigned); + PixelFormatInfo info(PixelFormatContent_ColorRGBA, header.format.bpp, PixelFormatSubType_Unsigned); if (header.format.flags & DDPF_RGB) { diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 6d05b493c..c8f3e49f1 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -89,7 +89,7 @@ namespace Nz if (!PixelFormat::IsConversionSupported(m_sharedImage->format, newFormat)) { - NazaraError("Conversion from " + PixelFormat::ToString(m_sharedImage->format) + " to " + PixelFormat::ToString(newFormat) + " is not supported"); + NazaraError("Conversion from " + PixelFormat::GetName(m_sharedImage->format) + " to " + PixelFormat::GetName(newFormat) + " is not supported"); return false; } #endif @@ -327,7 +327,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormat::Convert(PixelFormatType_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormat::ToString(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + PixelFormat::GetName(m_sharedImage->format)); return false; } @@ -405,7 +405,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormat::Convert(PixelFormatType_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormat::ToString(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + PixelFormat::GetName(m_sharedImage->format)); return false; } @@ -477,7 +477,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormat::Convert(PixelFormatType_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormat::ToString(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + PixelFormat::GetName(m_sharedImage->format)); return false; } diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index 8c571d62e..a9b740b8f 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -48,7 +48,7 @@ namespace Nz NazaraUnused(dst); NazaraUnused(end); - NazaraInternalError("Conversion from " + PixelFormat::ToString(from) + " to " + PixelFormat::ToString(to) + " is not supported"); + NazaraInternalError("Conversion from " + PixelFormat::GetName(from) + " to " + PixelFormat::GetName(to) + " is not supported"); return nullptr; } @@ -1270,15 +1270,13 @@ namespace Nz PixelFormatType PixelFormat::IdentifyFormat(const PixelFormatInfo& info) { - switch (info.bitsPerPixel) + for (unsigned int i = 0; i <= PixelFormatType_Max; ++i) { - case 32: - if (info.redMask == Bitset<>(0xFF000000) && - info.greenMask == Bitset<>(0x00FF0000) && - info.blueMask == Bitset<>(0x0000FF00) && - info.alphaMask == Bitset<>(0x000000FF)) - return PixelFormatType_RGBA8; - break; + PixelFormatInfo& info2 = s_pixelFormatInfos[i]; + if (info.bitsPerPixel == info2.bitsPerPixel && info.content == info2.content && + info.redMask == info2.redMask && info.greenMask == info2.greenMask && info.blueMask == info2.blueMask && info.alphaMask == info2.alphaMask && + info.redType == info2.redType && info.greenType == info2.greenType && info.blueType == info2.blueType && info.alphaType == info2.alphaType) + return static_cast(i); } return PixelFormatType_Undefined; @@ -1286,7 +1284,67 @@ namespace Nz bool PixelFormat::Initialize() { - // Réinitialisation + // Setup informations about every pixel format + s_pixelFormatInfos[PixelFormatType_A8] = PixelFormatInfo("A8", PixelFormatContent_ColorRGBA, 0, 0, 0, 0xFF, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_BGR8] = PixelFormatInfo("BGR8", PixelFormatContent_ColorRGBA, 0x0000FF, 0x00FF00, 0xFF0000, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_BGRA8] = PixelFormatInfo("BGRA8", PixelFormatContent_ColorRGBA, 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_DXT1] = PixelFormatInfo("DXT1", PixelFormatContent_ColorRGBA, 8, PixelFormatSubType_Compressed); + s_pixelFormatInfos[PixelFormatType_DXT3] = PixelFormatInfo("DXT3", PixelFormatContent_ColorRGBA, 16, PixelFormatSubType_Compressed); + s_pixelFormatInfos[PixelFormatType_DXT5] = PixelFormatInfo("DXT5", PixelFormatContent_ColorRGBA, 16, PixelFormatSubType_Compressed); + s_pixelFormatInfos[PixelFormatType_L8] = PixelFormatInfo("L8", PixelFormatContent_ColorRGBA, 0xFF, 0xFF, 0xFF, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_LA8] = PixelFormatInfo("LA8", PixelFormatContent_ColorRGBA, 0xFF00, 0xFF00, 0xFF00, 0x00FF, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_R8] = PixelFormatInfo("R8", PixelFormatContent_ColorRGBA, 0xFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_R8I] = PixelFormatInfo("R8I", PixelFormatContent_ColorRGBA, 0xFF, 0, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_R8UI] = PixelFormatInfo("R8UI", PixelFormatContent_ColorRGBA, 0xFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_R16] = PixelFormatInfo("R16", PixelFormatContent_ColorRGBA, 0xFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_R16F] = PixelFormatInfo("R16F", PixelFormatContent_ColorRGBA, 0xFFFF, 0, 0, 0, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_R16I] = PixelFormatInfo("R16I", PixelFormatContent_ColorRGBA, 0xFFFF, 0, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_R16UI] = PixelFormatInfo("R16UI", PixelFormatContent_ColorRGBA, 0xFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_R32F] = PixelFormatInfo("R32F", PixelFormatContent_ColorRGBA, 0xFFFFFFFF, 0, 0, 0, PixelFormatSubType_Float); + s_pixelFormatInfos[PixelFormatType_R32I] = PixelFormatInfo("R32I", PixelFormatContent_ColorRGBA, 0xFFFFFFFF, 0, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_R32UI] = PixelFormatInfo("R32UI", PixelFormatContent_ColorRGBA, 0xFFFFFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RG8] = PixelFormatInfo("RG8", PixelFormatContent_ColorRGBA, 0xFF00, 0x00FF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RG8I] = PixelFormatInfo("RG8I", PixelFormatContent_ColorRGBA, 0xFF00, 0x00FF, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RG8UI] = PixelFormatInfo("RG8UI", PixelFormatContent_ColorRGBA, 0xFF00, 0x00FF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RG16] = PixelFormatInfo("RG16", PixelFormatContent_ColorRGBA, 0xFFFF0000, 0x0000FFFF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RG16F] = PixelFormatInfo("RG16F", PixelFormatContent_ColorRGBA, 0xFFFF0000, 0x0000FFFF, 0, 0, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_RG16I] = PixelFormatInfo("RG16I", PixelFormatContent_ColorRGBA, 0xFFFF0000, 0x0000FFFF, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RG16UI] = PixelFormatInfo("RG16UI", PixelFormatContent_ColorRGBA, 0xFFFF0000, 0x0000FFFF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RG32F] = PixelFormatInfo("RG32F", PixelFormatContent_ColorRGBA, 0xFFFFFFFF00000000, 0x00000000FFFFFFFF, 0, 0, PixelFormatSubType_Float); + s_pixelFormatInfos[PixelFormatType_RG32I] = PixelFormatInfo("RG32I", PixelFormatContent_ColorRGBA, 0xFFFFFFFF00000000, 0x00000000FFFFFFFF, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RG32UI] = PixelFormatInfo("RG32UI", PixelFormatContent_ColorRGBA, 0xFFFFFFFF00000000, 0x00000000FFFFFFFF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGB8] = PixelFormatInfo("RGB8", PixelFormatContent_ColorRGBA, 0xFF000000, 0x00FF0000, 0x0000FF00, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGB16F] = PixelFormatInfo("RGB16F", PixelFormatContent_ColorRGBA, 0xFFFF00000000, 0x0000FFFF0000, 0x00000000FFFF, 0, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_RGB16I] = PixelFormatInfo("RGB16I", PixelFormatContent_ColorRGBA, 0xFFFF00000000, 0x0000FFFF0000, 0x00000000FFFF, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RGB16UI] = PixelFormatInfo("RGB16UI", PixelFormatContent_ColorRGBA, 0xFFFF000000000000, 0x0000FFFF00000000, 0x00000000FFFF0000, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGB32F] = PixelFormatInfo("RGB32F", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_RGB32I] = PixelFormatInfo("RGB32I", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RGB32UI] = PixelFormatInfo("RGB32UI", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGBA4] = PixelFormatInfo("RGBA4", PixelFormatContent_ColorRGBA, 0xF000, 0x0F00, 0x00F0, 0x000F, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGB5A1] = PixelFormatInfo("RGB5A1", PixelFormatContent_ColorRGBA, 0xF800, 0x07C0, 0x003E, 0x0001, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGBA8] = PixelFormatInfo("RGBA8", PixelFormatContent_ColorRGBA, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGBA16F] = PixelFormatInfo("RGBA16F", PixelFormatContent_ColorRGBA, 0xFFFF000000000000, 0x0000FFFF00000000, 0x00000000FFFF0000, 0x000000000000FFFF, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_RGBA16I] = PixelFormatInfo("RGBA16I", PixelFormatContent_ColorRGBA, 0xFFFF000000000000, 0x0000FFFF00000000, 0x00000000FFFF0000, 0x000000000000FFFF, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RGBA16UI] = PixelFormatInfo("RGBA16UI", PixelFormatContent_ColorRGBA, 0xFFFF000000000000, 0x0000FFFF00000000, 0x00000000FFFF0000, 0x000000000000FFFF, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_RGBA32F] = PixelFormatInfo("RGBA32F", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Half); + s_pixelFormatInfos[PixelFormatType_RGBA32I] = PixelFormatInfo("RGBA32I", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Int); + s_pixelFormatInfos[PixelFormatType_RGBA32UI] = PixelFormatInfo("RGBA32UI", PixelFormatContent_ColorRGBA, 0, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Depth16] = PixelFormatInfo("Depth16", PixelFormatContent_DepthStencil, 0xFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Depth24] = PixelFormatInfo("Depth24", PixelFormatContent_DepthStencil, 0xFFFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Depth24Stencil8] = PixelFormatInfo("Depth24Stencil8", PixelFormatContent_DepthStencil, 0xFFFFFF00, 0x000000FF, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Depth32] = PixelFormatInfo("Depth32", PixelFormatContent_DepthStencil, 0xFFFFFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Stencil1] = PixelFormatInfo("Stencil1", PixelFormatContent_Stencil, 0x1, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Stencil4] = PixelFormatInfo("Stencil4", PixelFormatContent_Stencil, 0xF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Stencil8] = PixelFormatInfo("Stencil8", PixelFormatContent_Stencil, 0xFF, 0, 0, 0, PixelFormatSubType_Unsigned); + s_pixelFormatInfos[PixelFormatType_Stencil16] = PixelFormatInfo("Stencil16", PixelFormatContent_Stencil, 0xFFFF, 0, 0, 0, PixelFormatSubType_Unsigned); + + for (unsigned int i = 0; i <= PixelFormatType_Max; ++i) + { + if (!s_pixelFormatInfos[i].Validate()) + NazaraWarning("Pixel format 0x" + String::Number(i, 16) + " (" + GetName(static_cast(i)) + ") failed validation tests"); + } + + // Reset functions std::memset(s_convertFunctions, 0, (PixelFormatType_Max+1)*(PixelFormatType_Max+1)*sizeof(PixelFormat::ConvertFunction)); /***********************************A8************************************/ @@ -1511,12 +1569,16 @@ namespace Nz void PixelFormat::Uninitialize() { + for (unsigned int i = 0; i <= PixelFormatType_Max; ++i) + s_pixelFormatInfos[i].Clear(); + std::memset(s_convertFunctions, 0, (PixelFormatType_Max+1)*(PixelFormatType_Max+1)*sizeof(PixelFormat::ConvertFunction)); for (unsigned int i = 0; i <= PixelFlipping_Max; ++i) s_flipFunctions[i].clear(); } + PixelFormatInfo PixelFormat::s_pixelFormatInfos[PixelFormatType_Max + 1]; PixelFormat::ConvertFunction PixelFormat::s_convertFunctions[PixelFormatType_Max+1][PixelFormatType_Max+1]; std::map PixelFormat::s_flipFunctions[PixelFlipping_Max+1]; }