VBOs overwriting one another?

Started by
2 comments, last by ardvarticus 13 years, 5 months ago
I've got an app that renders some boxes; they're textured from multiple texture atlases, so there's a VBO per atlas (well, there's a VBO per atlas per performance hint - static, dynamic and stream - but I'm only using static at the moment). However, when I try and render the VBOs, one after another, only the faces textured from the last atlas are drawn.

First, I create all the VBOs (I've checked, all the OGL pointers returned are unique) for all the arrays.

Next, the renderer calls updateVBOs, and the geometry for the boxes is generated and stuffed into the VBOs.

Lastly, each VBO is bound in turn, along with the atlas associated with it, and rendered.

The problem is, when I render it, only the geometry from the last texture atlas is rendered; sections of the other texture atlases are rendered onto the faces too.

For an experiment, I set up updateVBOs so that it'd only fill up vbos from a single atlas each frame - which atlas changes each frame. When I did this, the sections that are usually missed due to this problem reappear each time their atlas comes up.

Stuff I've checked so far:
The vector<vertex> used to fill the arrays from is cleared between VBOs
The VBOs are bound before they're meant to be filled or rendered
The geometry for the boxes is being output correctly

Thanks in advance for taking a look at this!
Advertisement
Oh, forgot to mention that all the code is here if you're interested:

http://code.google.com/p/ahengine/source/browse/#svn/branches/Issue2

The rendering happens in renderer.cpp VBOs are setup in initGL, drawn in DrawGLScene, and filled in updateVBOs.
update: I've ran gdebugger to take a look at what's going on; It looks fine to me though :/


//Here, the VBOs get bound and filled with data.
glBindBufferARB(GL_ARRAY_BUFFER, 1)
glBufferDataARB(GL_ARRAY_BUFFER, 43008, 0x00B90020, GL_STREAM_DRAW)
glBindBufferARB(GL_ARRAY_BUFFER, 4)
glBufferDataARB(GL_ARRAY_BUFFER, 7680, 0x00B90020, GL_STREAM_DRAW)

//Then, the vertex pointers are set
glVertexPointer(3, GL_FLOAT, 64, 0x00000000)
glNormalPointer(GL_FLOAT, 64, 0x0000000C)
glTexCoordPointer(2, GL_FLOAT, 64, 0x00000018)
glColorPointer(4, GL_FLOAT, 64, 0x00000020)
glVertexPointer(3, GL_FLOAT, 64, 0x00000000)
glNormalPointer(GL_FLOAT, 64, 0x0000000C)
glTexCoordPointer(2, GL_FLOAT, 64, 0x00000018)
glColorPointer(4, GL_FLOAT, 64, 0x00000020)
glVertexPointer(3, GL_FLOAT, 64, 0x00000000)
glNormalPointer(GL_FLOAT, 64, 0x0000000C)
glTexCoordPointer(2, GL_FLOAT, 64, 0x00000018)
glColorPointer(4, GL_FLOAT, 64, 0x00000020)

//Clearing the scene and applying transforms
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-2, -1, -5)
glRotatef(948.23944, 1, 0, 0)
glRotatef(1422.3354, 0, 1, 0)
glRotatef(2370.5, 0, 0, 1)

// Drawing the first VBO
glBindTexture(GL_TEXTURE_2D, 1)
glBindBufferARB(GL_ARRAY_BUFFER, 1)
glDrawArrays(GL_TRIANGLES, 0, 672)

//And the second (it's empty)
glBindTexture(GL_TEXTURE_2D, 2)
glBindBufferARB(GL_ARRAY_BUFFER, 2)
glDrawArrays(GL_TRIANGLES, 0, 0)

//And the third (it's empty too)
glBindTexture(GL_TEXTURE_2D, 3)
glBindBufferARB(GL_ARRAY_BUFFER, 3)
glDrawArrays(GL_TRIANGLES, 0, 0)

//And the fourth VBO
glBindTexture(GL_TEXTURE_2D, 4)
glBindBufferARB(GL_ARRAY_BUFFER, 4)
glDrawArrays(GL_TRIANGLES, 0, 120)
Ok, I found the problem; I'm just an idiot. glDrawArrays draws whatever VBO was bound when the vertex pointer was set, which was always the last one; So, no matter which VBO I bound, it always drew from the last one.

This topic is closed to new replies.

Advertisement