コード例 #1
0
 public void finish() {
   if (mEglContext != null) {
     mEGLContextFactory.destroyContext(mEgl, mEglDisplay, mEglContext);
     mEglContext = null;
   }
   if (mEglDisplay != null) {
     mEgl.eglTerminate(mEglDisplay);
     mEglDisplay = null;
   }
 }
コード例 #2
0
  /** Initialize EGL for a given configuration spec. */
  @SuppressWarnings("StatementWithEmptyBody")
  public void start() {
    // Log.d("EglHelper" + instanceId, "start()");
    if (mEgl == null) {
      // Log.d("EglHelper" + instanceId, "getting new EGL");
      /*
       * Get an EGL instance
       */
      mEgl = (EGL10) EGLContext.getEGL();
    } else {
      // Log.d("EglHelper" + instanceId, "reusing EGL");
    }

    if (mEglDisplay == null) {
      // Log.d("EglHelper" + instanceId, "getting new display");
      /*
       * Get to the default display.
       */
      mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    } else {
      // Log.d("EglHelper" + instanceId, "reusing display");
    }

    if (mEglConfig == null) {
      // Log.d("EglHelper" + instanceId, "getting new config");
      /*
       * We can now initialize EGL for that display
       */
      int[] version = new int[2];
      mEgl.eglInitialize(mEglDisplay, version);
      mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
    } else {
      // Log.d("EglHelper" + instanceId, "reusing config");
    }

    if (mEglContext == null) {
      // Log.d("EglHelper" + instanceId, "creating new context");
      /*
       * Create an OpenGL ES context. This must be done only once, an OpenGL context is a somewhat heavy object.
       */
      mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
      if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        throw new RuntimeException("createContext failed");
      }
    } else {
      // Log.d("EglHelper" + instanceId, "reusing context");
    }

    mEglSurface = null;
  }