The other day I was looking at a opensource engine, basically it was uploading the image from a file to a RAM buffer adding some decoding while streaming (I assume this is done "in-cache" so I can't count the decoding as an extra copy), then the buffer was feeded to glTexImage2D.

According to GL specifications, glTexImage2D is free to keep a in-RAM copy of the image and wait for the best moment to upload it to the GPU.

So basically we have

  • From disk to RAM
  • From RAM to RAM
  • From RAM to GPU

Thos are basically 4-5 BUS runs x Textures Size in megabytes bandwith payload

3 copies of the same data.

Isn't there anyway to reduce the copies to

  • From disk to RAM
  • from RAM to GPU

Or even

  • From disk to GPU


(Assuming hard-disk already have data in the correct memory layout and hence no decoding is necessary).


1 Answer 1


The answer is using a PBO, Pixel Buffer Object.

You map a opengl buffer and put the image data into there. Then unmap and bind that buffer to GL_PIXEL_UNPACK_BUFFER and call glTexImage2D with the data parameter set to (void* )0. This makes glTexImage2D use the buffer as the data source instead of the application memory. The data parameter is the offset into the buffer.

Because opengl was in charge of allocating that buffer and it's not mapped anymore it does not need to make a copy of the buffer.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .