arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

drawAlgArr.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////
00002 // 8/13/02      Aaron Lefohn    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 ////////////////////////////////////////////////////////////////////////
00019 
00020 #include <drawable/drawAlgorithm.h>
00021 #include <iostream>
00022 #include <util/gliftUtil.h>
00023 #include <GL/glUtil.h>
00024 
00025 using namespace gutz;
00026 using namespace std;
00027 
00028 using namespace glift;
00029 
00030 extern const GLenum g_texUnitName[NUM_TEX_UNIT_NAMES];
00031 
00032 #ifndef NDEBUG 
00033 //      #define SPEW_TEX_COORDS
00034 #endif
00035 
00036 /// WARNING: This assumes that all necessary arrays have been enabled. It sets pointers, but does
00037 //                      not check for enabled state.
00038 void DrawAlgArr::draw( GLenum primType, const arrayw2f& vert, const MultiTexCoord* curTexCoords,
00039                       const arrayw2f& norm, const arrayw2f& color, const arrayw1ub& edgeFlag,
00040                       const gutz::arrayw1ui* curIndices )
00041 {
00042    /// Enable client state and set pointers
00043    /// TODO: Should only set pointers here. Enable client state
00044    ///       in 'init()' and leave enabled
00045    enable( vert, curTexCoords, norm, color, edgeFlag );
00046 
00047    /// Draw it!!
00048    if( curIndices==NULL ) {
00049       glDrawArrays( primType, 0, vert.dim(0) );
00050    }
00051    else {
00052       const arrayw1ui& indices = *curIndices;
00053 
00054       if( indices.dim(0) > 0 ) {
00055          /// TODO: Can/Should this be glRangeElements? Would have to pass in begin/end of indices
00056          glDrawElements( primType, indices.dim(0), GL_UNSIGNED_INT, indices.data() );
00057          //cerr << "DrawAlgArr::indices.dim(0) = " << indices.dim(0) << ", indices.data() = " << indices.data() << endl;
00058       }
00059    }
00060 
00061    /// TODO: Should not disable here, but still need to set glActiveTexture to 0.
00062    disable( vert, curTexCoords, norm, color, edgeFlag );
00063 
00064    glerr("draw(...)");
00065 }
00066 
00067 //static GLfloat*                       f_curVertPtr = NULL;
00068 //static MultiTexCoord* f_curTexCoordsPtr = NULL;
00069 //static vector<GLfloat*> f_curTexPtr(32,NULL);
00070 
00071 void DrawAlgArr::enable( const arrayw2f& vert, const MultiTexCoord* curTexCoords,
00072                         const arrayw2f& norm, const arrayw2f& color, const arrayw1ub& edgeFlag )
00073 {
00074    //   if( f_curVertPtr != vert.data() ) {     
00075    //           f_curVertPtr = (GLfloat*)vert.data();
00076    glEnableClientState(GL_VERTEX_ARRAY); /// Setup vertices
00077    glVertexPointer( vert.dim(1), GL_FLOAT, 0, vert.data() );
00078    //   }
00079 
00080    //   if( f_curTexCoordsPtr != curTexCoords ) {
00081    //           f_curTexCoordsPtr = (MultiTexCoord*)curTexCoords;
00082 
00083    if( curTexCoords ) {                 
00084       for( uint t=0; t < (*curTexCoords).size(); t++) { /// Setup texture coords        
00085          int texCoordDimen = (*curTexCoords)[t].dim(1);
00086 
00087          const GLfloat* dataPtr = (*curTexCoords)[t].data();
00088          //if( f_curTexPtr[t] != dataPtr) {
00089          //     f_curTexPtr[t] = (GLfloat*)dataPtr;
00090          glClientActiveTexture( g_texUnitName[t] );
00091          glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00092          glTexCoordPointer( texCoordDimen, GL_FLOAT, 0, dataPtr );
00093          //}
00094       }
00095    }
00096    //   }
00097 
00098    if( !norm.empty() ) {                                  /// Setup normals
00099       glEnableClientState(GL_NORMAL_ARRAY);
00100       glNormalPointer( GL_FLOAT, 0, norm.data() );
00101    }
00102 
00103    if( !color.empty() ) {                                 /// Setup colors
00104       glEnableClientState(GL_COLOR_ARRAY);
00105       glColorPointer( color.dim(1), GL_FLOAT, 0, color.data() );                
00106    }
00107 
00108    if( !edgeFlag.empty() ) {                      /// Setup edgeFlags
00109       glEnableClientState(GL_EDGE_FLAG);
00110       glEdgeFlagPointer(0, edgeFlag.data());
00111    }
00112 }
00113 
00114 void DrawAlgArr::disable(const arrayw2f& vert, const MultiTexCoord* curTexCoords,
00115                          const arrayw2f& norm, const arrayw2f& color, const arrayw1ub& edgeFlag )
00116 {
00117    glDisableClientState(GL_VERTEX_ARRAY);
00118    if( !norm.empty() ) {
00119       glDisableClientState(GL_NORMAL_ARRAY);
00120    }
00121    if( !color.empty() ) {
00122       glDisableClientState(GL_COLOR_ARRAY);
00123    }
00124    if( !edgeFlag.empty() ) {
00125       glDisableClientState(GL_EDGE_FLAG_ARRAY);
00126    }
00127 
00128    if( curTexCoords ) {
00129       for( uint t=0; t < (*curTexCoords).size(); t++) { 
00130          glClientActiveTexture( g_texUnitName[t] );
00131          glDisableClientState(GL_TEXTURE_COORD_ARRAY);
00132       }
00133    }
00134 }
00135 
00136 

Send questions, comments, and bug reports to:
jmk