Using PBOs in JOGL

Could anyone point me towards a tutorial or some complete sample code on using PBOs with JOGL? I’ve searched all over the net and have checked several books but came up empty.

Thanks Stephen.

Are you refering to pbuffers (to enable offscreen rendering) or the pixel buffer object extension that extends vbos to allow you to move data between buffer objects and textures/screen?

If it’s the last one, pbo’s in that sense are used identically to how they are in normal opengl code. It may help you to find an example in c/c++ and it should transfer over almost identically (the gl commands will be the same). If that doesn’t work, let me know and I can try to explain it more (have to look up how I did it before).

It would be the latter this is the code that i was able to come up with but i get a garbled texture i’m pretty sure it’s got something to do with the gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER, GL.GL_WRITE_ONLY); line which should be assigned to my image data but i have no clue how to due that.

            texImage = loadImage(_filename); // this loads my image into and array of pixels called teximage.pixels.
	int [] tex = new int[1];
	int [] pbo = new int[1];

	gl.glGenTextures(1, tex, 0);
	gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]);
	gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE);
	gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
	gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
	gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, texImage.width, texImage.height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, null);
	
	gl.glGenBuffers(1, pbo, 0);
	gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, pbo[0]);
	gl.glBufferData(GL.GL_PIXEL_UNPACK_BUFFER, texImage.height * texImage.width * BufferUtil.SIZEOF_FLOAT, IntBuffer.wrap(texImage.pixels), GL.GL_STATIC_DRAW);
	gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER, GL.GL_WRITE_ONLY);
	gl.glUnmapBuffer(GL.GL_PIXEL_UNPACK_BUFFER);
	 gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, 0);

I then bind tex[0] in my animation loop. Thanks for the reply I was able to get FBOs and VBOs and eveything else working but PBO are being a pain in the ass :slight_smile:

Try something like:

 
      texImage = loadImage(_filename); // this loads my image into and array of pixels called teximage.pixels.
      int [] tex = new int[1];
      int [] pbo = new int[1];

      gl.glGenBuffers(1, pbo, 0);
      gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, pbo[0]);
      gl.glBufferData(GL.GL_PIXEL_UNPACK_BUFFER, texImage.height * texImage.width * BufferUtil.SIZEOF_FLOAT, IntBuffer.wrap(texImage.pixels), GL.GL_STATIC_DRAW);
      // ** gl.glMapBuffer(GL.GL_PIXEL_UNPACK_BUFFER, GL.GL_WRITE_ONLY);
      // ** gl.glUnmapBuffer(GL.GL_PIXEL_UNPACK_BUFFER);

      gl.glGenTextures(1, tex, 0);
      gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]);
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE);
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
      gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
      gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, texImage.width, texImage.height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, 0); // 0 is offset into bound unpack buffer

      gl.glBindBuffer(GL.GL_PIXEL_UNPACK_BUFFER, 0);

I believe your problem was that you never actually set any data for the texture. You first initialized the texture’s data to null (so it’s going to be filled with garbage) but didn’t ever send the pbo data into it. When using pbo’s to create textures, you use the image command with an integer arg to represent an offset (in bytes) into the bound unpack/pack buffer.

Also, I thought Map and Unmap were to be used when you want to edit a buffer’s contents directly (ie you’d map the buffer, write data to the pointer/arg returned and then unmap it).

works like a charm! Thank you so much!