summaryrefslogtreecommitdiff
path: root/indra/llrender/llimagegl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llrender/llimagegl.cpp')
-rw-r--r--indra/llrender/llimagegl.cpp139
1 files changed, 128 insertions, 11 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 3f8903ca09..0146ed3119 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -301,30 +301,48 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
{
switch (dataformat)
{
+#if GL_VERSION_3_0
case GL_COMPRESSED_RED: return 8;
case GL_COMPRESSED_RG: return 16;
+#endif
+#if GL_VERSION_1_3
case GL_COMPRESSED_RGB: return 24;
+#endif
+#if GL_VERSION_2_1
case GL_COMPRESSED_SRGB: return 32;
+#endif
+#if GL_VERSION_1_3
case GL_COMPRESSED_RGBA: return 32;
+#endif
+#if GL_VERSION_2_1
case GL_COMPRESSED_SRGB_ALPHA: return 32;
+#endif
+#if GL_VERSION_1_3
case GL_COMPRESSED_LUMINANCE: return 8;
case GL_COMPRESSED_LUMINANCE_ALPHA: return 16;
case GL_COMPRESSED_ALPHA: return 8;
+#endif
+#if GL_EXT_texture_compression_s3tc || GL_EXT_texture_compression_dxt1
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;
+#endif
+#if GL_EXT_texture_sRGB || GL_EXT_texture_compression_s3tc_srgb
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8;
+#endif
case GL_LUMINANCE: return 8;
- case GL_LUMINANCE8: return 8;
case GL_ALPHA: return 8;
- case GL_ALPHA8: return 8;
case GL_RED: return 8;
case GL_R8: return 8;
+#if GL_VERSION_1_1
+ case GL_LUMINANCE8: return 8;
+ case GL_ALPHA8: return 8;
case GL_COLOR_INDEX: return 8;
- case GL_LUMINANCE_ALPHA: return 16;
case GL_LUMINANCE8_ALPHA8: return 16;
+#endif
+ case GL_LUMINANCE_ALPHA: return 16;
case GL_RG: return 16;
case GL_RG8: return 16;
case GL_RGB: return 24;
@@ -334,8 +352,10 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
case GL_RGBA: return 32;
case GL_RGBA8: return 32;
case GL_RGB10_A2: return 32;
+#if GL_VERSION_2_1
case GL_SRGB_ALPHA: return 32;
case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac
+#endif
case GL_DEPTH_COMPONENT: return 24;
case GL_DEPTH_COMPONENT24: return 24;
case GL_R16F: return 16;
@@ -357,6 +377,8 @@ S64 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height)
{
switch (dataformat)
{
+#if GL_EXT_texture_compression_s3tc || GL_EXT_texture_compression_dxt1 \
+ || GL_EXT_texture_sRGB || GL_EXT_texture_compression_s3tc_srgb
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
@@ -366,6 +388,7 @@ S64 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height)
if (width < 4) width = 4;
if (height < 4) height = 4;
break;
+#endif
default:
break;
}
@@ -379,23 +402,31 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat)
{
switch (dataformat)
{
+#if GL_EXT_texture_compression_s3tc || GL_EXT_texture_compression_dxt1
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 3;
- case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 3;
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;
+#endif
+#if GL_EXT_texture_sRGB || GL_EXT_texture_compression_s3tc_srgb
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 3;
+ case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 4;
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 4;
+#endif
case GL_LUMINANCE: return 1;
case GL_ALPHA: return 1;
case GL_RED: return 1;
+#if GL_VERSION_1_1
case GL_COLOR_INDEX: return 1;
+#endif
case GL_LUMINANCE_ALPHA: return 2;
case GL_RG: return 2;
case GL_RGB: return 3;
case GL_SRGB: return 3;
case GL_RGBA: return 4;
+#if GL_VERSION_2_1
case GL_SRGB_ALPHA: return 4;
case GL_BGRA: return 4; // Used for QuickTime media textures on the Mac
+#endif
default:
LL_ERRS() << "LLImageGL::Unknown format: " << std::hex << dataformat << std::dec << LL_ENDL;
return 0;
@@ -409,6 +440,8 @@ void LLImageGL::updateStats(F32 current_time)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
sLastFrameTime = current_time;
+ sBindCount = 0;
+ sUniqueCount = 0;
}
//----------------------------------------------------------------------------
@@ -795,11 +828,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
}
else
{
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
LLImageGL::setManualImage(mTarget, gl_level, mFormatInternal, w, h, mFormatPrimary, GL_UNSIGNED_BYTE, (GLvoid*)data_in, mAllowCompression);
if (gl_level == 0)
@@ -808,11 +843,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
}
updatePickMask(w, h, data_in);
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
stop_glerror();
}
@@ -825,11 +862,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
{
stop_glerror();
{
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
S32 w = getWidth(mCurrentDiscardLevel);
S32 h = getHeight(mCurrentDiscardLevel);
@@ -839,10 +878,12 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
//use legacy mipmap generation mode (note: making this condional can cause rendering issues)
// -- but making it not conditional triggers deprecation warnings when core profile is enabled
// (some rendering issues while core profile is enabled are acceptable at this point in time)
+#if GL_VERSION_1_4
if (!LLRender::sGLCoreProfile)
{
glTexParameteri(mTarget, GL_GENERATE_MIPMAP, GL_TRUE);
}
+#endif
LLImageGL::setManualImage(mTarget, 0, mFormatInternal,
w, h,
@@ -853,11 +894,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
updatePickMask(w, h, data_in);
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
if (LLRender::sGLCoreProfile)
{
@@ -942,11 +985,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
llassert(w > 0 && h > 0 && cur_mip_data);
(void)cur_mip_data;
{
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
LLImageGL::setManualImage(mTarget, m, mFormatInternal, w, h, mFormatPrimary, mFormatType, cur_mip_data, mAllowCompression);
if (m == 0)
@@ -959,11 +1004,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
updatePickMask(w, h, cur_mip_data);
}
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
}
if (prev_mip_data && prev_mip_data != data_in)
{
@@ -998,11 +1045,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
}
else
{
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
LLImageGL::setManualImage(mTarget, 0, mFormatInternal, w, h,
mFormatPrimary, mFormatType, (GLvoid *)data_in, mAllowCompression);
@@ -1012,11 +1061,13 @@ bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32
stop_glerror();
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
}
}
@@ -1032,7 +1083,9 @@ U32 type_width_from_pixtype(U32 pixtype)
{
case GL_UNSIGNED_BYTE:
case GL_BYTE:
+#if GL_VERSION_1_2
case GL_UNSIGNED_INT_8_8_8_8_REV:
+#endif
type_width = 1;
break;
case GL_UNSIGNED_SHORT:
@@ -1179,11 +1232,13 @@ bool LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3
glPixelStorei(GL_UNPACK_ROW_LENGTH, data_width);
stop_glerror();
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
const U8* sub_datap = datap + (y_pos * data_width + x_pos) * getComponents();
// Update the GL texture
@@ -1207,11 +1262,13 @@ bool LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3
gGL.getTexUnit(0)->disable();
stop_glerror();
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
stop_glerror();
@@ -1316,24 +1373,30 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
{
if (pixformat == GL_ALPHA)
{ //GL_ALPHA is deprecated, convert to RGBA
+#if GL_VERSION_3_3
const GLint mask[] = { GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
+#endif
pixformat = GL_RED;
intformat = GL_R8;
}
if (pixformat == GL_LUMINANCE)
{ //GL_LUMINANCE is deprecated, convert to GL_RGBA
+#if GL_VERSION_3_3
const GLint mask[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
+#endif
pixformat = GL_RED;
intformat = GL_R8;
}
if (pixformat == GL_LUMINANCE_ALPHA)
{ //GL_LUMINANCE_ALPHA is deprecated, convert to RGBA
+#if GL_VERSION_3_3
const GLint mask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
+#endif
pixformat = GL_RG;
intformat = GL_RG8;
}
@@ -1410,39 +1473,63 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
{
case GL_RED:
case GL_R8:
+#if GL_VERSION_3_0
intformat = GL_COMPRESSED_RED;
+#endif
break;
case GL_RG:
case GL_RG8:
+#if GL_VERSION_3_0
intformat = GL_COMPRESSED_RG;
+#endif
break;
case GL_RGB:
case GL_RGB8:
+#if GL_VERSION_1_3
intformat = GL_COMPRESSED_RGB;
+#endif
break;
case GL_SRGB:
case GL_SRGB8:
+#if GL_VERSION_2_1
intformat = GL_COMPRESSED_SRGB;
+#endif
break;
case GL_RGBA:
case GL_RGBA8:
+#if GL_VERSION_1_3
intformat = GL_COMPRESSED_RGBA;
+#endif
break;
- case GL_SRGB_ALPHA:
case GL_SRGB8_ALPHA8:
+#if GL_VERSION_2_1
+ case GL_SRGB_ALPHA:
intformat = GL_COMPRESSED_SRGB_ALPHA;
+#endif
break;
case GL_LUMINANCE:
+#if GL_VERSION_1_1
case GL_LUMINANCE8:
+#endif
+#if GL_VERSION_1_3
intformat = GL_COMPRESSED_LUMINANCE;
+#endif
break;
case GL_LUMINANCE_ALPHA:
+#if GL_VERSION_1_1
case GL_LUMINANCE8_ALPHA8:
+#endif
+#if GL_VERSION_1_3
intformat = GL_COMPRESSED_LUMINANCE_ALPHA;
+#endif
break;
case GL_ALPHA:
+#if GL_VERSION_1_1
case GL_ALPHA8:
+#endif
+#if GL_VERSION_1_3
intformat = GL_COMPRESSED_ALPHA;
+#endif
break;
default:
LL_WARNS() << "Could not compress format: " << std::hex << intformat << std::dec << LL_ENDL;
@@ -1576,13 +1663,21 @@ bool LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
{
case 1:
// Use luminance alpha (for fonts)
+#if GL_VERSION_1_1
mFormatInternal = GL_LUMINANCE8;
+#else
+ mFormatInternal = GL_LUMINANCE;
+#endif
mFormatPrimary = GL_LUMINANCE;
mFormatType = GL_UNSIGNED_BYTE;
break;
case 2:
// Use luminance alpha (for fonts)
+#if GL_VERSION_1_1
mFormatInternal = GL_LUMINANCE8_ALPHA8;
+#else
+ mFormatInternal = GL_LUMINANCE_ALPHA;
+#endif
mFormatPrimary = GL_LUMINANCE_ALPHA;
mFormatType = GL_UNSIGNED_BYTE;
break;
@@ -1864,6 +1959,7 @@ bool LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre
LLImageDataLock lock(imageraw);
+#if GL_VERSION_1_3
if (is_compressed)
{
LLGLint glbytes;
@@ -1890,6 +1986,7 @@ bool LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre
glGetTexImage(GL_TEXTURE_2D, gl_discard, mFormatPrimary, mFormatType, (GLvoid*)(imageraw->getData()));
//stop_glerror();
}
+#endif // GL_VERSION_1_3
//-----------------------------------------------------------------------------------------------
if((error = glGetError()) != GL_NO_ERROR)
@@ -1978,11 +2075,13 @@ bool LLImageGL::getIsResident(bool test_now)
{
if (test_now)
{
+#if GL_VERSION_1_1
if (mTexName != 0)
{
glAreTexturesResident(1, (GLuint*)&mTexName, &mIsResident);
}
else
+#endif
{
mIsResident = false;
}
@@ -2112,12 +2211,16 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
mIsMask = false;
return; //no alpha channel.
case GL_RGBA:
+#if GL_VERSION_2_1
case GL_SRGB_ALPHA:
+#endif
mAlphaStride = 4;
break;
+#if GL_EXT_bgra
case GL_BGRA_EXT:
mAlphaStride = 4;
break;
+#endif
default:
break;
}
@@ -2127,6 +2230,7 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
{
mAlphaOffset = mAlphaStride - 1 ;
}
+#if GL_VERSION_1_2
else if(is_little_endian())
{
if (mFormatType == GL_UNSIGNED_INT_8_8_8_8)
@@ -2149,10 +2253,15 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
mAlphaOffset = 0 ;
}
}
+#endif // GL_VERSION_1_2
if( mAlphaStride < 1 || //unsupported format
- mAlphaOffset < 0 || //unsupported type
- (mFormatPrimary == GL_BGRA_EXT && mFormatType != GL_UNSIGNED_BYTE)) //unknown situation
+ mAlphaOffset < 0 //unsupported type
+#if GL_EXT_bgra
+ ||
+ (mFormatPrimary == GL_BGRA_EXT && mFormatType != GL_UNSIGNED_BYTE) //unknown situation
+#endif
+ )
{
LL_WARNS() << "Cannot analyze alpha for image with format type " << std::hex << mFormatType << std::dec << LL_ENDL;
@@ -2300,6 +2409,8 @@ bool LLImageGL::isCompressed()
bool is_compressed = false;
switch (mFormatPrimary)
{
+#if GL_EXT_texture_compression_s3tc || GL_EXT_texture_compression_dxt1 \
+ || GL_EXT_texture_sRGB || GL_EXT_texture_compression_s3tc_srgb
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
@@ -2308,6 +2419,7 @@ bool LLImageGL::isCompressed()
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
is_compressed = true;
break;
+#endif
default:
break;
}
@@ -2324,7 +2436,10 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
if (mFormatType != GL_UNSIGNED_BYTE ||
((mFormatPrimary != GL_RGBA)
- && (mFormatPrimary != GL_SRGB_ALPHA)))
+#if GL_VERSION_2_1
+ && (mFormatPrimary != GL_SRGB_ALPHA)
+#endif
+ ))
{
//cannot generate a pick mask for this texture
freePickMask();
@@ -2504,7 +2619,9 @@ bool LLImageGL::scaleDown(S32 desired_discard)
sScratchPBOSize = (U32)size;
}
+#if GL_VERSION_1_3
glGetTexImage(mTarget, mip, mFormatPrimary, mFormatType, nullptr);
+#endif
free_tex_image(mTexName);