Innitial commit of experimental v2 texture system port work. Compiles and runs on windows, at least. Fixing bugs as they come.

Need to test:
localassetbrowser
preview related floaters
hgfloatertexteditor
maps
media textures! Currently very hacky
web browser
alpha masks on avatars
bumpmaps
Are all sky components appearing?
LLViewerDynamicTexture (texture baking, browser, animated textures, anim previews, etc)
Snapshot related features
Customize avatar
vfs floater
UI textures in general
Texture priority issues
This commit is contained in:
Shyotl
2011-03-31 03:22:01 -05:00
committed by Siana Gearz
parent 758c5bbfeb
commit 5036cfe566
212 changed files with 8149 additions and 4443 deletions

View File

@@ -37,7 +37,6 @@
#include "llstl.h"
#include "llviewercontrol.h"
#include "lldir.h"
#include "llimagegl.h"
#include "m3math.h"
#include "m4math.h"
#include "v4math.h"
@@ -51,7 +50,7 @@
#include "llsky.h"
#include "lltextureentry.h"
#include "llviewercamera.h"
#include "llviewerimagelist.h"
#include "llviewertexturelist.h"
#include "pipeline.h"
#include "llspatialpartition.h"
#include "llviewershadermgr.h"
@@ -95,7 +94,16 @@ void LLStandardBumpmap::shutdown()
// static
void LLStandardBumpmap::restoreGL()
{
llassert( LLStandardBumpmap::sStandardBumpmapCount == 0 );
addstandard();
}
// static
void LLStandardBumpmap::addstandard()
{
// can't assert; we destroyGL and restoreGL a lot during *first* startup, which populates this list already, THEN we explicitly init the list as part of *normal* startup. Sigh. So clear the list every time before we (re-)add the standard bumpmaps.
//llassert( LLStandardBumpmap::sStandardBumpmapCount == 0 );
clear();
llinfos << "Adding standard bumpmaps." << llendl;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("None"); // BE_NO_BUMP
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Brightness"); // BE_BRIGHTNESS
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Darkness"); // BE_DARKNESS
@@ -127,9 +135,9 @@ void LLStandardBumpmap::restoreGL()
{
// *NOTE: This buffer size is hard coded into scanf() below.
char label[2048] = ""; /* Flawfinder: ignore */
char bump_file[2048] = ""; /* Flawfinder: ignore */
char bump_image_id[2048] = ""; /* Flawfinder: ignore */
fields_read = fscanf( /* Flawfinder: ignore */
file, "\n%2047s %2047s", label, bump_file);
file, "\n%2047s %2047s", label, bump_image_id);
if( EOF == fields_read )
{
break;
@@ -139,16 +147,19 @@ void LLStandardBumpmap::restoreGL()
llwarns << "Bad LLStandardBumpmap entry" << llendl;
return;
}
if(strlen(bump_image_id) == (UUID_STR_LENGTH - 1) + 4 && !stricmp(&(bump_image_id[UUID_STR_LENGTH-1]),".j2c"))
bump_image_id[UUID_STR_LENGTH-1] = 0; // truncate to a valid uuid (hopefully)
// llinfos << "Loading bumpmap: " << bump_file << " from viewerart" << llendl;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mLabel = label;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage =
gImageList.getImageFromFile(bump_file,
LLViewerTextureManager::getFetchedTexture(LLUUID(bump_image_id),
TRUE,
FALSE,
LLViewerTexture::BOOST_NONE,
LLViewerTexture::LOD_TEXTURE,
0,
0);
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setLoadedCallback(LLBumpImageList::onSourceStandardLoaded, 0, TRUE, FALSE, NULL );
0);
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setBoostLevel(LLViewerTexture::BOOST_BUMP) ;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setLoadedCallback(LLBumpImageList::onSourceStandardLoaded, 0, TRUE, FALSE, NULL, NULL );
LLStandardBumpmap::sStandardBumpmapCount++;
}
@@ -156,8 +167,9 @@ void LLStandardBumpmap::restoreGL()
}
// static
void LLStandardBumpmap::destroyGL()
void LLStandardBumpmap::clear()
{
llinfos << "Clearing standard bumpmaps." << llendl;
for( U32 i = 0; i < LLStandardBumpmap::sStandardBumpmapCount; i++ )
{
gStandardBumpmapList[i].mLabel.assign("");
@@ -166,6 +178,12 @@ void LLStandardBumpmap::destroyGL()
sStandardBumpmapCount = 0;
}
// static
void LLStandardBumpmap::destroyGL()
{
clear();
}
////////////////////////////////////////////////////////////////
@@ -570,27 +588,25 @@ void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL
// static
BOOL LLDrawPoolBump::bindBumpMap(LLDrawInfo& params, S32 channel)
{
LLImageGL* bump = NULL;
LLViewerTexture* bump = NULL;
U8 bump_code = params.mBump;
LLViewerImage* tex = params.mTexture;
//Note: texture atlas does not support bump texture now.
LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(params.mTexture) ;
if(!tex)
{
//if the texture is not a fetched texture
return FALSE;
}
switch( bump_code )
{
case BE_NO_BUMP:
bump = NULL;
case BE_NO_BUMP:
break;
case BE_BRIGHTNESS:
case BE_DARKNESS:
if( tex )
{
if(tex->getID()== IMG_DEFAULT)
{
return TRUE;
}
bump = gBumpImageList.getBrightnessDarknessImage( tex, bump_code );
}
bump = gBumpImageList.getBrightnessDarknessImage( tex, bump_code );
break;
default:
@@ -785,24 +801,32 @@ void LLBumpImageList::init()
LLStandardBumpmap::init();
}
void LLBumpImageList::shutdown()
void LLBumpImageList::clear()
{
llinfos << "Clearing dynamic bumpmaps." << llendl;
// these will be re-populated on-demand
mBrightnessEntries.clear();
mDarknessEntries.clear();
LLStandardBumpmap::clear();
}
void LLBumpImageList::shutdown()
{
clear();
LLStandardBumpmap::shutdown();
}
void LLBumpImageList::destroyGL()
{
mBrightnessEntries.clear();
mDarknessEntries.clear();
clear();
LLStandardBumpmap::destroyGL();
}
void LLBumpImageList::restoreGL()
{
// Images will be recreated as they are needed.
LLStandardBumpmap::restoreGL();
// Images will be recreated as they are needed.
}
@@ -818,9 +842,9 @@ LLBumpImageList::~LLBumpImageList()
void LLBumpImageList::addTextureStats(U8 bump, const LLUUID& base_image_id, F32 virtual_size)
{
bump &= TEM_BUMP_MASK;
LLViewerImage* bump_image = gStandardBumpmapList[bump].mImage;
LLViewerFetchedTexture* bump_image = gStandardBumpmapList[bump].mImage;
if( bump_image )
{
{
bump_image->addTextureStats(virtual_size);
}
}
@@ -832,11 +856,11 @@ void LLBumpImageList::updateImages()
for (bump_image_map_t::iterator iter = mBrightnessEntries.begin(); iter != mBrightnessEntries.end(); )
{
bump_image_map_t::iterator curiter = iter++;
LLImageGL* image = curiter->second;
LLViewerTexture* image = curiter->second;
if( image )
{
BOOL destroy = TRUE;
if( image->getHasGLTexture())
if( image->hasGLTexture())
{
if( image->getBoundRecently() )
{
@@ -859,11 +883,11 @@ void LLBumpImageList::updateImages()
for (bump_image_map_t::iterator iter = mDarknessEntries.begin(); iter != mDarknessEntries.end(); )
{
bump_image_map_t::iterator curiter = iter++;
LLImageGL* image = curiter->second;
LLViewerTexture* image = curiter->second;
if( image )
{
BOOL destroy = TRUE;
if( image->getHasGLTexture())
if( image->hasGLTexture())
{
if( image->getBoundRecently() )
{
@@ -887,16 +911,16 @@ void LLBumpImageList::updateImages()
// Note: the caller SHOULD NOT keep the pointer that this function returns. It may be updated as more data arrives.
LLImageGL* LLBumpImageList::getBrightnessDarknessImage(LLViewerImage* src_image, U8 bump_code )
LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedTexture* src_image, U8 bump_code )
{
llassert( (bump_code == BE_BRIGHTNESS) || (bump_code == BE_DARKNESS) );
LLImageGL* bump = NULL;
LLViewerTexture* bump = NULL;
const F32 BRIGHTNESS_DARKNESS_PIXEL_AREA_THRESHOLD = 1000;
if( src_image->mMaxVirtualSize > BRIGHTNESS_DARKNESS_PIXEL_AREA_THRESHOLD )
if( src_image->getMaxVirtualSize() > BRIGHTNESS_DARKNESS_PIXEL_AREA_THRESHOLD )
{
bump_image_map_t* entries_list = NULL;
void (*callback_func)( BOOL success, LLViewerImage *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) = NULL;
void (*callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) = NULL;
switch( bump_code )
{
@@ -923,17 +947,12 @@ LLImageGL* LLBumpImageList::getBrightnessDarknessImage(LLViewerImage* src_image,
LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,1);
raw->clear(0x77, 0x77, 0x77, 0xFF);
//------------------------------
bump = new LLImageGL( raw, TRUE);
//immediately assign bump to a global smart pointer in case some local smart pointer
//accidently releases it.
(*entries_list)[src_image->getID()] = bump;
//------------------------------
bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA);
(*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE);
(*entries_list)[src_image->getID()]->setExplicitFormat(GL_ALPHA8, GL_ALPHA);
// Note: this may create an LLImageGL immediately
src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()) );
src_image->setBoostLevel(LLViewerTexture::BOOST_BUMP) ;
src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL );
bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image
// bump_total++;
@@ -946,7 +965,7 @@ LLImageGL* LLBumpImageList::getBrightnessDarknessImage(LLViewerImage* src_image,
// static
void LLBumpImageList::onSourceBrightnessLoaded( BOOL success, LLViewerImage *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
void LLBumpImageList::onSourceBrightnessLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
{
LLUUID* source_asset_id = (LLUUID*)userdata;
LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_BRIGHTNESS );
@@ -957,7 +976,7 @@ void LLBumpImageList::onSourceBrightnessLoaded( BOOL success, LLViewerImage *src
}
// static
void LLBumpImageList::onSourceDarknessLoaded( BOOL success, LLViewerImage *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
void LLBumpImageList::onSourceDarknessLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
{
LLUUID* source_asset_id = (LLUUID*)userdata;
LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_DARKNESS );
@@ -967,14 +986,14 @@ void LLBumpImageList::onSourceDarknessLoaded( BOOL success, LLViewerImage *src_v
}
}
void LLBumpImageList::onSourceStandardLoaded( BOOL success, LLViewerImage* src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
void LLBumpImageList::onSourceStandardLoaded( BOOL success, LLViewerFetchedTexture* src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
{
if (success && LLPipeline::sRenderDeferred)
{
LLPointer<LLImageRaw> nrm_image = new LLImageRaw(src->getWidth(), src->getHeight(), 4);
generateNormalMapFromAlpha(src, nrm_image);
src_vi->setExplicitFormat(GL_RGBA, GL_RGBA);
src_vi->createGLTexture(0, nrm_image);
src_vi->createGLTexture(src_vi->getDiscardLevel(), nrm_image);
}
}
@@ -1014,8 +1033,8 @@ void LLBumpImageList::generateNormalMapFromAlpha(LLImageRaw* src, LLImageRaw* nr
LLVector3 right = LLVector3(norm_scale, 0, (F32) src_data[(j*resX+rX)*src_cmp+src_cmp-1]-cH);
LLVector3 left = LLVector3(-norm_scale, 0, (F32) src_data[(j*resX+lX)*src_cmp+src_cmp-1]-cH);
LLVector3 up = LLVector3(0, -norm_scale, (F32) src_data[(rY*resX+i)*src_cmp+src_cmp-1]-cH);
LLVector3 down = LLVector3(0, norm_scale, (F32) src_data[(lY*resX+i)*src_cmp+src_cmp-1]-cH);
LLVector3 up = LLVector3(0, -norm_scale, (F32) src_data[(lY*resX+i)*src_cmp+src_cmp-1]-cH);
LLVector3 down = LLVector3(0, norm_scale, (F32) src_data[(rY*resX+i)*src_cmp+src_cmp-1]-cH);
LLVector3 norm = right%down + down%left + left%up + up%right;
@@ -1034,7 +1053,7 @@ void LLBumpImageList::generateNormalMapFromAlpha(LLImageRaw* src, LLImageRaw* nr
}
// static
void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerImage *src_vi, LLImageRaw* src, LLUUID& source_asset_id, EBumpEffect bump_code )
void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLImageRaw* src, LLUUID& source_asset_id, EBumpEffect bump_code )
{
if( success )
{
@@ -1151,9 +1170,9 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerImage *src_vi, LLIma
}
//---------------------------------------------------
//immediately assign bump to a global smart pointer in case some local smart pointer
//accidently releases it.
LLPointer<LLImageGL> bump = new LLImageGL( TRUE);
// immediately assign bump to a global smart pointer in case some local smart pointer
// accidentally releases it.
LLPointer<LLViewerTexture> bump = LLViewerTextureManager::getLocalTexture( TRUE );
if (!LLPipeline::sRenderDeferred)
{
@@ -1162,8 +1181,8 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerImage *src_vi, LLIma
}
else
{
LLPointer<LLImageRaw> nrm_image = new LLImageRaw(src->getWidth(), src->getHeight(), 4);
generateNormalMapFromAlpha(src, nrm_image);
LLPointer<LLImageRaw> nrm_image = new LLImageRaw(dst_image->getWidth(), dst_image->getHeight(), 4);
generateNormalMapFromAlpha(dst_image, nrm_image);
bump->setExplicitFormat(GL_RGBA, GL_RGBA);
bump->createGLTexture(0, nrm_image);
}
@@ -1226,8 +1245,8 @@ void LLDrawPoolBump::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture)
{
if (params.mTexture.notNull())
{
gGL.getTexUnit(diffuse_channel)->bind(params.mTexture.get());
//params.mTexture->addTextureStats(params.mVSize);
gGL.getTexUnit(diffuse_channel)->bind(params.mTexture) ;
params.mTexture->addTextureStats(params.mVSize);
}
else
{