Added support for sRGB texture formats

This commit is contained in:
Matthew Reid
2020-10-12 15:13:38 +11:00
committed by Robert Osfield
parent bf279a59fa
commit 073cfab166
5 changed files with 100 additions and 58 deletions

View File

@@ -62,6 +62,10 @@
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
#endif
#ifndef GL_EXT_texture_compression_rgtc

View File

@@ -537,9 +537,12 @@ unsigned int Image::computeNumComponents(GLenum pixelFormat)
switch(pixelFormat)
{
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): return 3;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return 4;
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT): return 3;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return 4;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return 4;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT): return 4;
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT): return 1;
case(GL_COMPRESSED_RED_RGTC1_EXT): return 1;
case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): return 2;
@@ -718,10 +721,14 @@ unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type)
switch(format)
{
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return 8;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return 8;
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT): return 4;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return 8;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT): return 8;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return 8;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT): return 8;
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT): return 4;
case(GL_COMPRESSED_RED_RGTC1_EXT): return 4;
case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): return 8;
@@ -941,11 +948,15 @@ unsigned int Image::computeBlockSize(GLenum pixelFormat, GLenum packing)
{
switch(pixelFormat)
{
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
return osg::maximum(8u,packing); // block size of 8
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT):
return osg::maximum(8u, packing); // block size of 8
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG):
case(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG):
case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG):
@@ -1095,9 +1106,13 @@ bool Image::isCompressed() const
case(GL_COMPRESSED_RGBA_ARB):
case(GL_COMPRESSED_RGB_ARB):
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT):
case(GL_COMPRESSED_RED_RGTC1_EXT):
case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT):
@@ -2013,10 +2028,14 @@ bool Image::isImageTranslucent() const
case(GL_BGR):
return false;
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT):
return false;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
return dxtc_tool::isCompressedImageTranslucent(_s, _t, _pixelFormat, _data);
default:
return false;

View File

@@ -196,10 +196,10 @@ InternalPixelRelations compressedInternalFormats[] = {
, { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT , GL_RGBA , GL_COMPRESSED_RGBA_S3TC_DXT3_EXT }
, { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT , GL_RGBA , GL_COMPRESSED_RGBA_S3TC_DXT5_EXT }
// , { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT , GL_RGB , GL_COMPRESSED_SRGB_S3TC_DXT1_EXT }
// , { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT }
// , { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT }
// , { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT }
, { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT , GL_RGB , GL_COMPRESSED_SRGB_S3TC_DXT1_EXT }
, { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT }
, { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT }
, { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT , GL_RGBA , GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT }
};
bool isSizedInternalFormat(GLint internalFormat)
@@ -304,15 +304,19 @@ void Texture::TextureProfile::computeSize()
case(GL_RGBA): numBitsPerTexel = 32; break;
case(4): numBitsPerTexel = 32; break;
case(GL_COMPRESSED_ALPHA_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_INTENSITY_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGB_ARB): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_ALPHA_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_INTENSITY_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RGB_ARB): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT): numBitsPerTexel = 8; break;
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT): numBitsPerTexel = 4; break;
case(GL_COMPRESSED_RED_RGTC1_EXT): numBitsPerTexel = 4; break;
@@ -1793,7 +1797,9 @@ bool Texture::isCompressedInternalFormat(GLint internalFormat)
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT):
case(GL_COMPRESSED_RED_RGTC1_EXT):
case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT):
@@ -2150,16 +2156,20 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
OSG_NOTICE<<"Received a request to compress an image, but image size is not a multiple of four ("<<inwidth<<"x"<<inheight<<"). Reverting to uncompressed.\n";
switch(_internalFormat)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
case GL_ETC1_RGB8_OES:
case(GL_COMPRESSED_RGB8_ETC2):
case(GL_COMPRESSED_SRGB8_ETC2):
case GL_COMPRESSED_RGB: _internalFormat = GL_RGB; break;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
case GL_ETC1_RGB8_OES:
case(GL_COMPRESSED_RGB8_ETC2):
case(GL_COMPRESSED_SRGB8_ETC2):
case GL_COMPRESSED_RGB: _internalFormat = GL_RGB; break;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
case(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2):

View File

@@ -190,10 +190,12 @@ bool isCompressedImageTranslucent(size_t width, size_t height, GLenum format, vo
int blockCount = ((width + 3) >> 2) * ((height + 3) >> 2);
switch(format)
{
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
return false;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT):
return false;
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT):
{
const DXT1TexelsBlock *texelsBlock = reinterpret_cast<const DXT1TexelsBlock*>(imageData);
@@ -230,6 +232,7 @@ bool isCompressedImageTranslucent(size_t width, size_t height, GLenum format, vo
}
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
{
const DXT3TexelsBlock *texelsBlock = reinterpret_cast<const DXT3TexelsBlock*>(imageData);
// Only do the check on the first mipmap level, and stop when we see the first alpha texel
@@ -246,6 +249,7 @@ bool isCompressedImageTranslucent(size_t width, size_t height, GLenum format, vo
return false;
}
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
{
const DXT5TexelsBlock *texelsBlock = reinterpret_cast<const DXT5TexelsBlock*>(imageData);
// Only do the check on the first mipmap level, and stop when we see the first alpha texel

View File

@@ -158,6 +158,10 @@ inline bool isDXTC(GLenum pixelFormat)
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT):
return true;
default:
return false;
@@ -178,18 +182,19 @@ inline dxtc_pixels::dxtc_pixels(size_t Width, size_t Height, GLenum Format, void
m_Width(Width), m_Height(Height), m_Format(Format), m_pPixels(pPixels) { }
inline bool dxtc_pixels::DXT1() const {
return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (m_Format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT));
}
inline bool dxtc_pixels::DXT3() const {
return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
}
inline bool dxtc_pixels::DXT5() const {
return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
inline bool dxtc_pixels::DXT1() const {
return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (m_Format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
|| (m_Format == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT) || (m_Format == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT));
}
inline bool dxtc_pixels::DXT3() const {
return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) || (m_Format == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT));
}
inline bool dxtc_pixels::DXT5() const {
return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) || (m_Format == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT));
}