]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/itextures.h
Merge commit '515673c08f8718a237e90c2130a1f5294f966d6a'
[xonotic/netradiant.git] / include / itextures.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #if !defined(INCLUDED_ITEXTURES_H)
23 #define INCLUDED_ITEXTURES_H
24
25 #include "iimage.h"
26 #include "generic/constant.h"
27
28 struct qtexture_t;
29
30 class LoadImageCallback
31 {
32   typedef Image* (*LoadFunc)(void* environment, const char* name);
33 public:
34   void* m_environment;
35   LoadFunc m_func;
36
37   LoadImageCallback(void* environment, LoadFunc func) : m_environment(environment), m_func(func)
38   {
39   }
40   Image* loadImage(const char* name) const
41   {
42     return m_func(m_environment, name);
43   }
44 };
45
46 inline bool operator==(const LoadImageCallback& self, const LoadImageCallback& other)
47 {
48   return self.m_environment == other.m_environment && self.m_func == other.m_func; 
49 }
50 inline bool operator<(const LoadImageCallback& self, const LoadImageCallback& other)
51 {
52   return self.m_environment < other.m_environment || 
53         (!(other.m_environment < self.m_environment) && self.m_func < other.m_func); 
54 }
55
56 class TexturesCacheObserver
57 {
58 public:
59   virtual void unrealise() = 0;
60   virtual void realise() = 0;
61 };
62
63 class TexturesCache
64 {
65 public:
66   INTEGER_CONSTANT(Version, 1);
67   STRING_CONSTANT(Name, "textures");
68   virtual LoadImageCallback defaultLoader() const = 0;
69   virtual Image* loadImage(const char* name) = 0;
70   virtual qtexture_t* capture(const char* name) = 0;
71   virtual qtexture_t* capture(const LoadImageCallback& load, const char* name) = 0;
72   virtual void release(qtexture_t* texture) = 0;
73   virtual void attach(TexturesCacheObserver& observer) = 0;
74   virtual void detach(TexturesCacheObserver& observer) = 0;
75 };
76
77 #include "modulesystem.h"
78
79 template<typename Type>
80 class GlobalModule;
81 typedef GlobalModule<TexturesCache> GlobalTexturesModule;
82
83 template<typename Type>
84 class GlobalModuleRef;
85 typedef GlobalModuleRef<TexturesCache> GlobalTexturesModuleRef;
86
87 inline TexturesCache& GlobalTexturesCache()
88 {
89   return GlobalTexturesModule::getTable();
90 }
91
92 #endif