Game Development Reference
In-Depth Information
Listing 3-7 shows a fragment of the GLThread class taken from the GL cubes sample. When
the thread starts, the run() method is invoked, and a semaphore is used to ensure that
guardedRun() can be accessed by one thread only. guardedRun() performs other important
steps, such as the following:
Initializes the OpenGL ES for a given configuration specification.
The configuration specification defines information, such as pixel
format and image depth.
Creates the OpenGL surface and tells the renderer about it.
Checks whether the size of the surface has changed and tells the
renderer about it.
Queues and gets events to be run on the GL rendering thread.
Listing 3-7. Rendering Thread for the GL Cubes Sample
package opengl.scenes;
// ...
/**
* A generic GL Thread. Takes care of initializing EGL and GL.
* Delegates to a Renderer instance to do the actual drawing.
*/
public class GLThread extends Thread
{
public GLThread(Renderer renderer, SurfaceHolder holder) {
super();
mDone = false;
mWidth = 0;
mHeight = 0;
mRenderer = renderer;
mHolder = holder;
setName("GLThread");
}
@Override
public void run() {
try {
try {
sEglSemaphore.acquire();
} catch (InterruptedException e) {
return;
}
guardedRun();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
sEglSemaphore.release();
}
}
Search WWH ::




Custom Search