Beispiel #1
0
  /** Some initialization of the OpenGL stuff (that I don't understand...) */
  protected void init() {
    // Much of this code is from GLSurfaceView in the Google API Demos.
    // I encourage those interested to look there for documentation.
    egl = (EGL10) EGLContext.getEGL();
    dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(dpy, version);

    int[] configSpec = {
      EGL10.EGL_RED_SIZE, 5,
      EGL10.EGL_GREEN_SIZE, 6,
      EGL10.EGL_BLUE_SIZE, 5,
      EGL10.EGL_DEPTH_SIZE, 8,
      EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
    EGLConfig config = configs[0];

    eglContext = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);

    surface = egl.eglCreateWindowSurface(dpy, config, sHolder, null);
    egl.eglMakeCurrent(dpy, surface, surface, eglContext);

    gl = (GL10) eglContext.getGL();

    // Load the buffer and stuff
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepthf(1.0f);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    // Resize... whatever?
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, width, height);
    GLU.gluPerspective(gl, 45.0f, ((float) width) / height, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5.5f, 0, 0, 0, 0, 1, 0);
    gl.glNormal3f(0, 0, 1);
  }
Beispiel #2
0
  private static void initEGL() {
    if (sEGL != null) {
      return;
    }

    sEGL = (EGL10) EGLContext.getEGL();

    sEGLDisplay = sEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (sEGLDisplay == EGL10.EGL_NO_DISPLAY) {
      Log.w(LOGTAG, "can't get EGL display!");
      return;
    }

    // while calling eglInitialize here should not be necessary as it was already called
    // by the EGLPreloadingThread, it really doesn't cost much to call it again here,
    // and makes this code easier to think about: EGLPreloadingThread is only a
    // preloading optimization, not something we rely on for anything else.
    //
    // Also note that while calling eglInitialize isn't necessary on Android 4.x
    // (at least Android's HardwareRenderer does it for us already), it is necessary
    // on Android 2.x.
    int[] returnedVersion = new int[2];
    if (!sEGL.eglInitialize(sEGLDisplay, returnedVersion)) {
      Log.w(LOGTAG, "eglInitialize failed");
      return;
    }

    sEGLConfig = chooseConfig();
  }
  protected boolean checkGL20() {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(display, version);

    int EGL_OPENGL_ES2_BIT = 4;
    int[] configAttribs = {
      EGL10.EGL_RED_SIZE,
      4,
      EGL10.EGL_GREEN_SIZE,
      4,
      EGL10.EGL_BLUE_SIZE,
      4,
      EGL10.EGL_RENDERABLE_TYPE,
      EGL_OPENGL_ES2_BIT,
      EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[10];
    int[] num_config = new int[1];
    egl.eglChooseConfig(display, configAttribs, configs, 10, num_config);
    egl.eglTerminate(display);
    return num_config[0] > 0;
  }
    /** Initialize EGL for a given configuration spec. */
    public void start(SurfaceTexture mSurface) {
      if (LOG_EGL) {
        Log.d("EglHelper", "start() tid=" + Thread.currentThread().getId());
      }
      /*
       * Get an EGL instance
       */
      mEgl = (EGL10) EGLContext.getEGL();

      /*
       * Get to the default display.
       */
      mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
      }

      /*
       * We can now initialize EGL for that display
       */
      int[] version = new int[2];
      if (!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
      }

      mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
      if (mEglConfig == null) {
        throw new RuntimeException("eglConfig not initialized");
      }

      /*
       * Create an EGL context. We want to do this as rarely as we can, because an
       * EGL context is a somewhat heavy object.
       */
      mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);

      if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
      }
      if (LOG_EGL) {
        Log.d(
            "EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId());
      }

      mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface, null);
      if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
          Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        throw new RuntimeException(
            "createWindowSurface failed " + GLUtils.getEGLErrorString(error));
      }
      if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
        throw new RuntimeException(
            "eglMakeCurrent failed " + GLUtils.getEGLErrorString(mEgl.eglGetError()));
      }
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
      Log.d(TAG, "surfaceCreated");
      // Lots of stunningly tedious EGL setup. All we want is a 565 surface.
      egl = (EGL10) EGLContext.getEGL();
      display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
      int[] version = new int[2];
      if (!egl.eglInitialize(display, version)) {
        throw new RuntimeException("eglInitialize failed");
      }
      /*
      int[] attrib_list = new int[] {
      		EGL10.EGL_RED_SIZE, 5,
      		EGL10.EGL_GREEN_SIZE, 6,
      		EGL10.EGL_BLUE_SIZE, 5,
      		EGL10.EGL_ALPHA_SIZE, 0,
      		EGL10.EGL_DEPTH_SIZE, 0,
      		EGL10.EGL_NONE
      };
      egl.eglGetConfigs(display, configs, config_size, num_config)
      EGLConfig[] configs = new EGLConfig[1];
      int[] numConfigs = new int[] {1};
      egl.eglChooseConfig(display, attrib_list, configs, configs.length, numConfigs);
      if (0 == numConfigs[0]) {
      	throw new RuntimeException("No matching EGL config");
      }
      config = configs[0];
       */

      config = getEglConfig565(egl, display);

      ctxt = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);
    }
    GL createEglSurface(Surface surface) throws Surface.OutOfResourcesException {
      // Check preconditions.
      if (sEgl == null) {
        throw new RuntimeException("egl not initialized");
      }
      if (sEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
      }
      if (sEglConfig == null) {
        throw new RuntimeException("eglConfig not initialized");
      }
      if (Thread.currentThread() != mEglThread) {
        throw new IllegalStateException(
            "HardwareRenderer cannot be used " + "from multiple threads");
      }

      // In case we need to destroy an existing surface
      destroySurface();

      // Create an EGL surface we can render into.
      if (!createSurface(surface)) {
        return null;
      }

      initCaches();

      return mEglContext.getGL();
    }
    public void initEGL() {
      mEGL =
          (EGL10)
              GLDebugHelper.wrap(
                  EGLContext.getEGL(),
                  GLDebugHelper.CONFIG_CHECK_GL_ERROR | GLDebugHelper.CONFIG_CHECK_THREAD,
                  null);

      mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      int[] curGLVersion = new int[2];
      mEGL.eglInitialize(mGLDisplay, curGLVersion);

      Log.i("GL", "GL version = " + curGLVersion[0] + "." + curGLVersion[1]);

      EGLConfig[] configs = new EGLConfig[1];
      int[] num_config = new int[1];
      mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1, num_config);
      mGLConfig = configs[0];

      mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv.getHolder(), null);

      mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig, EGL10.EGL_NO_CONTEXT, null);

      mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
      mGL =
          (GL10)
              GLDebugHelper.wrap(
                  mGLContext.getGL(),
                  GLDebugHelper.CONFIG_CHECK_GL_ERROR
                      | GLDebugHelper.CONFIG_CHECK_THREAD
                      | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES,
                  null);
    }
    /**
     * Initialize EGL for a given configuration spec.
     *
     * @param configSpec
     */
    public void start() {
      /*
       * Get an EGL instance
       */
      mEgl = (EGL10) EGLContext.getEGL();

      /*
       * Get to the default display.
       */
      mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      /*
       * We can now initialize EGL for that display
       */
      int[] version = new int[2];
      mEgl.eglInitialize(mEglDisplay, version);
      mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

      /*
       * Create an OpenGL ES context. This must be done only once, an
       * OpenGL context is a somewhat heavy object.
       */
      mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null);

      mEglSurface = null;
    }
