vee_gl_texture.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef VEE_TEXTURE_H
00021 #define VEE_TEXTURE_H
00022 
00023 #include <GL/gl.h>
00024 
00025 #include <map>
00026 #include <string>
00027 
00028 class VEE_Image;
00029 
00033 class VEE_GlTexture2D
00034 {
00035 public:
00036   VEE_GlTexture2D();
00037   ~VEE_GlTexture2D();
00038 
00039   bool genTexture1D(const unsigned char *, unsigned n, 
00040         GLenum format, bool mipmaps);
00041   bool genTexture(const VEE_Image *, bool mipmaps);
00042 
00043   void allocateId();
00044   void unallocateId();
00045   
00046   GLuint id() const { return m_glId; }
00047 
00048   bool isDefined() const { return m_glId != (GLuint) -1; }
00049   
00051   void forgetId() { m_glId = (GLuint) -1; }
00052 
00053   void use(GLenum target = GL_TEXTURE_2D) 
00054   { 
00055     if(!isDefined()) {
00056       glDisable(target);
00057       return; 
00058     }
00059     else {
00060       glEnable(target);
00061       glBindTexture(target, m_glId);
00062     }
00063   }
00064 
00065   void use1D() { use(GL_TEXTURE_1D); }
00066   void use2D() { use(GL_TEXTURE_2D); }
00067   void use3D() { use(GL_TEXTURE_3D); }
00068 
00069   void allocateArea(int minW, int minH, GLenum format);
00070 
00071   int width()  const { return m_width; }
00072   int height() const { return m_height; }
00073 
00074 protected:
00075 
00077   GLuint m_glId;
00078 
00079   int   m_width, m_height;
00080   
00081 private:
00082   // VEE_GlTexture2D(const VEE_GlTexture2D & ) {}
00083   
00084 };
00085 
00088 
00089 class VEE_GlTexture2DBank
00090 {
00091 public:
00092   VEE_GlTexture2DBank();
00093   
00095   VEE_GlTexture2DBank(const VEE_GlTexture2DBank &) {}
00096 
00097   ~VEE_GlTexture2DBank();
00098 
00100   VEE_GlTexture2DBank & operator = (const VEE_GlTexture2DBank &)
00101   { return *this; }
00102 
00103   VEE_GlTexture2D *getTexture(const std::string &);
00104   VEE_GlTexture2D *buildTexture(const std::string &);
00105 
00106   void addTexture(const std::string &, const VEE_GlTexture2D &);
00107 
00108   void clear();
00109 
00110   uint size() { return m_textures.size(); }
00111 
00112   void loadTextures(const std::string & path,
00113         const std::string & name,
00114         const std::string & suffix = ".jpg",
00115         int number = 20);
00116 
00117   bool loadTexture(const std::string & filename,
00118        const std::string & name);
00119   
00120   typedef std::map<std::string, VEE_GlTexture2D>::iterator iterator;
00121 
00122   iterator textureBegin() { return m_textures.begin(); }
00123   iterator textureEnd()   { return m_textures.end(); }
00124 
00125 protected:
00126   std::map<std::string, VEE_GlTexture2D> m_textures;
00127   std::map<std::string, std::string>     m_fileTextures;
00128 };
00129 
00130 #endif

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6