用于纹理上传的OpenGL PBO,无法理解一件事

Lex*_*Lex 3 c++ opengl textures video-streaming pbo

好的,我在这里阅读了有关PBO的所有内容:http://www.opengl.org/wiki/Pixel_Buffer_Object ,还有http://www.songho.ca/opengl/gl_pbo.html,但我还有一个问题,我不知道我知道在我的情况下,我是否会从公益组织中获得任何好处:

我正在做视频流,目前我有一个函数将我的数据缓冲区复制到3个不同的纹理,然后我在片段着色器中做一些数学运算并显示纹理.

我认为PBO可以增加上传时间CPU - > GPU,但是这里就是说,我们这里的例子来自上面的第二个链接.

glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]);

        // map the buffer object into client's 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);
Run Code Online (Sandbox Code Playgroud)

那么,无论updatePixels函数的行为是什么,它仍然使用CPU周期将数据复制到映射缓冲区不是吗?

所以让我说我想以这样的方式使用PBO,也就是说,在一个函数中将我的帧像素更新为PBO,然后在display函数中调用glTexSubImage2D(应该立即返回)...我会看到任何速度在表现方面?我不明白为什么它会更快......好吧我们在glTex*调用期间不再等待了,但我们正在等待将帧上传到PBO的功能,不是吗?

有人可以帮我清楚吗?

谢谢

dat*_*olf 5

关于缓冲区对象的观点是,它们可以异步使用.你可以映射一个BO,然后让程序的其他部分更新它(想想线程,想想异步IO),同时你可以继续发出OpenGL命令.具有三重缓冲PBO的典型使用方案可能如下所示:

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
Run Code Online (Sandbox Code Playgroud)

这允许您的程序执行有用的工作,甚至将数据上传到OpenGL,同时它也用于渲染