Egl Helperjava

We have already explained the basics of what happens in the EglHelper code, such as using the configSpec, getting EGL displays, and so on. The code in Listing 10-9 reiterates those ideas, but it's more complete than the code you've seen so far.

Listing 10-9. The EglHelper Class

//filename: EglHelper.java public class EglHelper {

EGL10 mEgl; EGLDisplay mEglDisplay; EGLSurface mEglSurface; EGLConfig mEglConfig; EGLContext mEglContext; public EglHelper(){}

public void start(int[] configSpec) {

mEgl = (EGL10) EGLContext.getEGL();

mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

int[] version = new int[2]; mEgl.eglInitialize(mEglDisplay, version);

EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1];

mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config); mEglConfig = configs[0];

mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null);

mEglSurface = null;

public GL createSurface(SurfaceHolder holder) { if (mEglSurface != null) {

mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,

EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay, mEglSurface);

mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, holder, null); mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); GL gl = mEglContext.getGL(); return gl;

public boolean swap() {

mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST;

public void finish() {

mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay, mEglSurface); mEglSurface = null;

mEgl.eglDestroyContext(mEglDisplay, mEglContext); mEglContext = null;

mEgl.eglTerminate(mEglDisplay); mEglDisplay = null;

Now let's take a look at the Renderer interface that needs to be implemented by your own OpenGL drawing subclasses.

0 0

Post a comment