00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <drawable/drawAlgorithm.h>
00021 #include <iostream>
00022 #include <util/gliftUtil.h>
00023
00024 using namespace gutz;
00025 using namespace std;
00026
00027 using namespace glift;
00028
00029 #ifndef NDEBUG
00030
00031 #endif
00032
00033 extern const GLenum g_texUnitName[NUM_TEX_UNIT_NAMES];
00034
00035 void DrawAlgImm::draw( GLenum primType, const arrayw2f& vert, const MultiTexCoord* curTexCoords,
00036 const arrayw2f& norm, const arrayw2f& color, const arrayw1ub& edgeFlag,
00037 const arrayw1ui* curIndices )
00038 {
00039 int numVerts = vert.dim(0);
00040
00041 if( curIndices==NULL ) {
00042 glBegin(primType);
00043 for(int v=0; v < numVerts; v++) {
00044 draw(v, vert, curTexCoords, norm, color, edgeFlag);
00045 }
00046 glEnd();
00047 }
00048 else {
00049 const arrayw1ui& indices = *curIndices;
00050 glBegin(primType);
00051 for(int i=0; i < indices.dim(0); i++) {
00052 int v = indices[i];
00053 draw(v, vert, curTexCoords, norm, color, edgeFlag);
00054 }
00055 glEnd();
00056 }
00057 glerr("draw()");
00058 }
00059
00060 void DrawAlgImm::draw( int vertNum, const arrayw2f& vert, const MultiTexCoord* curTexCoords,
00061 const arrayw2f& norm, const arrayw2f& color,
00062 const arrayw1ub& edgeFlag )
00063 {
00064 int v = vertNum;
00065
00066 if( !norm.empty() ){ glNormal3fv( norm[v].data() ); }
00067 if( curTexCoords ){ setTexCoords( curTexCoords, v ); }
00068 if( !color.empty() ){ glColor3fv( color[v].data() ); }
00069 if( !edgeFlag.empty() ) { glEdgeFlag( edgeFlag[v] ); }
00070
00071 setVertPos( vert, v );
00072 }
00073
00074 void DrawAlgImm::setVertPos( const arrayw2f& vert, int vertNum )
00075 {
00076 int vertDimen = vert.dim(1);
00077
00078 switch(vertDimen) {
00079 case 2: glVertex2fv( vert[vertNum].data() ); break;
00080 case 3: glVertex3fv( vert[vertNum].data() ); break;
00081
00082 default: err() << "setVertPos(...) Error:\n\tvertex dimen (" << vertDimen
00083 << ") must be 2 or 3\n";
00084 }
00085
00086 #ifdef SPEW_TEX_COORDS
00087 estr() << "v[" << vertNum << "] = " << vert[vertNum][0] << ", " << vert[vertNum][1] << endl;
00088 #endif
00089 }
00090
00091 void DrawAlgImm::setTexCoords( const MultiTexCoord* curTexCoords, GLint vertNum )
00092 {
00093 #ifdef SPEW_TEX_COORDS
00094 err() << "setTexCoords(...):\n";
00095 #endif
00096
00097
00098
00099 if( (*curTexCoords).size() == 1 ) {
00100 int texCoordDimen = (*curTexCoords)[0].dim(1);
00101
00102 #ifdef SPEW_TEX_COORDS
00103 outputTexCoords( (*curTexCoords), texCoordDimen, 0, vertNum );
00104 #endif
00105
00106 switch(texCoordDimen) {
00107 case 1: glTexCoord1fv( (*curTexCoords)[0][vertNum].data() ); break;
00108 case 2: glTexCoord2fv( (*curTexCoords)[0][vertNum].data() ); break;
00109 case 3: glTexCoord3fv( (*curTexCoords)[0][vertNum].data() ); break;
00110 case 4: glTexCoord4fv( (*curTexCoords)[0][vertNum].data() ); break;
00111
00112 default: err() << "DrawAlgImm::setTexCoords(...) Error:\n\ttexCoord dimen (" << texCoordDimen
00113 << ") must be 1,2,3, or 4\n";
00114 }
00115 }
00116 else {
00117
00118 for( uint t=0; t < (*curTexCoords).size(); t++) {
00119 int texCoordDimen = (*curTexCoords)[t].dim(1);
00120
00121 #ifdef SPEW_TEX_COORDS
00122 outputTexCoords( (*curTexCoords), texCoordDimen, t, vertNum );
00123 #endif
00124
00125 switch(texCoordDimen) {
00126 case 1: glMultiTexCoord1fvARB( g_texUnitName[t], (*curTexCoords)[t][vertNum].data() ); break;
00127 case 2: glMultiTexCoord2fvARB( g_texUnitName[t], (*curTexCoords)[t][vertNum].data() ); break;
00128 case 3: glMultiTexCoord3fvARB( g_texUnitName[t], (*curTexCoords)[t][vertNum].data() ); break;
00129 case 4: glMultiTexCoord4fvARB( g_texUnitName[t], (*curTexCoords)[t][vertNum].data() ); break;
00130
00131 default: err() << "DrawAlgImm::setTexCoords() Error:\n\ttexCoord dimen (" << texCoordDimen
00132 << ") must be 1,2,or 3\n";
00133 }
00134 }
00135 #ifdef SPEW_TEX_COORDS
00136 estr() << "\n";
00137 #endif
00138
00139 }
00140 }
00141
00142 void DrawAlgImm::outputTexCoords( const MultiTexCoord& texCoords, int texCoordDimen, int texUnit, int vertNum )
00143 {
00144 int t = texUnit;
00145 int v = vertNum;
00146
00147 estr() << "\t" << t << ": ";
00148 for( int c=0; c < texCoordDimen-1; c++) {
00149 estr() << texCoords[t][v][c] << ", ";
00150 }
00151 estr() << texCoords[t][v][texCoordDimen-1] << "\n";
00152 }
00153