VBOs versus no VBOs - is this JOGL code right?

Is this code right - it draws lots of stuff, either using VBOs or not using VBOs if they are not available:

        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

        for (int i = 0; i < (layers * layers); i++) {
    		gl.glTranslatef(0.0f, 0.0f, 0.01f);
			if (JoglRunner.vboAvailable(gl)) { 
				gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBO[0]);
				gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
				gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBO[1]);
				gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
				gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 20000);
			} else {
				gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
				gl.glColorPointer(4, GL.GL_FLOAT, 0, colorBuffer);
				gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 20000);
			}
		}
		gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
 

I’m bothered by the call to enable client state that I sem to need before using a VBO - it doesn’t make sense to me - I am trying to avoid client state.

Hi

It seems correct but I don’t know the source code of JoglRunner.vboAvailable(GL). In the alpha version of TUER, I put this kind of code into separate class to avoid performing such tests each time I use some vertices during the display. Don’t forget that VBOs can be static or dynamic, you can use an “hint” to indicate that you’re going to change their content often or not. Static VBOs are faster on graphics cards with a correct support of this feature.

Edit.: you should have posted that into the JOGL section.

Thanks. You make a good point about vboAvailable() - I can make that method more efficient.

You can’t get away from the client state. OpenGL has to be told which attributes it should read from the VBO/pointer and which ones it should just use the current attribute set by glColor(), glTexCoord(), etc. You don’t always have texture coordinates, you don’t always have normals, you don’t always have per vertex colors, so glEnableClientState() defines which ones you’re actually sending. If you use shaders and have custom attributes you use glEnableVertexAttribArray(attributeLocation) instead, but it works in the same way. You could use VAOs to hold your client state though.