View Full Version : ARB_pbo question

01-11-2005, 04:50 AM

The new ARB_pbo extension (perhaps the older EXT_pbo, too?) suggests the following code for an iterated update of texture data inside the pbo-buffer:

// Reset the contents of the texSize-sized buffer object

// Map the texture image buffer (the contents of which
// are undefined due to the previous glBufferData)
pboMemory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,

// Modify (sub-)buffer data
memcpy(pboMemory, texData, texsize);

// Unmap the texture image buffer
Why should I not use this simpler code for the update: :confused:

glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, texSize, texData,

Daniel Wesslen
01-11-2005, 05:11 AM
Bad example - in the case of memcpy you're better off using glBufferData, but if you are generating data on the fly it may be better to write it into a mapped buffer.

01-11-2005, 05:20 AM
It's an example. It as lots of redundant stuff... ;)

01-11-2005, 08:09 AM
But I still cannot see, why one copy of the data can be avoid:

Streaming texture updates: If the application uses glMapBuffer/glUnmapBuffer to write its data for glTexSubImage into a buffer object, at least one of the data copies usually required to download a texture can be eliminated, significantly increasing texture download performance.

01-11-2005, 10:11 AM
But I still cannot see, why one copy of the data can be avoid:Here's why.

When you call "glBufferData", it copies stuff from your "texData" variable into the internal VBO. When you use mapping, you're writing (theoretically, as drivers could still force a copy operation) directly to the VBO server-side memory.

This eliminates a copy on your side. If you have an array of data, and you only update pieces of it, you don't need to keep that array of data yourself. You can let the server keep it, and update it via mapping. If you use glBufferData, you must keep an array and you force the driver to copy your array into VBO memory.

Now, their example is rather silly, becuase they use a "memcpy" (effectively manually doing what "glBufferData" does). However, if you were only updating a portion of the memory, it'd be better to use mapping and just update what you need to than to use glBufferData.