Graphics Programs Reference
In-Depth Information
Figure 3-1 . Decoupling of OpenGL ES graphics from XML-based views
Decoupling for Dedicated Performance
This decoupling is not restricted to a “physical” sense. Behind the scenes, the
GLSurfaceView class (via Renderer object) renders the OpenGL ES graphics on
a separate thread to dissociate any rendering functionality from the UI/main thread.
This helps to avoid the cramming of UI thread with various ES 2.0 calls, and, while
3D graphics are rendered on a dedicated thread, Android can still maintain the UI
thread to receive events from XML-based views, as well as sensors. We call this ded-
icated thread our renderer thread.
Note In the Android sensor API, the callback method
onSensorChanged requests data in an asynchronous manner, so
the UI thread is not blocked while waiting for a piece of data.
We can use standard Java techniques ( Thread class/ Runnable interface) to com-
municate between the UI and renderer thread. However, for all the examples in the
source code in which we have to update the rendering based on inputs received from
UI, we have only used static field(s) in various classes to share data between these
two threads. To ensure thread safety while the static field is being accessed, we used
either the volatile keyword with static field or the synchronized block.
 
Search WWH ::




Custom Search