00001 // Filename: materialPool.h 00002 // Created by: drose (30Apr01) 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 MATERIALPOOL_H 00020 #define MATERIALPOOL_H 00021 00022 #include <pandabase.h> 00023 00024 #include "material.h" 00025 00026 #include <indirectCompareTo.h> 00027 #include <pointerTo.h> 00028 00029 #include "pset.h" 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : MaterialPool 00033 // Description : The MaterialPool (there is only one in the universe) 00034 // serves to unify different pointers to the same 00035 // Material, so we do not (a) waste memory with many 00036 // different Material objects that are all equivalent, 00037 // and (b) waste time switching the graphics engine 00038 // between different Material states that are really the 00039 // same thing. 00040 // 00041 // The idea is to create a temporary Material 00042 // representing the lighting state you want to apply, 00043 // then call get_material(), passing in your temporary 00044 // Material. The return value will be a constant 00045 // Material object that should be modified (because it 00046 // is now shared among many different geometries), that 00047 // is the same as the temporary Material pointer you 00048 // supplied but may be a different pointer. 00049 //////////////////////////////////////////////////////////////////// 00050 class EXPCL_PANDA MaterialPool { 00051 PUBLISHED: 00052 INLINE static const Material *get_material(const CPT(Material) &temp); 00053 INLINE static int garbage_collect(); 00054 INLINE static void list_contents(ostream &out); 00055 00056 private: 00057 INLINE MaterialPool(); 00058 00059 const Material *ns_get_material(const CPT(Material) &temp); 00060 int ns_garbage_collect(); 00061 void ns_list_contents(ostream &out); 00062 00063 static MaterialPool *get_ptr(); 00064 00065 static MaterialPool *_global_ptr; 00066 typedef pset< CPT(Material), IndirectCompareTo<Material> > Materials; 00067 Materials _materials; 00068 }; 00069 00070 #include "materialPool.I" 00071 00072 #endif 00073 00074