xoreos  0.0.5
surfaceman.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 
28 
30 
31 namespace Graphics {
32 
33 namespace Shader {
34 
36  ShaderSurface *surface = new ShaderSurface(ShaderMan.getShaderObject("default/default.vert", SHADER_VERTEX), "defaultSurface");
37  _resourceMap[surface->getName()] = surface;
38 
39  surface = new ShaderSurface(ShaderMan.getShaderObject("default/text.vert", SHADER_VERTEX), "textSurface");
40  _resourceMap[surface->getName()] = surface;
41 
42  surface = new ShaderSurface(ShaderMan.getShaderObject("default/texture.vert", SHADER_VERTEX), "textureSurface");
43  _resourceMap[surface->getName()] = surface;
44 }
45 
47  deinit();
48 }
49 
51  status("Initialising default surfaces...");
52 }
53 
55  for (std::map<Common::UString, ShaderSurface *>::iterator iter = _resourceMap.begin(); iter != _resourceMap.end(); ++iter) {
56  delete iter->second;
57  }
58  _resourceMap.clear();
59 }
60 
62  std::map<Common::UString, ShaderSurface *>::iterator iter = _resourceMap.begin();
63  while (iter != _resourceMap.end()) {
64  ShaderSurface *surface = iter->second;
65  iter++;
66  if (surface->useCount() == 0) {
67  iter = delResource(iter);
68  } else {
69  iter++;
70  }
71  }
72 }
73 
75  if (!surface) {
76  return;
77  }
78 
79  std::map<Common::UString, ShaderSurface *>::iterator iter = _resourceMap.find(surface->getName());
80  if (iter == _resourceMap.end()) {
81  _resourceMap[surface->getName()] = surface;
82  }
83 }
84 
86  if (!surface) {
87  return;
88  }
89 
90  std::map<Common::UString, ShaderSurface *>::iterator iter = _resourceMap.find(surface->getName());
91  if (iter != _resourceMap.end()) {
92  delResource(iter);
93  }
94 }
95 
97  std::map<Common::UString, ShaderSurface *>::iterator iter = _resourceMap.find(name);
98  if (iter != _resourceMap.end()) {
99  return iter->second;
100  } else {
101  return 0;
102  }
103 }
104 
105 std::map<Common::UString, ShaderSurface *>::iterator SurfaceManager::delResource(std::map<Common::UString, ShaderSurface *>::iterator iter) {
106  std::map<Common::UString, ShaderSurface *>::iterator inext = iter;
107  inext++;
108  delete iter->second;
109  _resourceMap.erase(iter);
110 
111  return inext;
112 }
113 
114 } // End of namespace Shader
115 
116 } // End of namespace Graphics
A class holding an UTF-8 string.
Definition: ustring.h:48
The surface manager.
Definition: surfaceman.h:41
void init()
Initialise surface management, including default surface creation.
Definition: surfaceman.cpp:50
Utility templates and functions.
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Definition: singleton.h:122
void addSurface(ShaderSurface *surface)
Adds a surface to be managed.
Definition: surfaceman.cpp:74
The global shader surface manager.
void cleanup()
Remove any resource that has a usage count of zero.
Definition: surfaceman.cpp:61
void delSurface(ShaderSurface *surface)
Forcibly remove the surface from the map.
Definition: surfaceman.cpp:85
#define ShaderMan
Shortcut for accessing the shader manager.
Definition: shader.h:293
void status(const char *s,...)
Definition: util.cpp:52
std::map< Common::UString, ShaderSurface * >::iterator delResource(std::map< Common::UString, ShaderSurface *>::iterator iter)
Definition: surfaceman.cpp:105
std::map< Common::UString, ShaderSurface * > _resourceMap
Definition: surfaceman.h:64
ShaderSurface * getSurface(const Common::UString &name)
Returns a surface with the given name, or zero if it does not exist.
Definition: surfaceman.cpp:96
const Common::UString & getName() const
void deinit()
Deinitialise surface management subsystem.
Definition: surfaceman.cpp:54