Added OpenGL support for pixel formats A8/L8/LA8
Former-commit-id: b17942f7bf22daf90ddf5d8093da6c26b64a67ce
This commit is contained in:
parent
96798da027
commit
7316cbb694
|
|
@ -69,6 +69,7 @@ class NAZARA_API NzOpenGL
|
||||||
GLenum dataFormat;
|
GLenum dataFormat;
|
||||||
GLenum dataType;
|
GLenum dataType;
|
||||||
GLint internalFormat;
|
GLint internalFormat;
|
||||||
|
GLint swizzle[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
NzOpenGL() = delete;
|
NzOpenGL() = delete;
|
||||||
|
|
|
||||||
|
|
@ -1463,10 +1463,41 @@ void NzOpenGL::SetViewport(const NzRecti& viewport)
|
||||||
|
|
||||||
bool NzOpenGL::TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType type)
|
bool NzOpenGL::TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType type)
|
||||||
{
|
{
|
||||||
|
// Par défaut
|
||||||
|
format->swizzle[0] = GL_RED;
|
||||||
|
format->swizzle[1] = GL_GREEN;
|
||||||
|
format->swizzle[2] = GL_BLUE;
|
||||||
|
format->swizzle[3] = GL_ALPHA;
|
||||||
|
|
||||||
switch (pixelFormat)
|
switch (pixelFormat)
|
||||||
{
|
{
|
||||||
case nzPixelFormat_A8:
|
case nzPixelFormat_A8:
|
||||||
return false; ///FIXME: Tester le mode d'OpenGL pour se permettre une fonctionnalité dépréciée ?
|
if (type == FormatType_Texture) // Format supporté uniquement par les textures
|
||||||
|
{
|
||||||
|
if (GetVersion() >= 300)
|
||||||
|
{
|
||||||
|
format->dataFormat = GL_RED;
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = GL_R8;
|
||||||
|
|
||||||
|
// Simulation du format
|
||||||
|
format->swizzle[0] = GL_ONE;
|
||||||
|
format->swizzle[1] = GL_ONE;
|
||||||
|
format->swizzle[2] = GL_ONE;
|
||||||
|
format->swizzle[3] = GL_RED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Le bon vieux format GL_ALPHA
|
||||||
|
format->dataFormat = GL_ALPHA;
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = GL_ALPHA;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
case nzPixelFormat_BGR8:
|
case nzPixelFormat_BGR8:
|
||||||
format->dataFormat = GL_BGR;
|
format->dataFormat = GL_BGR;
|
||||||
|
|
@ -1499,8 +1530,58 @@ bool NzOpenGL::TranslateFormat(nzPixelFormat pixelFormat, Format* format, Format
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case nzPixelFormat_L8:
|
case nzPixelFormat_L8:
|
||||||
|
if (type == FormatType_Texture) // Format supporté uniquement par les textures
|
||||||
|
{
|
||||||
|
if (GetVersion() >= 300)
|
||||||
|
{
|
||||||
|
format->dataFormat = GL_RED;
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = GL_R8;
|
||||||
|
|
||||||
|
// Simulation du format
|
||||||
|
format->swizzle[0] = GL_RED;
|
||||||
|
format->swizzle[1] = GL_RED;
|
||||||
|
format->swizzle[2] = GL_RED;
|
||||||
|
format->swizzle[3] = GL_ONE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format->dataFormat = 0x1909; // GL_LUMINANCE
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = 0x1909; // GL_LUMINANCE
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
case nzPixelFormat_LA8:
|
case nzPixelFormat_LA8:
|
||||||
return false;
|
if (type == FormatType_Texture) // Format supporté uniquement par les textures
|
||||||
|
{
|
||||||
|
if (GetVersion() >= 300)
|
||||||
|
{
|
||||||
|
format->dataFormat = GL_RG;
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = GL_RG8;
|
||||||
|
|
||||||
|
// Simulation du format
|
||||||
|
format->swizzle[0] = GL_RED;
|
||||||
|
format->swizzle[1] = GL_RED;
|
||||||
|
format->swizzle[2] = GL_RED;
|
||||||
|
format->swizzle[3] = GL_GREEN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format->dataFormat = 0x190A; // GL_LUMINANCE_ALPHA
|
||||||
|
format->dataType = GL_UNSIGNED_BYTE;
|
||||||
|
format->internalFormat = 0x190A; // GL_LUMINANCE_ALPHA;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
case nzPixelFormat_R8:
|
case nzPixelFormat_R8:
|
||||||
format->dataFormat = GL_RED;
|
format->dataFormat = GL_RED;
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,15 @@ namespace
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Application du swizzle
|
||||||
|
if (NzOpenGL::GetVersion() >= 300)
|
||||||
|
{
|
||||||
|
glTexParameteri(target, GL_TEXTURE_SWIZZLE_R, openGLFormat.swizzle[0]);
|
||||||
|
glTexParameteri(target, GL_TEXTURE_SWIZZLE_G, openGLFormat.swizzle[1]);
|
||||||
|
glTexParameteri(target, GL_TEXTURE_SWIZZLE_B, openGLFormat.swizzle[2]);
|
||||||
|
glTexParameteri(target, GL_TEXTURE_SWIZZLE_A, openGLFormat.swizzle[3]);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1226,8 +1235,11 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
// Formats de base
|
// Formats de base
|
||||||
|
case nzPixelFormat_A8:
|
||||||
case nzPixelFormat_BGR8:
|
case nzPixelFormat_BGR8:
|
||||||
case nzPixelFormat_BGRA8:
|
case nzPixelFormat_BGRA8:
|
||||||
|
case nzPixelFormat_L8:
|
||||||
|
case nzPixelFormat_LA8:
|
||||||
case nzPixelFormat_RGB8:
|
case nzPixelFormat_RGB8:
|
||||||
case nzPixelFormat_RGBA8:
|
case nzPixelFormat_RGBA8:
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1272,13 +1284,6 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
|
||||||
case nzPixelFormat_RGBA32UI:
|
case nzPixelFormat_RGBA32UI:
|
||||||
return NzOpenGL::GetVersion() >= 300;
|
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)
|
// Formats de profondeur (Supportés avec les FBOs)
|
||||||
case nzPixelFormat_Depth16:
|
case nzPixelFormat_Depth16:
|
||||||
case nzPixelFormat_Depth24:
|
case nzPixelFormat_Depth24:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue