Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render-to-texture and synchronization

I have a cross-platform code base (iOS and Android) that uses a standard render-to-texture setup. Each frame (after initialization), the following sequence occurs:

  1. glBindFramebuffer of a framebuffer with a texture color attachment
  2. Render some stuff
  3. *
  4. glBindFramebuffer of the default framebuffer (0 on Android, usually 2 on iOS)
  5. glBindTexture of the texture that was the color attachment to the first framebuffer
  6. Render using the bound texture

On iOS and some Android devices (including the emulator), this works fine and as expected. On other devices (currently sitting in front of a Samsung Galaxy Note running 4.0.4), the second-phase rendering that uses the texture looks "jumpy". Other animations continue to run at 60 fps on the same screen as the "jumpy" bits; my conclusion is that the changes to the target texture are not always visible in the second rendering pass.

To test this theory, I insert a glFinish() at the step marked with a * above. On all devices, now, this has the correct behavior. Interestingly, glFlush() does NOT fix the problem. But glFinish() is expensive, and I haven't seen any documentation that suggests that this should be necessary.

So, here's my question: What must I do when finished rendering to a texture to make sure that the most-recently-drawn texture is available in later rendering passes?

like image 668
addaon Avatar asked Feb 26 '13 05:02

addaon


1 Answers

The code you describe should be fine.

As long as you are using a single context, and not opting in to any extensions that relax synchronization behavior (such as EXT_map_buffer_range), then every command must appear to execute as if it had executed in exactly the same order specified in the API, and in your API usage you're rendering to the texture before reading from it.

Given that, you are probably encountering driver bugs on those devices. Can you list which devices are encountering the issue? You'll probably find common hardware or drivers.

like image 194
Frogblast Avatar answered Oct 20 '22 17:10

Frogblast