Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_TEXTURE_TEXTURE_TYPES_H
00002 #define OPENTISSUE_GPU_TEXTURE_TEXTURE_TYPES_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013 #include <cassert>
00014
00015 namespace OpenTissue
00016 {
00017 namespace texture
00018 {
00026 inline unsigned int external_format( unsigned int channels )
00027 {
00028 switch ( channels )
00029 {
00030 case 4:
00031 return GL_RGBA;
00032 case 3:
00033 return GL_RGB;
00034 case 2:
00035 return GL_LUMINANCE_ALPHA;
00036 case 1:
00037 return GL_LUMINANCE;
00038 default:
00039 assert(!"external_format(): OpenGL only support up to 4 channels." );
00040 }
00041 return GL_INVALID_ENUM;
00042 }
00043
00053 template<typename T>
00054 inline unsigned int external_type();
00055
00056 template<>
00057 inline unsigned int external_type<double>() { return GL_DOUBLE; }
00058
00059 template<>
00060 inline unsigned int external_type<float>() { return GL_FLOAT; }
00061
00062 template<>
00063 inline unsigned int external_type<int>() { return GL_INT; }
00064
00065 template<>
00066 inline unsigned int external_type<unsigned int>() { return GL_UNSIGNED_INT; }
00067
00068 template<>
00069 inline unsigned int external_type<unsigned short>() { return GL_UNSIGNED_SHORT; }
00070
00071 template<>
00072 inline unsigned int external_type<short>() { return GL_SHORT; }
00073
00074 template<>
00075 inline unsigned int external_type<char>() { return GL_UNSIGNED_BYTE; }
00076
00077 template<>
00078 inline unsigned int external_type<unsigned char>() { return GL_UNSIGNED_BYTE; }
00079
00080
00095 template<typename T>
00096 inline unsigned int internal_format(int channels);
00097
00098
00099 template<>
00100 inline unsigned int internal_format<unsigned char>(int channels)
00101 {
00102 switch(channels)
00103 {
00104 case 1: return GL_INTENSITY8;
00105 case 2: return GL_LUMINANCE8_ALPHA8;
00106 case 3: return GL_RGB8;
00107 case 4: return GL_RGBA8;
00108 }
00109 return GL_INVALID_ENUM;
00110 }
00111
00112 template<>
00113 inline unsigned int internal_format<char>(int channels)
00114 {
00115 switch(channels)
00116 {
00117 case 1: return GL_INTENSITY8;
00118 case 2: return GL_LUMINANCE8_ALPHA8;
00119 case 3: return GL_RGB8;
00120 case 4: return GL_RGBA8;
00121 }
00122 return GL_INVALID_ENUM;
00123 }
00124
00125 template<>
00126 inline unsigned int internal_format<short>(int channels)
00127 {
00128 switch(channels)
00129 {
00130 case 1: return GL_INTENSITY16;
00131 case 2: return GL_LUMINANCE16_ALPHA16;
00132 case 3: return GL_RGB16;
00133 case 4: return GL_RGBA16;
00134 }
00135 return GL_INVALID_ENUM;
00136 }
00137
00138 template<>
00139 inline unsigned int internal_format<unsigned short>(int channels)
00140 {
00141 switch(channels)
00142 {
00143 case 1: return GL_INTENSITY16;
00144 case 2: return GL_LUMINANCE16_ALPHA16;
00145 case 3: return GL_RGB16;
00146 case 4: return GL_RGBA16;
00147 }
00148 return GL_INVALID_ENUM;
00149 }
00150
00151 template<>
00152 inline unsigned int internal_format<int>(int channels)
00153 {
00154 switch(channels)
00155 {
00156 case 1: return GL_FLOAT_R32_NV;
00157 case 2: return GL_LUMINANCE_ALPHA;
00158 case 3: return GL_RGB;
00159 case 4: return GL_RGBA;
00160 }
00161 return GL_INVALID_ENUM;
00162 }
00163
00164 template<>
00165 inline unsigned int internal_format<unsigned int>(int channels)
00166 {
00167 switch(channels)
00168 {
00169 case 1: return GL_FLOAT_R32_NV;
00170 case 2: return GL_LUMINANCE_ALPHA;
00171 case 3: return GL_RGB;
00172 case 4: return GL_RGBA;
00173 }
00174 return GL_INVALID_ENUM;
00175 }
00176
00177 template<>
00178 inline unsigned int internal_format<float>(int channels)
00179 {
00180 switch(channels)
00181 {
00182 case 1: return GL_FLOAT_R32_NV;
00183 case 2: return GL_LUMINANCE_ALPHA;
00184 case 3: return GL_RGB;
00185 case 4: return GL_RGBA;
00186 }
00187 return GL_INVALID_ENUM;
00188 }
00189
00190 }
00191
00192 }
00193
00194
00195 #endif