add set_fake_texture_image

This commit is contained in:
David Rose 2003-11-20 03:35:24 +00:00
parent 1dc36ab4d0
commit 1cbe39e68e
3 changed files with 68 additions and 15 deletions

View File

@ -16,9 +16,10 @@
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: TexturePool::has_texture
// Access: Public, Static
// Access: Published, Static
// Description: Returns true if the texture has ever been loaded,
// false otherwise.
////////////////////////////////////////////////////////////////////
@ -29,7 +30,7 @@ has_texture(const string &filename) {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::verify_texture
// Access: Public, Static
// Access: Published, Static
// Description: Loads the given filename up into a texture, if it has
// not already been loaded, and returns true to indicate
// success, or false to indicate failure. If this
@ -44,7 +45,7 @@ verify_texture(const string &filename) {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::load_texture
// Access: Public, Static
// Access: Published, Static
// Description: Loads the given filename up into a texture, if it has
// not already been loaded, and returns the new texture.
// If a texture with the same filename was previously
@ -58,7 +59,7 @@ load_texture(const string &filename, int primary_file_num_channels) {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::load_texture
// Access: Public, Static
// Access: Published, Static
// Description: Loads the given filename up into a texture, if it has
// not already been loaded, and returns the new texture.
// If a texture with the same filename was previously
@ -75,7 +76,7 @@ load_texture(const string &filename, const string &alpha_filename,
////////////////////////////////////////////////////////////////////
// Function: TexturePool::add_texture
// Access: Public, Static
// Access: Published, Static
// Description: Adds the indicated already-loaded texture to the
// pool. The texture must have a filename set for its
// name. The texture will always replace any
@ -89,7 +90,7 @@ add_texture(Texture *texture) {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::release_texture
// Access: Public, Static
// Access: Published, Static
// Description: Removes the indicated texture from the pool,
// indicating it will never be loaded again; the texture
// may then be freed. If this function is never called,
@ -107,7 +108,7 @@ release_texture(Texture *texture) {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::release_all_textures
// Access: Public, Static
// Access: Published, Static
// Description: Releases all textures in the pool and restores the
// pool to the empty state.
////////////////////////////////////////////////////////////////////
@ -118,7 +119,7 @@ release_all_textures() {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::garbage_collect
// Access: Public, Static
// Access: Published, Static
// Description: Releases only those textures in the pool that have a
// reference count of exactly 1; i.e. only those
// textures that are not being used outside of the pool.
@ -131,7 +132,7 @@ garbage_collect() {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::list_contents
// Access: Public, Static
// Access: Published, Static
// Description: Lists the contents of the texture pool to the
// indicated output stream.
////////////////////////////////////////////////////////////////////
@ -140,6 +141,50 @@ list_contents(ostream &out) {
get_ptr()->ns_list_contents(out);
}
////////////////////////////////////////////////////////////////////
// Function: TexturePool::set_fake_texture_image
// Access: Published, Static
// Description: Sets a bogus filename that will be loaded in lieu of
// any textures requested from this point on.
////////////////////////////////////////////////////////////////////
INLINE void TexturePool::
set_fake_texture_image(const string &filename) {
get_ptr()->_fake_texture_image = filename;
}
////////////////////////////////////////////////////////////////////
// Function: TexturePool::clear_fake_texture_image
// Access: Published, Static
// Description: Restores normal behavior of loading the textures
// actually requested.
////////////////////////////////////////////////////////////////////
INLINE void TexturePool::
clear_fake_texture_image() {
set_fake_texture_image(string());
}
////////////////////////////////////////////////////////////////////
// Function: TexturePool::has_fake_texture_image
// Access: Published, Static
// Description: Returns true if fake_texture_image mode has been
// enabled, false if we are in the normal mode.
////////////////////////////////////////////////////////////////////
INLINE bool TexturePool::
has_fake_texture_image() {
return !get_fake_texture_image().empty();
}
////////////////////////////////////////////////////////////////////
// Function: TexturePool::get_fake_texture_image
// Access: Published, Static
// Description: Returns the filename that was specified with a
// previous call to set_fake_texture_image().
////////////////////////////////////////////////////////////////////
INLINE const string &TexturePool::
get_fake_texture_image() {
return get_ptr()->_fake_texture_image;
}
////////////////////////////////////////////////////////////////////
// Function: TexturePool::Constructor
// Access: Private
@ -149,4 +194,5 @@ list_contents(ostream &out) {
////////////////////////////////////////////////////////////////////
INLINE TexturePool::
TexturePool() {
_fake_texture_image = fake_texture_image;
}

View File

@ -35,8 +35,8 @@ bool TexturePool::
ns_has_texture(const Filename &orig_filename) {
Filename filename(orig_filename);
if (!fake_texture_image.empty()) {
filename = fake_texture_image;
if (!_fake_texture_image.empty()) {
filename = _fake_texture_image;
}
if (use_vfs) {
@ -68,8 +68,8 @@ Texture *TexturePool::
ns_load_texture(const Filename &orig_filename, int primary_file_num_channels) {
Filename filename(orig_filename);
if (!fake_texture_image.empty()) {
filename = fake_texture_image;
if (!_fake_texture_image.empty()) {
filename = _fake_texture_image;
}
if (use_vfs) {
@ -119,8 +119,8 @@ ns_load_texture(const Filename &orig_filename,
Filename filename(orig_filename);
Filename alpha_filename(orig_alpha_filename);
if (!fake_texture_image.empty()) {
return ns_load_texture(fake_texture_image, primary_file_num_channels);
if (!_fake_texture_image.empty()) {
return ns_load_texture(_fake_texture_image, primary_file_num_channels);
}
if (use_vfs) {

View File

@ -22,6 +22,7 @@
#include "pandabase.h"
#include "texture.h"
#include "filename.h"
#include "config_gobj.h"
#include "pmap.h"
@ -54,6 +55,11 @@ PUBLISHED:
INLINE static void list_contents(ostream &out);
INLINE static void set_fake_texture_image(const string &filename);
INLINE static void clear_fake_texture_image();
INLINE static bool has_fake_texture_image();
INLINE static const string &get_fake_texture_image();
private:
INLINE TexturePool();
@ -74,6 +80,7 @@ private:
static TexturePool *_global_ptr;
typedef pmap<string, PT(Texture) > Textures;
Textures _textures;
string _fake_texture_image;
};
#include "texturePool.I"