aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender
diff options
context:
space:
mode:
authorJacek Antonelli2010-02-09 21:11:42 -0600
committerJacek Antonelli2010-02-16 18:50:15 -0600
commite6247fbe78c4d3dacb74f3b2359aba2b6538133b (patch)
tree10c42d670a2c635b4339f7f68809c221756774f8 /linden/indra/llrender
parentPorted some cURL and HTTP-related changes from Snowglobe. (diff)
downloadmeta-impy-e6247fbe78c4d3dacb74f3b2359aba2b6538133b.zip
meta-impy-e6247fbe78c4d3dacb74f3b2359aba2b6538133b.tar.gz
meta-impy-e6247fbe78c4d3dacb74f3b2359aba2b6538133b.tar.bz2
meta-impy-e6247fbe78c4d3dacb74f3b2359aba2b6538133b.tar.xz
Ported many texture engine changes from Snowglobe.
Diffstat (limited to 'linden/indra/llrender')
-rw-r--r--linden/indra/llrender/llcubemap.cpp4
-rw-r--r--linden/indra/llrender/llimagegl.cpp273
-rw-r--r--linden/indra/llrender/llimagegl.h82
-rw-r--r--linden/indra/llrender/llrender.cpp20
-rw-r--r--linden/indra/llrender/llrender.h2
-rw-r--r--linden/indra/llrender/llrendertarget.cpp4
6 files changed, 315 insertions, 70 deletions
diff --git a/linden/indra/llrender/llcubemap.cpp b/linden/indra/llrender/llcubemap.cpp
index 754d90c..a5c677d 100644
--- a/linden/indra/llrender/llcubemap.cpp
+++ b/linden/indra/llrender/llcubemap.cpp
@@ -94,7 +94,7 @@ void LLCubeMap::initGL()
94 mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE)); 94 mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE));
95 mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); 95 mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP);
96 mRawImages[i] = new LLImageRaw(64, 64, 4); 96 mRawImages[i] = new LLImageRaw(64, 64, 4);
97 mImages[i]->createGLTexture(0, mRawImages[i], texname); 97 mImages[i]->createGLTexture(0, mRawImages[i], texname, TRUE);
98 98
99 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); 99 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname);
100 mImages[i]->setAddressMode(LLTexUnit::TAM_CLAMP); 100 mImages[i]->setAddressMode(LLTexUnit::TAM_CLAMP);
@@ -106,7 +106,7 @@ void LLCubeMap::initGL()
106 } 106 }
107 else 107 else
108 { 108 {
109 llwarns << "Using cube map without extension!" << llendl 109 llwarns << "Using cube map without extension!" << llendl;
110 } 110 }
111} 111}
112 112
diff --git a/linden/indra/llrender/llimagegl.cpp b/linden/indra/llrender/llimagegl.cpp
index d1efb11..27b1d55 100644
--- a/linden/indra/llrender/llimagegl.cpp
+++ b/linden/indra/llrender/llimagegl.cpp
@@ -43,8 +43,6 @@
43#include "llmath.h" 43#include "llmath.h"
44#include "llgl.h" 44#include "llgl.h"
45#include "llrender.h" 45#include "llrender.h"
46
47
48//---------------------------------------------------------------------------- 46//----------------------------------------------------------------------------
49 47
50const F32 MIN_TEXTURE_LIFETIME = 10.f; 48const F32 MIN_TEXTURE_LIFETIME = 10.f;
@@ -61,8 +59,33 @@ S32 LLImageGL::sCount = 0;
61 59
62BOOL LLImageGL::sGlobalUseAnisotropic = FALSE; 60BOOL LLImageGL::sGlobalUseAnisotropic = FALSE;
63F32 LLImageGL::sLastFrameTime = 0.f; 61F32 LLImageGL::sLastFrameTime = 0.f;
62BOOL LLImageGL::sAllowReadBackRaw = FALSE ;
64 63
65std::set<LLImageGL*> LLImageGL::sImageList; 64std::set<LLImageGL*> LLImageGL::sImageList;
65
66//****************************************************************************************************
67//The below for texture auditing use only
68//****************************************************************************************************
69//-----------------------
70//debug use
71BOOL gAuditTexture = FALSE ;
72#define MAX_TEXTURE_LOG_SIZE 22 //2048 * 2048
73std::vector<S32> LLImageGL::sTextureLoadedCounter(MAX_TEXTURE_LOG_SIZE + 1) ;
74std::vector<S32> LLImageGL::sTextureBoundCounter(MAX_TEXTURE_LOG_SIZE + 1) ;
75std::vector<S32> LLImageGL::sTextureCurBoundCounter(MAX_TEXTURE_LOG_SIZE + 1) ;
76S32 LLImageGL::sCurTexSizeBar = -1 ;
77S32 LLImageGL::sCurTexPickSize = -1 ;
78LLPointer<LLImageGL> LLImageGL::sDefaultTexturep = NULL;
79S32 LLImageGL::sMaxCatagories = 1 ;
80
81std::vector<S32> LLImageGL::sTextureMemByCategory;
82std::vector<S32> LLImageGL::sTextureMemByCategoryBound ;
83std::vector<S32> LLImageGL::sTextureCurMemByCategoryBound ;
84//------------------------
85//****************************************************************************************************
86//End for texture auditing use only
87//****************************************************************************************************
88
66//************************************************************************************** 89//**************************************************************************************
67//below are functions for debug use 90//below are functions for debug use
68//do not delete them even though they are not currently being used. 91//do not delete them even though they are not currently being used.
@@ -110,6 +133,20 @@ void LLImageGL::checkTexSize() const
110//************************************************************************************** 133//**************************************************************************************
111 134
112//---------------------------------------------------------------------------- 135//----------------------------------------------------------------------------
136//static
137void LLImageGL::initClass(S32 num_catagories)
138{
139 sMaxCatagories = num_catagories ;
140
141 sTextureMemByCategory.resize(sMaxCatagories);
142 sTextureMemByCategoryBound.resize(sMaxCatagories) ;
143 sTextureCurMemByCategoryBound.resize(sMaxCatagories) ;
144}
145
146//static
147void LLImageGL::cleanupClass()
148{
149}
113 150
114//static 151//static
115S32 LLImageGL::dataFormatBits(S32 dataformat) 152S32 LLImageGL::dataFormatBits(S32 dataformat)
@@ -176,12 +213,44 @@ void LLImageGL::updateStats(F32 current_time)
176 sLastFrameTime = current_time; 213 sLastFrameTime = current_time;
177 sBoundTextureMemoryInBytes = sCurBoundTextureMemory; 214 sBoundTextureMemoryInBytes = sCurBoundTextureMemory;
178 sCurBoundTextureMemory = 0; 215 sCurBoundTextureMemory = 0;
216
217 if(gAuditTexture)
218 {
219 for(U32 i = 0 ; i < sTextureCurBoundCounter.size() ; i++)
220 {
221 sTextureBoundCounter[i] = sTextureCurBoundCounter[i] ;
222 sTextureCurBoundCounter[i] = 0 ;
223 }
224 for(U32 i = 0 ; i < sTextureCurMemByCategoryBound.size() ; i++)
225 {
226 sTextureMemByCategoryBound[i] = sTextureCurMemByCategoryBound[i] ;
227 sTextureCurMemByCategoryBound[i] = 0 ;
228 }
229 }
179} 230}
180 231
181//static 232//static
182S32 LLImageGL::updateBoundTexMem(const S32 delta) 233S32 LLImageGL::updateBoundTexMemStatic(const S32 delta, const S32 size, S32 category)
234{
235 if(gAuditTexture)
236 {
237 sTextureCurBoundCounter[getTextureCounterIndex(size)]++ ;
238 sTextureCurMemByCategoryBound[category] += delta ;
239 }
240
241 LLImageGL::sCurBoundTextureMemory += delta ;
242 return LLImageGL::sCurBoundTextureMemory;
243}
244
245S32 LLImageGL::updateBoundTexMem()const
183{ 246{
184 LLImageGL::sCurBoundTextureMemory += delta; 247 if(gAuditTexture)
248 {
249 sTextureCurBoundCounter[getTextureCounterIndex(mTextureMemory / mComponents)]++ ;
250 sTextureCurMemByCategoryBound[mCategory] += mTextureMemory ;
251 }
252
253 LLImageGL::sCurBoundTextureMemory += mTextureMemory ;
185 return LLImageGL::sCurBoundTextureMemory; 254 return LLImageGL::sCurBoundTextureMemory;
186} 255}
187 256
@@ -195,6 +264,7 @@ void LLImageGL::destroyGL(BOOL save_state)
195 gGL.getTexUnit(stage)->unbind(LLTexUnit::TT_TEXTURE); 264 gGL.getTexUnit(stage)->unbind(LLTexUnit::TT_TEXTURE);
196 } 265 }
197 266
267 sAllowReadBackRaw = true ;
198 for (std::set<LLImageGL*>::iterator iter = sImageList.begin(); 268 for (std::set<LLImageGL*>::iterator iter = sImageList.begin();
199 iter != sImageList.end(); iter++) 269 iter != sImageList.end(); iter++)
200 { 270 {
@@ -204,7 +274,7 @@ void LLImageGL::destroyGL(BOOL save_state)
204 if (save_state && glimage->isGLTextureCreated() && glimage->mComponents) 274 if (save_state && glimage->isGLTextureCreated() && glimage->mComponents)
205 { 275 {
206 glimage->mSaveData = new LLImageRaw; 276 glimage->mSaveData = new LLImageRaw;
207 if(!glimage->readBackRaw(glimage->mCurrentDiscardLevel, glimage->mSaveData, false)) 277 if(!glimage->readBackRaw(glimage->mCurrentDiscardLevel, glimage->mSaveData, false)) //necessary, keep it.
208 { 278 {
209 glimage->mSaveData = NULL ; 279 glimage->mSaveData = NULL ;
210 } 280 }
@@ -214,6 +284,7 @@ void LLImageGL::destroyGL(BOOL save_state)
214 stop_glerror(); 284 stop_glerror();
215 } 285 }
216 } 286 }
287 sAllowReadBackRaw = false ;
217} 288}
218 289
219//static 290//static
@@ -231,7 +302,7 @@ void LLImageGL::restoreGL()
231 { 302 {
232 if (glimage->getComponents() && glimage->mSaveData->getComponents()) 303 if (glimage->getComponents() && glimage->mSaveData->getComponents())
233 { 304 {
234 glimage->createGLTexture(glimage->mCurrentDiscardLevel, glimage->mSaveData); 305 glimage->createGLTexture(glimage->mCurrentDiscardLevel, glimage->mSaveData, 0, TRUE, glimage->getCategory());
235 stop_glerror(); 306 stop_glerror();
236 } 307 }
237 glimage->mSaveData = NULL; // deletes data 308 glimage->mSaveData = NULL; // deletes data
@@ -311,7 +382,7 @@ void LLImageGL::init(BOOL usemipmaps)
311 mTextureState = NO_DELETE ; 382 mTextureState = NO_DELETE ;
312 mTextureMemory = 0; 383 mTextureMemory = 0;
313 mLastBindTime = 0.f; 384 mLastBindTime = 0.f;
314 385
315 mTarget = GL_TEXTURE_2D; 386 mTarget = GL_TEXTURE_2D;
316 mBindTarget = LLTexUnit::TT_TEXTURE; 387 mBindTarget = LLTexUnit::TT_TEXTURE;
317 mUseMipMaps = usemipmaps; 388 mUseMipMaps = usemipmaps;
@@ -338,7 +409,9 @@ void LLImageGL::init(BOOL usemipmaps)
338 mHasExplicitFormat = FALSE; 409 mHasExplicitFormat = FALSE;
339 410
340 mGLTextureCreated = FALSE ; 411 mGLTextureCreated = FALSE ;
412
341 mIsMask = FALSE; 413 mIsMask = FALSE;
414 mCategory = -1 ;
342} 415}
343 416
344void LLImageGL::cleanup() 417void LLImageGL::cleanup()
@@ -438,6 +511,10 @@ void LLImageGL::dump()
438} 511}
439 512
440//---------------------------------------------------------------------------- 513//----------------------------------------------------------------------------
514void LLImageGL::forceUpdateBindStats(void) const
515{
516 mLastBindTime = sLastFrameTime;
517}
441 518
442void LLImageGL::updateBindStats(void) const 519void LLImageGL::updateBindStats(void) const
443{ 520{
@@ -451,7 +528,8 @@ void LLImageGL::updateBindStats(void) const
451 { 528 {
452 // we haven't accounted for this texture yet this frame 529 // we haven't accounted for this texture yet this frame
453 sUniqueCount++; 530 sUniqueCount++;
454 updateBoundTexMem(mTextureMemory); 531
532 updateBoundTexMem();
455 mLastBindTime = sLastFrameTime; 533 mLastBindTime = sLastFrameTime;
456 } 534 }
457 } 535 }
@@ -464,7 +542,7 @@ bool LLImageGL::bindError(const S32 stage) const
464} 542}
465 543
466//virtual 544//virtual
467bool LLImageGL::bindDefaultImage(const S32 stage) const 545bool LLImageGL::bindDefaultImage(const S32 stage)
468{ 546{
469 return false; 547 return false;
470} 548}
@@ -503,7 +581,6 @@ void LLImageGL::setImage(const LLImageRaw* imageraw)
503void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) 581void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
504{ 582{
505// LLFastTimer t1(LLFastTimer::FTM_TEMP1); 583// LLFastTimer t1(LLFastTimer::FTM_TEMP1);
506 llpushcallstacks ;
507 bool is_compressed = false; 584 bool is_compressed = false;
508 if (mFormatPrimary >= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && mFormatPrimary <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) 585 if (mFormatPrimary >= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && mFormatPrimary <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
509 { 586 {
@@ -716,12 +793,10 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
716 } 793 }
717 stop_glerror(); 794 stop_glerror();
718 mGLTextureCreated = true; 795 mGLTextureCreated = true;
719 llpushcallstacks ;
720} 796}
721 797
722BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height) 798BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, BOOL force_fast_update)
723{ 799{
724 llpushcallstacks ;
725 if (!width || !height) 800 if (!width || !height)
726 { 801 {
727 return TRUE; 802 return TRUE;
@@ -737,7 +812,8 @@ BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3
737 return FALSE; 812 return FALSE;
738 } 813 }
739 814
740 if (x_pos == 0 && y_pos == 0 && width == getWidth() && height == getHeight() && data_width == width && data_height == height) 815 // HACK: allow the caller to explicitly force the fast path (i.e. using glTexSubImage2D here instead of calling setImage) even when updating the full texture.
816 if (!force_fast_update && x_pos == 0 && y_pos == 0 && width == getWidth() && height == getHeight() && data_width == width && data_height == height)
741 { 817 {
742 setImage(datap, FALSE); 818 setImage(datap, FALSE);
743 } 819 }
@@ -810,20 +886,20 @@ BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3
810 stop_glerror(); 886 stop_glerror();
811 mGLTextureCreated = true; 887 mGLTextureCreated = true;
812 } 888 }
813 llpushcallstacks ;
814 return TRUE; 889 return TRUE;
815} 890}
816 891
817BOOL LLImageGL::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height) 892BOOL LLImageGL::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, BOOL force_fast_update)
818{ 893{
819 return setSubImage(imageraw->getData(), imageraw->getWidth(), imageraw->getHeight(), x_pos, y_pos, width, height); 894 return setSubImage(imageraw->getData(), imageraw->getWidth(), imageraw->getHeight(), x_pos, y_pos, width, height, force_fast_update);
820} 895}
821 896
822// Copy sub image from frame buffer 897// Copy sub image from frame buffer
823BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height) 898BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height)
824{ 899{
825 if (gGL.getTexUnit(0)->bind(this, true)) 900 if (gGL.getTexUnit(0)->bind(this, false, true))
826 { 901 {
902 //checkTexSize() ;
827 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, fb_x, fb_y, x_pos, y_pos, width, height); 903 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, fb_x, fb_y, x_pos, y_pos, width, height);
828 mGLTextureCreated = true; 904 mGLTextureCreated = true;
829 stop_glerror(); 905 stop_glerror();
@@ -883,14 +959,14 @@ BOOL LLImageGL::createGLTexture()
883 return TRUE ; 959 return TRUE ;
884} 960}
885 961
886BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename/*=0*/) 962BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename/*=0*/, BOOL to_create, S32 category)
887{ 963{
888 llpushcallstacks ;
889 if (gGLManager.mIsDisabled) 964 if (gGLManager.mIsDisabled)
890 { 965 {
891 llwarns << "Trying to create a texture while GL is disabled!" << llendl; 966 llwarns << "Trying to create a texture while GL is disabled!" << llendl;
892 return FALSE; 967 return FALSE;
893 } 968 }
969
894 mGLTextureCreated = false ; 970 mGLTextureCreated = false ;
895 llassert(gGLManager.mInited); 971 llassert(gGLManager.mInited);
896 stop_glerror(); 972 stop_glerror();
@@ -903,8 +979,10 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
903 discard_level = llclamp(discard_level, 0, (S32)mMaxDiscardLevel); 979 discard_level = llclamp(discard_level, 0, (S32)mMaxDiscardLevel);
904 980
905 // Actual image width/height = raw image width/height * 2^discard_level 981 // Actual image width/height = raw image width/height * 2^discard_level
906 S32 w = imageraw->getWidth() << discard_level; 982 S32 raw_w = imageraw->getWidth() ;
907 S32 h = imageraw->getHeight() << discard_level; 983 S32 raw_h = imageraw->getHeight() ;
984 S32 w = raw_w << discard_level;
985 S32 h = raw_h << discard_level;
908 986
909 // setSize may call destroyGLTexture if the size does not match 987 // setSize may call destroyGLTexture if the size does not match
910 setSize(w, h, imageraw->getComponents()); 988 setSize(w, h, imageraw->getComponents());
@@ -940,13 +1018,21 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
940 } 1018 }
941 } 1019 }
942 1020
1021 if(!to_create) //not create a gl texture
1022 {
1023 destroyGLTexture();
1024 mCurrentDiscardLevel = discard_level;
1025 mLastBindTime = sLastFrameTime;
1026 return TRUE ;
1027 }
1028
1029 mCategory = category ;
943 const U8* rawdata = imageraw->getData(); 1030 const U8* rawdata = imageraw->getData();
944 return createGLTexture(discard_level, rawdata, FALSE, usename); 1031 return createGLTexture(discard_level, rawdata, FALSE, usename);
945} 1032}
946 1033
947BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, S32 usename) 1034BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, S32 usename)
948{ 1035{
949 llpushcallstacks ;
950 llassert(data_in); 1036 llassert(data_in);
951 1037
952 if (discard_level < 0) 1038 if (discard_level < 0)
@@ -1014,7 +1100,14 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
1014 if (old_name != 0) 1100 if (old_name != 0)
1015 { 1101 {
1016 sGlobalTextureMemoryInBytes -= mTextureMemory; 1102 sGlobalTextureMemoryInBytes -= mTextureMemory;
1103
1104 if(gAuditTexture)
1105 {
1106 decTextureCounter() ;
1107 }
1108
1017 LLImageGL::deleteTextures(1, &old_name); 1109 LLImageGL::deleteTextures(1, &old_name);
1110
1018 stop_glerror(); 1111 stop_glerror();
1019 } 1112 }
1020 1113
@@ -1022,13 +1115,15 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
1022 sGlobalTextureMemoryInBytes += mTextureMemory; 1115 sGlobalTextureMemoryInBytes += mTextureMemory;
1023 setActive() ; 1116 setActive() ;
1024 1117
1118 if(gAuditTexture)
1119 {
1120 incTextureCounter() ;
1121 }
1025 // mark this as bound at this point, so we don't throw it out immediately 1122 // mark this as bound at this point, so we don't throw it out immediately
1026 mLastBindTime = sLastFrameTime; 1123 mLastBindTime = sLastFrameTime;
1027
1028 llpushcallstacks ;
1029 return TRUE; 1124 return TRUE;
1030} 1125}
1031 1126#if 0
1032BOOL LLImageGL::setDiscardLevel(S32 discard_level) 1127BOOL LLImageGL::setDiscardLevel(S32 discard_level)
1033{ 1128{
1034 llassert(discard_level >= 0); 1129 llassert(discard_level >= 0);
@@ -1080,25 +1175,14 @@ BOOL LLImageGL::setDiscardLevel(S32 discard_level)
1080 return FALSE; 1175 return FALSE;
1081 } 1176 }
1082} 1177}
1083 1178#endif
1084BOOL LLImageGL::isValidForSculpt(S32 discard_level, S32 image_width, S32 image_height, S32 ncomponents)
1085{
1086 assert_glerror();
1087 S32 gl_discard = discard_level - mCurrentDiscardLevel;
1088 LLGLint glwidth = 0;
1089 glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_WIDTH, (GLint*)&glwidth);
1090 LLGLint glheight = 0;
1091 glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_HEIGHT, (GLint*)&glheight);
1092 LLGLint glcomponents = 0 ;
1093 glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&glcomponents);
1094 assert_glerror();
1095
1096 return glwidth >= image_width && glheight >= image_height && (GL_RGB8 == glcomponents || GL_RGBA8 == glcomponents) ;
1097}
1098 1179
1099BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok) 1180BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok)
1100{ 1181{
1101 llpushcallstacks ; 1182 // VWR-13505 : Merov : Allow gl texture read back so save texture works again (temporary)
1183 //llassert_always(sAllowReadBackRaw) ;
1184 //llerrs << "should not call this function!" << llendl ;
1185
1102 if (discard_level < 0) 1186 if (discard_level < 0)
1103 { 1187 {
1104 discard_level = mCurrentDiscardLevel; 1188 discard_level = mCurrentDiscardLevel;
@@ -1201,7 +1285,7 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre
1201 return FALSE ; 1285 return FALSE ;
1202 } 1286 }
1203 //----------------------------------------------------------------------------------------------- 1287 //-----------------------------------------------------------------------------------------------
1204 llpushcallstacks ; 1288
1205 return TRUE ; 1289 return TRUE ;
1206} 1290}
1207 1291
@@ -1219,12 +1303,19 @@ void LLImageGL::destroyGLTexture()
1219 stop_glerror(); 1303 stop_glerror();
1220 } 1304 }
1221 } 1305 }
1222 1306
1223 sGlobalTextureMemoryInBytes -= mTextureMemory; 1307 if(mTextureMemory)
1224 mTextureMemory = 0; 1308 {
1225 1309 if(gAuditTexture)
1310 {
1311 decTextureCounter() ;
1312 }
1313 sGlobalTextureMemoryInBytes -= mTextureMemory;
1314 mTextureMemory = 0;
1315 }
1316
1226 LLImageGL::deleteTextures(1, &mTexName); 1317 LLImageGL::deleteTextures(1, &mTexName);
1227 mTextureState = DELETED ; 1318 mTextureState = DELETED ;
1228 mTexName = 0; 1319 mTexName = 0;
1229 mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. 1320 mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel.
1230 mGLTextureCreated = FALSE ; 1321 mGLTextureCreated = FALSE ;
@@ -1338,6 +1429,11 @@ S32 LLImageGL::getMipBytes(S32 discard_level) const
1338 return res; 1429 return res;
1339} 1430}
1340 1431
1432BOOL LLImageGL::isJustBound() const
1433{
1434 return (BOOL)(sLastFrameTime - mLastBindTime < 0.5f);
1435}
1436
1341BOOL LLImageGL::getBoundRecently() const 1437BOOL LLImageGL::getBoundRecently() const
1342{ 1438{
1343 return (BOOL)(sLastFrameTime - mLastBindTime < MIN_TEXTURE_LIFETIME); 1439 return (BOOL)(sLastFrameTime - mLastBindTime < MIN_TEXTURE_LIFETIME);
@@ -1539,6 +1635,87 @@ BOOL LLImageGL::getMask(const LLVector2 &tc)
1539 return res; 1635 return res;
1540} 1636}
1541 1637
1638void LLImageGL::setCategory(S32 category)
1639{
1640 if(!gAuditTexture)
1641 {
1642 return ;
1643 }
1644 if(mCategory != category)
1645 {
1646 if(mCategory > -1)
1647 {
1648 sTextureMemByCategory[mCategory] -= mTextureMemory ;
1649 }
1650 sTextureMemByCategory[category] += mTextureMemory ;
1651
1652 mCategory = category;
1653 }
1654}
1655
1656//for debug use
1657//val is a "power of two" number
1658S32 LLImageGL::getTextureCounterIndex(U32 val)
1659{
1660 //index range is [0, MAX_TEXTURE_LOG_SIZE].
1661 if(val < 2)
1662 {
1663 return 0 ;
1664 }
1665 else if(val >= (1 << MAX_TEXTURE_LOG_SIZE))
1666 {
1667 return MAX_TEXTURE_LOG_SIZE ;
1668 }
1669 else
1670 {
1671 S32 ret = 0 ;
1672 while(val >>= 1)
1673 {
1674 ++ret;
1675 }
1676 return ret ;
1677 }
1678}
1679void LLImageGL::incTextureCounterStatic(U32 val, S32 ncomponents, S32 category)
1680{
1681 sTextureLoadedCounter[getTextureCounterIndex(val)]++ ;
1682 sTextureMemByCategory[category] += (S32)val * ncomponents ;
1683}
1684void LLImageGL::decTextureCounterStatic(U32 val, S32 ncomponents, S32 category)
1685{
1686 sTextureLoadedCounter[getTextureCounterIndex(val)]-- ;
1687 sTextureMemByCategory[category] += (S32)val * ncomponents ;
1688}
1689void LLImageGL::incTextureCounter()
1690{
1691 sTextureLoadedCounter[getTextureCounterIndex(mTextureMemory / mComponents)]++ ;
1692 sTextureMemByCategory[mCategory] += mTextureMemory ;
1693}
1694void LLImageGL::decTextureCounter()
1695{
1696 sTextureLoadedCounter[getTextureCounterIndex(mTextureMemory / mComponents)]-- ;
1697 sTextureMemByCategory[mCategory] -= mTextureMemory ;
1698}
1699void LLImageGL::setCurTexSizebar(S32 index, BOOL set_pick_size)
1700{
1701 sCurTexSizeBar = index ;
1702
1703 if(set_pick_size)
1704 {
1705 sCurTexPickSize = (1 << index) ;
1706 }
1707 else
1708 {
1709 sCurTexPickSize = -1 ;
1710 }
1711}
1712void LLImageGL::resetCurTexSizebar()
1713{
1714 sCurTexSizeBar = -1 ;
1715 sCurTexPickSize = -1 ;
1716}
1717//----------------------------------------------------------------------------
1718
1542//---------------------------------------------------------------------------- 1719//----------------------------------------------------------------------------
1543 1720
1544 1721
diff --git a/linden/indra/llrender/llimagegl.h b/linden/indra/llrender/llimagegl.h
index 2f08a5a..c8df101 100644
--- a/linden/indra/llrender/llimagegl.h
+++ b/linden/indra/llrender/llimagegl.h
@@ -46,7 +46,6 @@
46#define MEGA_BYTES_TO_BYTES(x) ((x) << 20) 46#define MEGA_BYTES_TO_BYTES(x) ((x) << 20)
47 47
48//============================================================================ 48//============================================================================
49
50class LLImageGL : public LLRefCount 49class LLImageGL : public LLRefCount
51{ 50{
52 friend class LLTexUnit; 51 friend class LLTexUnit;
@@ -57,6 +56,7 @@ public:
57 static S32 dataFormatComponents(S32 dataformat); 56 static S32 dataFormatComponents(S32 dataformat);
58 57
59 void updateBindStats(void) const; 58 void updateBindStats(void) const;
59 void forceUpdateBindStats(void) const;
60 60
61 // needs to be called every frame 61 // needs to be called every frame
62 static void updateStats(F32 current_time); 62 static void updateStats(F32 current_time);
@@ -65,9 +65,10 @@ public:
65 static void destroyGL(BOOL save_state = TRUE); 65 static void destroyGL(BOOL save_state = TRUE);
66 static void restoreGL(); 66 static void restoreGL();
67 67
68 // Sometimes called externally for textures not using LLImageGL (should go away...) 68 // Sometimes called externally for textures not using LLImageGL (should go away...)
69 static S32 updateBoundTexMem(const S32 delta); 69 static S32 updateBoundTexMemStatic(const S32 delta, const S32 size, S32 category) ;
70 70 S32 updateBoundTexMem()const;
71
71 static bool checkSize(S32 width, S32 height); 72 static bool checkSize(S32 width, S32 height);
72 73
73 // Not currently necessary for LLImageGL, but required in some derived classes, 74 // Not currently necessary for LLImageGL, but required in some derived classes,
@@ -89,7 +90,7 @@ protected:
89public: 90public:
90 virtual void dump(); // debugging info to llinfos 91 virtual void dump(); // debugging info to llinfos
91 virtual bool bindError(const S32 stage = 0) const; 92 virtual bool bindError(const S32 stage = 0) const;
92 virtual bool bindDefaultImage(const S32 stage = 0) const; 93 virtual bool bindDefaultImage(const S32 stage = 0) ;
93 virtual void forceImmediateUpdate() ; 94 virtual void forceImmediateUpdate() ;
94 95
95 void setSize(S32 width, S32 height, S32 ncomponents); 96 void setSize(S32 width, S32 height, S32 ncomponents);
@@ -101,20 +102,22 @@ public:
101 static void setManualImage(U32 target, S32 miplevel, S32 intformat, S32 width, S32 height, U32 pixformat, U32 pixtype, const void *pixels); 102 static void setManualImage(U32 target, S32 miplevel, S32 intformat, S32 width, S32 height, U32 pixformat, U32 pixtype, const void *pixels);
102 103
103 BOOL createGLTexture() ; 104 BOOL createGLTexture() ;
104 BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0); 105 BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE,
106 S32 category = sMaxCatagories - 1);
105 BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, S32 usename = 0); 107 BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, S32 usename = 0);
106 void setImage(const LLImageRaw* imageraw); 108 void setImage(const LLImageRaw* imageraw);
107 void setImage(const U8* data_in, BOOL data_hasmips = FALSE); 109 void setImage(const U8* data_in, BOOL data_hasmips = FALSE);
108 BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height); 110 BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, BOOL force_fast_update = FALSE);
109 BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height); 111 BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, BOOL force_fast_update = FALSE);
110 BOOL setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height); 112 BOOL setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height);
111 BOOL setDiscardLevel(S32 discard_level); 113
112 // Read back a raw image for this discard level, if it exists 114 // Read back a raw image for this discard level, if it exists
113 BOOL readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok); 115 BOOL readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok);
114 void destroyGLTexture(); 116 void destroyGLTexture();
115 117
116 void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE); 118 void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
117 void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; } 119 void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
120 void setComponents(S8 ncomponents) { mComponents = ncomponents; }
118 121
119 S32 getDiscardLevel() const { return mCurrentDiscardLevel; } 122 S32 getDiscardLevel() const { return mCurrentDiscardLevel; }
120 S32 getMaxDiscardLevel() const { return mMaxDiscardLevel; } 123 S32 getMaxDiscardLevel() const { return mMaxDiscardLevel; }
@@ -127,6 +130,7 @@ public:
127 S32 getBytes(S32 discard_level = -1) const; 130 S32 getBytes(S32 discard_level = -1) const;
128 S32 getMipBytes(S32 discard_level = -1) const; 131 S32 getMipBytes(S32 discard_level = -1) const;
129 BOOL getBoundRecently() const; 132 BOOL getBoundRecently() const;
133 BOOL isJustBound() const;
130 LLGLenum getPrimaryFormat() const { return mFormatPrimary; } 134 LLGLenum getPrimaryFormat() const { return mFormatPrimary; }
131 135
132 BOOL getHasGLTexture() const { return mTexName != 0; } 136 BOOL getHasGLTexture() const { return mTexName != 0; }
@@ -147,8 +151,6 @@ public:
147 BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; } 151 BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
148 BOOL getDontDiscard() const { return mDontDiscard; } 152 BOOL getDontDiscard() const { return mDontDiscard; }
149 153
150 BOOL isValidForSculpt(S32 discard_level, S32 image_width, S32 image_height, S32 ncomponents) ;
151
152 void updatePickMask(S32 width, S32 height, const U8* data_in); 154 void updatePickMask(S32 width, S32 height, const U8* data_in);
153 BOOL getMask(const LLVector2 &tc); 155 BOOL getMask(const LLVector2 &tc);
154 156
@@ -175,6 +177,7 @@ public:
175 void forceActive() ; 177 void forceActive() ;
176 void setNoDelete() ; 178 void setNoDelete() ;
177 179
180 void setTextureSize(S32 size) {mTextureMemory = size;}
178protected: 181protected:
179 void init(BOOL usemipmaps); 182 void init(BOOL usemipmaps);
180 virtual void cleanup(); // Clean up the LLImageGL so it can be reinitialized. Be careful when using this in derived class destructors 183 virtual void cleanup(); // Clean up the LLImageGL so it can be reinitialized. Be careful when using this in derived class destructors
@@ -183,7 +186,7 @@ public:
183 // Various GL/Rendering options 186 // Various GL/Rendering options
184 S32 mTextureMemory; 187 S32 mTextureMemory;
185 mutable F32 mLastBindTime; // last time this was bound, by discard level 188 mutable F32 mLastBindTime; // last time this was bound, by discard level
186 189
187private: 190private:
188 LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL 191 LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL
189 U8* mPickMask; //downsampled bitmap approximation of alpha channel. NULL if no alpha channel 192 U8* mPickMask; //downsampled bitmap approximation of alpha channel. NULL if no alpha channel
@@ -198,7 +201,7 @@ private:
198 U16 mWidth; 201 U16 mWidth;
199 U16 mHeight; 202 U16 mHeight;
200 S8 mCurrentDiscardLevel; 203 S8 mCurrentDiscardLevel;
201 204
202protected: 205protected:
203 LLGLenum mTarget; // Normally GL_TEXTURE2D, sometimes something else (ex. cube maps) 206 LLGLenum mTarget; // Normally GL_TEXTURE2D, sometimes something else (ex. cube maps)
204 LLTexUnit::eTextureType mBindTarget; // Normally TT_TEXTURE, sometimes something else (ex. cube maps) 207 LLTexUnit::eTextureType mBindTarget; // Normally TT_TEXTURE, sometimes something else (ex. cube maps)
@@ -237,7 +240,7 @@ public:
237 static S32 sCount; 240 static S32 sCount;
238 241
239 static F32 sLastFrameTime; 242 static F32 sLastFrameTime;
240 243
241 static LLGLuint sCurrentBoundTextures[MAX_GL_TEXTURE_UNITS]; // Currently bound texture ID 244 static LLGLuint sCurrentBoundTextures[MAX_GL_TEXTURE_UNITS]; // Currently bound texture ID
242 245
243 // Global memory statistics 246 // Global memory statistics
@@ -253,6 +256,57 @@ public:
253#else 256#else
254 BOOL getMissed() const { return FALSE; }; 257 BOOL getMissed() const { return FALSE; };
255#endif 258#endif
259
260public:
261 static void initClass(S32 num_catagories) ;
262 static void cleanupClass() ;
263private:
264 static S32 sMaxCatagories ;
265
266 //the flag to allow to call readBackRaw(...).
267 //can be removed if we do not use that function at all.
268 static BOOL sAllowReadBackRaw ;
269//
270//****************************************************************************************************
271//The below for texture auditing use only
272//****************************************************************************************************
273private:
274 S32 mCategory ;
275public:
276 void setCategory(S32 category) ;
277 S32 getCategory()const {return mCategory ;}
278
279 //for debug use: show texture size distribution
280 //----------------------------------------
281 static LLPointer<LLImageGL> sDefaultTexturep; //default texture to replace normal textures
282 static std::vector<S32> sTextureLoadedCounter ;
283 static std::vector<S32> sTextureBoundCounter ;
284 static std::vector<S32> sTextureCurBoundCounter ;
285 static S32 sCurTexSizeBar ;
286 static S32 sCurTexPickSize ;
287
288 static S32 getTextureCounterIndex(U32 val) ;
289 static void incTextureCounterStatic(U32 val, S32 ncomponents, S32 category) ;
290 static void decTextureCounterStatic(U32 val, S32 ncomponents, S32 category) ;
291 static void setCurTexSizebar(S32 index, BOOL set_pick_size = TRUE) ;
292 static void resetCurTexSizebar();
293
294 void incTextureCounter() ;
295 void decTextureCounter() ;
296 //----------------------------------------
297
298 //for debug use: show texture category distribution
299 //----------------------------------------
300
301 static std::vector<S32> sTextureMemByCategory;
302 static std::vector<S32> sTextureMemByCategoryBound ;
303 static std::vector<S32> sTextureCurMemByCategoryBound ;
304 //----------------------------------------
305//****************************************************************************************************
306//End of definitions for texture auditing use only
307//****************************************************************************************************
308
256}; 309};
257 310
311extern BOOL gAuditTexture;
258#endif // LL_LLIMAGEGL_H 312#endif // LL_LLIMAGEGL_H
diff --git a/linden/indra/llrender/llrender.cpp b/linden/indra/llrender/llrender.cpp
index ba95a19..93ff822 100644
--- a/linden/indra/llrender/llrender.cpp
+++ b/linden/indra/llrender/llrender.cpp
@@ -177,7 +177,7 @@ void LLTexUnit::disable(void)
177 } 177 }
178} 178}
179 179
180bool LLTexUnit::bind(LLImageGL* texture, bool forceBind) 180bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind)
181{ 181{
182 stop_glerror(); 182 stop_glerror();
183 if (mIndex < 0) return false; 183 if (mIndex < 0) return false;
@@ -192,12 +192,25 @@ bool LLTexUnit::bind(LLImageGL* texture, bool forceBind)
192 192
193 if (!texture->getTexName()) //if texture does not exist 193 if (!texture->getTexName()) //if texture does not exist
194 { 194 {
195 //if deleted, will re-generate it immediately 195 if (texture->isDeleted())
196 texture->forceImmediateUpdate() ; 196 {
197 // This will re-generate the texture immediately.
198 texture->forceImmediateUpdate() ;
199 }
197 200
201 texture->forceUpdateBindStats() ;
198 return texture->bindDefaultImage(mIndex); 202 return texture->bindDefaultImage(mIndex);
199 } 203 }
200 204
205 if(gAuditTexture && for_rendering && LLImageGL::sCurTexPickSize > 0)
206 {
207 if(texture->getWidth() * texture->getHeight() == LLImageGL::sCurTexPickSize)
208 {
209 texture->updateBindStats();
210 return bind(LLImageGL::sDefaultTexturep.get());
211 }
212 }
213
201 if ((mCurrTexture != texture->getTexName()) || forceBind) 214 if ((mCurrTexture != texture->getTexName()) || forceBind)
202 { 215 {
203 activate(); 216 activate();
@@ -214,6 +227,7 @@ bool LLTexUnit::bind(LLImageGL* texture, bool forceBind)
214 setTextureFilteringOption(texture->mFilterOption); 227 setTextureFilteringOption(texture->mFilterOption);
215 } 228 }
216 } 229 }
230
217 return true; 231 return true;
218} 232}
219 233
diff --git a/linden/indra/llrender/llrender.h b/linden/indra/llrender/llrender.h
index 437c715..ce84e74 100644
--- a/linden/indra/llrender/llrender.h
+++ b/linden/indra/llrender/llrender.h
@@ -148,7 +148,7 @@ public:
148 148
149 // Binds the LLImageGL to this texture unit 149 // Binds the LLImageGL to this texture unit
150 // (automatically enables the unit for the LLImageGL's texture type) 150 // (automatically enables the unit for the LLImageGL's texture type)
151 bool bind(LLImageGL* texture, bool forceBind = false); 151 bool bind(LLImageGL* texture, bool for_rendering = false, bool forceBind = false);
152 152
153 // Binds a cubemap to this texture unit 153 // Binds a cubemap to this texture unit
154 // (automatically enables the texture unit for cubemaps) 154 // (automatically enables the texture unit for cubemaps)
diff --git a/linden/indra/llrender/llrendertarget.cpp b/linden/indra/llrender/llrendertarget.cpp
index b7f3177..4cf8451 100644
--- a/linden/indra/llrender/llrendertarget.cpp
+++ b/linden/indra/llrender/llrendertarget.cpp
@@ -139,7 +139,7 @@ void LLRenderTarget::addColorAttachment(U32 color_fmt)
139 139
140 U32 offset = mTex.size(); 140 U32 offset = mTex.size();
141 if (offset >= 4 || 141 if (offset >= 4 ||
142 offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)) 142 (offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)))
143 { 143 {
144 llerrs << "Too many color attachments!" << llendl; 144 llerrs << "Too many color attachments!" << llendl;
145 } 145 }
@@ -608,7 +608,7 @@ void LLMultisampleBuffer::addColorAttachment(U32 color_fmt)
608 608
609 U32 offset = mTex.size(); 609 U32 offset = mTex.size();
610 if (offset >= 4 || 610 if (offset >= 4 ||
611 offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)) 611 (offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)))
612 { 612 {
613 llerrs << "Too many color attachments!" << llendl; 613 llerrs << "Too many color attachments!" << llendl;
614 } 614 }