From d53603f85b754c75af4581e93e4504f040d0f7bb Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 11 Feb 2002 19:21:27 +0000 Subject: [PATCH] add set_keep_ram_image --- panda/src/gobj/texture.I | 40 ++++++++++++++++++++++++++++++++++---- panda/src/gobj/texture.cxx | 3 ++- panda/src/gobj/texture.h | 3 +++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 81e7451059..36c8768826 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -87,16 +87,48 @@ uses_mipmaps() const { //////////////////////////////////////////////////////////////////// // Function: Texture::has_ram_image // Access: Public -// Description: Returns true if the Texture keeps has its image -// contents available in main RAM, false if it exists -// only in texture memory or in the prepared GSG -// context. +// Description: Returns true if the Texture has its image contents +// available in main RAM, false if it exists only in +// texture memory or in the prepared GSG context. //////////////////////////////////////////////////////////////////// INLINE bool Texture:: has_ram_image() const { return !_pbuffer->_image.empty(); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::set_keep_ram_image +// Access: Public +// Description: Sets the flag that indicates whether this Texture is +// eligible to have its main RAM copy of the texture +// memory dumped when the texture is prepared for +// rendering. +// +// This will be true for most textures, which can reload +// their images if needed by rereading the input file. +// However, textures that were generated dynamically and +// cannot be easily reloaded will want to set this flag +// to true, so that the _pbuffer member will always keep +// its image copy around. +//////////////////////////////////////////////////////////////////// +INLINE void Texture:: +set_keep_ram_image(bool keep_ram_image) { + _keep_ram_image = keep_ram_image; +} + +//////////////////////////////////////////////////////////////////// +// Function: Texture::get_keep_ram_image +// Access: Public +// Description: Returns the flag that indicates whether this Texture +// is eligible to have its main RAM copy of the texture +// memory dumped when the texture is prepared for +// rendering. See set_keep_ram_image(). +//////////////////////////////////////////////////////////////////// +INLINE bool Texture:: +get_keep_ram_image() const { + return _keep_ram_image; +} + //////////////////////////////////////////////////////////////////// // Function: Texture::apply // Access: Public diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 6426e6d6ae..1fe2dbd78d 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -121,6 +121,7 @@ Texture() : ImageBuffer() { _wrapu = WM_repeat; _wrapv = WM_repeat; _anisotropic_degree = 1; + _keep_ram_image = false; _pbuffer = new PixelBuffer; _has_requested_size = false; _all_dirty_flags = 0; @@ -366,7 +367,7 @@ prepare(GraphicsStateGuardianBase *gsg) { // context isn't. _all_dirty_flags = 0; - if (!keep_texture_ram) { + if (!keep_texture_ram && !_keep_ram_image) { // Once we have prepared the texture, we can generally safely // remove the pixels from main RAM. The GSG is now responsible // for remembering what it looks like. diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index e3a86d72ca..bf6216d010 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -105,6 +105,8 @@ public: INLINE bool has_ram_image() const; PixelBuffer *get_ram_image(); + INLINE void set_keep_ram_image(bool keep_ram_image); + INLINE bool get_keep_ram_image() const; INLINE void apply(GraphicsStateGuardianBase *gsg); @@ -134,6 +136,7 @@ private: FilterType _minfilter; FilterType _magfilter; int _anisotropic_degree; + bool _keep_ram_image; // A Texture keeps a list (actually, a map) of all the GSG's that it // has been prepared into. Each GSG conversely keeps a list (a set)