Panda3D

textureStagePool.h

00001 // Filename: textureStagePool.h
00002 // Created by:  drose (03May10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef TEXTURESTAGEPOOL_H
00016 #define TEXTURESTAGEPOOL_H
00017 
00018 #include "pandabase.h"
00019 #include "textureStage.h"
00020 #include "pointerTo.h"
00021 #include "pmutex.h"
00022 #include "pset.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : TextureStagePool
00026 // Description : The TextureStagePool (there is only one in the universe)
00027 //               serves to unify different pointers to the same
00028 //               TextureStage, mainly to help developers use a common
00029 //               pointer to access things that are loaded from
00030 //               different model files.
00031 //
00032 //               It runs in one of three different modes, according to
00033 //               set_mode().  See that method for more information.
00034 ////////////////////////////////////////////////////////////////////
00035 class EXPCL_PANDA_GOBJ TextureStagePool {
00036 PUBLISHED:
00037   enum Mode {
00038     M_none,
00039     M_name,
00040     M_unique,
00041   };
00042 
00043   INLINE static TextureStage *get_stage(TextureStage *temp);
00044   INLINE static void release_stage(TextureStage *temp);
00045   INLINE static void release_all_stages();
00046 
00047   INLINE static void set_mode(Mode mode);
00048   INLINE static Mode get_mode();
00049 
00050   INLINE static int garbage_collect();
00051   INLINE static void list_contents(ostream &out);
00052   static void write(ostream &out);
00053 
00054 private:
00055   TextureStagePool();
00056 
00057   TextureStage *ns_get_stage(TextureStage *temp);
00058   void ns_release_stage(TextureStage *temp);
00059   void ns_release_all_stages();
00060 
00061   void ns_set_mode(Mode mode);
00062   Mode ns_get_mode();
00063 
00064   int ns_garbage_collect();
00065   void ns_list_contents(ostream &out) const;
00066 
00067   static TextureStagePool *get_global_ptr();
00068 
00069   static TextureStagePool *_global_ptr;
00070 
00071   Mutex _lock;
00072 
00073   // We store a map of CPT(TextureStage) to PT(TextureStage).  These are two
00074   // equivalent structures, but different pointers.  The first pointer
00075   // never leaves this class.  If the second pointer changes value,
00076   // we'll notice it and return a new one.
00077   typedef pmap<CPT(TextureStage), PT(TextureStage), indirect_compare_to<const TextureStage *> > StagesByProperties;
00078   StagesByProperties _stages_by_properties;
00079 
00080   typedef pmap<string, PT(TextureStage) > StagesByName;
00081   StagesByName _stages_by_name;
00082 
00083   Mode _mode;
00084 };
00085 
00086 EXPCL_PANDA_GOBJ ostream &operator << (ostream &out, TextureStagePool::Mode mode);
00087 EXPCL_PANDA_GOBJ istream &operator >> (istream &in, TextureStagePool::Mode &mode);
00088 
00089 #include "textureStagePool.I"
00090 
00091 #endif
00092 
00093 
 All Classes Functions Variables Enumerations