00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef N_TEXTURE
00018 #define N_TEXTURE
00019
00020 #include <iostream>
00021 #include <string>
00022 #include <map>
00023 #include "PNGLoader.h"
00024 #include "PData.h"
00025
00026 using namespace std;
00027
00028 namespace Fluxus
00029 {
00030
00033 class TextureState
00034 {
00035 public:
00036
00037 TextureState(): TexEnv(GL_MODULATE), Min(GL_LINEAR_MIPMAP_LINEAR),
00038 Mag(GL_LINEAR_MIPMAP_LINEAR), WrapS(GL_REPEAT), WrapT(GL_REPEAT), WrapR(GL_REPEAT),
00039 Priority(1), MinLOD(-1000), MaxLOD(1000) {}
00040
00041 int TexEnv;
00042 int Min;
00043 int Mag;
00044 int WrapS;
00045 int WrapT;
00046 int WrapR;
00047 dColour BorderColour;
00048 float Priority;
00049 dColour EnvColour;
00050 float MinLOD;
00051 float MaxLOD;
00052 };
00053
00062 class TexturePainter
00063 {
00064 public:
00066 static TexturePainter* Get()
00067 {
00068 if (m_Singleton==NULL) m_Singleton=new TexturePainter;
00069 return m_Singleton;
00070 }
00071
00072 static void Shutdown()
00073 {
00074 if (m_Singleton!=NULL) delete m_Singleton;
00075 }
00076
00078 void Initialise();
00079
00081 void ClearCache();
00082
00085 class CreateParams
00086 {
00087 public:
00088 CreateParams(): ID(-1), Type(GL_TEXTURE_2D), GenerateMipmaps(true), MipLevel(0), Border(0) {}
00089
00090 int ID;
00091 int Type;
00092 bool GenerateMipmaps;
00093 int MipLevel;
00094 int Border;
00095 };
00096
00100
00102 unsigned int LoadTexture(const string &Filename, CreateParams ¶ms);
00103
00105 bool LoadPData(const string &Filename, unsigned int &w, unsigned int &h, TypedPData<dColour> &pixels);
00106
00108 bool SavePData(const string &Filename, unsigned int w, unsigned int h, const TypedPData<dColour> &pixels);
00109
00111 unsigned int MakeTexture(unsigned int w, unsigned int h, PData *data);
00113
00118
00121 bool SetCurrent(unsigned int *ids, TextureState *states);
00122
00124 void DisableAll();
00125
00127 void Dump();
00129
00130 private:
00133 class TextureDesc
00134 {
00135 public:
00136 TextureDesc() : Format(NONE) {}
00137 unsigned int Width;
00138 unsigned int Height;
00139 PixelFormat Format;
00140 };
00141
00145 class CubeMapDesc
00146 {
00147 public:
00148 CubeMapDesc() { Positive[0]=0; Positive[1]=0; Positive[2]=0;
00149 Negative[0]=0; Negative[1]=0; Negative[2]=0; }
00150 unsigned int Positive[3];
00151 unsigned int Negative[3];
00152 };
00153
00154 TexturePainter();
00155 ~TexturePainter();
00156 void ApplyState(int type, TextureState &state, bool cubemap);
00157 unsigned int LoadCubeMap(const string &Fullpath, CreateParams ¶ms);
00158 void UploadTexture(TextureDesc desc, CreateParams params, const unsigned char *ImageData);
00159 static TexturePainter *m_Singleton;
00160
00161 map<string,int> m_LoadedMap;
00162 map<string,int> m_LoadedCubeMap;
00163 map<unsigned int,TextureDesc> m_TextureMap;
00164 map<unsigned int,CubeMapDesc> m_CubeMapMap;
00165 };
00166
00167 }
00168
00169 #endif