mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
GL: Added sRGB texture caps.
This commit is contained in:
parent
bd17691a41
commit
d4cde9cbfa
2 changed files with 80 additions and 54 deletions
|
@ -178,6 +178,7 @@ namespace bgfx { namespace gl
|
|||
struct TextureFormatInfo
|
||||
{
|
||||
GLenum m_internalFmt;
|
||||
GLenum m_internalFmtSrgb;
|
||||
GLenum m_fmt;
|
||||
GLenum m_type;
|
||||
bool m_supported;
|
||||
|
@ -185,55 +186,55 @@ namespace bgfx { namespace gl
|
|||
|
||||
static TextureFormatInfo s_textureFormat[] =
|
||||
{
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3
|
||||
{ GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4
|
||||
{ GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5
|
||||
{ GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H
|
||||
{ GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7
|
||||
{ GL_ETC1_RGB8_OES, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1
|
||||
{ GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2
|
||||
{ GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A
|
||||
{ GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1
|
||||
{ GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12
|
||||
{ GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1
|
||||
{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, false }, // R8
|
||||
{ GL_R16, GL_RED, GL_UNSIGNED_SHORT, false }, // R16
|
||||
{ GL_R16F, GL_RED, GL_HALF_FLOAT, false }, // R16F
|
||||
{ GL_R32UI, GL_RED, GL_UNSIGNED_INT, false }, // R32
|
||||
{ GL_R32F, GL_RED, GL_FLOAT, false }, // R32F
|
||||
{ GL_RG8, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8
|
||||
{ GL_RG16, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16
|
||||
{ GL_RG16F, GL_RG, GL_FLOAT, false }, // RG16F
|
||||
{ GL_RG32UI, GL_RG, GL_UNSIGNED_INT, false }, // RG32
|
||||
{ GL_RG32F, GL_RG, GL_FLOAT, false }, // RG32F
|
||||
{ GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
|
||||
{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
|
||||
{ GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16
|
||||
{ GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F
|
||||
{ GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32
|
||||
{ GL_RGBA32F, GL_RGBA, GL_FLOAT, false }, // RGBA32F
|
||||
{ GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5
|
||||
{ GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, false }, // RGBA4
|
||||
{ GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, false }, // RGB5A1
|
||||
{ GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2
|
||||
{ GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // R11G11B10F
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth
|
||||
{ GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16
|
||||
{ GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24
|
||||
{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8
|
||||
{ GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F
|
||||
{ GL_STENCIL_INDEX8, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2
|
||||
{ GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3
|
||||
{ GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4
|
||||
{ GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5
|
||||
{ GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H
|
||||
{ GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7
|
||||
{ GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1
|
||||
{ GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2
|
||||
{ GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A
|
||||
{ GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1
|
||||
{ GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12
|
||||
{ GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22
|
||||
{ GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1
|
||||
{ GL_R8, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8
|
||||
{ GL_R16, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16
|
||||
{ GL_R16F, GL_ZERO, GL_RED, GL_HALF_FLOAT, false }, // R16F
|
||||
{ GL_R32UI, GL_ZERO, GL_RED, GL_UNSIGNED_INT, false }, // R32
|
||||
{ GL_R32F, GL_ZERO, GL_RED, GL_FLOAT, false }, // R32F
|
||||
{ GL_RG8, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8
|
||||
{ GL_RG16, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16
|
||||
{ GL_RG16F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG16F
|
||||
{ GL_RG32UI, GL_ZERO, GL_RG, GL_UNSIGNED_INT, false }, // RG32
|
||||
{ GL_RG32F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG32F
|
||||
{ GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8
|
||||
{ GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8
|
||||
{ GL_RGBA16, GL_ZERO, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16
|
||||
{ GL_RGBA16F, GL_ZERO, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F
|
||||
{ GL_RGBA32UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32
|
||||
{ GL_RGBA32F, GL_ZERO, GL_RGBA, GL_FLOAT, false }, // RGBA32F
|
||||
{ GL_RGB565, GL_ZERO, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5
|
||||
{ GL_RGBA4, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, false }, // RGBA4
|
||||
{ GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, false }, // RGB5A1
|
||||
{ GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2
|
||||
{ GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // R11G11B10F
|
||||
{ GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth
|
||||
{ GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16
|
||||
{ GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24
|
||||
{ GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8
|
||||
{ GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32
|
||||
{ GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F
|
||||
{ GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F
|
||||
{ GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8
|
||||
};
|
||||
BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) );
|
||||
|
||||
|
@ -944,10 +945,14 @@ namespace bgfx { namespace gl
|
|||
tfi.m_type = _type;
|
||||
}
|
||||
|
||||
bool isTextureFormatValid(TextureFormat::Enum _format)
|
||||
bool isTextureFormatValid(TextureFormat::Enum _format, bool srgb = false)
|
||||
{
|
||||
const TextureFormatInfo& tfi = s_textureFormat[_format];
|
||||
if (GL_ZERO == tfi.m_internalFmt)
|
||||
GLenum internalFmt = srgb
|
||||
? tfi.m_internalFmtSrgb
|
||||
: tfi.m_internalFmt
|
||||
;
|
||||
if (GL_ZERO == internalFmt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -961,11 +966,11 @@ namespace bgfx { namespace gl
|
|||
|
||||
if (isCompressed(_format) )
|
||||
{
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, 0, tfi.m_internalFmt, 16, 16, 0, size, data);
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, 0, internalFmt, 16, 16, 0, size, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, tfi.m_internalFmt, 16, 16, 0, tfi.m_fmt, tfi.m_type, data);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, 16, 16, 0, tfi.m_fmt, tfi.m_type, data);
|
||||
}
|
||||
|
||||
GLenum err = glGetError();
|
||||
|
@ -1344,7 +1349,7 @@ namespace bgfx { namespace gl
|
|||
if (TextureFormat::Unknown != ii
|
||||
&& TextureFormat::UnknownDepth != ii)
|
||||
{
|
||||
s_textureFormat[ii].m_supported = isTextureFormatValid( (TextureFormat::Enum)ii);
|
||||
s_textureFormat[ii].m_supported = isTextureFormatValid(TextureFormat::Enum(ii) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1371,6 +1376,11 @@ namespace bgfx { namespace gl
|
|||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
supported |= isTextureFormatValid(TextureFormat::Enum(ii), true)
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB
|
||||
: BGFX_CAPS_FORMAT_TEXTURE_NONE
|
||||
;
|
||||
|
||||
supported |= computeSupport
|
||||
&& GL_ZERO != s_imageFormat[ii]
|
||||
? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
|
||||
|
|
|
@ -305,6 +305,22 @@ typedef uint64_t GLuint64;
|
|||
# define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
|
||||
#endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG
|
||||
|
||||
#ifndef GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT
|
||||
# define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
|
||||
#endif // GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT
|
||||
|
||||
#ifndef GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT
|
||||
# define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
|
||||
#endif // GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT
|
||||
|
||||
#ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT
|
||||
# define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
|
||||
#endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT
|
||||
|
||||
#ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT
|
||||
# define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
|
||||
#endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT
|
||||
|
||||
#ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
|
||||
# define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
|
||||
#endif // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
|
||||
|
|
Loading…
Reference in a new issue