2

I'm porting my game engine to iOS and am running in to an exception at my [EAGLContext presentRenderbuffer:] call. My engine has all rendering code on a separate thread to the main one; the engine works by creating the CAEAGLLayer and EAGLContext on the main thread, activating the context and creating the framebuffer for the view, then deactivating the context. After that for each frame my render thread then activates the context, binds the framebuffer, draws, and finally presents the render buffer.

Is it possible to call presentRenderbuffer: on a secondary thread, or is that the cause of my issues?

Rajveer
  • 847
  • 11
  • 28

2 Answers2

2

It looks like this behaviour must have changed as I am able to use an EAGLContext on a secondary thread without issues (testing on iOS7/iOS8)

Rajveer
  • 847
  • 11
  • 28
0

Unless some differences have been made the answer is NO, you may not present the render buffer on any but the main thread. The closest you can probably get to is using a texture bound FBO on the secondary thread to which you do all the drawing and then pass the texture to the main thread (needs a shared context) and redraw the texture only to the main thread render buffer.

Another way might be using a triple buffering where your draw thread would swap buffer 1 and 2 once finished drawing and the main thread would swap buffer 3 and 2 once done presenting. Let me know if you try to implement this as I am curious of the outcome.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • 1
    I think this behavior must have changed. The issue I was having ended up being that I wasn't binding the render buffer before calling presentRenderbuffer (lol), but once I fixed that the presentRenderbuffer call seems to work fine on a secondary thread, as long as the context is active on it. To be pedantic I'm double checking this by checking [NSThread isMainThread] returns false just before the call. This is on iOS7 with an ES3 context and on an iPad Mini 2. – Rajveer Dec 15 '14 at 23:35
  • Great to hear that. What used to happen was that your screen was sometimes just black when presenting on non-main thread and sometimes it worked perfectly. Even minimizing the application and opening it again could change the result. I do hope you will not get such results... – Matic Oblak Dec 16 '14 at 07:31
  • Interesting, thanks for the information! I'll do some rigorous testing over the next few days to see if I can replicate those issues, and will report back my findings. – Rajveer Dec 16 '14 at 09:55