copying texture from GPU to CPU using pixel buffer objects
<p>I am new to OpenGL and have currently copying the contents of a 2D texture back to CPU memory as follows:</p>

<pre><code>std::vector&lt;unsigned char&gt; frame-data(width * height * 4);
glBindTexture(GL_TEXTURE_2D, tid);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &amp;frame_data[0]);                 
</code></pre>

<p>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:</p>

<pre><code>GLuint  pbo;
glGenBuffers(1, &amp;pbo);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glBufferData(GL_PIXEL_PACK_BUFFER, width*height* 4, NULL, GL_STREAM_READ); 
</code></pre>

<p>I think the above lines need to be just executed once to initialize the PBO.</p>

<p>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 <code>glMapBuffer</code> but I am not sure how to attach this texture to my PBO.</p>