00001 /* 00002 Copyright (C) 2001-2006, William Joseph. 00003 All Rights Reserved. 00004 00005 This file is part of GtkRadiant. 00006 00007 GtkRadiant is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 GtkRadiant is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GtkRadiant; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #if !defined(INCLUDED_ITEXTURES_H) 00023 #define INCLUDED_ITEXTURES_H 00024 00025 #include "iimage.h" 00026 #include "generic/constant.h" 00027 00028 struct qtexture_t; 00029 00030 class LoadImageCallback 00031 { 00032 typedef Image* (*LoadFunc) (void* environment, const std::string& name); 00033 public: 00034 void* m_environment; 00035 LoadFunc m_func; 00036 00037 LoadImageCallback (void* environment, LoadFunc func) : 00038 m_environment(environment), m_func(func) 00039 { 00040 } 00041 Image* loadImage (const std::string& name) const 00042 { 00043 return m_func(m_environment, name); 00044 } 00045 }; 00046 00047 inline bool operator== (const LoadImageCallback& self, const LoadImageCallback& other) 00048 { 00049 return self.m_environment == other.m_environment && self.m_func == other.m_func; 00050 } 00051 inline bool operator< (const LoadImageCallback& self, const LoadImageCallback& other) 00052 { 00053 return self.m_environment < other.m_environment || (!(other.m_environment < self.m_environment) && self.m_func 00054 < other.m_func); 00055 } 00056 00057 class TexturesCacheObserver 00058 { 00059 public: 00060 virtual ~TexturesCacheObserver () 00061 { 00062 } 00063 virtual void unrealise () = 0; 00064 virtual void realise () = 0; 00065 }; 00066 00067 class TexturesCache 00068 { 00069 public: 00070 INTEGER_CONSTANT(Version, 1); 00071 STRING_CONSTANT(Name, "textures"); 00072 virtual ~TexturesCache () 00073 { 00074 } 00075 virtual LoadImageCallback defaultLoader () const = 0; 00076 virtual Image* loadImage (const std::string& name) = 0; 00077 virtual qtexture_t* capture (const std::string& name) = 0; 00078 virtual qtexture_t* capture (const LoadImageCallback& load, const std::string& name) = 0; 00079 virtual void release (qtexture_t* texture) = 0; 00080 virtual void attach (TexturesCacheObserver& observer) = 0; 00081 virtual void detach (TexturesCacheObserver& observer) = 0; 00082 }; 00083 00084 #include "modulesystem.h" 00085 00086 template<typename Type> 00087 class GlobalModule; 00088 typedef GlobalModule<TexturesCache> GlobalTexturesModule; 00089 00090 template<typename Type> 00091 class GlobalModuleRef; 00092 typedef GlobalModuleRef<TexturesCache> GlobalTexturesModuleRef; 00093 00094 inline TexturesCache& GlobalTexturesCache () 00095 { 00096 return GlobalTexturesModule::getTable(); 00097 } 00098 00099 #endif