diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 25e09c10a..a5aec05bc 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -130,6 +130,7 @@ enum nzPixelFormat { nzPixelFormat_Undefined = -1, + nzPixelFormat_A8, // 1*uint8 nzPixelFormat_BGR8, // 3*uint8 nzPixelFormat_BGRA8, // 4*uint8 nzPixelFormat_DXT1, diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index c92f8b8c0..2154d2f05 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -168,6 +168,9 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format) { switch (format) { + case nzPixelFormat_A8: + return 8; + case nzPixelFormat_BGR8: return 24; @@ -287,20 +290,14 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format) inline nzUInt8 NzPixelFormat::GetBytesPerPixel(nzPixelFormat format) { - nzUInt8 bytesPerPixel = GetBitsPerPixel(format)/8; - - #if NAZARA_UTILITY_SAFE - if (bytesPerPixel == 0) - NazaraWarning("This format is either invalid or using less than one byte per pixel"); - #endif - - return bytesPerPixel; + return GetBitsPerPixel(format)/8; } inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format) { switch (format) { + case nzPixelFormat_A8: case nzPixelFormat_BGR8: case nzPixelFormat_BGRA8: case nzPixelFormat_DXT1: @@ -372,6 +369,7 @@ inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) { switch (format) { + case nzPixelFormat_A8: case nzPixelFormat_BGRA8: case nzPixelFormat_DXT3: case nzPixelFormat_DXT5: @@ -444,6 +442,7 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format) case nzPixelFormat_DXT5: return true; + case nzPixelFormat_A8: case nzPixelFormat_BGR8: case nzPixelFormat_BGRA8: case nzPixelFormat_L8: @@ -529,6 +528,9 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format) { switch (format) { + case nzPixelFormat_A8: + return "A8"; + case nzPixelFormat_BGR8: return "BGR8"; diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index ef9e096d9..3c8b5c872 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1465,6 +1465,9 @@ bool NzOpenGL::TranslateFormat(nzPixelFormat pixelFormat, Format* format, Format { switch (pixelFormat) { + case nzPixelFormat_A8: + return false; ///FIXME: Tester le mode d'OpenGL pour se permettre une fonctionnalité dépréciée ? + case nzPixelFormat_BGR8: format->dataFormat = GL_BGR; format->dataType = GL_UNSIGNED_BYTE; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index cb5b4ff45..b2d59cb6e 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -1272,6 +1272,13 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format) case nzPixelFormat_RGBA32UI: return NzOpenGL::GetVersion() >= 300; + // Dépréciés depuis OpenGL 3 + ///FIXME: Accepter si le contexte OpenGL est de compatibilité/OpenGL 2 ? + case nzPixelFormat_A8: + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + return false; + // Formats de profondeur (Supportés avec les FBOs) case nzPixelFormat_Depth16: case nzPixelFormat_Depth24: @@ -1286,12 +1293,7 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format) case nzPixelFormat_Stencil16: return false; - // Dépréciés depuis OpenGL 3 - ///FIXME: Il doit bien exister des remplaçants (GL_RED ?) - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - return false; - + // Formats compressés case nzPixelFormat_DXT1: case nzPixelFormat_DXT3: case nzPixelFormat_DXT5: @@ -1302,7 +1304,6 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format) } NazaraError("Invalid pixel format"); - return false; } diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index 776781251..07fc36431 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -50,6 +50,94 @@ namespace return nullptr; } + /**********************************A8***********************************/ + template<> + nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) + { + while (start < end) + { + *dst++ = 0xFF; + *dst++ = 0xFF; + *dst++ = 0xFF; + *dst++ = *start; + + start += 1; + } + + return dst; + } + + template<> + nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) + { + while (start < end) + { + *dst++ = 0xFF; + *dst++ = *start; + + start += 1; + } + + return dst; + } + + template<> + nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) + { + nzUInt16* ptr = reinterpret_cast(dst); + while (start < end) + { + *ptr = (static_cast(c8to5(start[2])) << 11) | + (static_cast(c8to5(start[1])) << 6) | + (static_cast(c8to5(start[0])) << 1) | + ((*start > 0xF) ? 1 : 0); // > 128 + + #ifdef NAZARA_BIG_ENDIAN + NzByteSwap(ptr, sizeof(nzUInt16)); + #endif + + ptr++; + start += 1; + } + + return reinterpret_cast(ptr); + } + + template<> + nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) + { + nzUInt16* ptr = reinterpret_cast(dst); + while (start < end) + { + *ptr = 0xFFF0 | c8to4(*start); + + #ifdef NAZARA_BIG_ENDIAN + NzByteSwap(ptr, sizeof(nzUInt16)); + #endif + + ptr++; + start += 1; + } + + return dst; + } + + template<> + nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) + { + while (start < end) + { + *dst++ = 0xFF; + *dst++ = 0xFF; + *dst++ = 0xFF; + *dst++ = *start; + + start += 1; + } + + return dst; + } + /**********************************BGR8***********************************/ template<> nzUInt8* ConvertPixels(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst) @@ -243,7 +331,7 @@ namespace *ptr = (static_cast(c8to5(start[2])) << 11) | (static_cast(c8to5(start[1])) << 6) | (static_cast(c8to5(start[0])) << 1) | - ((start[3] == 0xFF) ? 1 : 0); + ((start[3] > 0xF) ? 1 : 0); // > 128 #ifdef NAZARA_BIG_ENDIAN NzByteSwap(ptr, sizeof(nzUInt16)); @@ -465,7 +553,7 @@ namespace { nzUInt16 l = static_cast(c8to5(start[0])); - *ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] == 0xFF) ? 1 : 0); + *ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] > 0xF) ? 1 : 0); #ifdef NAZARA_BIG_ENDIAN NzByteSwap(ptr, sizeof(nzUInt16)); @@ -638,7 +726,7 @@ namespace nzUInt16 b = c4to5((pixel & 0x00F0) >> 4); nzUInt16 a = c4to5((pixel & 0x000F) >> 0); - *ptr = (r << 11) | (g << 6) | (b << 1) | ((a == 0xFF) ? 1 : 0); + *ptr = (r << 11) | (g << 6) | (b << 1) | ((a > 0x3) ? 1 : 0); #ifdef NAZARA_BIG_ENDIAN NzByteSwap(ptr, sizeof(nzUInt16)); @@ -1044,7 +1132,7 @@ namespace *ptr = (static_cast(c8to5(start[0])) << 11) | (static_cast(c8to5(start[1])) << 6) | (static_cast(c8to5(start[2])) << 1) | - ((start[3] == 0xFF) ? 1 : 0); + ((start[3] > 0xF) ? 1 : 0); // > 128 #ifdef NAZARA_BIG_ENDIAN NzByteSwap(ptr, sizeof(nzUInt16)); @@ -1106,6 +1194,13 @@ bool NzPixelFormat::Initialize() // Réinitialisation std::memset(s_convertFunctions, 0, (nzPixelFormat_Max+1)*(nzPixelFormat_Max+1)*sizeof(NzPixelFormat::ConvertFunction)); + /***********************************A8************************************/ + RegisterConverter(); + RegisterConverter(); + RegisterConverter(); + RegisterConverter(); + RegisterConverter(); + /**********************************BGR8***********************************/ RegisterConverter(); RegisterConverter();