OpenGL PBO for texture loading, can't figure out one thing

Ok, I read all about PBO here: http://www.opengl.org/wiki/Pixel_Buffer_Object and there http://www.songho.ca/opengl/gl_pbo.html but I still have a question and I dont know if i will benefit from PBO in my case:

I am doing video streams, currently I have a function to copy my data buffers to 3 different textures and then I do some math in the fragment shader and I display the texture.

I thought PBO might increase CPU -> GPU load times, but here, let's say we have this example taken from the second link above.

glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]);

        // map the buffer object into client memory
        // Note that glMapBufferARB() causes sync issue.
        // If GPU is working with this buffer, glMapBufferARB() will wait(stall)
        // for GPU to finish its job. To avoid waiting (stall), you can call
        // first glBufferDataARB() with NULL pointer before glMapBufferARB().
        // If you do that, the previous data in PBO will be discarded and
        // glMapBufferARB() returns a new allocated pointer immediately
        // even if GPU is still working with the previous data.
        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB);
        GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
        if(ptr)
        {
            // update data directly on the mapped buffer
            updatePixels(ptr, DATA_SIZE);
            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
        }

        // measure the time modifying the mapped buffer
        t1.stop();
        updateTime = t1.getElapsedTimeInMilliSec();
        ///////////////////////////////////////////////////

        // it is good idea to release PBOs with ID 0 after use.
        // Once bound with 0, all pixel operations behave normal ways.
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

      

Ok, whatever the behavior of the function updatePixels

, it still uses CPU cycles to copy data into the mapped buffer, right?

So, let's say I wanted to use PBO in such a way that I update the frame pixels in the PBO in a function, and then in the function display

call glTexSubImage2D (which should return immediately). Will I see acceleration in terms of performance? I don’t understand why it would be faster ... well we don’t wait during the glTex * call, but we wait during the function that loads the frame into PBO, right?

Can someone please clarify this for me?

thank

+3


source to share


1 answer


The point around buffer objects is that they can be used asynchronously. You can map the BO and then add another piece of program update (think threads, think asynchronous IO), while you can keep issuing OpenGL commands. A typical use case with triple buffered PBO might look like this:

wait_for_video_frame_load_complete(buffer[k-2])

glUnmapBuffer buffer[k-2]

glTexSubImage2D from buffer[k-2]

buffer[k] = glMapBuffer

start_load_next_video_frame(buffer[k]);

draw_texture

SwapBuffers

      



This allows your program to do useful work and even load data into OpenGL and use it for rendering.

+5


source







All Articles