Try some swizzling instead of forcing everything to rgba8 with core profile. Avoids manual conversions with scratch buffers. Works for all pixel datatypes. Cleaner. Uses less vram.

Also, fixed textures when running core pofile.
This commit is contained in:
Shyotl
2014-05-14 03:05:53 -05:00
parent 98f9a09b39
commit 117eca3c98
3 changed files with 40 additions and 81 deletions

View File

@@ -235,6 +235,8 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
case GL_ALPHA: return 8;
case GL_COLOR_INDEX: return 8;
case GL_LUMINANCE_ALPHA: return 16;
case GL_RED: return 8;
case GL_RG: return 16;
case GL_RGB: return 24;
case GL_RGB8: return 24;
case GL_RGBA: return 32;
@@ -271,6 +273,8 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat)
case GL_ALPHA: return 1;
case GL_COLOR_INDEX: return 1;
case GL_LUMINANCE_ALPHA: return 2;
case GL_RED: return 1;
case GL_RG: return 2;
case GL_RGB: return 3;
case GL_RGBA: return 4;
case GL_BGRA: return 4; // Used for QuickTime media textures on the Mac
@@ -811,6 +815,12 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
stop_glerror();
}
if (LLRender::sGLCoreProfile)
{
glGenerateMipmap(mTarget);
}
stop_glerror();
}
}
else
@@ -1078,91 +1088,47 @@ static LLFastTimer::DeclareTimer FTM_SET_MANUAL_IMAGE("setManualImage");
void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 width, S32 height, U32 pixformat, U32 pixtype, const void *pixels, bool allow_compression)
{
LLFastTimer t(FTM_SET_MANUAL_IMAGE);
bool use_scratch = false;
U32* scratch = NULL;
if (LLRender::sGLCoreProfile)
{
if (pixformat == GL_ALPHA && pixtype == GL_UNSIGNED_BYTE)
if (pixformat == GL_ALPHA)
{ //GL_ALPHA is deprecated, convert to RGBA
use_scratch = true;
scratch = new U32[width*height];
U32 pixel_count = (U32) (width*height);
for (U32 i = 0; i < pixel_count; i++)
{
U8* pix = (U8*) &scratch[i];
pix[0] = pix[1] = pix[2] = 0;
pix[3] = ((U8*) pixels)[i];
const GLint mask[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
pixformat = GL_RED;
intformat = GL_R8;
}
pixformat = GL_RGBA;
intformat = GL_RGBA8;
}
if (pixformat == GL_LUMINANCE && pixtype == GL_UNSIGNED_BYTE)
if (pixformat == GL_LUMINANCE)
{ //GL_LUMINANCE is deprecated, convert to GL_RGBA
use_scratch = true;
scratch = new U32[width*height];
U32 pixel_count = (U32) (width*height);
for (U32 i = 0; i < pixel_count; i++)
{
U8 lum = ((U8*) pixels)[i];
U8* pix = (U8*) &scratch[i];
pix[0] = pix[1] = pix[2] = lum;
pix[3] = 1.f;
const GLint mask[] = {GL_RED, GL_RED, GL_RED, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
pixformat = GL_RED;
intformat = GL_R8;
}
pixformat = GL_RGBA;
intformat = GL_RGBA8;
}
if (pixformat == GL_LUMINANCE_ALPHA && pixtype == GL_UNSIGNED_BYTE)
if (pixformat == GL_LUMINANCE_ALPHA)
{ //GL_LUMINANCE_ALPHA is deprecated, convert to RGBA
use_scratch = true;
scratch = new U32[width*height];
U32 pixel_count = (U32) (width*height);
for (U32 i = 0; i < pixel_count; i++)
{
U8 lum = ((U8*) pixels)[i*2+0];
U8 alpha = ((U8*) pixels)[i*2+1];
U8* pix = (U8*) &scratch[i];
pix[0] = pix[1] = pix[2] = lum;
pix[3] = alpha;
const GLint mask[] = {GL_RED, GL_RED, GL_RED, GL_GREEN};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask);
pixformat = GL_RG;
intformat = GL_RG8;
}
pixformat = GL_RGBA;
intformat = GL_RGBA8;
}
if (pixformat == GL_LUMINANCE && pixtype == GL_UNSIGNED_BYTE)
{ //GL_LUMINANCE_ALPHA is deprecated, convert to RGB
use_scratch = true;
scratch = new U32[width*height];
U32 pixel_count = (U32) (width*height);
for (U32 i = 0; i < pixel_count; i++)
{
U8 lum = ((U8*) pixels)[i];
U8* pix = (U8*) &scratch[i];
pix[0] = pix[1] = pix[2] = lum;
pix[3] = 255;
}
pixformat = GL_RGBA;
intformat = GL_RGB8;
}
}
if (LLImageGL::sCompressTextures && allow_compression)
{
switch (intformat)
{
case GL_RED:
case GL_R8:
intformat = GL_COMPRESSED_RED;
break;
case GL_RG:
case GL_RG8:
intformat = GL_COMPRESSED_RG;
break;
case GL_RGB:
case GL_RGB8:
intformat = GL_COMPRESSED_RGB;
@@ -1190,13 +1156,8 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
}
stop_glerror();
glTexImage2D(target, miplevel, intformat, width, height, 0, pixformat, pixtype, use_scratch ? scratch : pixels);
glTexImage2D(target, miplevel, intformat, width, height, 0, pixformat, pixtype, pixels);
stop_glerror();
if (use_scratch)
{
delete [] scratch;
}
}
//create an empty GL texture: just create a texture name

View File

@@ -471,10 +471,8 @@ void LLPostProcess::createNoiseTexture()
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseTexture);
stop_glerror();
if(gGLManager.mGLVersion >= 4.f)
LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_R8, NOISE_SIZE, NOISE_SIZE, GL_RED, GL_UNSIGNED_BYTE, &buffer[0], false);
else
LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_LUMINANCE8, NOISE_SIZE, NOISE_SIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, &buffer[0], false);
stop_glerror();
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_WRAP);

View File

@@ -68,8 +68,8 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) :
LLFacePool(POOL_TERRAIN),
mTexturep(texturep)
{
U32 format = GL_ALPHA8;
U32 int_format = GL_ALPHA;
U32 format = GL_ALPHA;
U32 int_format = GL_ALPHA8;
// Hack!
sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
@@ -77,7 +77,7 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) :
mAlphaRampImagep = LLViewerTextureManager::getFetchedTextureFromFile("alpha_gradient.tga",
TRUE, LLGLTexture::BOOST_UI,
LLViewerTexture::FETCHED_TEXTURE,
format, int_format,
int_format, format,
LLUUID("e97cf410-8e61-7005-ec06-629eba4cd1fb"));
//gGL.getTexUnit(0)->bind(mAlphaRampImagep.get());
@@ -86,7 +86,7 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) :
m2DAlphaRampImagep = LLViewerTextureManager::getFetchedTextureFromFile("alpha_gradient_2d.j2c",
TRUE, LLGLTexture::BOOST_UI,
LLViewerTexture::FETCHED_TEXTURE,
format, int_format,
int_format, format,
LLUUID("38b86f85-2575-52a9-a531-23108d8da837"));
//gGL.getTexUnit(0)->bind(m2DAlphaRampImagep.get());