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.cpp121
1 files changed, 113 insertions, 8 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 9df0fef5d1..08c05a0771 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -301,28 +301,46 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
{
switch (dataformat)
{
+#if GL_VERSION_3_0
case GL_COMPRESSED_RED: return 8;
+#endif
case GL_COMPRESSED_RG: return 16;
+#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_COLOR_INDEX: return 8;
+#endif
case GL_LUMINANCE_ALPHA: return 16;
case GL_LUMINANCE8_ALPHA8: return 16;
case GL_RG: return 16;
@@ -332,8 +350,10 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
case GL_RGB8: return 24;
case GL_RGBA: return 32;
case GL_RGBA8: 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;
@@ -355,6 +375,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:
@@ -364,6 +386,7 @@ S64 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height)
if (width < 4) width = 4;
if (height < 4) height = 4;
break;
+#endif
default:
break;
}
@@ -377,23 +400,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;
@@ -793,11 +824,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)
@@ -806,11 +839,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();
}
@@ -823,11 +858,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);
@@ -837,10 +874,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,
@@ -851,11 +890,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)
{
@@ -940,11 +981,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)
@@ -957,11 +1000,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)
{
@@ -996,11 +1041,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);
@@ -1010,11 +1057,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
}
}
@@ -1030,7 +1079,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:
@@ -1177,11 +1228,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
@@ -1205,11 +1258,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();
@@ -1416,31 +1471,51 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
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;
@@ -1574,13 +1649,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;
@@ -1862,6 +1945,7 @@ bool LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre
LLImageDataLock lock(imageraw);
+#if GL_VERSION_1_3
if (is_compressed)
{
LLGLint glbytes;
@@ -1888,6 +1972,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)
@@ -1976,11 +2061,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;
}
@@ -2110,12 +2197,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;
}
@@ -2125,6 +2216,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)
@@ -2147,10 +2239,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;
@@ -2298,6 +2395,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:
@@ -2306,6 +2405,7 @@ bool LLImageGL::isCompressed()
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
is_compressed = true;
break;
+#endif
default:
break;
}
@@ -2322,7 +2422,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();
@@ -2500,7 +2603,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);