gKitGL
ImageArray.h
00001 
00002 #ifndef _IMAGE_ARRAY_H
00003 #define _IMAGE_ARRAY_H
00004 
00005 #include <vector>
00006 
00007 #include "Image.h"
00008 
00009 
00010 namespace gk {
00011 
00012 template< class T >
00013 class TImageArray
00014 {
00015     TImageArray( );
00016     TImageArray( const TImageArray& );
00017     TImageArray& operator= ( const TImageArray& );
00018     
00019 protected:
00020     std::vector< TImage<T> *> m_images;
00021     unsigned int m_width;
00022     unsigned int m_height;
00023     
00024     int isValid( TImage<T> *image )
00025     {
00026         if(image == NULL)
00027             return -1;
00028         if(m_images.size() == 0)
00029         {
00030             m_width= image->width();
00031             m_height= image->height();
00032             return 0;
00033         }
00034         
00035         return (image->width() == m_width && image->height() == m_height) ? 0 : -1;
00036     }
00037     
00038 
00039 public:
00040     TImageArray( const unsigned int count= 1 )
00041         :
00042         m_images(),
00043         m_width(0),
00044         m_height(0)
00045     {
00046         m_images.reserve(count);
00047     }
00048 
00049     virtual ~TImageArray( ) {}
00050 
00051     unsigned int width( ) const
00052     {
00053         return m_width;
00054     }
00055     
00056     unsigned int height( ) const
00057     {
00058         return m_height;
00059     }
00060     
00061     unsigned int size( ) const
00062     {
00063         return m_images.size();
00064     }
00065     
00066     void clear( )
00067     {
00068         m_images.clear();
00069     }
00070     
00071     int push_back( TImage<T> *image )
00072     {
00073         if(isValid(image) < 0)
00074             return -1;
00075         m_images.push_back(image);
00076         return 0;
00077     }
00078     
00079     int push_back( TImage<T>& image )
00080     {
00081         if(isValid(&image) < 0)
00082             return -1;
00083         m_images.push_back(&image);
00084         return 0;
00085     }
00086     
00087     const TImage<T> *operator[] ( const unsigned int index ) const
00088     {
00089         if(index >= (unsigned int) m_images.size())
00090             return NULL;
00091         
00092         return m_images[index];
00093     }
00094     
00095     TImage<T> * &operator[] ( const unsigned int index )
00096     {
00097         assert(index < (unsigned int) m_images.size());
00098         return m_images[index];
00099     }
00100 };
00101 
00102 //! declaration d'un image array hdr, pixels rgba.
00103 typedef TImageArray<HDRPixel> HDRImageArray;
00104 //! declaration d'un image array, pixels rgba.
00105 typedef TImageArray<Pixel> ImageArray;
00106 
00107 template< class T >
00108 class TImageCube : public TImageArray<T>
00109 {
00110 public:
00111     TImageCube( )
00112         :
00113         TImageArray<T>(6)
00114     {}
00115     
00116     ~TImageCube( ) {}
00117     
00118     const TImage<T> *operator[] ( const unsigned int face ) const
00119     {
00120         if(face < GL_TEXTURE_CUBE_MAP_POSITIVE_X)       //dependence opengl
00121             return TImageArray<T>::operator[](face);
00122         if(face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
00123             return TImageArray<T>::operator[](face - GL_TEXTURE_CUBE_MAP_POSITIVE_X);
00124         assert(0);
00125     }
00126     
00127     TImage<T> * &operator[] ( const unsigned int face )
00128     {
00129         if(face < GL_TEXTURE_CUBE_MAP_POSITIVE_X)       //dependence opengl
00130             return TImageArray<T>::operator[](face);
00131         if(face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
00132             return TImageArray<T>::operator[](face - GL_TEXTURE_CUBE_MAP_POSITIVE_X);
00133         assert(0);
00134     }
00135 };
00136 
00137 //! declaration d'une image cube hdr, pixels rgba.
00138 typedef TImageCube<HDRPixel> HDRImageCube;
00139 //! declaration d'une image cube, pixels rgba.
00140 typedef TImageCube<Pixel> ImageCube;
00141 
00142 }
00143 
00144 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends