Multiple pixel buffer objects

I’m trying to use 4 pixel buffer objects instead of four textures, but I’m getting confused about the texture id’s and pixel buffer id’s. I’ve seen a few examples but they all only use one texture, and I want to have four which I select at various stages and render.

My code does the following:


// initialise textures
int[] tids = new int[4];
gl.glGenTextures(4, tids, 0);
int[] pbids = new int[4];
gl.glGenBuffers(4, pbids, 0);
for (int i=0; i<4; i++)
{
  gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, 0);
  gl.glEnable( GL.GL_TEXTURE_2D );
  gl.glBindTexture(GL.GL_TEXTURE_2D, tids[i]);
  gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, 128, 128, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, null);
  gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
  gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
  gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, pbids[i]);
  gl.glBufferData(GL.GL_PIXEL_UNPACK_BUFFER_ARB, 128*128*4, null, GL.GL_STREAM_DRAW);
}

When I want to write to the textures I do the following:


gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, pbids[index_between_0_4]);
ByteBuffer mappedBuffer = gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, GL.GL_WRITE_ONLY);
mappedBuffer.put(texture_bytes);
gl.glUnmapBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB);
gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, 0);
gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, 0);

Now when I want to render using any of the texture is where I have the problem as It doesn’t seem to work. I get something but bot what I expect.


gl.glBindTexture(GL.GL_TEXTURE_2D, tids[0-4]);
gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER_ARB, pbid[index_between_0_4]);
......
render quads.

Do I need to bind the texture ID and the pixel buffer ID or only one of them.

Can anybody help me.

I’m no expert on pixel buffer objects, but have you looked at the “Streaming textures using pixel buffer objects” example in the ARB_pixel_buffer_object spec?

I looked but it only streams to one texture so it dosen’t show how to deal with multiple textures. However I have just stumbled across what seems to be the culprit. A lot of the examples use glBindBuffer(…) when it should be glBindBufferARB

Also it seems the flow is the following: get a texture ID name, select the texture using the ID, bind a buffer using a previously requested buffer ID then that action links the buffer to the texture. Then when you write to the buffer and unbind the buffer, it shows up in the texture where ever you are using that texture (selecting the texture in the normal way throught the texture ID).

I’m gonna play a little more to make sure it works as I think. I’ll post the results here for anybody who is interested.

Thanks