...
QImage img("d:/big_image.png");
const unsigned int imageWidth = img.width();
const unsigned int imageHeight = img.height();
// create texture
GLuint tex = 0;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, imageWidth, imageHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
// create PBO
GLuint pbo = 0;
glGenBuffers(1, &pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
// allocate storage for PBO
glBufferData(GL_PIXEL_UNPACK_BUFFER, imageWidth * 4 * imageHeight, 0, GL_DYNAMIC_DRAW);
// map PBO
void *pboBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, imageWidth * imageHeight * 4, GL_MAP_WRITE_BIT);
if (pboBuffer) {
unsigned char *pixel = (unsigned char *)pboBuffer;
for (int i = 0; i < imageHeight; i++) {
memcpy(pixel, img.scanLine(i), img.bytesPerLine());
pixel += img.bytesPerLine();
}
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
}
// copy PBO to texture
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageWidth, imageHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0);
// download texture image
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, img.bits());
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteBuffers(1, &pbo);
glDeleteTextures(1, &tex);
img.save("d:/output.bmp");
...