Utility: Rework PixelFormat (WIP)

Former-commit-id: bb48562e5f5caac023fcfca7840931aaae7a7821
This commit is contained in:
Lynix
2016-05-17 14:23:45 +02:00
parent 4ecc701ad2
commit 8a38bb767d
9 changed files with 306 additions and 561 deletions

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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);