00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <texture/texData.h>
00021 #include <GL/glUtil.h>
00022 #include <iostream>
00023
00024 using namespace std;
00025 using namespace gutz;
00026
00027 using namespace glift;
00028
00029
00030 TexData::TexData( GLenum texDimenName, const vec3i& origin, const vec3i& dimen, int borderW,
00031 GLenum glFormat, GLenum dataFormat, GLenum dataType, void* data,
00032 bool isCompressed, int numDataBytes )
00033 : m_data( data ),
00034 m_texDimenName( texDimenName ),
00035 m_glFormat( glFormat ),
00036 m_dataFormat( dataFormat ),
00037 m_dataType( dataType ),
00038 m_texOrigin( origin ),
00039 m_dimen( dimen ),
00040 m_borderW( borderW ),
00041 m_isCompressed( isCompressed ),
00042 m_numBytes( numDataBytes )
00043 {
00044 checkInput();
00045 }
00046
00047 void TexData::checkInput()
00048 {
00049
00050 checkDimenName( m_texDimenName );
00051 checkFormatGL( m_glFormat );
00052 checkFormatData( m_dataFormat );
00053 }
00054
00055
00056 void TexData::checkDimenName( GLenum texDimenName )
00057 {
00058 if( texDimenName != GL_TEXTURE_1D &&
00059 texDimenName != GL_TEXTURE_2D &&
00060 texDimenName != GL_TEXTURE_3D ) {
00061 err() << "checkDimenName(...) Error:\n\t'texDimenName' ( " << texDimenName
00062 << " ) is not supported. Use 6 2D texData's for a cube map.\n";
00063 exit(1);
00064 }
00065 }
00066
00067
00068
00069 void TexData::checkFormatGL( GLenum format )
00070 {
00071 if( format != GL_RGB &&
00072 format != GL_RGB8 &&
00073 format != GL_RGB16 &&
00074 format != GL_RGBA &&
00075 format != GL_RGBA8 &&
00076 format != GL_RGBA16 &&
00077 format != GL_RED &&
00078 format != GL_GREEN &&
00079 format != GL_BLUE &&
00080 format != GL_ALPHA &&
00081 format != GL_ALPHA8 &&
00082 format != GL_ALPHA16 &&
00083 format != GL_LUMINANCE &&
00084 format != GL_LUMINANCE8 &&
00085 format != GL_LUMINANCE16 &&
00086 format != GL_LUMINANCE_ALPHA &&
00087 format != GL_LUMINANCE8_ALPHA8 &&
00088 format != GL_LUMINANCE16_ALPHA16 &&
00089
00090 format != GL_RGBA_FLOAT32_ATI &&
00091 format != GL_RGB_FLOAT32_ATI &&
00092 format != GL_ALPHA_FLOAT32_ATI &&
00093 format != GL_INTENSITY_FLOAT32_ATI &&
00094 format != GL_LUMINANCE_FLOAT32_ATI &&
00095 format != GL_LUMINANCE_ALPHA_FLOAT32_ATI &&
00096 format != GL_RGBA_FLOAT16_ATI &&
00097 format != GL_RGB_FLOAT16_ATI &&
00098 format != GL_ALPHA_FLOAT16_ATI &&
00099 format != GL_INTENSITY_FLOAT16_ATI &&
00100 format != GL_LUMINANCE_FLOAT16_ATI &&
00101 format != GL_LUMINANCE_ALPHA_FLOAT16_ATI &&
00102
00103 format != GL_COMPRESSED_ALPHA_ARB &&
00104 format != GL_COMPRESSED_LUMINANCE_ARB &&
00105 format != GL_COMPRESSED_LUMINANCE_ALPHA_ARB &&
00106 format != GL_COMPRESSED_INTENSITY_ARB &&
00107 format != GL_COMPRESSED_RGB_ARB &&
00108 format != GL_COMPRESSED_RGBA_ARB )
00109 {
00110 err() << "checkInFormat(...) Error:\n\t'format' ( " << format
00111 << " ) is not supported.\n";
00112 exit(1);
00113 }
00114 }
00115
00116
00117 void TexData::checkFormatData( GLenum format )
00118 {
00119 if( format != GL_COLOR_INDEX &&
00120 format != GL_RGB &&
00121 format != GL_RGBA &&
00122 format != GL_RED &&
00123 format != GL_GREEN &&
00124 format != GL_BLUE &&
00125 format != GL_ALPHA &&
00126 format != GL_LUMINANCE &&
00127 format != GL_LUMINANCE_ALPHA &&
00128
00129 format != GL_RGBA_FLOAT32_ATI &&
00130 format != GL_RGB_FLOAT32_ATI &&
00131 format != GL_ALPHA_FLOAT32_ATI &&
00132 format != GL_INTENSITY_FLOAT32_ATI &&
00133 format != GL_LUMINANCE_FLOAT32_ATI &&
00134 format != GL_LUMINANCE_ALPHA_FLOAT32_ATI &&
00135 format != GL_RGBA_FLOAT16_ATI &&
00136 format != GL_RGB_FLOAT16_ATI &&
00137 format != GL_ALPHA_FLOAT16_ATI &&
00138 format != GL_INTENSITY_FLOAT16_ATI &&
00139 format != GL_LUMINANCE_FLOAT16_ATI &&
00140 format != GL_LUMINANCE_ALPHA_FLOAT16_ATI )
00141 {
00142 err() << "checkExFormat(...) Error:\n\t'format' ( " << format
00143 << " ) is not supported.\n";
00144 exit(1);
00145 }
00146
00147 }
00148
00149
00150 void TexData::texImageND( GLenum texType, int mipLevel )
00151 {
00152 if( m_isCompressed ) {
00153 switch( m_texDimenName )
00154 {
00155 case GL_TEXTURE_1D:
00156 glCompressedTexImage1DARB( texType, mipLevel, m_dataFormat, m_dimen.x,
00157 m_borderW, m_numBytes, m_data );
00158 break;
00159 case GL_TEXTURE_2D:
00160 glCompressedTexImage2DARB( texType, mipLevel, m_dataFormat, m_dimen.x, m_dimen.y,
00161 m_borderW, m_numBytes, m_data );
00162 break;
00163 case GL_TEXTURE_3D :
00164 glCompressedTexImage3DARB( texType, mipLevel, m_dataFormat, m_dimen.x, m_dimen.y, m_dimen.z,
00165 m_borderW, m_numBytes, m_data );
00166 break;
00167 default:
00168 err() << "texImageND Error:\n\tUnsupported texDimenName ("
00169 << texType << endl;
00170 exit(1);
00171 }
00172
00173 }
00174 else {
00175 switch( m_texDimenName )
00176 {
00177 case GL_TEXTURE_1D:
00178 glTexImage1D( texType, mipLevel, m_glFormat, m_dimen.x,
00179 m_borderW, m_dataFormat, m_dataType, m_data );
00180 break;
00181 case GL_TEXTURE_2D:
00182 glTexImage2D( texType, mipLevel, m_glFormat, m_dimen.x, m_dimen.y,
00183 m_borderW, m_dataFormat, m_dataType, m_data );
00184 break;
00185 case GL_TEXTURE_3D :
00186 glTexImage3D( texType, mipLevel, m_glFormat, m_dimen.x, m_dimen.y, m_dimen.z,
00187 m_borderW, m_dataFormat, m_dataType, m_data );
00188 break;
00189 default:
00190 err() << "texImageND Error:\n\tUnsupported texDimenName ("
00191 << texType << endl;
00192 exit(1);
00193 }
00194 }
00195 }
00196
00197
00198 void TexData::texSubImageND( GLenum texType, int mipLevel )
00199 {
00200 if( m_isCompressed ) {
00201 switch( m_texDimenName )
00202 {
00203 case GL_TEXTURE_1D:
00204 glCompressedTexSubImage1DARB( texType, mipLevel, m_texOrigin.x,
00205 m_dimen.x,
00206 m_dataFormat, m_numBytes, m_data );
00207 break;
00208 case GL_TEXTURE_2D:
00209 glCompressedTexSubImage2DARB( texType, mipLevel, m_texOrigin.x, m_texOrigin.y,
00210 m_dimen.x, m_dimen.y,
00211 m_dataFormat, m_numBytes, m_data );
00212 break;
00213 case GL_TEXTURE_3D :
00214 glCompressedTexSubImage3DARB( texType, mipLevel, m_texOrigin.x, m_texOrigin.y, m_texOrigin.z,
00215 m_dimen.x, m_dimen.y, m_dimen.z,
00216 m_dataFormat, m_numBytes, m_data );
00217 break;
00218 default:
00219 err() << "texImageND Error:\n\tUnsupported texDimenName ("
00220 << texType << endl;
00221 exit(1);
00222 }
00223
00224 }
00225 else {
00226 switch( m_texDimenName )
00227 {
00228 case GL_TEXTURE_1D:
00229 glTexSubImage1D( texType, mipLevel, m_texOrigin.x,
00230 m_dimen.x,
00231 m_dataFormat, m_dataType, m_data);
00232 break;
00233 case GL_TEXTURE_2D:
00234 glTexSubImage2D( texType, mipLevel, m_texOrigin.x, m_texOrigin.y,
00235 m_dimen.x, m_dimen.y,
00236 m_dataFormat, m_dataType, m_data);
00237 break;
00238 case GL_TEXTURE_3D :
00239 glTexSubImage3D( texType, mipLevel, m_texOrigin.x, m_texOrigin.y, m_texOrigin.z,
00240 m_dimen.x, m_dimen.y, m_dimen.z,
00241 m_dataFormat, m_dataType, m_data);
00242 break;
00243 default:
00244 err() << "texImageND Error:\n\tUnsupported texDimenName ("
00245 << texType << endl;
00246 exit(1);
00247 }
00248 }
00249 }
00250
00251
00252 void TexData::setTexData( GLenum texType, int mipLevel )
00253 {
00254 if( m_texOrigin == 0 ) {
00255 texImageND( texType, mipLevel );
00256 }
00257 else {
00258 texSubImageND( texType, mipLevel );
00259 }
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293