Beispiel #9
0
  // EGL functions
  public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) {
    try {
      if (SDLActivity.mEGLDisplay == null) {
        Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);

        EGL10 egl = (EGL10) EGLContext.getEGL();

        EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

        int[] version = new int[2];
        egl.eglInitialize(dpy, version);

        EGLConfig[] configs = new EGLConfig[1];
        int[] num_config = new int[1];
        if (!egl.eglChooseConfig(dpy, attribs, configs, 1, num_config) || num_config[0] == 0) {
          Log.e("SDL", "No EGL config available");
          return false;
        }
        EGLConfig config = configs[0];

        SDLActivity.mEGLDisplay = dpy;
        SDLActivity.mEGLConfig = config;
        SDLActivity.mGLMajor = majorVersion;
        SDLActivity.mGLMinor = minorVersion;
      }
      return SDLActivity.createEGLSurface();

    } catch (Exception e) {
      Log.v("SDL", e + "");
      for (StackTraceElement s : e.getStackTrace()) {
        Log.v("SDL", s.toString());
      }
      return false;
    }
  }
Beispiel #10
0
  private boolean initGLES() {

    EGL10 egl = (EGL10) EGLContext.getEGL();

    mEglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
      Log.e(TAG, "Fail to get Display");
      return false;
    }

    int[] version = new int[2];
    if (!egl.eglInitialize(mEglDisplay, version)) {
      Log.e(TAG, "Fail to eglInitialize");
      return false;
    }

    int[] configSpec = {EGL10.EGL_NONE};
    EGLConfig[] configs = new EGLConfig[1];

    int[] numConfigs = new int[1];
    if (!egl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, numConfigs)) {
      Log.e(TAG, "Fail to Choose Config");
      return false;
    }
    mEglConfig = configs[0];

    mEglContext = egl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null);
    if (mEglContext == EGL10.EGL_NO_CONTEXT) {
      Log.e(TAG, "Fail to Create OpenGL Context");
      return false;
    }
    return true;
  }
    /**
     * Ensures the current EGL context is the one we expect.
     *
     * @return {@link #SURFACE_STATE_ERROR} if the correct EGL context cannot be made current,
     *     {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or {@link
     *     #SURFACE_STATE_SUCCESS} if the EGL context was the correct one
     */
    int checkCurrent() {
      if (mEglThread != Thread.currentThread()) {
        throw new IllegalStateException(
            "Hardware acceleration can only be used with a "
                + "single UI thread.\nOriginal thread: "
                + mEglThread
                + "\n"
                + "Current thread: "
                + Thread.currentThread());
      }

      if (!mEglContext.equals(sEgl.eglGetCurrentContext())
          || !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL_DRAW))) {
        if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
          Log.e(LOG_TAG, "eglMakeCurrent failed " + GLUtils.getEGLErrorString(sEgl.eglGetError()));
          fallback(true);
          return SURFACE_STATE_ERROR;
        } else {
          if (mUpdateDirtyRegions) {
            enableDirtyRegions();
            mUpdateDirtyRegions = false;
          }
          return SURFACE_STATE_UPDATED;
        }
      }
      return SURFACE_STATE_SUCCESS;
    }
