//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
#endif
#include <simgear/compiler.h>
+#include <simgear/debug/logstream.hxx>
#include <plib/sg.h>
-#include <plib/ssg.h>
#include <simgear/screen/extensions.hxx>
#include <simgear/screen/RenderTexture.h>
-#include SG_GLU_H
+#include <osg/GLU>
#include "bbcache.hxx"
if( bbListCount ) {
for(int i = 0 ; i < bbListCount ; i++) {
+ bbList[i].cldID = 0;
if(bbList[i].texID)
glDeleteTextures(1, & bbList[i].texID);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
glBindTexture(GL_TEXTURE_2D, 0);
cacheSizeKb = (textureDimension * textureDimension * 4);
cacheSizeKb *= cacheCount;
cacheSizeKb /= 1024;
- if(rt) {
- rt->BeginCapture();
- glViewport(0, 0, textureDimension, textureDimension);
- rt->EndCapture();
+ if(rtAvailable) {
+ if( rt->BeginCapture() ) {
+ glViewport(0, 0, textureDimension, textureDimension);
+ rt->EndCapture();
+ }
}
return true;
}
SGBbCache::SGBbCache(void) :
bbListCount(0),
- cacheSizeKb(0),
textureWH(0),
+ cacheSizeKb(0),
builtBBCount(0),
+ frameNumber(0),
rt(0),
rtAvailable(false),
- frameNumber(0),
- maxImpostorRegenFrame(10)
+ maxImpostorRegenFrame(20)
{
}
SGBbCache::~SGBbCache(void) {
- if(rt)
- delete rt;
+ delete rt;
freeTextureMemory();
}
void SGBbCache::init(int cacheCount) {
+ GLint colorBits = 0;
+ glGetIntegerv( GL_BLUE_BITS, &colorBits );
rt = new RenderTexture();
// don't use default rtt on nvidia/win because of poor performance of glCopyTexSubImage2D
// wihtout default pattrib params - see opengl forum
- rt->Reset("rgba tex2D ctt");
+ if( colorBits < 8 )
+ rt->Reset("rgba=5,5,5,1 ctt");
+ else
+ rt->Reset("rgba ctt");
+
+// rt->Reset("rgba tex2D ctt");
// rt->Reset("rgba tex2D");
if( rt->Initialize(256, 256, true) ) {
- rtAvailable = true;
+ SG_LOG(SG_ALL, SG_INFO, "bbcache:Initialize sucessfull");
if (rt->BeginCapture())
{
+ SG_LOG(SG_ALL, SG_INFO, "bbcache:BeginCapture sucessfull, RTT available");
+ rtAvailable = true;
glViewport(0, 0, 256, 256);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
rt->EndCapture();
- }
- }
+ } else
+ SG_LOG(SG_ALL, SG_WARN, "bbcache:BeginCapture failed, RTT not available for 3D clouds");
+ } else
+ SG_LOG(SG_ALL, SG_WARN, "bbcache:Initialize failed, RTT not available for 3D clouds");
if( cacheCount )
- allocTextureMemory( cacheCount, 256 );
+ allocTextureMemory( cacheCount, 64 );
}
-// TODO:not callable atm, texture size not handled correctly
+
bool SGBbCache::setCacheSize(int count, int textureDimension) {
if( count < 0 || count > 500)
return false;
return allocTextureMemory( count, textureDimension);
}
-// TODO:not callable atm, texture size not handled correctly
+
bool SGBbCache::setCacheSize(int sizeKb) {
if( sizeKb < 0 || sizeKb > 256*1024)
return false;
return true;
int count = 1;
int textureDimension = 256;
- if( cacheSizeKb >= 8*1024 ) {
+ if( sizeKb >= 8*1024 ) {
// more than 32 256x256 textures
textureDimension = 256;
- } else if( cacheSizeKb >= 2*1024 ) {
+ } else if( sizeKb >= 2*1024 ) {
// more than 32 128x128 textures
textureDimension = 128;
} else {
bbList[i].angleX = -999;
bbList[i].angleY = -999;
bbList[i].frameUsed = 0;
+ bbList[i].needRedraw = true;
return i;
}
}
// bbList[bbId].angleY = angleY;
bbList[bbId].frame = frameNumber;
bbList[bbId].frameUsed = frameNumber;
+ bbList[bbId].needRedraw = false;
builtBBCount ++;
builtBBframe ++;
}
if( builtBBframe >= maxImpostorRegenFrame )
return true;
- if( fabs(angleY - bbList[bbId].angleY) >= 5.0 )
- return false;
+ if( bbList[bbId].needRedraw )
+ return false;
+
+// if( fabs(angleY - bbList[bbId].angleY) >= 4.0 )
+// return false;
- if( fabs(angleX - bbList[bbId].angleX) >= 5.0 )
- return false;
+// if( fabs(angleX - bbList[bbId].angleX) >= 4.0 )
+// return false;
bbList[bbId].frameUsed = frameNumber;
return true;
void SGBbCache::startNewFrame(void) {
builtBBframe = 0;
// TOTO:find reasonable value
- int minFrameNumber = frameNumber - 500;
+ int minFrameNumber = frameNumber - 100;
frameNumber++;
// cleanup of unused enties
for( int bbId = 0 ; bbId < bbListCount ; bbId++)
bbList[bbId].cldID = 0;
}
}
+
+// force all impostors to be rebuilt, this will enventually be done over several frames
+void SGBbCache::invalidateCache(void) {
+
+ for( int bbId = 0 ; bbId < bbListCount ; bbId++)
+// bbList[bbId].cldID = 0;
+ bbList[bbId].needRedraw = true;
+}
+
+// flag the impostor for a lazy update
+void SGBbCache::invalidate(int cldId, int bbId) {
+ if( bbId < 0 || bbId >= bbListCount )
+ return;
+ if( bbList[bbId].cldID != cldId )
+ return;
+ bbList[bbId].needRedraw = true;
+}
+