From 3d872fb21f089ce06da576ee08660a0245262cc5 Mon Sep 17 00:00:00 2001
From: Dave Houlton <euclid@lindenlab.com>
Date: Mon, 8 Jun 2020 15:47:41 -0600
Subject: SL-13281, add missing srgb->linear conversion for specular

---
 indra/llrender/llimagegl.cpp      | 80 ++++++++++++++++++++++++---------------
 indra/llrender/llrender.cpp       | 22 +++++++----
 indra/llrender/llrendertarget.cpp | 10 ++---
 3 files changed, 68 insertions(+), 44 deletions(-)

(limited to 'indra/llrender')

diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index ff74380217..3b6a49735e 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -985,38 +985,56 @@ BOOL LLImageGL::preAddToAtlas(S32 discard_level, const LLImageRaw* raw_image)
 		return FALSE;
 	}
 
-	if( !mHasExplicitFormat )
-	{
-		switch (mComponents)
-		{
-			case 1:
-			// Use luminance alpha (for fonts)
-			mFormatInternal = GL_LUMINANCE8;
-			mFormatPrimary = GL_LUMINANCE;
-			mFormatType = GL_UNSIGNED_BYTE;
-			break;
-			case 2:
-			// Use luminance alpha (for fonts)
-			mFormatInternal = GL_LUMINANCE8_ALPHA8;
-			mFormatPrimary = GL_LUMINANCE_ALPHA;
-			mFormatType = GL_UNSIGNED_BYTE;
-			break;
-			case 3:
-			mFormatInternal = GL_RGB8;
-			mFormatPrimary = GL_RGB;
-			mFormatType = GL_UNSIGNED_BYTE;
-			break;
-			case 4:
-			mFormatInternal = GL_RGBA8;
-			mFormatPrimary = GL_RGBA;
-			mFormatType = GL_UNSIGNED_BYTE;
-			break;
-			default:
-			LL_ERRS() << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL;
-		}
-	}
+    if (!mHasExplicitFormat)
+    {
+        switch (mComponents)
+        {
+            case 1:
+                // Use luminance alpha (for fonts)
+                mFormatInternal = GL_LUMINANCE8;
+                mFormatPrimary  = GL_LUMINANCE;
+                mFormatType     = GL_UNSIGNED_BYTE;
+                break;
+            case 2:
+                // Use luminance alpha (for fonts)
+                mFormatInternal = GL_LUMINANCE8_ALPHA8;
+                mFormatPrimary  = GL_LUMINANCE_ALPHA;
+                mFormatType     = GL_UNSIGNED_BYTE;
+                break;
+            case 3:
+#if USE_SRGB_DECODE
+                if (gGLManager.mHasTexturesRGBDecode)
+                {
+                    mFormatInternal = GL_SRGB8;
+                }
+                else
+#endif
+                {
+                    mFormatInternal = GL_RGB8;
+                }
+                mFormatPrimary = GL_RGB;
+                mFormatType    = GL_UNSIGNED_BYTE;
+                break;
+            case 4:
+#if USE_SRGB_DECODE
+                if (gGLManager.mHasTexturesRGBDecode)
+                {
+                    mFormatInternal = GL_SRGB8_ALPHA8;
+                }
+                else
+#endif
+                {
+                    mFormatInternal = GL_RGBA8;
+                }
+                mFormatPrimary = GL_RGBA;
+                mFormatType    = GL_UNSIGNED_BYTE;
+                break;
+            default:
+                LL_ERRS() << "Bad number of components for texture: " << (U32) getComponents() << LL_ENDL;
+        }
+    }
 
-	mCurrentDiscardLevel = discard_level;	
+    mCurrentDiscardLevel = discard_level;	
 	mDiscardLevelInAtlas = discard_level;
 	mTexelsInAtlas = raw_image->getWidth() * raw_image->getHeight() ;
 	mLastBindTime = sLastFrameTime;
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index ebc4659bcf..eb9da34ca8 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -849,26 +849,32 @@ void LLTexUnit::debugTextureUnit(void)
 	}
 }
 
-void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) {
+void LLTexUnit::setTextureColorSpace(eTextureColorSpace space)
+{
     mTexColorSpace = space;
 
 #if USE_SRGB_DECODE
-    if (gGLManager.mHasTexturesRGBDecode) {
-
-        if (space == TCS_SRGB) {
+    if (gGLManager.mHasTexturesRGBDecode)
+    {
+        if (space == TCS_SRGB)
+        {
             glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
         }
-        else {
+        else
+        {
             glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
         }
 
-        if (gDebugGL) {
+        if (gDebugGL)
+        {
             assert_glerror();
         }
     }
+    else
 #endif
-    glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
-
+    {
+        glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
+    }
 }
 
 LLLightState::LLLightState(S32 index)
diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp
index 9fb4f7f2b0..e3c0255290 100644
--- a/indra/llrender/llrendertarget.cpp
+++ b/indra/llrender/llrendertarget.cpp
@@ -501,23 +501,23 @@ U32 LLRenderTarget::getNumTextures() const
 	return mTex.size();
 }
 
-
 void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options)
 {
-	gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index));
+    gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index));
 
     bool isSRGB = false;
     llassert(mInternalFormat.size() > index);
     switch (mInternalFormat[index])
     {
-        case GL_SRGB_ALPHA:
         case GL_SRGB:
+        case GL_SRGB8:
+        case GL_SRGB_ALPHA:
         case GL_SRGB8_ALPHA8:
             isSRGB = true;
-        break;
+            break;
 
         default:
-        break;
+            break;
     }
 
     gGL.getTexUnit(channel)->setTextureFilteringOption(filter_options);
-- 
cgit v1.2.3