Beispiel #12
0
 private boolean createSurface() {
   EGL10 egl = (EGL10) EGLContext.getEGL();
   mEglSurface = egl.eglCreateWindowSurface(mEglDisplay, mEglConfig, getHolder(), null);
   if (mEglSurface == EGL10.EGL_NO_SURFACE) {
     return false;
   }
   return true;
 }
 private void destroySurfaceForTimeWarp() {
   if (null != mMainSurface) {
     Log.v(TAG, "destroying mMainSurface: 0x%x", mMainSurface.hashCode());
     final EGL10 egl = (EGL10) EGLContext.getEGL();
     final EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
     egl.eglDestroySurface(display, mMainSurface);
     mMainSurface = null;
   }
 }
Beispiel #14
0
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    EGL10 egl = (EGL10) EGLContext.getEGL();

    YabauseRunnable.lockGL();
    egl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
    YabauseRunnable.initViewport(width, height);
    YabauseRunnable.unlockGL();
  }
  /** 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;
  }
Beispiel #16
0
 public static boolean createEGLContext() {
   EGL10 egl = (EGL10) EGLContext.getEGL();
   int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
   int contextAttrs[] =
       new int[] {EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE};
   SDLActivity.mEGLContext =
       egl.eglCreateContext(
           SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs);
   if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) {
     Log.e("SDL", "Couldn't create context");
     return false;
   }
   return true;
 }
Beispiel #17
0
  private void createSurface() {
    hasSurface = false;

    if (surface != null) {
      egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
      egl.eglDestroySurface(display, surface);
    }

    surface = egl.eglCreateWindowSurface(display, config, surfaceHolder, null);
    egl.eglMakeCurrent(display, surface, surface, eglContext);

    gl = eglContext.getGL();

    hasSurface = true;
  }
    public void initgl() {
      cleanupgl();

      // Create new surface. Must succeed.
      surface = egl.eglCreateWindowSurface(display, config, getHolder(), null);
      if (null == surface) {
        throw new RuntimeException("eglCreateWindowSurface");
      }

      // Bind the rendering context to the surface.
      if (!egl.eglMakeCurrent(display, surface, surface, ctxt)) {
        throw new RuntimeException("eglMakeCurrent");
      }
      gl = (GL10) ctxt.getGL();
    }
Beispiel #19
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;
    }
  }
    void initializeEgl() {
      synchronized (sEglLock) {
        if (sEgl == null && sEglConfig == null) {
          sEgl = (EGL10) EGLContext.getEGL();

          // Get to the default display.
          sEglDisplay = sEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY);

          if (sEglDisplay == EGL_NO_DISPLAY) {
            throw new RuntimeException(
                "eglGetDisplay failed " + GLUtils.getEGLErrorString(sEgl.eglGetError()));
          }

          // We can now initialize EGL for that display
          int[] version = new int[2];
          if (!sEgl.eglInitialize(sEglDisplay, version)) {
            throw new RuntimeException(
                "eglInitialize failed " + GLUtils.getEGLErrorString(sEgl.eglGetError()));
          }

          checkEglErrorsForced();

          sEglConfig = chooseEglConfig();
          if (sEglConfig == null) {
            // We tried to use EGL_SWAP_BEHAVIOR_PRESERVED_BIT, try again without
            if (sDirtyRegions) {
              sDirtyRegions = false;
              sEglConfig = chooseEglConfig();
              if (sEglConfig == null) {
                throw new RuntimeException("eglConfig not initialized");
              }
            } else {
              throw new RuntimeException("eglConfig not initialized");
            }
          }
        }
      }

      ManagedEGLContext managedContext = sEglContextStorage.get();
      mEglContext = managedContext != null ? managedContext.getContext() : null;
      mEglThread = Thread.currentThread();

      if (mEglContext == null) {
        mEglContext = createContext(sEgl, sEglDisplay, sEglConfig);
        sEglContextStorage.set(createManagedContext(mEglContext));
      }
    }
Beispiel #21
0
  public static void deleteGLContext() {
    if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLContext != EGL10.EGL_NO_CONTEXT) {
      EGL10 egl = (EGL10) EGLContext.getEGL();
      egl.eglMakeCurrent(
          SDLActivity.mEGLDisplay,
          EGL10.EGL_NO_SURFACE,
          EGL10.EGL_NO_SURFACE,
          EGL10.EGL_NO_CONTEXT);
      egl.eglDestroyContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLContext);
      SDLActivity.mEGLContext = EGL10.EGL_NO_CONTEXT;

      if (SDLActivity.mEGLSurface != EGL10.EGL_NO_SURFACE) {
        egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);
        SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE;
      }
    }
  }
Beispiel #22
0
  // Called when we lose the surface
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    Log.v("SDL", "surfaceDestroyed()");
    // Call this *before* setting mIsSurfaceReady to 'false'
    SDLActivity.handlePause();
    SDLActivity.mIsSurfaceReady = false;

    /* We have to clear the current context and destroy the egl surface here
     * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
     * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d
     */

    EGL10 egl = (EGL10) EGLContext.getEGL();
    egl.eglMakeCurrent(
        SDLActivity.mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);
    SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE;
  }
  /*
   * React to the creation of a new surface by creating and returning an OpenGL interface that renders to that
   * surface.
   */
  public GL createSurface(SurfaceHolder holder) {
    /*
     * The window size has changed, so we need to create a new surface.
     */
    if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {

      /*
       * Unbind and destroy the old EGL surface, if there is one.
       */
      mEgl.eglMakeCurrent(
          mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
      mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
    }

    /*
     * Create an EGL surface we can render into.
     */
    mEglSurface =
        mEGLWindowSurfaceFactory.createWindowSurface(mEgl, mEglDisplay, mEglConfig, holder);

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
      throw new RuntimeException("createWindowSurface failed");
    }

    /*
     * Before we can issue GL commands, we need to make sure the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
      throw new RuntimeException("eglMakeCurrent failed.");
    }

    GL gl = mEglContext.getGL();
    if (mGLWrapper != null) {
      gl = mGLWrapper.wrap(gl);
    }

    /*
     * if ((mDebugFlags & (DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS))!= 0) { int configFlags = 0; Writer log =
     * null; if ((mDebugFlags & DEBUG_CHECK_GL_ERROR) != 0) { configFlags |= GLDebugHelper.CONFIG_CHECK_GL_ERROR; }
     * if ((mDebugFlags & DEBUG_LOG_GL_CALLS) != 0) { log = new LogWriter(); } gl = GLDebugHelper.wrap(gl,
     * configFlags, log); }
     */
    return gl;
  }
