Beispiel #1
0
  public static boolean createEGLSurface() {
    if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
      EGL10 egl = (EGL10) EGLContext.getEGL();
      if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) createEGLContext();

      if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
        Log.v("SDL", "Creating new EGL Surface");
        SDLActivity.mEGLSurface =
            egl.eglCreateWindowSurface(
                SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null);
        if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
          Log.e("SDL", "Couldn't create surface");
          return false;
        }
      } else Log.v("SDL", "EGL Surface remains valid");

      if (egl.eglGetCurrentContext() != SDLActivity.mEGLContext) {
        if (!egl.eglMakeCurrent(
            SDLActivity.mEGLDisplay,
            SDLActivity.mEGLSurface,
            SDLActivity.mEGLSurface,
            SDLActivity.mEGLContext)) {
          Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
          // TODO: Notify the user via a message that the old context could not be restored, and
          // that textures need to be manually restored.
          createEGLContext();
          if (!egl.eglMakeCurrent(
              SDLActivity.mEGLDisplay,
              SDLActivity.mEGLSurface,
              SDLActivity.mEGLSurface,
              SDLActivity.mEGLContext)) {
            Log.e("SDL", "Failed making EGL Context current");
            return false;
          }
        } else Log.v("SDL", "EGL Context made current");
      } else Log.v("SDL", "EGL Context remains current");

      return true;
    } else {
      Log.e(
          "SDL",
          "Surface creation failed, display = "
              + SDLActivity.mEGLDisplay
              + ", config = "
              + SDLActivity.mEGLConfig);
      return false;
    }
  }