summaryrefslogtreecommitdiff
path: root/indra/llrender/llimagegl.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2023-09-05 23:14:03 +0800
committerErik Kundiman <erik@megapahit.org>2023-09-05 23:14:03 +0800
commited44bcf9f763a7d1f7549eb1f03d8aa7fb933ef7 (patch)
tree0d37e52d48fd72f61ce4f6ac718a494c8b45c5a7 /indra/llrender/llimagegl.cpp
parent6e9102ad408282ea6d5f8926f4a6ed377fe922ef (diff)
Preprocess non portable GL funcs & macros
so that implementations that don't include a certain GL implementation won't fail trying to compile the code.
Diffstat (limited to 'indra/llrender/llimagegl.cpp')
-rw-r--r--indra/llrender/llimagegl.cpp79
1 files changed, 77 insertions, 2 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 8e83f2b401..34f668d1a2 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -212,14 +212,18 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
case GL_LUMINANCE: return 8;
case GL_ALPHA: return 8;
case GL_RED: return 8;
+#if GL_VERSION_1_1
case GL_COLOR_INDEX: return 8;
+#endif
case GL_LUMINANCE_ALPHA: return 16;
case GL_RGB: return 24;
case GL_SRGB: return 24;
case GL_RGB8: return 24;
case GL_RGBA: 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
default:
LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL;
return 0;
@@ -262,13 +266,17 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat)
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_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: " << dataformat << LL_ENDL;
return 0;
@@ -746,11 +754,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)
@@ -759,11 +769,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();
}
@@ -776,11 +788,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);
@@ -790,10 +804,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,
@@ -804,11 +820,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)
{
@@ -892,11 +910,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)
@@ -909,11 +929,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)
{
@@ -948,11 +970,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);
@@ -962,11 +986,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
}
}
@@ -1011,13 +1037,17 @@ BOOL LLImageGL::preAddToAtlas(S32 discard_level, const LLImageRaw* raw_image)
{
case 1:
// Use luminance alpha (for fonts)
+#if GL_VERSION_1_1
mFormatInternal = GL_LUMINANCE8;
+#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;
+#endif
mFormatPrimary = GL_LUMINANCE_ALPHA;
mFormatType = GL_UNSIGNED_BYTE;
break;
@@ -1063,22 +1093,26 @@ BOOL LLImageGL::preAddToAtlas(S32 discard_level, const LLImageRaw* raw_image)
glPixelStorei(GL_UNPACK_ROW_LENGTH, raw_image->getWidth());
stop_glerror();
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
stop_glerror();
}
+#endif
return TRUE ;
}
void LLImageGL::postAddToAtlas()
{
+#if GL_VERSION_1_1
if(mFormatSwapBytes)
{
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
+#endif
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
gGL.getTexUnit(0)->setTextureFilteringOption(mFilterOption);
@@ -1153,11 +1187,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
datap += (y_pos * data_width + x_pos) * getComponents();
// Update the GL texture
@@ -1169,11 +1205,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();
@@ -1336,35 +1374,57 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
{
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;
case GL_RED:
case GL_R8:
+#if GL_VERSION_3_0
intformat = GL_COMPRESSED_RED;
+#endif
break;
default:
LL_WARNS() << "Could not compress format: " << std::hex << intformat << LL_ENDL;
@@ -1478,13 +1538,17 @@ 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;
+#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;
+#endif
mFormatPrimary = GL_LUMINANCE_ALPHA;
mFormatType = GL_UNSIGNED_BYTE;
break;
@@ -1826,6 +1890,7 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre
}
//-----------------------------------------------------------------------------------------------
+#if GL_VERSION_1_3
if (is_compressed)
{
LLGLint glbytes;
@@ -1852,6 +1917,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)
@@ -1941,11 +2007,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;
}
@@ -2075,7 +2143,9 @@ 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;
case GL_BGRA_EXT:
@@ -2090,6 +2160,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)
@@ -2112,6 +2183,7 @@ void LLImageGL::calcAlphaChannelOffsetAndStride()
mAlphaOffset = 0 ;
}
}
+#endif // GL_VERSION_1_2
if( mAlphaStride < 1 || //unsupported format
mAlphaOffset < 0 || //unsupported type
@@ -2266,7 +2338,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
return;