I am using render to texture and I want to read data back to CPU side of the program. I am using PBO to do this. However, if I save content of texture to the file, data are vertically flipped (upside down). Is this a normal behavior, or I have something incorrect?
glGenBuffers(1, pboID); glBindBuffer(GL_PIXEL_PACK_BUFFER, pboID); glBufferData(GL_PIXEL_PACK_BUFFER, texture->info.rawDataSize, 0, GL_DYNAMIC_READ); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, texture->GetRenderTarget()->GetFrameBufferID()); glReadBuffer(texture->GetAttachement()); glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pboID); glReadPixels(0, 0, texture->info.width, texture->info.height, texture->info.glFormat, GL_UNSIGNED_BYTE, 0); glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pboID); void * textureData = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); //save tetxure data to file //unlock PBO and FrameBuffer
I know that texture coordinates are "flipped" in comparison to DirectX, so during rendering on the screen, I am flipping the y-coordinate as well (
y = y - 1). But how to download texture data "non-flipped"?