This works fine as long as regionPos/regionSize cover the whole texture. If it’s only a partial update, the texture content is mixed up afterwards (I still have to investigate on this). If I just pass the buffer to glTexSubImage2D, partial updates work fine. Is there some kind of limitation for PBOs and partial texture updates?
I’m using a NVidia Geforce 7900GT, Windows XP x64, 97.92 drivers.
I’ve just tested this with my code, and it works fine here. Keep in mind that it will read the data from the PBO as one contiguous array of elements, that is the indexing into the PBO changes. That is
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
pboMem = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
int i = 0;
for (int y = regionPos[1]; y < regionSize[1]; y++) {
for (int x = regionPos[0]; x < regionSize[0]; x++) {
pboMem[i++] = whatever; // assuming pboMem is a pointer to the appropriate element type, ie 32bit int in case of RGBA texture
}
}
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
// Update (sub-)teximage from texture image buffer
glTexSubImage2D(
GL_TEXTURE_2D, 0,
regionPos[0], regionPos[1],
regionSize[0], regionSize[1],
mFormat,
mType,
0);
Mind you I don’t code in C/C++, and this is my attempt at adapting my code.