示例#1
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;
    }
  }
示例#2
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());
      }
    }
  }
示例#3
0
  // EGL functions
  public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) {
    try {
      EGL10 egl = (EGL10) EGLContext.getEGL();

      if (SDLActivity.mEGLDisplay == null) {
        SDLActivity.mEGLDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        int[] version = new int[2];
        egl.eglInitialize(SDLActivity.mEGLDisplay, version);
      }

      if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) {
        // No current GL context exists, we will create a new one.
        Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);
        EGLConfig[] configs = new EGLConfig[128];
        int[] num_config = new int[1];
        if (!egl.eglChooseConfig(SDLActivity.mEGLDisplay, attribs, configs, 1, num_config)
            || num_config[0] == 0) {
          Log.e("SDL", "No EGL config available");
          return false;
        }
        EGLConfig config = null;
        int bestdiff = -1, bitdiff;
        int[] value = new int[1];

        // eglChooseConfig returns a number of configurations that match or exceed the requested
        // attribs.
        // From those, we select the one that matches our requirements more closely
        Log.v("SDL", "Got " + num_config[0] + " valid modes from egl");
        for (int i = 0; i < num_config[0]; i++) {
          bitdiff = 0;
          // Go through some of the attributes and compute the bit difference between what we want
          // and what we get.
          for (int j = 0; ; j += 2) {
            if (attribs[j] == EGL10.EGL_NONE) break;

            if (attribs[j + 1] != EGL10.EGL_DONT_CARE
                && (attribs[j] == EGL10.EGL_RED_SIZE
                    || attribs[j] == EGL10.EGL_GREEN_SIZE
                    || attribs[j] == EGL10.EGL_BLUE_SIZE
                    || attribs[j] == EGL10.EGL_ALPHA_SIZE
                    || attribs[j] == EGL10.EGL_DEPTH_SIZE
                    || attribs[j] == EGL10.EGL_STENCIL_SIZE)) {
              egl.eglGetConfigAttrib(SDLActivity.mEGLDisplay, configs[i], attribs[j], value);
              bitdiff += value[0] - attribs[j + 1]; // value is always >= attrib
            }
          }

          if (bitdiff < bestdiff || bestdiff == -1) {
            config = configs[i];
            bestdiff = bitdiff;
          }

          if (bitdiff == 0) break; // we found an exact match!
        }

        Log.d("SDL", "Selected mode with a total bit difference of " + bestdiff);

        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;
    }
  }
示例#4
0
  // EGL functions
  public boolean initEGL(int majorVersion, int minorVersion) {
    Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);

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

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

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

      int EGL_OPENGL_ES_BIT = 1;
      int EGL_OPENGL_ES2_BIT = 4;
      int renderableType = 0;
      if (majorVersion == 2) {
        renderableType = EGL_OPENGL_ES2_BIT;
      } else if (majorVersion == 1) {
        renderableType = EGL_OPENGL_ES_BIT;
      }
      int[] configSpec = {
        // EGL10.EGL_DEPTH_SIZE,   16,
        EGL10.EGL_RENDERABLE_TYPE, renderableType, EGL10.EGL_NONE
      };
      EGLConfig[] configs = new EGLConfig[1];
      int[] num_config = new int[1];
      if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) {
        Log.e("SDL", "No EGL config available");
        return false;
      }
      EGLConfig config = configs[0];

      EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
      if (ctx == EGL10.EGL_NO_CONTEXT) {
        Log.e("SDL", "Couldn't create context");
        return false;
      }

      EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
      if (surface == EGL10.EGL_NO_SURFACE) {
        Log.e("SDL", "Couldn't create surface");
        return false;
      }

      if (!egl.eglMakeCurrent(dpy, surface, surface, ctx)) {
        Log.e("SDL", "Couldn't make context current");
        return false;
      }

      mEGLContext = ctx;
      mEGLDisplay = dpy;
      mEGLSurface = surface;

    } catch (Exception e) {
      Log.v("SDL", e + "");
      for (StackTraceElement s : e.getStackTrace()) {
        Log.v("SDL", s.toString());
      }
    }

    return true;
  }