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.