00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00064 U32 TextureId() const { return textureId; }
00065
00067
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
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
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*,
00144 const std::string& textureName,
00145 int id,
00146 int options );
00147
00150 const Texture* CreateTexture( int size,
00151 const std::string& textureName,
00152 int id,
00153 int options );
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 };
00180
00181 #endif
00182