From 3f42a08968d49762bd7a5c745e8ba92d776b839e Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Jun 2009 22:11:28 +0000 Subject: [PATCH] automatically reload texture when changing compression mode --- panda/src/gobj/texture.I | 16 ++++++++++++ panda/src/gobj/texture.cxx | 53 ++++++++++++++++++-------------------- panda/src/gobj/texture.h | 3 ++- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 3ca8001482..4da69b1825 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -306,6 +306,22 @@ store(PNMImage &pnmimage, int z, int n) const { return do_store_one(pnmimage, z, n); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::reload +// Access: Published +// Description: Re-reads the Texture from its disk file. Useful when +// you know the image on disk has recently changed, and +// you want to update the Texture image. +// +// Returns true on success, false on failure (in which +// case, the Texture may or may not still be valid). +//////////////////////////////////////////////////////////////////// +bool Texture:: +reload() { + MutexHolder holder(_lock); + return do_reload(); +} + //////////////////////////////////////////////////////////////////// // Function: Texture::has_filename // Access: Published diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 4f53ebc89f..0fdb9d42a5 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -720,34 +720,6 @@ read_dds(istream &in, const string &filename, bool header_only) { return do_read_dds(in, filename, header_only); } -//////////////////////////////////////////////////////////////////// -// Function: Texture::reload -// Access: Published -// Description: Re-reads the Texture from its disk file. Useful when -// you know the image on disk has recently changed, and -// you want to update the Texture image. -// -// Returns true on success, false on failure (in which -// case, the Texture may or may not still be valid). -//////////////////////////////////////////////////////////////////// -bool Texture:: -reload() { - MutexHolder holder(_lock); - if (_loaded_from_image && !_fullpath.empty()) { - do_clear_ram_image(); - do_unlock_and_reload_ram_image(true); - if (do_has_ram_image()) { - // An explicit call to reload() should increment image_modified. - ++_image_modified; - return true; - } - return false; - } - - // We don't have a filename to load from. - return false; -} - //////////////////////////////////////////////////////////////////// // Function: Texture::load_related // Access: Published @@ -4034,6 +4006,9 @@ do_set_compression(Texture::CompressionMode compression) { if (_compression != compression) { ++_properties_modified; _compression = compression; + if (do_has_ram_image()) { + do_reload(); + } } } @@ -4550,6 +4525,28 @@ do_set_pad_size(int x, int y, int z) { _pad_z_size = z; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::do_reload +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +bool Texture:: +do_reload() { + if (_loaded_from_image && !_fullpath.empty()) { + do_clear_ram_image(); + do_unlock_and_reload_ram_image(true); + if (do_has_ram_image()) { + // An explicit call to reload() should increment image_modified. + ++_image_modified; + return true; + } + return false; + } + + // We don't have a filename to load from. + return false; +} + //////////////////////////////////////////////////////////////////// // Function: Texture::convert_from_pnmimage // Access: Private, Static diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 8457caae87..625ce8bb5c 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -247,7 +247,7 @@ PUBLISHED: INLINE bool store(PNMImage &pnmimage) const; INLINE bool store(PNMImage &pnmimage, int z, int n) const; - bool reload(); + INLINE bool reload(); Texture *load_related(const InternalName *suffix) const; INLINE bool has_filename() const; @@ -551,6 +551,7 @@ protected: void do_clear_ram_mipmap_images(); void do_generate_ram_mipmap_images(); void do_set_pad_size(int x, int y, int z); + bool do_reload(); // This nested class declaration is used below. class RamImage {