I’m trying to add VBO’s to my program to compare them against apple’s VAO stuff, but am not sure if I’m doing this right…the program is an object oriented data flow language for sound and graphics, and has a wrapper set for OpenGL, plus some specific workhorse objects: these include things like [pix_texture] for texturing and shape and [vertex_draw] for loading vertex arrays and calling glDrawArrays()…
…anyway, in the following snippet I’m trying to cache the buffers:
if (m_vao){
glEnableClientState( GL_VERTEX_ARRAY );
if ( !m_nVBOVertices ){
glGenBuffersARB( 1, &m_nVBOVertices );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
glBufferDataARB( GL_ARRAY_BUFFER_ARB, state->VertexArraySize*4*sizeof(float),
state->VertexArray, GL_DYNAMIC_DRAW_ARB );
glVertexPointer( 4, GL_FLOAT,0, (char*) NULL);
}else{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
glVertexPointer( 4, GL_FLOAT,0, (char*) NULL);
}
}
if(m_color && (state->ColorArray != NULL || state->HaveColorArray == 0) ){
glEnableClientState(GL_COLOR_ARRAY);
if ( !m_nVBOColor ){
glGenBuffersARB( 1, &m_nVBOColor );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOColor);
glBufferDataARB( GL_ARRAY_BUFFER_ARB, state->VertexArraySize*4*sizeof(float),
state->ColorArray, GL_DYNAMIC_DRAW_ARB );
glColorPointer(4,GL_FLOAT,0,(char*) NULL);
}else{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOColor);
glColorPointer(4,GL_FLOAT,0,(char*) NULL);
}
}else{
glDisableClientState(GL_COLOR_ARRAY);
}
if ( state->HaveTexCoordArray || state->TexCoordArray != NULL ){
if ( !m_nVBOTexCoords ){
glGenBuffersARB( 1, &m_nVBOTexCoords );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords);
glBufferDataARB( GL_ARRAY_BUFFER_ARB, state->VertexArraySize*2*sizeof(float),
state->TexCoordArray, GL_DYNAMIC_DRAW_ARB );
glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL);
}else{
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords);
glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL);
}
}
if(state->HaveNormalArray || state->NormalArray!=NULL){
glEnableClientState(GL_NORMAL_ARRAY);
if ( !m_nVBONormals ){
glGenBuffersARB( 1, &m_nVBONormals );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, state->VertexArraySize*sizeof(float),
state->NormalArray, GL_DYNAMIC_DRAW_ARB );
glNormalPointer(GL_FLOAT,0, (char *) NULL);
}else{
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals );
glNormalPointer(GL_FLOAT,0, (char *) NULL);
}
}
glDrawArrays(m_drawType,0,size);
glDisableClientState(GL_VERTEX_ARRAY);
if(m_color)glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
…does anything here look wildly wrong? It seems to work ok on my 10.3.5 alBook, but apparently linux users get a slowdown…
thanx
james