Panda3D
Loading...
Searching...
No Matches
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 */
32class EXPCL_PANDA_GOBJ TextureStagePool {
33PUBLISHED:
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
52private:
53 TextureStagePool();
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.
75 typedef pmap<CPT(TextureStage), PT(TextureStage), indirect_compare_to<const TextureStage *> > StagesByProperties;
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
84EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStagePool::Mode mode);
85EXPCL_PANDA_GOBJ std::istream &operator >> (std::istream &in, TextureStagePool::Mode &mode);
86
87#include "textureStagePool.I"
88
89#endif
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
static void list_contents(std::ostream &out)
Lists the contents of the TextureStage pool to the indicated output stream.
static void release_all_stages()
Releases all TextureStages in the pool and restores the pool to the empty state.
set_mode
Specifies the fundamental operating mode of the TextureStagePool.
get_mode
Returns the fundamental operating mode of the TextureStagePool.
static void write(std::ostream &out)
Lists the contents of the TextureStage pool to the indicated output stream.
static TextureStage * get_stage(TextureStage *temp)
Returns a TextureStage pointer that represents the same TextureStage described by temp,...
static int garbage_collect()
Releases only those TextureStages in the pool that have a reference count of exactly 1; i....
static void release_stage(TextureStage *temp)
Removes the indicated TextureStage from the pool.
Defines the properties of a named stage of the multitexture pipeline.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.