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.cpp64
1 files changed, 27 insertions, 37 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 26e6aad770..9df0fef5d1 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -2179,15 +2179,15 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
// this will mid-skew the data (and thus increase the chances of not
// being used as a mask) from high-frequency alpha maps which
// suffer the worst from aliasing when used as alpha masks.
- if (w >= 4 && h >= 4)
+ if (w >= 2 && h >= 2)
{
- llassert(w%4 == 0);
- llassert(h%4 == 0);
+ llassert(w % 2 == 0);
+ llassert(h % 2 == 0);
const GLubyte* rowstart = ((const GLubyte*) data_in) + mAlphaOffset;
- for (U32 y = 0; y < h; y+=4)
+ for (U32 y = 0; y < h; y += 2)
{
const GLubyte* current = rowstart;
- for (U32 x = 0; x < w; x+=4)
+ for (U32 x = 0; x < w; x += 2)
{
const U32 s1 = current[0];
alphatotal += s1;
@@ -2210,8 +2210,7 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
sample[asum/(16*4)] += 4;
}
-
- rowstart += 4 * w * mAlphaStride;
+ rowstart += 2 * w * mAlphaStride;
}
length *= 2; // we sampled everything twice, essentially
}
@@ -2453,41 +2452,32 @@ bool LLImageGL::scaleDown(S32 desired_discard)
if (gGLManager.mDownScaleMethod == 0)
{ // use an FBO to downscale the texture
- // allocate new texture
- U32 temp_texname = 0;
- generateTextures(1, &temp_texname);
- gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, temp_texname, true);
- {
- LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glTexImage2D");
- glTexImage2D(mTarget, 0, mFormatInternal, desired_width, desired_height, 0, mFormatPrimary, mFormatType, NULL);
- }
-
- // account for new texture getting created
- alloc_tex_image(desired_width, desired_height, mFormatInternal, 1);
-
- // Use render-to-texture to scale down the texture
- {
- LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glFramebufferTexture2D");
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTarget, temp_texname, 0);
- }
-
glViewport(0, 0, desired_width, desired_height);
// draw a full screen triangle
- gGL.getTexUnit(0)->bind(this);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+ if (gGL.getTexUnit(0)->bind(this, true, true))
+ {
+ glDrawArrays(GL_TRIANGLES, 0, 3);
- // delete old texture and assign new texture name
- deleteTextures(1, &mTexName);
- mTexName = temp_texname;
+ free_tex_image(mTexName);
+ glTexImage2D(mTarget, 0, mFormatInternal, desired_width, desired_height, 0, mFormatPrimary, mFormatType, nullptr);
+ glCopyTexSubImage2D(mTarget, 0, 0, 0, 0, 0, desired_width, desired_height);
+ alloc_tex_image(desired_width, desired_height, mFormatInternal, 1);
- if (mHasMipMaps)
- { // generate mipmaps if needed
- LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glGenerateMipmap");
- gGL.getTexUnit(0)->bind(this);
- glGenerateMipmap(mTarget);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+ mTexOptionsDirty = true;
+
+ if (mHasMipMaps)
+ { // generate mipmaps if needed
+ LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glGenerateMipmap");
+ gGL.getTexUnit(0)->bind(this);
+ glGenerateMipmap(mTarget);
+ gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+ }
+ }
+ else
+ {
+ LL_WARNS_ONCE("LLImageGL") << "Failed to bind texture for downscaling." << LL_ENDL;
+ return false;
}
}
else