Browse Source

fix some issues with model-cache-dir

David Rose 19 years ago
parent
commit
bd4d95f48b
2 changed files with 29 additions and 10 deletions
  1. 11 6
      panda/src/gobj/texture.cxx
  2. 18 4
      panda/src/gobj/texturePool.cxx

+ 11 - 6
panda/src/gobj/texture.cxx

@@ -138,8 +138,12 @@ operator = (const Texture &copy) {
   Namable::operator = (copy);
   Namable::operator = (copy);
   _filename = copy._filename;
   _filename = copy._filename;
   _alpha_filename = copy._alpha_filename;
   _alpha_filename = copy._alpha_filename;
-  _fullpath = copy._fullpath;
-  _alpha_fullpath = copy._alpha_fullpath;
+  if (!copy._fullpath.empty()) {
+    // Since the fullpath is often empty on a file loaded directly
+    // from a txo, we only assign the fullpath if it is not empty.
+    _fullpath = copy._fullpath;
+    _alpha_fullpath = copy._alpha_fullpath;
+  }
   _primary_file_num_channels = copy._primary_file_num_channels;
   _primary_file_num_channels = copy._primary_file_num_channels;
   _alpha_file_channel = copy._alpha_file_channel;
   _alpha_file_channel = copy._alpha_file_channel;
   _x_size = copy._x_size;
   _x_size = copy._x_size;
@@ -3175,11 +3179,7 @@ make_from_bam(const FactoryParams &params) {
     // and don't load from the file.
     // and don't load from the file.
     me = new Texture(name);
     me = new Texture(name);
     me->_filename = filename;
     me->_filename = filename;
-    me->_fullpath = filename;
-    me->_fullpath.make_absolute();
     me->_alpha_filename = alpha_filename;
     me->_alpha_filename = alpha_filename;
-    me->_alpha_fullpath = alpha_filename;
-    me->_alpha_fullpath.make_absolute();
     me->_primary_file_num_channels = primary_file_num_channels;
     me->_primary_file_num_channels = primary_file_num_channels;
     me->_alpha_file_channel = alpha_file_channel;
     me->_alpha_file_channel = alpha_file_channel;
     me->_texture_type = texture_type;
     me->_texture_type = texture_type;
@@ -3395,6 +3395,11 @@ write_datagram(BamWriter *manager, Datagram &me) {
       << "Unsupported bam-texture-mode: " << (int)file_texture_mode << "\n";
       << "Unsupported bam-texture-mode: " << (int)file_texture_mode << "\n";
   }
   }
 
 
+  if (filename.empty()) {
+    // If we don't have a filename, we have to store rawdata anyway.
+    has_rawdata = true;
+  }
+
   me.add_string(get_name());
   me.add_string(get_name());
   me.add_string(filename);
   me.add_string(filename);
   me.add_string(alpha_filename);
   me.add_string(alpha_filename);

+ 18 - 4
panda/src/gobj/texturePool.cxx

@@ -224,7 +224,9 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels,
   ti = _textures.find(filename);
   ti = _textures.find(filename);
   if (ti != _textures.end()) {
   if (ti != _textures.end()) {
     // This texture was previously loaded.
     // This texture was previously loaded.
-    return (*ti).second;
+    Texture *tex = (*ti).second;
+    nassertr(!tex->get_fullpath().empty(), tex);
+    return tex;
   }
   }
 
 
   PT(Texture) tex;
   PT(Texture) tex;
@@ -261,8 +263,9 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels,
   }
   }
 
 
   // Set the original filename, before we searched along the path.
   // Set the original filename, before we searched along the path.
-  nassertr(tex != (Texture *)NULL, false);
+  nassertr(tex != (Texture *)NULL, NULL);
   tex->set_filename(orig_filename);
   tex->set_filename(orig_filename);
+  tex->set_fullpath(filename);
   tex->_texture_pool_key = filename;
   tex->_texture_pool_key = filename;
   _textures[filename] = tex;
   _textures[filename] = tex;
 
 
