Utility/PixelFormat: Add preliminary support for SRGB formats (WIP)
This commit is contained in:
@@ -15,11 +15,16 @@ namespace Nz
|
||||
// TODO: Fill this switch
|
||||
switch (pixelFormat)
|
||||
{
|
||||
case PixelFormat_A8: return GLTextureFormat { GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
|
||||
case PixelFormat_BGR8: return GLTextureFormat { GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
|
||||
case PixelFormat_BGRA8: return GLTextureFormat { GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
|
||||
case PixelFormat_RGB8: return GLTextureFormat { GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
|
||||
case PixelFormat_RGBA8: return GLTextureFormat { GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
|
||||
case PixelFormat_A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
|
||||
case PixelFormat_BGR8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
|
||||
case PixelFormat_BGR8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
|
||||
case PixelFormat_BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
|
||||
case PixelFormat_BGRA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
|
||||
case PixelFormat_Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
|
||||
case PixelFormat_RGB8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
|
||||
case PixelFormat_RGB8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
|
||||
case PixelFormat_RGBA8: return GLTextureFormat{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
|
||||
case PixelFormat_RGBA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,9 @@ namespace Nz
|
||||
|
||||
PixelFormat_A8, // 1*uint8
|
||||
PixelFormat_BGR8, // 3*uint8
|
||||
PixelFormat_BGR8_SRGB, // 3*uint8
|
||||
PixelFormat_BGRA8, // 4*uint8
|
||||
PixelFormat_BGRA8_SRGB, // 4*uint8
|
||||
PixelFormat_DXT1,
|
||||
PixelFormat_DXT3,
|
||||
PixelFormat_DXT5,
|
||||
@@ -202,6 +204,7 @@ namespace Nz
|
||||
PixelFormat_RG32UI, // 2*uint32
|
||||
PixelFormat_RGB5A1, // 3*uint5 + alpha bit
|
||||
PixelFormat_RGB8, // 3*uint8
|
||||
PixelFormat_RGB8_SRGB, // 3*uint8
|
||||
PixelFormat_RGB16F, // 3*half
|
||||
PixelFormat_RGB16I, // 4*int16
|
||||
PixelFormat_RGB16UI, // 4*uint16
|
||||
@@ -210,6 +213,7 @@ namespace Nz
|
||||
PixelFormat_RGB32UI, // 4*uint32
|
||||
PixelFormat_RGBA4, // 4*uint4
|
||||
PixelFormat_RGBA8, // 4*uint8
|
||||
PixelFormat_RGBA8_SRGB, // 4*uint8
|
||||
PixelFormat_RGBA16F, // 4*half
|
||||
PixelFormat_RGBA16I, // 4*int16
|
||||
PixelFormat_RGBA16UI, // 4*uint16
|
||||
|
||||
@@ -185,27 +185,14 @@ namespace Nz
|
||||
}
|
||||
#endif
|
||||
|
||||
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
|
||||
if (!func)
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(reinterpret_cast<const UInt8*>(src), reinterpret_cast<const UInt8*>(src) + GetBytesPerPixel(srcFormat), reinterpret_cast<UInt8*>(dst)))
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Convert(srcFormat, dstFormat, src, static_cast<const UInt8*>(src) + GetBytesPerPixel(srcFormat), dst);
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::Convert(PixelFormat srcFormat, PixelFormat dstFormat, const void* start, const void* end, void* dst)
|
||||
{
|
||||
if (srcFormat == dstFormat)
|
||||
{
|
||||
std::memcpy(dst, start, reinterpret_cast<const UInt8*>(end)-reinterpret_cast<const UInt8*>(start));
|
||||
std::memcpy(dst, start, reinterpret_cast<const UInt8*>(end) - reinterpret_cast<const UInt8*>(start));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,11 @@ namespace Nz
|
||||
switch (format)
|
||||
{
|
||||
case VK_FORMAT_B8G8R8A8_UNORM: return PixelFormat::PixelFormat_BGRA8;
|
||||
case VK_FORMAT_B8G8R8A8_SRGB: return PixelFormat::PixelFormat_BGRA8_SRGB;
|
||||
case VK_FORMAT_D24_UNORM_S8_UINT: return PixelFormat::PixelFormat_Depth24Stencil8;
|
||||
case VK_FORMAT_D32_SFLOAT: return PixelFormat::PixelFormat_Depth32;
|
||||
case VK_FORMAT_R8G8B8A8_UNORM: return PixelFormat::PixelFormat_RGBA8;
|
||||
case VK_FORMAT_R8G8B8A8_SRGB: return PixelFormat::PixelFormat_RGBA8_SRGB;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user