I am new to OpenGL and have currently copying the contents of a 2D texture back to CPU memory as follows:
std::vector<unsigned char> frame-data(width * height * 4);
glBindTexture(GL_TEXTURE_2D, tid);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &frame_data[0]);
I noticed this is quite sluggish and I started reading about PBOs and thought of trying to see if that makes things a bit smoother. So I create the PBO as follows:
GLuint pbo;
glGenBuffers(1, &pbo);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glBufferData(GL_PIXEL_PACK_BUFFER, width*height* 4, NULL, GL_STREAM_READ);
I think the above lines need to be just executed once to initialize the PBO.
My question is now how do I actually map the data from texture to this PBO object? I know at one point after that I will need to call glMapBuffer
but I am not sure how to attach this texture to my PBO.