@@ -272,6 +275,7 @@ ns_load_texture(const Filename &orig_filename, int primary_file_num_channels,
     cache->store(record);
     cache->store(record);
   }
   }
 
 
+  nassertr(!tex->get_fullpath().empty(), tex);
   return tex;
   return tex;
 }
 }
 
 
@@ -305,7 +309,9 @@ ns_load_texture(const Filename &orig_filename,
   ti = _textures.find(filename);
   ti = _textures.find(filename);
   if (ti != _textures.end()) {
   if (ti != _textures.end()) {
     // This texture was previously loaded.
     // This texture was previously loaded.
-    return (*ti).second;
+    Texture *tex = (*ti).second;
+    nassertr(!tex->get_fullpath().empty(), tex);
+    return tex;
   }
   }
 
 
   PT(Texture) tex;
   PT(Texture) tex;
@@ -343,9 +349,11 @@ ns_load_texture(const Filename &orig_filename,
   }
   }
 
 
   // Set the original filenames, before we searched along the path.
   // Set the original filenames, before we searched along the path.
-  nassertr(tex != (Texture *)NULL, false);
+  nassertr(tex != (Texture *)NULL, NULL);
   tex->set_filename(orig_filename);
   tex->set_filename(orig_filename);
+  tex->set_fullpath(filename);
   tex->set_alpha_filename(orig_alpha_filename);
   tex->set_alpha_filename(orig_alpha_filename);
+  tex->set_alpha_fullpath(alpha_filename);
   tex->_texture_pool_key = filename;
   tex->_texture_pool_key = filename;
   _textures[filename] = tex;
   _textures[filename] = tex;
 
 
@@ -355,6 +363,7 @@ ns_load_texture(const Filename &orig_filename,
     cache->store(record);
     cache->store(record);
   }
   }
 
 
+  nassertr(!tex->get_fullpath().empty(), tex);
   return tex;
   return tex;
 }
 }
 
 
@@ -417,6 +426,7 @@ ns_load_3d_texture(const Filename &filename_pattern,
   // Set the original filename, before we searched along the path.
   // Set the original filename, before we searched along the path.
   nassertr(tex != (Texture *)NULL, false);
   nassertr(tex != (Texture *)NULL, false);
   tex->set_filename(filename_pattern);
   tex->set_filename(filename_pattern);
+  tex->set_fullpath(filename);
   tex->_texture_pool_key = filename;
   tex->_texture_pool_key = filename;
   _textures[filename] = tex;
   _textures[filename] = tex;
 
 
@@ -426,6 +436,7 @@ ns_load_3d_texture(const Filename &filename_pattern,
     cache->store(record);
     cache->store(record);
   }
   }
 
 
+  nassertr(!tex->get_fullpath().empty(), tex);
   return tex;
   return tex;
 }
 }
 
 
@@ -487,6 +498,7 @@ ns_load_cube_map(const Filename &filename_pattern, bool read_mipmaps) {
   // Set the original filename, before we searched along the path.
   // Set the original filename, before we searched along the path.
   nassertr(tex != (Texture *)NULL, false);
   nassertr(tex != (Texture *)NULL, false);
   tex->set_filename(filename_pattern);
   tex->set_filename(filename_pattern);
+  tex->set_fullpath(filename);
   tex->_texture_pool_key = filename;
   tex->_texture_pool_key = filename;
   _textures[filename] = tex;
   _textures[filename] = tex;
 
 
@@ -496,6 +508,7 @@ ns_load_cube_map(const Filename &filename_pattern, bool read_mipmaps) {
     cache->store(record);
     cache->store(record);
   }
   }
 
 
+  nassertr(!tex->get_fullpath().empty(), tex);
   return tex;
   return tex;
 }
 }
 
 
@@ -536,6 +549,7 @@ ns_add_texture(Texture *tex) {
   // We blow away whatever texture was there previously, if any.
   // We blow away whatever texture was there previously, if any.
   tex->_texture_pool_key = filename;
   tex->_texture_pool_key = filename;
   _textures[filename] = tex;
   _textures[filename] = tex;
+  nassertv(!tex->get_fullpath().empty());
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////