Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Use OpenGL Framebuffer as SDL texture

  1. #1
    Newbie Newbie
    Join Date
    Dec 2018

    Use OpenGL Framebuffer as SDL texture

    I have an OpenGL application that is rendering a video to a HMD. I now want to display an exact copy of the displayed video in an SDL window on a monitor. What I'm currently doing is very unefficient:
    • Create an SDL window and SDL texture with the same dimensions as the OpenGL viewport
    • For each video frame (after rendering to HMD):
      • Use glReadPixels to get the current framebuffer content
      • Lock the previously created texture and copy content to it, then unlock
      • Use SDL RenderCopy and RenderPresent to render the texture to the window

    So basically I'm just duplicating the framebuffer for each video frame. I think this is unnecessary since the GPU already contains what I need. How can I use the OpenGL framebuffer in the SDL window directly without copying it?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Quote Originally Posted by gwendolin View Post
    How can I use the OpenGL framebuffer in the SDL window directly without copying it?
    Provided that both framebuffers are implemented by the same OpenGL driver and you can rely upon support for at least OpenGL 3.0, you can use glBlitFramebuffer() to blit (part of) the contents of one framebuffer to another.

    If the two framebuffers are implemented by different video hardware, there probably isn't going to be an efficient solution, although there are some things which can be done to avoid the implicit synchronisation which is likely with a naive approach.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts