14

I want to render my scene in one thread and then blit the result in window owned by another thread. To avoid reading the framebuffer back to cpu memory, I would like to use a framebuffer object. So far I have not been able to get this to work (white texture), which makes me believe that this is not supported by opengl.

  1. Is it possible to share framebuffer objects between different contexts?
  2. Is it possible to share a framebuffer object between different threads, given that the object is only bound by one thread at a time?

If someone can point me to where this is described in the documentation, that would be a bonus.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Plow
  • 4,001
  • 3
  • 20
  • 21
  • 1
    A bounty will be awarded to anyone for a working sample code - dead or alive :) - or at least a step by step guide how to either setup a FBO sharing, or implement it using sharing a texture and renderbuffer. – Suma May 31 '11 at 08:57
  • @Suma Sharing textures is platform specific. In Windows it is done with wglShareLists(), which needs to be called before generating the texture(s) which are attached to your FBO with glFramebufferTexture(). My understanding is that you should be able to use this texture from your other context even if your OpenGL implementation/version does not allow you to share the FBO directly. – Plow May 31 '11 at 12:04
  • Yes, I understand this, however I was unable to find a complete and working example how exactly one would do this, and when experimenting with it based on what I already know I was unable to get it right so far. When Googling I have found this this or similar question asked many times on various forums, but the answer was never satisfactory. (As with the OP, I am interested about Windows now). – Suma May 31 '11 at 12:12
  • @Suma Ok that is discouraging. I have not been able to test this myself since I do not have access to the second context until textures already have been added, something that wglShareLists() does not support. – Plow May 31 '11 at 12:25

1 Answers1

12

It is not possible to share framebuffers between different contexts. See the first paragraph of Appendix D, OpenGL 3.3 spec. However, you can share textures and renderbuffers, which should give you want you need.

As for the threading: It should be possible, but it is generally advised not to issue GL commands from multiple threads (Because it is just very hard to synchronize). Usually, you would copy the contents to a pixel-buffer-object and and map it from the GL thread, then use the mapped pointer from the other thread.

ltjax
  • 15,837
  • 3
  • 39
  • 62
  • 5
    Ragarding multithreading: While it's true that one should not mix rendering calls from multiple threads it should be noted, that render context may be migrated between threads perfectly well. Any single rendering context may be active in only one thread at a time, but you may perfectly well detach a context (MakeCurrent(NULL)) and reattach it in another thread afterwards. – datenwolf Dec 08 '10 at 14:54
  • 1
    The specs does not list the FBO as shareable, but they do not specifically exclude the possibility. I have found a page (http://www.pyglet.org/doc/programming_guide/sharing_objects_between_contexts.html) which is listing FBO as shareable, is it wrong then? – Suma May 31 '11 at 08:55
  • 4
    It seems FBO sharing is different with different OGL versions. Cf. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=270430&page=2 ("If you are using GL 2.1 and EXT_fbo, then the FBO ID is shared. ... If you are using GL 3.0 (forward), ... FBO ID is not shared.") – Suma May 31 '11 at 10:37