gKitGL
TPTexture.h
00001 
00002 #ifndef _TP_TEXTURE_H
00003 #define _TP_TEXTURE_H
00004 
00005 #include "GL/GLPlatform.h"
00006 #include "GLResource.h"
00007 #include "Image.h"
00008 #include "ImageArray.h"
00009 #include "GL/TPProgramName.h"
00010 
00011 
00012 namespace gk {
00013 
00014 enum 
00015 {
00016     UNIT0= 0,
00017     UNIT1= 1,
00018     UNIT2= 2,
00019     UNIT3= 3,
00020     UNIT4= 4,
00021     UNIT5= 5,
00022     UNIT6= 6,
00023     UNIT7= 7
00024 };
00025 
00026 //! representation du format des pixels d'une texture
00027 struct TextureFormat
00028 {
00029     GLenum internal;
00030     GLenum data_format;
00031     GLenum data_type;
00032     int samples;
00033     bool fixed_samples;
00034     
00035     TextureFormat( )
00036         :
00037         internal(GL_RGBA),
00038         data_format(GL_RGBA),
00039         data_type(GL_UNSIGNED_BYTE),
00040         samples(0),
00041         fixed_samples(false)
00042     {}
00043     
00044     TextureFormat( const GLenum _internal, const GLenum _format, const GLenum _type, const int _samples= 0, const bool _fixed= false )
00045         :
00046         internal(_internal),
00047         data_format(_format),
00048         data_type(_type),
00049         samples(_samples),
00050         fixed_samples(_fixed)
00051     {}
00052 };
00053 
00054 extern TextureFormat TextureRGBA;
00055 extern TextureFormat TextureRGBA16F;
00056 extern TextureFormat TextureRGBA32F;
00057 extern TextureFormat TextureDepth;
00058 extern TextureFormat TextureDepth24;
00059 extern TextureFormat TextureDepth32;
00060 
00061 extern TextureFormat TextureR32UI;
00062 extern TextureFormat TextureR16UI;
00063 extern TextureFormat TextureRG16UI;
00064 extern TextureFormat TextureR32F;
00065 extern TextureFormat TextureRG32F;
00066 extern TextureFormat TextureR16F;
00067 extern TextureFormat TextureRG16F;
00068 
00069 extern TextureFormat TextureRGBA_MS4;
00070 extern TextureFormat TextureDepth_MS4;
00071 
00072 //! utilisation interne. representation d'une texture openGL.
00073 class GLTexture : public GLResource
00074 {
00075     // non copyable
00076     GLTexture();
00077     GLTexture( const GLTexture& );
00078     GLTexture& operator= ( const GLTexture& );
00079 
00080 protected:
00081     GLenum m_target;
00082     TextureFormat m_format;
00083     int m_width;
00084     int m_height;
00085     int m_depth;
00086     
00087 public:
00088     //! constructeur.
00089     GLTexture( const GLenum target )
00090         :
00091         GLResource(),
00092         m_target(target),
00093         m_format(),
00094         m_width(0),
00095         m_height(0),
00096         m_depth(0)
00097     {
00098         glGenTextures(1, &m_name);
00099     }
00100     
00101     //! desctructeur.
00102     virtual ~GLTexture( ) 
00103     {
00104         glDeleteTextures(1, &m_name);
00105     }
00106     
00107     //! gestion objet opengl.
00108     int createGLResource( )
00109     {
00110         return (m_name != 0) ? 0 : -1;
00111     }
00112     
00113     //! gestion objet opengl.
00114     int releaseGLResource( )
00115     {
00116         return (m_name != 0) ? 0 : -1;
00117     }
00118 
00119     //! renvoie le type de texture : GL_TEXTURE_2D, etc.
00120     GLenum target( ) const
00121     {
00122         return m_target;
00123     }
00124     
00125     //! renvoie le format de la texture GL_RGBA, etc.
00126     const TextureFormat& format( ) const
00127     {
00128         return m_format;
00129     }
00130     
00131     //! renvoie la largeur de la texture.
00132     int width( ) const
00133     {
00134         return m_width;
00135     }
00136     
00137     //! renvoie la hauteur de la texture 2d ou 3d, ou le nombre de textures dans un texture1DArray.
00138     int height( ) const
00139     {
00140         return m_height;
00141     }
00142 
00143     //! renvoie la profondeur de la texture 3d, ou le nombre de textures dans un texture2DArray.
00144     int depth( ) const
00145     {
00146         return m_depth;
00147     }
00148 
00149     //! renvoie le nombre de textures dans un textureArray.
00150     int count( ) const
00151     {
00152         if(m_target == GL_TEXTURE_1D_ARRAY)
00153             return m_height;
00154         else if(m_target == GL_TEXTURE_2D_ARRAY)
00155             return m_depth;
00156         else if(m_target == GL_TEXTURE_CUBE_MAP)
00157             return 6;
00158         // else if(m_target == GL_TEXTURE_CUBE_MAP_ARRAY) return m_depth * 6;
00159         
00160         // texture normale.
00161         return 1;
00162     }
00163     
00164     //! renvoie une image contenant les pixels de la texture. 'level' permet de choisir quel niveau de mipmap recuperer.
00165     //! l'application est proprietaire de l'image renvoyee, et de sa liberation.
00166     Image *getImage( const int unit, const int level= 0 ) const;
00167 
00168     //! renvoie une image contenant les pixels de la texture. 'level' permet de choisir quel niveau de mipmap recuperer.
00169     //! l'application est proprietaire de l'image renvoyee, et de sa liberation.
00170     HDRImage *getHDRImage( const int unit, const int level= 0 ) const;
00171     
00172     //! renvoie un ensemble d'images contenant les pixels de la texture. 'level' permet de choisir quel niveau de mipmap recuperer.
00173     //! l'application est proprietaire des images renvoyees, et de leur liberation.
00174     ImageArray *getImageArray( const int unit, const int level= 0 ) const;
00175     
00176     //! renvoie un ensemble d'images contenant les pixels de la texture. 'level' permet de choisir quel niveau de mipmap recuperer.
00177     //! l'application est proprietaire des images renvoyees, et de leur liberation.
00178     HDRImageArray *getHDRImageArray( const int unit, const int level= 0 ) const;
00179     
00180     //! \todo getImageCube, cas particulier de ImageArray.
00181     //! \todo channels( ), renvoie le nombre de composantes des pixels de la texture. rgba= 4, rgb= 3, red= 1, depth= 1, etc.
00182 };
00183 
00184 class GLTexture1D : public GLTexture
00185 {
00186 public:
00187     GLTexture1D( )
00188         :
00189         GLTexture(GL_TEXTURE_1D)
00190     {}
00191     
00192     ~GLTexture1D( ) {}
00193 };
00194 
00195 class GLTexture1DArray : public GLTexture
00196 {
00197 public:
00198     GLTexture1DArray( )
00199         :
00200         GLTexture(GL_TEXTURE_1D_ARRAY)
00201     {}
00202     
00203     ~GLTexture1DArray( ) {}
00204 };
00205 
00206 class GLTexture2D : public GLTexture
00207 {
00208 public:
00209     GLTexture2D( const GLenum target )
00210         :
00211         GLTexture(target)
00212     {}
00213     
00214     virtual ~GLTexture2D( ) {}
00215 
00216     GLTexture2D( const int unit, const int w, const int h, const TextureFormat& format= TextureRGBA );
00217     
00218     GLTexture2D( const int unit, const HDRImage *image, const TextureFormat& format= TextureRGBA32F );
00219     
00220     GLTexture2D( const int unit, const Image *image, const TextureFormat& format= TextureRGBA );
00221 };
00222 
00223 class GLDepthTexture : public GLTexture2D
00224 {
00225 public:
00226     GLDepthTexture( )
00227         :
00228         GLTexture2D(GL_TEXTURE_2D)
00229     {}
00230     
00231     GLDepthTexture( const int unit, const int w, const int h, const TextureFormat& format= TextureDepth );
00232     
00233     ~GLDepthTexture( ) {}
00234     
00235     HDRImage *getHDRImage( const int unit ) const;
00236 };
00237 
00238 class GLTexture2DArray : public GLTexture2D
00239 {
00240 public:
00241     GLTexture2DArray( )
00242         :
00243         GLTexture2D(GL_TEXTURE_2D_ARRAY)
00244     {}
00245     
00246     ~GLTexture2DArray( ) {}
00247     
00248     GLTexture2DArray( const int unit, const int w, const int h, const int count, const TextureFormat& format= TextureRGBA );
00249     
00250     GLTexture2DArray( const int unit, const HDRImageArray *images, const TextureFormat& format= TextureRGBA32F );
00251     
00252     GLTexture2DArray( const int unit, const ImageArray *images, const TextureFormat& format= TextureRGBA );
00253 };
00254 
00255 class GLTextureCube : public GLTexture2D
00256 {
00257 public:
00258     GLTextureCube( )
00259         :
00260         GLTexture2D(GL_TEXTURE_CUBE_MAP)
00261     {}
00262     
00263     ~GLTextureCube( ) {}
00264     
00265     GLTextureCube( const int unit, const int w, const int h, const TextureFormat& format= TextureRGBA );
00266     
00267     GLTextureCube( const int unit, const HDRImageCube *faces, const TextureFormat& format= TextureRGBA32F );
00268     
00269     GLTextureCube( const int unit, const ImageCube *faces, const TextureFormat& format= TextureRGBA );
00270 };
00271 
00272 class GLDepthTextureCube : public GLTexture2D
00273 {
00274 public:
00275     GLDepthTextureCube( )
00276         :
00277         GLTexture2D(GL_TEXTURE_CUBE_MAP)
00278     {}
00279     
00280     ~GLDepthTextureCube( ) {}
00281 
00282     GLDepthTextureCube( const int unit, const int w, const int h, const TextureFormat& format= TextureDepth );
00283 };
00284 
00285 class GLTextureCubeArray : public GLTexture
00286 {
00287 public:
00288     GLTextureCubeArray( )
00289         :
00290         GLTexture(GL_TEXTURE_CUBE_MAP_ARRAY_ARB)
00291     {
00292         //! \todo verifier le support de gl_arb_texture_cube_map_array
00293     }
00294     
00295     ~GLTextureCubeArray( ) {}
00296 };
00297 
00298 
00299 class GLTexture3D : public GLTexture
00300 {
00301 public:
00302     GLTexture3D( )
00303         :
00304         GLTexture(GL_TEXTURE_3D)
00305     {}
00306     
00307     ~GLTexture3D( ) {}
00308 };
00309 
00310 }
00311 
00312 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends