I am working with multiple particle systems which I am attempting to composite together in a frame buffer to be used in another shader. Each compute shader is working when I run each of them on their own, but something breaks when I attempt to call more than one sequentially. I have tried this many ways so hopefully I am close with at least one of them.
Combining buffers via glBufferSubData:
VBO/VAO
//generate vbo and load data
GLES31.glGenBuffers(1, vbo, 0)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, vbo[0])
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, 4 * (particleCoords.size + particleCoords2.size + particleCoords3.size), null, GLES31.GL_STATIC_DRAW)
GLES31.glBufferSubData(GLES31.GL_SHADER_STORAGE_BUFFER, 0, particleCoords.size * 4, particleCoordBuffer)
GLES31.glBufferSubData(GLES31.GL_SHADER_STORAGE_BUFFER, particleCoords.size * 4, particleCoords2.size * 4, particleCoord2Buffer)
GLES31.glBufferSubData(GLES31.GL_SHADER_STORAGE_BUFFER, (particleCoords.size + particleCoords2.size) * 4, particleCoords3.size * 4, particleCoord3Buffer)
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, vbo[0])
// generate vao
GLES31.glGenVertexArrays(1, vao, 0)
Update positions with compute shader
GLES31.glBindVertexArray(vao[0])
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, vbo[0])
GLES31.glEnableVertexAttribArray(ShaderManager.particlePositionHandle)
GLES31.glVertexAttribPointer(ShaderManager.particlePositionHandle, COORDS_PER_VERTEX, GLES31.GL_FLOAT, false, COORDS_PER_VERTEX * 4, computeOffsetForIndex(index) / COORDS_PER_VERTEX)//computeOffsetForIndex(index) * 4)
GLES31.glUseProgram(ShaderManager.particleComputeProgram)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, vbo[0])
GLES31.glUniform1i(ShaderManager.particleTimeHandle, time)
GLES31.glDispatchCompute((sizeForIndex(index) / COORDS_PER_VERTEX) / 128 + 1, 1, 1)
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
// cleanup
GLES31.glBindVertexArray(0)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0)
GLES31.glDisableVertexAttribArray(ShaderManager.particlePositionHandle)
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0)
Draw particles
GLES31.glUseProgram(ShaderManager.particleDrawProgram)
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT)
GLES31.glActiveTexture(GLES31.GL_TEXTURE0)
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, snowTexture[0])
GLES31.glUniform1i(ShaderManager.particleTextureHandle, 0)
GLES31.glEnableVertexAttribArray(ShaderManager.particlePositionHandle)
GLES31.glVertexAttribPointer(ShaderManager.particlePositionHandle, COORDS_PER_VERTEX, GLES31.GL_FLOAT, false, COORDS_PER_VERTEX * 4, computeOffsetForIndex(index) / COORDS_PER_VERTEX)
GLES31.glBindVertexArray(vao[0])
GLES31.glDrawArrays(GLES31.GL_POINTS, computeOffsetForIndex(index) / COORDS_PER_VERTEX, sizeForIndex(index) / COORDS_PER_VERTEX)
// cleanup
GLES31.glDisableVertexAttribArray(ShaderManager.particlePositionHandle)
GLES31.glBindVertexArray(0)
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0)
GLES31.glBindTexture(GLES31.GL_TEXTURE0, 0)
onDrawFrame
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, particleFramebuffer[0])
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, particleFrameTexture[0])
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, screenWidth, screenHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null)
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR)
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_LINEAR)
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, particleFrameTexture[0], 0)
for (i in 0 until (ShaderManager.particleShaderInfo?.computeIds?.size ?: 0)) {
updateParticles(i)
drawParticles(i)
}
This results in the first particle system animating and drawing as anticipated. Any systems updated after the first do not animate and all draw at (0,0,0). Starting from index 1 has the same results only properly updating the first system and not the remaining. This makes me think something is off when running the shaders one after the other, but seems it shouldn't be an issue as the data from each call is unrelated.
Multiple VBO/VAO
What I thought made the most sense was using a separate VBO/VAO for each system, though it seems I'm missing something when it comes to swapping the bound buffer on the GL_SHADER_STORAGE_BUFFER. This attempt resulted in none of my systems updating correctly. I understand that glVertexAttribPointer only cares about what is currently bound, but perhaps persistence of the changed buffer is lost then?
// generate vbo and load data
GLES31.glGenBuffers(1, vbo, 0)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, vbo[0])
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, 4 * (particleCoords.size), particleCoordBuffer, GLES31.GL_STATIC_DRAW)
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, vbo[0])
// generate vao
GLES31.glGenVertexArrays(1, vao, 0)
//-------2----------
// generate vbo and load data
GLES31.glGenBuffers(1, vbo2, 0)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, vbo2[0])
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, 4 * particleCoords2.size, particleCoord2Buffer, GLES31.GL_STATIC_DRAW)
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, vbo2[0])
// generate vao
GLES31.glGenVertexArrays(1, vao2, 0)
//--------3-----------
// generate vbo and load data
GLES31.glGenBuffers(1, vbo3, 0)
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, vbo3[0])
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, 4 * particleCoords3.size, particleCoord3Buffer, GLES31.GL_STATIC_DRAW)
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, vbo3[0])
// generate vao
GLES31.glGenVertexArrays(1, vao3, 0)
The update and draw functions for this approach are the same as above other than the VBO and VAO being swapped out each call for the appropriate objects for the index. I understand that binding a buffer replaces the previous buffer, so perhaps the persisted data is also lost at that point?
Hopefully I'm on the right track, but would welcome a better approach. Thanks for taking a look!
UPDATE
It appears my issue is not actually related to the compute shaders or the data structure being used. It seems the issue actually lies with the sampling of the frame buffer textures and mixing them in the final draw call.
I am currently mixing in a color based on the alpha channel in the frame buffer textures but the output is puzzling. Doing this with each of the three textures successfully adds tex1 and tex2, but not tex3.
outColor = mix(outColor, vec4(1.0), texture2D(tex1, f_texcoord).a);
outColor = mix(outColor, vec4(1.0), texture2D(tex2, f_texcoord).a);
outColor = mix(outColor, vec4(1.0), texture2D(tex3, f_texcoord).a);
Commenting out the mixing of tex1 results in the last two mixes working as expected. This very much confuses me and I'm not sure what the cause could be. Clearly the textures are assigned to the correct indexes as I can access them properly, it's just that I'm unable to add all three. I'm also sampling two other textures in this shader that are working as expected.
Any thoughts would be greatly appreciated!
Related
I have a performance problem in my opengl 2.0 game. Framerate was good until I made a change in the game. Its some sort of outbreak game with 64 shapes (bricks). What I now want is when the ball hits a brick its not immediately removed - it changes status and that includes changing the texture or more correctly - the uv-coord of the atlas. I have a textureatlas and what I do is just to call GLES20.bindBuffer() for every texture in the loop, instead of calling the outside the loop. Earlier I had the same uv-coord for all shapes but now I change it depending on the bricks status and thats why I need to use binding inside the loop
private void drawShape() {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboDataListLevelSprites.get(iName).getBuff_id_vertices());
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, 0);
//used this snipped before when using the same image (uv-coords) for all bricks
/*GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboDataListLevelSprites.get(iName).getBuff_id_uvs());
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
*/
for (Iterator<BrickProperties> it = arrayListBricks.iterator(); it.hasNext(); ) {
BrickProperties bp = it.next();
//now bindbuffer inside loop just too switch uv-coords of the atlas when its time to use another image
int buffIndexVal = bp.get_status_diff();
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, BrickProperties.get_buff_id_uvs()[buffIndexVal]);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, bp.getTranslateData()[0], bp.getTranslateData()[1], bp.getTranslateData()[2]);
if (bp.get_status() == 0) {
it.remove();
}
render();
}
}
private void render() {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
}
I understand the reason to the performance drop is all the bindbuffer calls to the GPU but how could I possibly get around this problem?
It is one thing that you are binding a buffer for every object but then there is another thing you are using 2 buffers to draw a single object. You also have redundant call to unbind the buffer at the start of your render method, simply remove that.
In most cases (may be all cases) you want interleaved vertex data for increased performance. So use
{
position,
textureCoordinates
}
in a single buffer.
I see in your case you have 2 states of the same object where the second one will change vertex coordinates but not position coordinates. It might make sense to share the position data between the two if the buffer is relatively large (which I assume is not). Anyway for such sharing I would suggest you rather use your buffer structure as
{
position,
textureCoordinates,
secondaryTextureCoordinates
}
then use a separate buffer or even to put the secondary texture coordinates to another part of the same buffer.
So if the vertex buffers are relatively small then I suggest you to use "atlas" procedure. For your case that would mean creating twice the size of the buffer and put all the coordinates (having position duplicated) and put this vertex data so that there is one part after another.
I assume you can easily do that for your current drawing and effectively reduce the number of bound buffers to 0 per draw call (you only ned to bind it at some initialization). Now you will have the second part where you will set the attribute pointers for each of the drawn element just so that you may control which texture coordinates are used. This will again present redundant calls which may be avoided in your case:
Since the data structure is consistent in your buffer there is really no reason to set the pointers more the once. Simply set them once to the beginning when buffer is bound and then use the offset in draw call to control what part of the buffer is actually used GLES20.glDrawArrays(GLES20.GL_TRIANGLES, offset, 6).
If done properly your draw method should looks something like:
for (Iterator<BrickProperties> it = arrayListBricks.iterator(); it.hasNext(); ) {
BrickProperties bp = it.next();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, bp.getTranslateData()[0], bp.getTranslateData()[1], bp.getTranslateData()[2]);
if (bp.get_status() == 0) {
it.remove();
}
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, bp.vertexOffset, 6);
}
This removes all the bindings and preserves only matrix operations and draw calls. If there are other drawings in the pipeline you need the buffer binding before the loop otherwise you may put it as a part of the initialization. In both cases the calls should be reduced significantly.
To add a note here it is a common practice to have another object that tracks the openGL states to avoid redundant calls. Instead of calling GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferID.. you would rather call something like contextObject.bindVertexBuffer(bufferID) which would check if the bufferID is the same as in previous call. And if it is then no actual binding would be done. If you create and use such system then it makes little difference on where you call the buffer binding and rest of the object setup since redundant calls will have no effect. Still this procedure alone will not make your situation optimal so you still need both.
You could bind buffer and draw all the objects with the same UV-s at once. Instead of iterating through each brick, iterate through all objects that use the same UV-s.
Also, try batching the objects so that you draw them all at once. Using Index Buffer Objects may help in this.
I want to copy texture1 to texture2. The background is that I generate 15 empty texture id and bind them to GLES11Ext.GL_TEXTURE_EXTERNAL_OES, the following is my code:
int[] textures = new int[15];
GLES20.glGenTextures(15, textures, 0);
GlUtil.checkGlError("glGenTextures");
for(int i=0;i<15;i++)
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[i]);
then I always transfer camera preview to textures[0], I want copy the texture from textures[0] to textures[1] in order to keep the frame content of timestamp 1, and copy the texture from textures[0] to textures[2] in order to keep the frame content of timestamp 2... it looks like buffer some texture data in GPU and render some of that in the future. So I want to know is there anyway to do this? And can I just use textures[2]=textures[0] to copy texture data?
There isn't a very direct way to copy texture data in ES 2.0. The easiest way is probably using glCopyTexImage2D(). To use this, you have to create an FBO, and attach the source texture to it. Say if srcTexId is the id of the source texture, and dstTexId the id of the destination texture:
GLuint fboId = 0;
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, srcTexId, 0);
glBindTexture(GL_TEXTURE_2D, dstTexId);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0);
That being said, from your description, I don't believe that this is really what you should be doing, for the following reasons:
I don't think copying texture data as shown above will work for the external textures you are using.
Copying texture data will always be expensive, and sounds completely unnecessary to solve your problem.
It sounds like you want to keep the 15 most recent camera images. To do this, you can simply track which of your 15 textures contains the most recent image, and treat the list of the 15 texture ids as a circular buffer.
Say initially you create your texture ids:
int[] textures = new int[15];
GLES20.glGenTextures(15, textures, 0);
int newestIdx = 0;
Then every time you receive a new frame, you write it to the next entry in your list of texture ids, wrapping around at 15:
newestIdx = (newestIdx + 1) % 15;
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[newestIdx]);
// Capture new frame into currently bound texture.
Then, every time you want to use the ith frame, with 0 referring to the most recent, 1 to the frame before that, etc, you bind it with:
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[(newestIdx + i) % 15]);
So the textures never get copied. You just keep track of which texture contains which frame, and access them accordingly.
I want to create a static starfield in libgdx.
My first way was: create a Decal and a DecalBatch over it.
When I draw the Decal I use a Billboarding technic on the Decal
star.decal.setRotation(camera.direction, camera.up);
next: I wanted to animate the alphas on the decals, so I created on a random way some time:
star.decal.setColor(1, 1, 1, 0.6f+((float) Math.random()*0.4f) );
It is working, but my FPS went down from 55 FPS to 25 FPS (because of my 500-1000 stars)
Can I use only one batch call in any way? Maybe a particleMaterial with only one Vertex list and with a GL_POINT mode that is always face to front of my camera?
How can I do this in libgdx?
The Batch is way to complex than what you need , on every frame it needs to copy all the vertices of the sprites in another array and do calculations on them to find the scale rotation etc..
As you suspect GL_POINT sprites will be way faster and in a medium range device it should be able to render in 60 fps like 2000 points that have different position and color
here is some old code of mine ,its in c and it uses opengl es 1.1 and propably there will be a more simple way to do it in libgdx
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable (GL_POINT_SPRITE_OES);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, TXTparticle);
glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
glPointSize(30);
glColorPointer(4, GL_FLOAT, 32, particlesC);//particlesC the vertices color
glVertexPointer(3, GL_FLOAT, 24, particlesV);//particlesV the vertices
glDrawArrays(GL_POINTS, 0, vertvitLenght/6);
glDisable( GL_POINT_SPRITE_OES );
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
Im having trouble with texturing a cube with different textures per face. I can draw the cube with one texture on all the faces, but when I try use multiple textures it fails. The way im trying to do it is like so:
//my indexing array located in a header file
#define NUM_IMAGE_OBJECT_INDEX 36
static const unsigned short cubeIndices[NUM_IMAGE_OBJECT_INDEX] =
{
0, 1, 2, 2, 3, 0, // front
4, 5, 6, 6, 7, 4, // right
8, 9,10, 10,11, 8, // top
12,13,14, 14,15,12, // left
16,17,18, 18,19,16, // bottom
20,21,22, 22,23,20 // back
};
now in my rendering function, this currently works for drawing the cube with a single texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iconTextureID);
glDrawElements(GL_TRIANGLES, NUM_IMAGE_OBJECT_INDEX, GL_UNSIGNED_SHORT, 0);
this does not work
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iconTextureID);
glDrawElements(GL_TRIANGLES, NUM_IMAGE_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*)&cubeIndices[0]);
which should equate to the same thing, from looking at some other examples. Ultimately I would like to be doing this something like this:
for(int i = 0; i < 6; i++){
iconTextureID = textureID[i];
glBindTexture(GL_TEXTURE_2D, iconTextureID);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const GLvoid*)&cubeIndices[i*6]); //index 0-5 use texture 1, 6-11 use texture 2, etc
}
does anyone know what could be wrong with this indexing? ive basically copy pasted this code from an android project (which works), currently trying to do this on ios.
In OpenGL ES 2.0, index data can come from either buffer objects or pointers to client memory. Your code is obviously using a buffer object. Though you don't show the creation of this buffer object, where you upload your client array of pointers, or where you call glBindBuffer(GL_ELEMENT_ARRAY_BUFFER) before rendering with it. It must be there or your code would have crashed. When a buffer is bound to GL_ELEMENT_ARRAY_BUFFER, OpenGL expects the "pointer" given to glDrawElements to be a byte offset into the buffer object, not a client-memory pointer.
This is why copy-and-paste coding is a bad idea. Where you copied from was probably using client memory; you are not.
If you want your looping code to work, you need to do the pointer arithmetic yourself:
for(int i = 0; i < 6; i++)
{
iconTextureID = textureID[i];
glBindTexture(GL_TEXTURE_2D, iconTextureID);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, reinterpret_cast<void*>(i * 6 * sizeof(GLushort)));
}
I am trying to create a simple test program on android (API 10) using OpenGL ES 2.0 to draw a simple rectangle. I can get this to work with float buffers referencing the vertices directly, but i would rather do it with VBOs/IBOs. I have looked for countless hours trying to find a simple explanation (tutorial), but have yet to come across one. My code compiles and runs just fine, but nothing is showing up on the screen other than the clear color.
Here are some code chunks to help explain how I have it set up right now.
Part of onSurfaceChanged():
int[] buffers = new int[2];
GLES20.glGenBuffers(2, buffers, 0);
rectVerts = buffers[0];
rectInds = buffers[1];
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, rectVerts);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, (rectBuffer.limit()*4), rectBuffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, rectInds);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, (rectIndices.limit()*4), rectIndices, GLES20.GL_STATIC_DRAW);
Part of onDrawFrame():
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, rectVerts);
GLES20.glEnableVertexAttribArray(0);
GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, rectInds);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_INT, 0);
I don't see anything immediately wrong, but here's some ideas you can touch on.
1) 'Compiling and running fine' is a useless metric for an opengl program. Errors are reported through actively calling glGetError and checking compile and link status of the shaders with glGet(Shader|Program)iv. Do you check for errors anywhere?
2) You shouldn't be assuming that 0 is the correct index for vertices. It may work now but will likely break later if you change your shader. Get the correct index with glGetAttribLocation.
3) You're binding the verts buffer onDraw, but I don't see anything about the indices buffer. Is that always bound?
4) You could also try drawing your VBO with glDrawArrays to get the index buffer out of the equation, just to help debugging to see which part is wrong.
Otherwise what you have looks correct as far as I can tell in that small snippet. Maybe something else outside of it is going wrong.