]> git.mxchange.org Git - simgear.git/commitdiff
Add a texture cache mechanism. Fortunately this oly seems affective for empty.rgb ...
authorehofman <ehofman>
Sat, 22 Apr 2006 09:38:14 +0000 (09:38 +0000)
committerehofman <ehofman>
Sat, 22 Apr 2006 09:38:14 +0000 (09:38 +0000)
simgear/scene/material/mat.cxx
simgear/scene/material/mat.hxx

index 8a8f635a4d56475d6ed006ce503233a1346a04cb..8d197edee6eebad64cd67acc5ce395b746f09000 100644 (file)
@@ -43,6 +43,9 @@ SG_USING_STD(map);
 
 #include "mat.hxx"
 
+static map<string, ssgTexture *> _tex_cache;
+static map<string, ssgTexture *>::iterator _tex_cache_iter;
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Constructors and destructor.
@@ -208,9 +211,8 @@ SGMaterial::load_texture ( int n )
         if ( !_status[i].texture_loaded ) {
             SG_LOG( SG_GENERAL, SG_INFO, "Loading deferred texture "
                                           << _status[i].texture_path );
-            _status[i].state->setTexture(
-                   (char *)_status[i].texture_path.c_str(),
-                   wrapu, wrapv, mipmap );
+            assignTexture(_status[i].state, _status[i].texture_path,
+                                         wrapu, wrapv, mipmap );
             _status[i].texture_loaded = true;
        }
     }
@@ -254,8 +256,7 @@ SGMaterial::build_ssg_state( bool defer_tex_load )
 
         if ( !defer_tex_load ) {
             SG_LOG(SG_INPUT, SG_INFO, "    " << _status[i].texture_path );
-           state->setTexture( (char *)_status[i].texture_path.c_str(),
-                                wrapu, wrapv );
+           assignTexture( state, _status[i].texture_path, wrapu, wrapv );
             _status[i].texture_loaded = true;
         } else {
             _status[i].texture_loaded = false;
@@ -286,6 +287,22 @@ void SGMaterial::set_ssg_state( ssgSimpleState *s )
     _status.push_back( _internal_state( s, "", true ) );
 }
 
+void SGMaterial::assignTexture( ssgSimpleState *state, string &fname,
+                 int _wrapu, int _wrapv, int _mipmap )
+{
+   _tex_cache_iter = _tex_cache.find(fname);
+   if (_tex_cache_iter == _tex_cache.end())
+   {
+      state->setTexture((char *)fname.c_str(), _wrapu, _wrapv, _mipmap);
+      _tex_cache[fname] = state->getTexture();
+   }
+   else
+   {
+      state->setTexture(_tex_cache_iter->second);
+      // cout << "Cache hit: " << fname << endl;
+   }
+}
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
index 8631fdc1dc612923b2f8e2495f33e60e672d58db..c7534e70441ee0957970d8fd2c52dfb0dde59d2f 100644 (file)
@@ -243,6 +243,7 @@ private:
   void build_ssg_state( bool defer_tex_load );
   void set_ssg_state( ssgSimpleState *s );
 
+  void assignTexture( ssgSimpleState *state, string &fname, int _wrapu = TRUE, int _wrapv = TRUE, int _mipmap = TRUE );
 
 };