Creating and Using the OpenGL Test Harness

The OpenGL test harness that you'll develop in this section will serve as an excellent tool to learn and experiment with OpenGL programming. It will hide the OpenGL ES and Android-specific initializations through the designed encapsulation. These processes will be encapsulated:

1. Obtaining an EGL context

2. Initializing the EGL context with a SurfaceView

3. Dealing with threading issues when working with the SurfaceView

4. Setting up the camera to provide a standard set of dimensions for your drawing

We'll base this test harness on the many OpenGL samples that ship with the Android SDK. This will allow you to integrate those samples into this framework if you need to do that. The implementation is loosely based on a Java class in the Android SDK samples (com.example. android.apis.graphics.GLSurfaceView), but we'll show you how to code it from the ground mEglSurface); mEglContext);

up to give it more abstraction and functionality. Here are some reasons to use the test harness rather than GLSurfaceView:

• There is no documentation on how the complex sample code works.

• GLSurfaceView is a bit difficult to follow because a number of inner classes obscure the basic idea.

• GLSurfaceView assumes that you want to animate everything you draw. For example, if you were to draw a triangle, GLSurfaceView would draw it again and again in a loop whether or not a redraw is needed.

• The GLSurfaceView abstraction works at a more basic level (mostly around SurfaceView and threading), so it doesn't encapsulate camera settings and other common OpenGL chores.

We'll help you with these issues as we create and use the test harness. We won't use any inner classes to expose the abstractions, so you'll have a clear understanding of the responsibilities of each class. And we'll provide you with a class diagram identifying each of the test-harness classes and their responsibilities (see Figure 10-2).

We'll also make animation nonessential for the test harness so that you can easily test your code for simpler cases. We'll explain every part of the code so you'll realize how it works. And once this test harness is in place, you rarely have to modify it. You'll be able to focus on your OpenGL code instead.

We will now present the test-harness design and code, as well as some snapshots of the emulator containing OpenGL drawings.

0 0

Post a comment