TexturePainter.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 &params);
00103     
00105     bool LoadPData(const string &Filename, unsigned int &w, unsigned int &h, TypedPData<dColour> &pixels);
00106     
00108     unsigned int MakeTexture(unsigned int w, unsigned int h, PData *data);
00110     
00115     
00118     bool SetCurrent(unsigned int *ids, TextureState *states);
00119 
00121     void DisableAll();
00123     
00124 private:
00127     class TextureDesc
00128     {
00129     public:
00130         TextureDesc() : Format(NONE) {}
00131         int Width;
00132         int Height;
00133         PixelFormat Format;
00134     };
00135     
00139     class CubeMapDesc
00140     {
00141     public:
00142         CubeMapDesc() { Positive[0]=0; Positive[1]=0; Positive[2]=0; 
00143                         Negative[0]=0; Negative[1]=0; Negative[2]=0; }
00144         unsigned int Positive[3];
00145         unsigned int Negative[3];
00146     };
00147 
00148     TexturePainter();
00149     ~TexturePainter();
00150     void ApplyState(int type, TextureState &state, bool cubemap);
00151     unsigned int LoadCubeMap(const string &Fullpath, CreateParams &params);
00152     void UploadTexture(TextureDesc desc, CreateParams params, const unsigned char *ImageData);
00153     static TexturePainter *m_Singleton;
00154 
00155     map<string,int> m_LoadedMap;
00156     map<string,int> m_LoadedCubeMap;
00157     map<unsigned int,TextureDesc> m_TextureMap;
00158     map<unsigned int,CubeMapDesc> m_CubeMapMap;
00159 };
00160 
00161 }
00162 
00163 #endif

Generated on Mon Feb 11 06:54:25 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1