Hi all, just started moving my rendering code from VAs to VBOs and i’m having some problems with them.
heres the relevent chunk of code:
//decide whether to use VA or VBO
if(Globals.useVertexBufferObjects)
{
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vboHandle);
gl.glVertexPointer(3,GL.GL_FLOAT,0,BufferUtils.bufferOffset(0));
}
else
gl.glVertexPointer(3,GL.GL_FLOAT,0,vertBuffer);
//Draw base terrain
gl.glDrawElements(GL.GL_TRIANGLES,uvIndices.length,GL.GL_UNSIGNED_INT,uvIndices);
//Draw all the appropriate terrain texture layers.
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4f(1.0f,1.0f,1.0f,0.5f);
gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
gl.glEnable(GL.GL_COLOR_MATERIAL);
gl.glTexCoordPointer(2, GL.GL_FLOAT,0,uvBuffer);
GeoTerrainType tempType;
for(c1 = 0;c1 < terrainTypes.size() ;c1 ++)
{
tempType = (GeoTerrainType)terrainTypes.get(c1);
if(!tempType.isDrawable()) continue;
gl.glBindTexture(GL.GL_TEXTURE_2D, tempType.texture.getTextureID());
gl.glColorPointer(4,GL.GL_UNSIGNED_BYTE,0,tempType.byteColorBuffer);
gl.glDrawElements(GL.GL_TRIANGLES,uvIndices.length,GL.GL_UNSIGNED_INT,uvIndices);
}
gl.glPopAttrib();
gl.glDisableClientState(GL.GL_COLOR_ARRAY);
if(Globals.useVertexBufferObjects)
{
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB,0);
}
First of all, this works perfectly with the VA codepath instead of the VBO codepath (ie Globals.useVertexBufferObjects is false) . When i switch to the VBO codepath however, the first glDrawElements call works correctly (the ‘base terrain draw’ above) but then the second one fails with an EXCEPTION_ACCESS_VIOLATION.
If there was something wrong with any of the mem buffers then the VA codepath wouldn’t work, If something was wrong with the VBO allocation then the first DrawElements call would fail so i’m at a bit of a loss. The only thing i can think of is maybe when you’re using the same VBO multiple times on the same bind you have to reset it in some way ? I can’t find any literature on this tho …
Any ideas ?
D.
and incidentally, just previewing the post there, why on earth did the forum software stick a space in between ‘uv’ and ‘Indices’ in the drawElements calls ???