texture.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2007
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 #ifndef TEXTURE_INCLUDED
00023 #define TEXTURE_INCLUDED
00024 
00025 
00026 #ifdef _MSC_VER
00027 #pragma warning ( disable : 4786 )
00028 #endif
00029 #include <string>
00030 #include <map>
00031 #include <vector>
00032 
00033 #include "SDL.h"
00034 #include "../grinliz/gltypes.h"
00035 #include "../grinliz/glcolor.h"
00036 #include "lilith3dgl.h"
00037 
00038 
00039 namespace lilith3d
00040 {
00041 
00042 
00048 class Texture
00049 {
00050         friend class TextureManager;
00051 
00052   public:
00053         Texture()       {
00054                 nameId = 0;
00055                 textureId = 0;
00056         }
00057 
00059         const std::string&      Name() const    { return name; }
00061         U32                                     NameId() const  { return nameId; }
00062 
00063         // The id reported to opengl
00064         U32 TextureId() const   { return textureId; }
00065 
00067         //bool EmitsLight() const       { return flags.IsSet( EMISSIVE ) != 0; }
00068 
00072         void SetTexture( SDL_Surface* surface ) const;
00073 
00074         const grinliz::Color4F& AverageColor() const { return averageColor; }
00075         const grinliz::Color3F  AverageOpaqueColor() const { return averageOpaqueColor; }
00076 
00077         enum {
00078                 ALPHA           = 0x01,
00079 //              EMISSIVE        = 0x02,
00080         };
00081 
00082   private:
00083         std::string name;
00084         std::string filename;
00085         U32 nameId;
00086         U32 textureId;
00087         grinliz::Flag<U32> flags;
00088 
00089         grinliz::Color4F averageColor;
00090         grinliz::Color3F averageOpaqueColor;
00091 };
00092 
00093 
00094 struct TextureInputDesc
00095 {
00096         const char* name;
00097         U32                     id;
00098         U32                     x, y;
00099 };
00100 
00101 
00105 class TextureManager
00106 {
00107   public:
00108         enum {
00109                 NO_MIPMAP = 0x01,
00110                 //EMITS_LIGHT = 0x02,
00111                 TRANSPARENT_BORDER = 0x04,
00112         };
00113 
00115         static TextureManager* Instance()       {       return instance;
00116                                                                                 }
00117         TextureManager();
00118         ~TextureManager();
00119 
00121         void SetImportPath( const std::string& path )   { importPath = path; }
00122         const std::string& ImportPath()                                 { return importPath; }
00123 
00125         bool LoadRequiredTextures();
00126 
00128         bool UseHighQuality()                                                   { return highQuality; }
00129 
00136         const Texture* LoadTexture(     const std::string& fileName,            
00137                                                                 const std::string& textureName,
00138                                                                 int id = 0,
00139                                                                 int flags = 0 );
00140                                                 
00143         const Texture* CreateTexture(   SDL_Surface*,                                           // Create from an SDL 32 bit surface. ABGR.
00144                                                                         const std::string& textureName,         // Name to give the texture
00145                                                                         int id,                                                         // More name, for instance water:2
00146                                                                         int options );                  // Is this a glow or light texture?
00147 
00150         const Texture* CreateTexture(   int size,                                                       // 32 bit ABGR.
00151                                                                         const std::string& textureName,         // Name to give the texture
00152                                                                         int id,                                                         // More name, for instance water:2
00153                                                                         int options );                  // Is this a glow or light texture?
00154 
00156         const Texture* GetTexture( const std::string& textureName, U32 nameId );
00157 
00159         unsigned TextureMemory() { return textureMemory; }
00160 
00161   private:
00162         int ToGLFormat( SDL_PixelFormat* format );
00163         void CalcAverageColor( SDL_Surface* surface, U8* start, int size, grinliz::Color3F* opaque, grinliz::Color4F* transparent );
00164 
00165         static TextureManager* instance;
00166         
00167         unsigned textureMemory;
00168         enum {
00169                 MAX_TEXTURES = 256,
00170                 MAX_IMAGES = 256
00171         };
00172         int textureDefCount;
00173         Texture textureDefArr[ MAX_TEXTURES ];
00174 
00175         std::string importPath;
00176         bool highQuality;
00177         int terrainCount;
00178 };
00179 };      // namespace lilith3d
00180 
00181 #endif
00182 

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1