Beispiel #24
0
  // EGL buffer flip
  public static void flipEGL() {
    try {
      EGL10 egl = (EGL10) EGLContext.getEGL();

      egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);

      // drawing here

      egl.eglWaitGL();

      egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);

    } catch (Exception e) {
      Log.v("SDL", "flipEGL(): " + e);
      for (StackTraceElement s : e.getStackTrace()) {
        Log.v("SDL", s.toString());
      }
    }
  }
Beispiel #25
0
    /**
     * Initialize EGL for a given configuration spec.
     *
     * @param configSpec
     */
    public void start() {
      /*
       * Get an EGL instance
       */
      mEgl = (EGL10) EGLContext.getEGL();

      /*
       * Get to the default display.
       */
      mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
      }

      /*
       * We can now initialize EGL for that display
       */
      int[] version = new int[2];
      if (!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
      }
      GlView view = mGLSceneViewWeakRef.get();
      if (view == null) {
        mEglConfig = null;
        mEglContext = null;
      } else {
        mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

        /*
         * Create an EGL context. We want to do this as rarely as we can, because an
         * EGL context is a somewhat heavy object.
         */
        mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
      }
      if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
      }

      mEglSurface = null;
    }
Beispiel #26
0
  public void initialize(int[] configSpec, Renderer rendererInterface) {
    renderer = rendererInterface;

    egl = (EGL10) EGLContext.getEGL();

    display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    egl.eglInitialize(display, null);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    egl.eglChooseConfig(display, configSpec, configs, 1, num_config);
    config = configs[0];

    eglContext = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);

    hasSurface = false;
    surface = null;
    createSurface();
  }
