From 1ea11e7073c0903c3f7b096802a2f44ef176ad1a Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 3 Aug 2006 13:52:35 +0000 Subject: [PATCH] don't insist on loading alpha version of related texture --- panda/src/gobj/texture.cxx | 24 ++++++++++++++++++------ panda/src/gobj/texture.h | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 410555a1cd..290a5e8c6c 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -611,7 +611,7 @@ reload() { // texture doesn't have a filename. //////////////////////////////////////////////////////////////////// Texture *Texture:: -load_related(const PT(InternalName) &suffix) const { +load_related(const InternalName *suffix) const { RelatedTextures::const_iterator ti; ti = _related_textures.find(suffix); if (ti != _related_textures.end()) { @@ -628,13 +628,25 @@ load_related(const PT(InternalName) &suffix) const { Filename alph = get_alpha_fullpath(); alph.set_basename_wo_extension(alph.get_basename_wo_extension() + suffix->get_name()); - res = TexturePool::load_texture(main, alph, - _primary_file_num_channels, - _alpha_file_channel); + VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); + if (vfs->exists(alph)) { + // The alpha variant of the filename, with the suffix, exists. + // Use it to load the texture. + res = TexturePool::load_texture(main, alph, + _primary_file_num_channels, + _alpha_file_channel); + } else { + // If the alpha variant of the filename doesn't exist, just go + // ahead and load the related texture without alpha. + res = TexturePool::load_texture(main); + } + } else { - res = TexturePool::load_texture(main, - _primary_file_num_channels); + // No alpha filename--just load the single file. It doesn't + // necessarily have the same number of channels as this one. + res = TexturePool::load_texture(main); } + // I'm casting away the const-ness of 'this' because this // field is only a cache. ((Texture *)this)->_related_textures.insert(RelatedTextures::value_type(suffix, res)); diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 991bf2ff57..a1902a7884 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -223,7 +223,7 @@ PUBLISHED: INLINE bool store(PNMImage &pnmimage, int z, int n) const; bool reload(); - Texture *load_related(const PT(InternalName) &suffix) const; + Texture *load_related(const InternalName *suffix) const; INLINE bool has_filename() const; INLINE const Filename &get_filename() const; @@ -508,7 +508,7 @@ protected: // of the special maps are derived by concatenating a suffix to // the name of the diffuse map. The following table enables // lookup of the special maps given the diffuse map and the suffix. - typedef pmap RelatedTextures; + typedef pmap RelatedTextures; RelatedTextures _related_textures; CompressionMode _ram_image_compression;