diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index da4547b1e0..0a33f8ae5b 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -133,6 +133,7 @@ setup_cube_map(int size, ComponentType component_type, //////////////////////////////////////////////////////////////////// INLINE bool Texture:: read(const Filename &fullpath) { + ++_modified; return do_read(fullpath, Filename(), 0, 0, 0, 0, false, false); } @@ -150,6 +151,7 @@ read(const Filename &fullpath) { INLINE bool Texture:: read(const Filename &fullpath, const Filename &alpha_fullpath, int primary_file_num_channels, int alpha_file_channel) { + ++_modified; return do_read(fullpath, alpha_fullpath, primary_file_num_channels, alpha_file_channel, 0, 0, false, false); } @@ -167,6 +169,7 @@ read(const Filename &fullpath, const Filename &alpha_fullpath, INLINE bool Texture:: read(const Filename &fullpath, int z, int n, bool read_pages, bool read_mipmaps) { + ++_modified; return do_read(fullpath, Filename(), 0, 0, z, n, read_pages, read_mipmaps); } @@ -243,6 +246,7 @@ INLINE bool Texture:: read(const Filename &fullpath, const Filename &alpha_fullpath, int primary_file_num_channels, int alpha_file_channel, int z, int n, bool read_pages, bool read_mipmaps) { + ++_modified; return do_read(fullpath, alpha_fullpath, primary_file_num_channels, alpha_file_channel, z, n, read_pages, read_mipmaps); } @@ -324,6 +328,7 @@ write(const Filename &fullpath, int z, int n, //////////////////////////////////////////////////////////////////// INLINE bool Texture:: load(const PNMImage &pnmimage) { + ++_modified; return do_load_one(pnmimage, 0, 0); } @@ -335,6 +340,7 @@ load(const PNMImage &pnmimage) { //////////////////////////////////////////////////////////////////// INLINE bool Texture:: load(const PNMImage &pnmimage, int z, int n) { + ++_modified; return do_load_one(pnmimage, z, n); } @@ -763,6 +769,39 @@ get_ram_image_compression() const { return _ram_image_compression; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::modify_ram_image +// Access: Published +// Description: Returns a modifiable pointer to the system-RAM image. +// This assumes the RAM image should be uncompressed. +// If the RAM image has been dumped, or is stored +// compressed, creates a new one. +// +// This does *not* affect keep_ram_image. +//////////////////////////////////////////////////////////////////// +INLINE PTA_uchar Texture:: +modify_ram_image() { + do_modify_ram_image(); + ++_modified; + return _ram_images[0]._image; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::make_ram_image +// Access: Published +// Description: Discards the current system-RAM image for the +// texture, if any, and allocates a new buffer of the +// appropriate size. Returns the new buffer. +// +// This does *not* affect keep_ram_image. +//////////////////////////////////////////////////////////////////// +INLINE PTA_uchar Texture:: +make_ram_image() { + ++_modified; + do_make_ram_image(); + return _ram_images[0]._image; +} + //////////////////////////////////////////////////////////////////// // Function: Texture::set_keep_ram_image // Access: Published @@ -876,6 +915,23 @@ get_expected_ram_mipmap_page_size(int n) const { return (size_t)(get_expected_mipmap_x_size(n) * get_expected_mipmap_y_size(n) * _num_components * _component_width); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::modify_ram_mipmap_image +// Access: Published +// Description: Returns a modifiable pointer to the system-RAM image +// for the nth mipmap level. This assumes the RAM image +// is uncompressed; if this is not the case, raises an +// assertion. +// +// This does *not* affect keep_ram_image. +//////////////////////////////////////////////////////////////////// +INLINE PTA_uchar Texture:: +modify_ram_mipmap_image(int n) { + do_modify_ram_mipmap_image(n); + ++_modified; + return _ram_images[n]._image; +} + //////////////////////////////////////////////////////////////////// // Function: Texture::get_modified // Access: Published diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index b5e5a9f924..25b7fce828 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -866,49 +866,6 @@ get_ram_image() { return _ram_images[0]._image; } -//////////////////////////////////////////////////////////////////// -// Function: Texture::modify_ram_image -// Access: Published -// Description: Returns a modifiable pointer to the system-RAM image. -// This assumes the RAM image should be uncompressed. -// If the RAM image has been dumped, or is stored -// compressed, creates a new one. -// -// This does *not* affect keep_ram_image. -//////////////////////////////////////////////////////////////////// -PTA_uchar Texture:: -modify_ram_image() { - if (_ram_images.empty() || _ram_images[0]._image.empty() || - _ram_image_compression != CM_off) { - make_ram_image(); - } else { - clear_ram_mipmap_images(); - } - - ++_modified; - return _ram_images[0]._image; -} - -//////////////////////////////////////////////////////////////////// -// Function: Texture::make_ram_image -// Access: Published -// Description: Discards the current system-RAM image for the -// texture, if any, and allocates a new buffer of the -// appropriate size. Returns the new buffer. -// -// This does *not* affect keep_ram_image. -//////////////////////////////////////////////////////////////////// -PTA_uchar Texture:: -make_ram_image() { - _ram_images.clear(); - _ram_images.push_back(RamImage()); - _ram_images[0]._page_size = get_expected_ram_page_size(); - _ram_images[0]._image = PTA_uchar::empty_array(get_expected_ram_image_size()); - _ram_image_compression = CM_off; - ++_modified; - return _ram_images[0]._image; -} - //////////////////////////////////////////////////////////////////// // Function: Texture::set_ram_image // Access: Published @@ -1016,29 +973,6 @@ get_ram_mipmap_image(int n) { return CPTA_uchar(); } -//////////////////////////////////////////////////////////////////// -// Function: Texture::modify_ram_mipmap_image -// Access: Published -// Description: Returns a modifiable pointer to the system-RAM image -// for the nth mipmap level. This assumes the RAM image -// is uncompressed; if this is not the case, raises an -// assertion. -// -// This does *not* affect keep_ram_image. -//////////////////////////////////////////////////////////////////// -PTA_uchar Texture:: -modify_ram_mipmap_image(int n) { - nassertr(_ram_image_compression == CM_off, PTA_uchar()); - - if (n >= (int)_ram_images.size() || - _ram_images[n]._image.empty()) { - make_ram_mipmap_image(n); - } - - ++_modified; - return _ram_images[n]._image; -} - //////////////////////////////////////////////////////////////////// // Function: Texture::make_ram_mipmap_image // Access: Published @@ -2150,11 +2084,11 @@ do_load_one(const PNMImage &pnmimage, int z, int n) { return false; } - modify_ram_image(); + do_modify_ram_image(); _loaded_from_image = true; } - modify_ram_mipmap_image(n); + do_modify_ram_mipmap_image(n); // Ensure the PNMImage is an appropriate size. int x_size = get_expected_mipmap_x_size(n); @@ -2182,8 +2116,6 @@ do_load_one(const PNMImage &pnmimage, int z, int n) { pnmimage); } - ++_modified; - return true; } @@ -2228,7 +2160,7 @@ void Texture:: reload_ram_image() { gobj_cat.info() << "Reloading texture " << get_name() << "\n"; - make_ram_image(); + do_make_ram_image(); int z = 0; int n = 0; @@ -2245,6 +2177,53 @@ reload_ram_image() { z, n, _has_read_pages, _has_read_mipmaps); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::do_modify_ram_image +// Access: Protected +// Description: This is called internally to uniquify the ram image +// pointer without updating _modified. +//////////////////////////////////////////////////////////////////// +void Texture:: +do_modify_ram_image() { + if (_ram_images.empty() || _ram_images[0]._image.empty() || + _ram_image_compression != CM_off) { + do_make_ram_image(); + } else { + clear_ram_mipmap_images(); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::do_make_ram_image +// Access: Protected +// Description: This is called internally to make a new ram image +// without updating _modified. +//////////////////////////////////////////////////////////////////// +void Texture:: +do_make_ram_image() { + _ram_images.clear(); + _ram_images.push_back(RamImage()); + _ram_images[0]._page_size = get_expected_ram_page_size(); + _ram_images[0]._image = PTA_uchar::empty_array(get_expected_ram_image_size()); + _ram_image_compression = CM_off; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::do_modify_ram_mipmap_image +// Access: Protected +// Description: This is called internally to uniquify the nth mipmap +// image pointer without updating _modified. +//////////////////////////////////////////////////////////////////// +void Texture:: +do_modify_ram_mipmap_image(int n) { + nassertv(_ram_image_compression == CM_off); + + if (n >= (int)_ram_images.size() || + _ram_images[n]._image.empty()) { + make_ram_mipmap_image(n); + } +} + //////////////////////////////////////////////////////////////////// // Function: Texture::up_to_power_2 diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 5a618f5e78..65aebaa7c9 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -276,8 +276,8 @@ PUBLISHED: INLINE size_t get_expected_ram_page_size() const; CPTA_uchar get_ram_image(); INLINE CompressionMode get_ram_image_compression() const; - PTA_uchar modify_ram_image(); - PTA_uchar make_ram_image(); + INLINE PTA_uchar modify_ram_image(); + INLINE PTA_uchar make_ram_image(); void set_ram_image(PTA_uchar image, CompressionMode compression = CM_off, size_t page_size = 0); void clear_ram_image(); @@ -292,7 +292,7 @@ PUBLISHED: INLINE size_t get_expected_ram_mipmap_image_size(int n) const; INLINE size_t get_expected_ram_mipmap_page_size(int n) const; CPTA_uchar get_ram_mipmap_image(int n); - PTA_uchar modify_ram_mipmap_image(int n); + INLINE PTA_uchar modify_ram_mipmap_image(int n); PTA_uchar make_ram_mipmap_image(int n); void set_ram_mipmap_image(int n, PTA_uchar image, size_t page_size = 0); void clear_ram_mipmap_image(int n); @@ -375,6 +375,10 @@ protected: virtual void reconsider_dirty(); virtual void reload_ram_image(); + void do_modify_ram_image(); + void do_make_ram_image(); + void do_modify_ram_mipmap_image(int n); + bool reconsider_z_size(int z); bool reconsider_image_properties(int x_size, int y_size, int num_components, ComponentType component_type, int z);