00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <texture/texNd.h>
00021 #include <iostream>
00022
00023 using namespace std;
00024 using namespace gutz;
00025
00026 using namespace glift;
00027
00028
00029
00030
00031 Tex1D::Tex1D( const MultiTexOState& texState, PBuffGlift* pbuff )
00032 : CoreTex( GL_TEXTURE_1D, texState, NULL, pbuff )
00033 {}
00034
00035 Tex1D::Tex1D( const MultiTexOState& texState, TexData* texData, PBuffGlift* pbuff )
00036 : CoreTex( GL_TEXTURE_1D, texState, texData, pbuff )
00037 {}
00038
00039
00040 void Tex1D::copyToTex( int mipLevel, const vec3i& texOrig,
00041 const vec2i& screenOrig, const vec2i& copySize )
00042 {
00043 bindDef();
00044 glCopyTexSubImage1D( texType(), mipLevel,
00045 texOrig.x,
00046 screenOrig.x, screenOrig.y,
00047 copySize.x );
00048 releaseDef();
00049 }
00050
00051
00052
00053
00054 Tex2D::Tex2D( const MultiTexOState& texState, PBuffGlift* pbuff )
00055 : CoreTex( GL_TEXTURE_2D, texState, NULL, pbuff )
00056 {}
00057
00058 Tex2D::Tex2D( const MultiTexOState& texState, TexData* texData, PBuffGlift* pbuff )
00059 : CoreTex( GL_TEXTURE_2D, texState, texData, pbuff )
00060 {}
00061
00062
00063 void Tex2D::copyToTex2D()
00064 {
00065 int mipLevel = 0;
00066 vec2i texOrig(0);
00067 vec2i screenOrig(0);
00068 vec2i dimen( dimen().x, dimen().y );
00069
00070 copyToTex( mipLevel, texOrig, screenOrig, dimen );
00071 }
00072
00073
00074 void Tex2D::copyToTex( int mipLevel, const vec3i& texOrig,
00075 const vec2i& screenOrig, const vec2i& copySize )
00076 {
00077 bindDef();
00078 glCopyTexSubImage2D( texType(), mipLevel,
00079 texOrig.x, texOrig.y,
00080 screenOrig.x, screenOrig.y,
00081 copySize.x, copySize.y );
00082 releaseDef();
00083 }
00084
00085
00086
00087
00088 TexRect::TexRect( const MultiTexOState& texState, PBuffGlift* pbuff )
00089 : CoreTex( getTarget(), texState, NULL, pbuff )
00090 {}
00091
00092 TexRect::TexRect( const MultiTexOState& texState, TexData* texData, PBuffGlift* pbuff )
00093 : CoreTex( getTarget(), texState, texData, pbuff )
00094 {}
00095
00096
00097 void TexRect::copyToTex2D()
00098 {
00099 int mipLevel = 0;
00100 vec2i texOrig(0);
00101 vec2i screenOrig(0);
00102 vec2i dimen( dimen().x, dimen().y );
00103
00104 copyToTex( mipLevel, texOrig, screenOrig, dimen );
00105 }
00106
00107
00108 void TexRect::copyToTex( int mipLevel, const vec3i& texOrig,
00109 const vec2i& screenOrig, const vec2i& copySize )
00110 {
00111 bindDef();
00112 glCopyTexSubImage2D( texType(), mipLevel,
00113 texOrig.x, texOrig.y,
00114 screenOrig.x, screenOrig.y,
00115 copySize.x, copySize.y );
00116 releaseDef();
00117 }
00118
00119 GLenum TexRect::getTarget()
00120 {
00121 GLenum target;
00122 if( glew.NV_texture_rectangle ) {
00123 target = GL_TEXTURE_RECTANGLE_NV;
00124 }
00125 else if( glew.EXT_texture_rectangle ) {
00126 target = GL_TEXTURE_RECTANGLE_EXT;
00127 }
00128 else {
00129 err() << "getTarget() Error:\n\tTexture rectangles not supported on this GPU.\n";
00130 exit(1);
00131 }
00132 return target;
00133 }
00134
00135
00136
00137
00138 Tex3D::Tex3D( const MultiTexOState& texState, TexData* texData )
00139 : CoreTex( GL_TEXTURE_3D, texState, texData )
00140 {}
00141
00142
00143 void Tex3D::copyToTex( int mipLevel, const vec3i& texOrig,
00144 const vec2i& screenOrig, const vec2i& copySize )
00145 {
00146 bindDef();
00147 glCopyTexSubImage3D( texType(), mipLevel,
00148 texOrig.x, texOrig.y, texOrig.z,
00149 screenOrig.x, screenOrig.y,
00150 copySize.x, copySize.y );
00151 releaseDef();
00152 }
00153
00154
00155
00156
00157 TexCube::TexCube( const MultiTexOState& texState, const VecTexDataP& texData )
00158 : CoreTex( GL_TEXTURE_CUBE_MAP_ARB, texState, NULL ),
00159 m_pbuff( VecPbuffP(6) ),
00160 m_writeFace( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB )
00161 {
00162 initPbuffVec( NULL, NULL, NULL, NULL, NULL, NULL );
00163
00164 if( texData.size() == 6 ) {
00165 initData( texData );
00166 }
00167 else if( texData.size() > 0 ) {
00168 err() << "TexCube(...) Error:\n"
00169 << "\ttexData must contain 6 TexData pointers.\n";
00170 exit(1);
00171 }
00172 }
00173
00174 TexCube::TexCube( const MultiTexOState& texState, PBuffGlift* pbPX, PBuffGlift* pbNX,
00175 PBuffGlift* pbPY, PBuffGlift* pbNY, PBuffGlift* pbPZ, PBuffGlift* pbNZ,
00176 const VecTexDataP& texData )
00177 : CoreTex( GL_TEXTURE_CUBE_MAP_ARB, texState, NULL ),
00178 m_pbuff( VecPbuffP(6) ),
00179 m_writeFace( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB )
00180 {
00181 initPbuffVec( pbPX, pbNX, pbPY, pbNY, pbPZ, pbNZ );
00182
00183
00184 for(uint i=0; i < m_pbuff.size(); i++) {
00185 if( m_pbuff[i] == NULL ) {
00186 err() << "TexCube(...) Error\n"
00187 << "\tPbuffer[" << i << "] == NULL. All pbuffers must be non-NULL.\n";
00188 exit(1);
00189 }
00190 }
00191
00192
00193 if( texData.size() == 6 ) {
00194 initData( texData );
00195 }
00196 else if( texData.size() > 0 ) {
00197 err() << "TexCube(...) Error:\n"
00198 << "\ttexData must contain 6 TexData pointers.\n";
00199 exit(1);
00200 }
00201 }
00202
00203 void TexCube::initPbuffVec( PBuffGlift* pbPX, PBuffGlift* pbNX, PBuffGlift* pbPY, PBuffGlift* pbNY,
00204 PBuffGlift* pbPZ, PBuffGlift* pbNZ )
00205 {
00206 m_pbuff[0] = pbPX;
00207 m_pbuff[1] = pbPX;
00208 m_pbuff[2] = pbPY;
00209 m_pbuff[3] = pbNY;
00210 m_pbuff[4] = pbPZ;
00211 m_pbuff[5] = pbNZ;
00212 }
00213
00214 void TexCube::initData( const VecTexDataP& texData )
00215 {
00216 setTexData( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, texData[0] );
00217 setTexData( GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, texData[1] );
00218 setTexData( GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, texData[2] );
00219 setTexData( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, texData[3] );
00220 setTexData( GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, texData[4] );
00221 setTexData( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, texData[5] );
00222 }
00223
00224
00225 void TexCube::setCopyCubeFace( GLenum cubeFace )
00226 {
00227 checkCubeFace( cubeFace );
00228 m_writeFace = cubeFace;
00229 }
00230
00231
00232 void TexCube::copyToTex( GLenum cubeFace )
00233 {
00234 checkCubeFace( cubeFace );
00235 m_writeFace = cubeFace;
00236
00237 vec2i texOrig(0);
00238 vec2i screenOrig(0);
00239 vec2i copyDimen( dimen().x, dimen().y );
00240
00241 copyToTex( 0, texOrig, screenOrig, copyDimen );
00242 }
00243
00244
00245 void TexCube::copyToTex( int mipLevel, const vec3i& texOrig,
00246 const vec2i& screenOrig, const vec2i& copySize )
00247 {
00248 bindDef();
00249 glCopyTexSubImage2D( m_writeFace, mipLevel,
00250 texOrig.x, texOrig.y,
00251 screenOrig.x, screenOrig.y,
00252 copySize.x, copySize.y );
00253 releaseDef();
00254 }
00255
00256
00257
00258
00259 void TexCube::setTexData( GLenum cubeFace, TexData* texData, int mipLevel, bool setTexSize )
00260 {
00261
00262 if( texData->texType() != GL_TEXTURE_2D ) {
00263 err() << "setTexData(...) Error:\n"
00264 << "\ttexData must be two dimensional.\n";
00265 exit(1);
00266 }
00267
00268
00269 checkCubeFace( cubeFace );
00270
00271
00272 if( setTexSize ) {
00273 dataDimen( texData->dimen() );
00274 }
00275 bindDef();
00276 texData->setTexData(cubeFace, mipLevel);
00277 releaseDef();
00278 }
00279
00280
00281 void TexCube::checkCubeFace( GLenum cubeFace )
00282 {
00283 if( cubeFace != GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
00284 cubeFace != GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB &&
00285 cubeFace != GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB &&
00286 cubeFace != GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB &&
00287 cubeFace != GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB &&
00288 cubeFace != GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB )
00289 {
00290 err() << "checkCubeFace(...) Error:\n\tInvalid cubeFace.\n";
00291 exit(1);
00292 }
00293 }
00294
00295 void TexCube::bindDef()
00296 {
00297
00298 CoreTex::bindDef();
00299
00300
00301
00302 if( m_pbuff[0] && tryToBindPbuff() ) {
00303 for(uint i=0; i < m_pbuff.size(); i++) {
00304 m_pbuff[i]->bind();
00305 }
00306 }
00307 }
00308
00309 void TexCube::releaseDef()
00310 {
00311
00312 if( m_pbuff[0] && tryToBindPbuff() ) {
00313 for(uint i=0; i < m_pbuff.size(); i++) {
00314 m_pbuff[i]->release();
00315 }
00316 }
00317
00318
00319 CoreTex::releaseDef();
00320 }
00321
00322