Panda3D
textureStagePool.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file textureStagePool.h
10  * @author drose
11  * @date 2010-05-03
12  */
13 
14 #ifndef TEXTURESTAGEPOOL_H
15 #define TEXTURESTAGEPOOL_H
16 
17 #include "pandabase.h"
18 #include "textureStage.h"
19 #include "pointerTo.h"
20 #include "pmutex.h"
21 #include "pset.h"
22 
23 /**
24  * The TextureStagePool (there is only one in the universe) serves to unify
25  * different pointers to the same TextureStage, mainly to help developers use
26  * a common pointer to access things that are loaded from different model
27  * files.
28  *
29  * It runs in one of three different modes, according to set_mode(). See that
30  * method for more information.
31  */
32 class EXPCL_PANDA_GOBJ TextureStagePool {
33 PUBLISHED:
34  enum Mode {
35  M_none,
36  M_name,
37  M_unique,
38  };
39 
40  INLINE static TextureStage *get_stage(TextureStage *temp);
41  INLINE static void release_stage(TextureStage *temp);
42  INLINE static void release_all_stages();
43 
44  INLINE static void set_mode(Mode mode);
45  INLINE static Mode get_mode();
46  MAKE_PROPERTY(mode, get_mode, set_mode);
47 
48  INLINE static int garbage_collect();
49  INLINE static void list_contents(std::ostream &out);
50  static void write(std::ostream &out);
51 
52 private:
54 
55  TextureStage *ns_get_stage(TextureStage *temp);
56  void ns_release_stage(TextureStage *temp);
57  void ns_release_all_stages();
58 
59  void ns_set_mode(Mode mode);
60  Mode ns_get_mode();
61 
62  int ns_garbage_collect();
63  void ns_list_contents(std::ostream &out) const;
64 
65  static TextureStagePool *get_global_ptr();
66 
67  static TextureStagePool *_global_ptr;
68 
69  Mutex _lock;
70 
71  // We store a map of CPT(TextureStage) to PT(TextureStage). These are two
72  // equivalent structures, but different pointers. The first pointer never
73  // leaves this class. If the second pointer changes value, we'll notice it
74  // and return a new one.
76  StagesByProperties _stages_by_properties;
77 
78  typedef pmap<std::string, PT(TextureStage) > StagesByName;
79  StagesByName _stages_by_name;
80 
81  Mode _mode;
82 };
83 
84 EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStagePool::Mode mode);
85 EXPCL_PANDA_GOBJ std::istream &operator >> (std::istream &in, TextureStagePool::Mode &mode);
86 
87 #include "textureStagePool.I"
88 
89 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The TextureStagePool (there is only one in the universe) serves to unify different pointers to the sa...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
Definition: stl_compares.h:96
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:35