Beispiel #27
0
  private void endGLES() {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    if (mEglSurface != null) {
      // レンダリングコンテキストとの結びつけは解除
      egl.eglMakeCurrent(
          mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);

      egl.eglDestroySurface(mEglDisplay, mEglSurface);
      mEglSurface = null;
    }

    if (mEglContext != null) {
      egl.eglDestroyContext(mEglDisplay, mEglContext);
      mEglContext = null;
    }

    if (mEglDisplay != null) {
      egl.eglTerminate(mEglDisplay);
      mEglDisplay = null;
    }
  }
  private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException {
    /* Get an EGL instance. */
    final EGL10 egl = (EGL10) EGLContext.getEGL();

    /* Get to the default display. */
    final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    /* We can now initialize EGL for that display. */
    final int[] version = new int[2];
    egl.eglInitialize(eglDisplay, version);

    final ConfigChooser configChooser =
        new ConfigChooser(
            false); // TODO Doesn't correlate to possible multisampling request in EngineOptions...

    try {
      configChooser.chooseConfig(egl, eglDisplay);
    } catch (final IllegalArgumentException e) {
      throw new DeviceNotSupportedException(DeviceNotSupportedCause.EGLCONFIG_NOT_FOUND, e);
    }
  }
 @Override
 public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
   eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext();
   setupGL(gl);
   logConfig(config);
   updatePpi();
   Mesh.invalidateAllMeshes(app);
   Texture.invalidateAllTextures(app);
   ShaderProgram.invalidateAllShaderPrograms(app);
   FrameBuffer.invalidateAllFrameBuffers(app);
   Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());
   Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());
   Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());
   Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());
   Display display = app.getWindowManager().getDefaultDisplay();
   this.width = display.getWidth();
   this.height = display.getHeight();
   mean = new WindowedMean(5);
   this.lastFrameTime = System.nanoTime();
   gl.glViewport(0, 0, this.width, this.height);
   isSurfaceCreated = true;
 }
 private void logConfig(EGLConfig config) {
   EGL10 egl = (EGL10) EGLContext.getEGL();
   EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
   int r = getAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0);
   int g = getAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
   int b = getAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
   int a = getAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
   int d = getAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
   int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
   int samples =
       Math.max(
           getAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0),
           getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0));
   boolean coverageSample =
       getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0) != 0;
   Gdx.app.log("AndroidGraphics", "framebuffer: (" + r + ", " + g + ", " + b + ", " + a + ")");
   Gdx.app.log("AndroidGraphics", "depthbuffer: (" + d + ")");
   Gdx.app.log("AndroidGraphics", "stencilbuffer: (" + s + ")");
   Gdx.app.log("AndroidGraphics", "samples: (" + samples + ")");
   Gdx.app.log("AndroidGraphics", "coverage sampling: (" + coverageSample + ")");
   bufferFormat = new BufferFormat(r, g, b, a, d, s, samples, coverageSample);
 }