Re: [Plib-devel] Vertex array code
Brought to you by:
sjbaker
From: Eric E. <Eri...@fr...> - 2000-05-15 19:37:54
|
"Vallevand, Mark K" wrote: > > Here is the vertex array code for ssg. > <<plib.tar.gz>> > I've included a diff file of changes to existing files, the original > files, the changed files, and the new files. There isn't any > documentation except this email message. I based the changes > on plib 1.1.9.- > [...] Well done, I was planning to do it myself for Torcs. In order to allow optionnal arrays, I merged the codes from VtxTable and VtxArray (see the result below)... I have also a proposal for VtxTable, I don't know if it is interesting to do it that way (the number of vertices used to switch between the array and the other method should be tuned). Just an idea for the compiled vertex arrays: it would be interesting to manage the client states and arrays pointers externally (as textures) in order to share bigger arrays between leaves and to use index arrays to select small parts in each leaf. But this will be more complex to do and need a changes in the structure, like loading the arrays in a specific parent ssgEntity for example, and have the client states managed also by the parent ssgEntity. Eric. Here is my proposal for the draw_geometry functions (not yet tested). void ssgVtxArray::draw_geometry () { int num_colours = getNumColours () ; int num_normals = getNumNormals () ; int num_texcoords = getNumTexCoords () ; glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; if ( num_colours == 0 ) glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ; else if ( num_colours == 1 ) glColor4fv ( ( (sgVec4 *) colours->get(0) ) [ 0 ] ) ; else if ( num_colours > 1 ) { glEnableClientState ( GL_COLOR_ARRAY ) ; glColorPointer ( 4, GL_FLOAT, 0, colours->get(0) ) ; } if ( num_normals == 1 ) glNormal3fv ( ( (sgVec3 *) normals->get(0) ) [ 0 ] ) ; else if ( num_normals > 1 ) { glEnableClientState ( GL_NORMAL_ARRAY ) ; glNormalPointer ( GL_FLOAT, 0, normals->get(0) ) ; } if ( num_texcoords > 1 ) { glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glTexCoordPointer ( 2, GL_FLOAT, 0, texcoords->get(0) ) ; } glEnableClientState ( GL_VERTEX_ARRAY ) ; glVertexPointer ( 3, GL_FLOAT, 0, vertices->get(0) ) ; int i = getNumIndices (); int *ii = indices->get(0); glDrawElements ( gltype, i, GL_UNSIGNED_INT, ii ) ; glPopClientAttrib ( ) ; } void ssgVtxTable::draw_geometry () { int num_colours = getNumColours () ; int num_normals = getNumNormals () ; int num_vertices = getNumVertices () ; int num_texcoords = getNumTexCoords () ; sgVec3 *vx = (sgVec3 *) vertices -> get(0) ; sgVec3 *nm = (sgVec3 *) normals -> get(0) ; sgVec2 *tx = (sgVec2 *) texcoords -> get(0) ; sgVec4 *cl = (sgVec4 *) colours -> get(0) ; if ( num_vertices < 9 /* To Be Tuned */ ) { glBegin ( gltype ) ; if ( num_colours == 0 ) glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ; if ( num_colours == 1 ) glColor4fv ( cl [ 0 ] ) ; if ( num_normals == 1 ) glNormal3fv ( nm [ 0 ] ) ; for ( int i = 0 ; i < num_vertices ; i++ ) { if ( num_colours > 1 ) glColor4fv ( cl [ i ] ) ; if ( num_normals > 1 ) glNormal3fv ( nm [ i ] ) ; if ( num_texcoords > 1 ) glTexCoord2fv ( tx [ i ] ) ; glVertex3fv ( vx [ i ] ) ; } glEnd () ; } else { glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT ) ; if ( num_colours == 0 ) glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ; else if ( num_colours == 1 ) glColor4fv ( cl [ 0 ] ) ; else if ( num_colours > 1 ) { glEnableClientState ( GL_COLOR_ARRAY ) ; glColorPointer ( 4, GL_FLOAT, 0, cl ) ; } if ( num_normals == 1 ) glNormal3fv ( nm [ 0 ] ) ; else if ( num_normals > 1 ) { glEnableClientState ( GL_NORMAL_ARRAY ) ; glNormalPointer ( GL_FLOAT, 0, nm ) ; } if ( num_texcoords > 1 ) { glEnableClientState ( GL_TEXTURE_COORD_ARRAY ) ; glTexCoordPointer ( 2, GL_FLOAT, 0, tx ) ; } glEnableClientState ( GL_VERTEX_ARRAY ) ; glVertexPointer ( 3, GL_FLOAT, 0, vx ) ; glDrawArrays ( gltype, 0, num_vertices ) ; glPopClientAttrib ( ) ; } } |