Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/texturePool.h

Go to the documentation of this file.
00001 // Filename: texturePool.h
00002 // Created by:  drose (26Apr00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef TEXTUREPOOL_H
00020 #define TEXTUREPOOL_H
00021 
00022 #include "pandabase.h"
00023 #include "texture.h"
00024 #include "filename.h"
00025 
00026 #include "pmap.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : TexturePool
00030 // Description : This is the preferred interface for loading textures
00031 //               from image files.  It unifies all references to the
00032 //               same filename, so that multiple models that reference
00033 //               the same textures don't waste texture memory
00034 //               unnecessarily.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA TexturePool {
00037 PUBLISHED:
00038   // These functions take string parameters instead of Filenames
00039   // because that's somewhat more convenient to the scripting
00040   // language.
00041   INLINE static bool has_texture(const string &filename);
00042   INLINE static bool verify_texture(const string &filename);
00043   INLINE static Texture *load_texture(const string &filename, 
00044                                       int primary_file_num_channels = 0);
00045   INLINE static Texture *load_texture(const string &filename,
00046                                       const string &alpha_filename, 
00047                                       int primary_file_num_channels = 0,
00048                                       int alpha_file_channel = 0);
00049   INLINE static void add_texture(Texture *texture);
00050   INLINE static void release_texture(Texture *texture);
00051   INLINE static void release_all_textures();
00052 
00053   INLINE static int garbage_collect();
00054 
00055   INLINE static void list_contents(ostream &out);
00056 
00057 private:
00058   INLINE TexturePool();
00059 
00060   bool ns_has_texture(const Filename &orig_filename);
00061   Texture *ns_load_texture(const Filename &orig_filename, int primary_file_num_channels);
00062   Texture *ns_load_texture(const Filename &orig_filename, 
00063                            const Filename &orig_alpha_filename, 
00064                            int primary_file_num_channels,
00065                            int alpha_file_channel);
00066   void ns_add_texture(Texture *texture);
00067   void ns_release_texture(Texture *texture);
00068   void ns_release_all_textures();
00069   int ns_garbage_collect();
00070   void ns_list_contents(ostream &out);
00071 
00072   static TexturePool *get_ptr();
00073 
00074   static TexturePool *_global_ptr;
00075   typedef pmap<string,  PT(Texture) > Textures;
00076   Textures _textures;
00077 };
00078 
00079 #include "texturePool.I"
00080 
00081 #endif
00082 
00083 

Generated on Fri May 2 00:39:45 2003 for Panda by doxygen1.3