Pablo Márquez wrote:
[...]
> Regarding your suggestion, I guess I'll have to use a mutex to ensure
> the egl surface is not accessed simultaneously by more than one thread.
>
> I expected the EGL device driver would handle this better...
Danger, Will Robinson!
The whole area of multithreaded rendering is basically as buggy as hell
on Android. This isn't Android's fault --- you're absolutely at the
mercy of the GLES vendor libraries, and they're infamously bad. You will
*not* get this working portably.
In our product, we have three different build configurations, for:
- platforms which do multithreaded rendering correctly (each thread can
have a context bound to a different surface);
- platforms which ignore multithreaded rendering completely (there is a
single global context, bound to a single surface, which all threads use);
- platforms which try to do multithreaded rendering but just get it wrong.
As an example of the last: on some of our test devices, mostly Samsungs,
unbinding a context from a thread causes the screen to go black.
It gets particularly bad when you try to handle context lost events
correctly. The NDK will send you an event to tell you that the EGL
context is being invalidated, but then expect you to handle that
synchronously; if you don't free up all resources before the event
returns, weird stuff happens. This means that if you have a separate
render thread with a bound context you have to somehow get that thread
to unbind the context before the NDK event returns, as only code running
from that thread can do it...
In my experience the only totally reliable setup is to do all your
OpenGL work synchronously from the NDK event thread. This is a bit
problematic if, like us, your app fundamentally wants to do its
rendering from a worker thread. (Yes, we have tried using RPC to
delegate all OpenGL and EGL functions to the main event thread. No, it
wasn't worth it...)
--
┌─── dg@cowlark.com ─────
http://www.cowlark.com ─────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that
│ cursing is more dangerous than being hit by a car." --- Scott Adams