include/TextureUtils.h

Go to the documentation of this file.
00001 #ifndef TEXTURE_UTILS_H
00002 #define TEXTURE_UTILS_H
00003 
00004 #include "GenUtils.h"
00005 #include "glwxOpenGL.h"
00006 
00007 /*******************************************************************************************/
00008 /*MediaInfo                                                                                */
00009 /*                                                                                         */
00010 /*******************************************************************************************/
00011 
00012 template <class MediaInfoType>
00013 class MediaInfo
00014 {
00015   public:
00016 
00017     MediaInfo(const std::string &mediaPath_, MediaInfoType mediaArg = 0)
00018     {
00019       userCount = 1;
00020       mediaPath = mediaPath_;
00021       media     = mediaArg;
00022     }
00023 
00024     MediaInfo(const MediaInfo &copy)
00025     {
00026       this->operator=(copy);
00027     }
00028 
00029     MediaInfo &operator =(const MediaInfo &copy)
00030     {
00031       if(this != &copy)
00032       {
00033         userCount = copy.userCount;
00034         mediaPath = copy.mediaPath;
00035         media     = copy.media;
00036       }
00037       return *this;
00038     }
00039 
00040     void setMediaPath(const char *mediaPath_)
00041     {
00042       mediaPath = mediaPath_;
00043     }
00044 
00045     const std::string &getMediaPath() const
00046     {
00047       return mediaPath;
00048     }
00049 
00050     void increaseUserCount()
00051     {
00052       userCount++;
00053     }
00054 
00055     void decreaseUserCount()
00056     {
00057       userCount--;
00058     }
00059 
00060     unsigned int getUserCount()
00061     {
00062       return userCount;
00063     }
00064 
00065     MediaInfoType &getMedia()
00066     {
00067       return media;
00068     }
00069 
00070     void  setMedia(MediaInfoType &mediaArg)
00071     {
00072       media = mediaArg;
00073     }
00074 
00075     bool operator > (const MediaInfo &info)
00076     {
00077       return mediaPath > info.mediaPath;
00078     }
00079 
00080     bool operator < (const MediaInfo &info)
00081     {
00082       return  mediaPath < info.mediaPath;
00083     }
00084 
00085     bool operator == (const MediaInfo &info)
00086     {
00087       return (mediaPath == info.mediaPath) &&
00088              (userCount == info.userCount) &&
00089              (media     == info.media    );
00090     }
00091 
00092     bool operator != (const MediaInfo &info)
00093     {
00094       return !this->operator ==(info);
00095     }
00096 
00097   protected:
00098     unsigned int   userCount;
00099     MediaInfoType  media;
00100     std::string    mediaPath;
00101 
00102 };
00103 
00104 typedef MediaInfo<unsigned int> TextureInfo;
00105 
00106 /*******************************************************************************************/
00107 /*TexturesManager                                                                          */
00108 /*                                                                                         */
00109 /*******************************************************************************************/
00110 
00111 class TexturesManager
00112 {
00113   public:
00114     static bool        addTextureInfo(TextureInfo *textureInfo);
00115     static TextureInfo *getTextureInfo(const char* texturePath);
00116     static TextureInfo *getTextureInfo(GLuint textureID);
00117     static void         flushUnusedTextures();
00118 
00119     static void printTexturesInfo();
00120     static void flushAllTextures();
00121   private:
00122     static vector<TextureInfo*> textureCollection;
00123 
00124 };
00125 
00126 /*******************************************************************************************/
00127 /*Image                                                                                    */
00128 /*                                                                                         */
00129 /*******************************************************************************************/
00130 
00131 class Image
00132 {
00133   private:
00134     std::string     path;
00135     unsigned char  *dataBuffer;
00136     unsigned int    internalFormat,
00137                     components,
00138                     format;
00139 
00140     unsigned short  height,
00141                     width,
00142                     depth;
00143 
00144     bool loadTGA(const char* filename);
00145     bool loadUncompressed8BitTGA(const char * filename);
00146     bool loadCompressedTrueColorTGA(const char * filename);
00147     bool loadUncompressedTrueColorTGA(const char * filename);
00148         bool loadPPM(const char * filename);
00149 #ifdef GLWX_PNG_SUPPORT
00150         bool loadPNG(const char* filename);
00151 #endif
00152     bool loadJPG(const char* filename);
00153     void getJPGInfo();
00154     int  decodeScanJPG();
00155     int  decodeJPG();
00156 
00157   public:
00158     Image(const char* path = NULL);
00159    ~Image();
00160 
00161    static bool isDDSVolume(const char* filename);
00162    static bool isDDSCube  (const char* filename);
00163 
00164    void setHeight(unsigned short);
00165    void setWidth(unsigned short);
00166    void setDepth(unsigned short);
00167 
00168    void setFormat(unsigned int );
00169    void setDataBuffer(const unsigned char* );
00170    void flipVertically();
00171    void setInternalFormat(unsigned int );
00172    void setComponentsCount(unsigned int );
00173 
00174    bool load(const char*);
00175 
00176    const std::string    &getPath()            const;
00177    const unsigned int    getComponentsCount() const;
00178    const unsigned int    getInternalFormat()  const;
00179    const unsigned char*  getDataBuffer()      const;
00180    const unsigned int    getFormat()          const;
00181 
00182    const unsigned short getHeight() const;
00183    const unsigned short getWidth()  const;
00184    const unsigned short getDepth()  const;
00185 };
00186 
00187 
00188 /*******************************************************************************************/
00189 /*Texture                                                                                  */
00190 /*                                                                                         */
00191 /*******************************************************************************************/
00192 
00193 class Texture : public IOXMLObject
00194 {
00195   public:
00196     Texture(GLuint target = GL_TEXTURE_2D);
00197     Texture(const Texture &copy);
00198     Texture &operator = (const Texture &);
00199    ~Texture();
00200 
00201     virtual bool loadXMLSettings(const TiXmlElement *element);
00202     virtual bool exportXMLSettings(std::ofstream &xmlFile  );
00203 
00204     bool load2D(const char* infoEndOrPath,
00205                 GLuint clampS    = GL_REPEAT,
00206                 GLuint clampT    = GL_REPEAT,
00207                 GLuint magFilter = GL_LINEAR,
00208                 GLuint minFilter = GL_LINEAR_MIPMAP_LINEAR,
00209                 bool   mipmap    = true);
00210 
00211     bool load2DImage(const Image &image,
00212                      GLuint clampS    = GL_REPEAT,
00213                      GLuint clampT    = GL_REPEAT,
00214                      GLuint magFilter = GL_LINEAR,
00215                      GLuint minFilter = GL_LINEAR_MIPMAP_LINEAR,
00216                      bool  mipmap    = true);
00217 
00218     /*bool loadCube(const char* infoEndOrPath,
00219                   GLuint clampS    = GL_CLAMP_TO_EDGE,
00220                   GLuint clampT    = GL_CLAMP_TO_EDGE,
00221                   GLuint magFilter = GL_LINEAR,
00222                   GLuint minFilter = GL_LINEAR_MIPMAP_LINEAR,
00223                   bool  mipmap    = true);
00224 
00225     bool create1DShell(const char* name,
00226                        GLuint width     = 128,
00227                        GLuint inFormat  = GL_RGBA8,
00228                        GLuint format    = GL_RGBA,
00229                        GLuint clampS    = GL_REPEAT,
00230                        GLuint clampT    = GL_REPEAT,
00231                        GLuint magFilter = GL_LINEAR,
00232                        GLuint minFilter = GL_LINEAR);
00233 
00234     bool create2DShell(const char* name,
00235                        GLuint width     = 128,
00236                        GLuint height    = 128,
00237                        GLuint inFormat  = GL_RGBA8,
00238                        GLuint format    = GL_RGBA,
00239                        GLuint clampS    = GL_REPEAT,
00240                        GLuint clampT    = GL_REPEAT,
00241                        GLuint magFilter = GL_LINEAR,
00242                        GLuint minFilter = GL_LINEAR);
00243 
00244     bool createRectShell(const char* name,
00245                          GLuint width     = 128,
00246                          GLuint height    = 128,
00247                          GLuint inFormat  = GL_RGBA8,
00248                          GLuint format    = GL_RGBA,
00249                          GLuint clampS    = GL_CLAMP_TO_EDGE,
00250                          GLuint clampT    = GL_CLAMP_TO_EDGE,
00251                          GLuint magFilter = GL_LINEAR,
00252                          GLuint minFilter = GL_LINEAR);
00253 
00254     bool create3DShell(const char* name,
00255                        GLuint width     = 64,
00256                        GLuint height    = 64,
00257                        GLuint depth     = 64,
00258                        GLuint inFormat  = GL_RGBA8,
00259                        GLuint format    = GL_RGBA,
00260                        GLuint clampS    = GL_REPEAT,
00261                        GLuint clampT    = GL_REPEAT,
00262                        GLuint clampR    = GL_REPEAT,
00263                        GLuint magFilter = GL_LINEAR,
00264                        GLuint minFilter = GL_LINEAR);
00265 
00266     bool createCubeShell(const char* name,
00267                          GLuint size      = 128,
00268                          GLuint inFormat  = GL_RGBA8,
00269                          GLuint format    = GL_RGBA,
00270                          GLuint clampS    = GL_CLAMP_TO_EDGE,
00271                          GLuint clampT    = GL_CLAMP_TO_EDGE,
00272                          GLuint magFilter = GL_LINEAR,
00273                          GLuint minFilter = GL_LINEAR);
00274 
00275     bool createNoise3D(const  char* name,
00276                        GLuint size = 128);
00277 
00278     bool createNormalizingCube(const char* name,
00279                                GLuint size         = 128,
00280                                bool   buildMipmaps = true);*/
00281 
00282     void copyCurrentBuffer(int newTarget = -1);
00283 
00284     const bool activate(GLuint unit = 0);
00285     const bool deactivate();
00286 
00287 
00288     void  setID(GLuint textureID);
00289     const GLuint  getID() const;
00290 
00291     void  setTarget(GLuint target);
00292     const GLuint  getTarget() const;
00293 
00294     const GLuint  getHeight() const;
00295     const GLuint  getWidth()  const;
00296     const GLuint  getDepth()  const;
00297     void  destroy();
00298 
00299   protected:
00300     GLuint  height,
00301             width,
00302             depth;
00303   private:
00304     GLuint  currUnit,
00305             target,
00306             id;
00307 
00308     bool loadTextureFace(const Image &image, GLuint target, bool   mipmap);
00309 
00310     bool finalizeLoading(const char* string);
00311     bool checkForRepeat (const char* string);
00312 
00313     int getMagFilteri(const std::string &value);
00314     int getMinFilteri(const std::string &value);
00315     int getWrapModei (const std::string &value);
00316     int getTypei     (const std::string &value);
00317 
00318     int getValidWrapMode (int clamp);
00319     int getValidMagFilter(int filter);
00320     int getValidMinFilter(int filter);
00321 
00322 };
00323 #endif

Generated on Wed Dec 5 20:32:03 2007 for GLWX by  doxygen 1.5.3