Exemplo n.º 1
0
  // SystemListener:update
  @Override
  public void onDrawFrame(GL10 gl) {
    if (needClose.get()) {
      deinitInThread();
      return;
    }

    if (renderable.get()) {
      if (!created.get()) {
        throw new IllegalStateException("onDrawFrame without create");
      }

      long milliStart = System.currentTimeMillis();

      listener.update();
      if (autoFlush) {
        renderer.onFrame();
      }

      long milliDelta = System.currentTimeMillis() - milliStart;

      // Enforce a FPS cap
      if (milliDelta < minFrameDuration) {
        // logger.log(Level.INFO, "Time per frame {0}", milliDelta);
        try {
          Thread.sleep(minFrameDuration - milliDelta);
        } catch (InterruptedException e) {
        }
      }
    }
  }
Exemplo n.º 2
0
 // SystemListener:reshape
 @Override
 public void onSurfaceChanged(GL10 gl, int width, int height) {
   logger.log(
       Level.INFO, "GL Surface changed, width: {0} height: {1}", new Object[] {width, height});
   settings.setResolution(width, height);
   listener.reshape(width, height);
 }
Exemplo n.º 3
0
  protected void initInThread() {
    created.set(true);

    logger.info("OGLESContext create");
    logger.log(Level.INFO, "Running on thread: {0}", Thread.currentThread().getName());

    // Setup unhandled Exception Handler
    Thread.currentThread()
        .setUncaughtExceptionHandler(
            new Thread.UncaughtExceptionHandler() {

              public void uncaughtException(Thread thread, Throwable thrown) {
                listener.handleError("Exception thrown in " + thread.toString(), thrown);
              }
            });

    if (clientOpenGLESVersion < 2) {
      throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
    }

    timer = new AndroidTimer();
    renderer = new OGLESShaderRenderer();

    renderer.initialize();
    listener.initialize();

    JmeSystem.setSoftTextDialogInput(this);

    needClose.set(false);
    renderable.set(true);
  }
Exemplo n.º 4
0
  /** De-initialize in the OpenGL thread. */
  protected void deinitInThread() {
    if (renderable.get()) {
      created.set(false);
      if (renderer != null) {
        renderer.cleanup();
      }

      listener.destroy();

      listener = null;
      renderer = null;
      timer = null;

      // do android specific cleaning here
      logger.info("Display destroyed.");

      renderable.set(false);
    }
  }
Exemplo n.º 5
0
  /**
   * <code>createView</code> creates the GLSurfaceView that the renderer will draw to.
   *
   * <p>The result GLSurfaceView will receive input events and forward them to the Application. Any
   * rendering will be done into the GLSurfaceView. Only one GLSurfaceView can be created at this
   * time. The given configType specifies how to determine the display configuration.
   *
   * @param configType ConfigType.FASTEST (Default) | ConfigType.LEGACY | ConfigType.BEST
   * @param eglConfigVerboseLogging if true show all found configs
   * @return GLSurfaceView The newly created view
   */
  public GLSurfaceView createView(ConfigType configType, boolean eglConfigVerboseLogging) {
    // if simulated joysticks are used, init the window to update the activity used to
    // get the window orientation
    if (androidSensorJoyInput != null && androidSensorJoyInput instanceof AndroidSensorJoyInput) {
      ((AndroidSensorJoyInput) androidSensorJoyInput).initWindow();
    }

    // Start to set up the view
    view = new AndroidGLSurfaceView(JmeAndroidSystem.getActivity());
    if (androidInput == null) {
      androidInput = new AndroidInput(view);
    } else {
      androidInput.setView(view);
    }
    if (configType == ConfigType.LEGACY) {
      // Hardcoded egl setup
      clientOpenGLESVersion = 2;
      view.setEGLContextClientVersion(2);
      // RGB565, Depth16
      view.setEGLConfigChooser(5, 6, 5, 0, 16, 0);
      logger.info("ConfigType.LEGACY using RGB565");
    } else {
      EGL10 egl = (EGL10) EGLContext.getEGL();
      EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      int[] version = new int[2];
      if (egl.eglInitialize(display, version) == true) {
        logger.log(
            Level.INFO, "Display EGL Version: {0}.{1}", new Object[] {version[0], version[1]});
      }

      try {
        // Create a config chooser
        AndroidConfigChooser configChooser = new AndroidConfigChooser(configType);
        // Init chooser
        if (!configChooser.findConfig(egl, display)) {
          listener.handleError("Unable to find suitable EGL config", null);
          return null;
        }

        clientOpenGLESVersion = configChooser.getClientOpenGLESVersion();
        if (clientOpenGLESVersion < 2) {
          listener.handleError("OpenGL ES 2.0 is not supported on this device", null);
          return null;
        }

        // Requesting client version from GLSurfaceView which is extended by
        // AndroidInput.
        view.setEGLContextClientVersion(clientOpenGLESVersion);
        view.setEGLConfigChooser(configChooser);
        view.getHolder().setFormat(configChooser.getPixelFormat());
      } finally {
        if (display != null) {
          egl.eglTerminate(display);
        }
      }
    }

    view.setFocusableInTouchMode(true);
    view.setFocusable(true);
    view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
    if (configType == ConfigType.BEST_TRANSLUCENT) {
      // This is important to allow the GL surface to have a translucent background
      view.setZOrderOnTop(true);
    }
    view.setRenderer(this);

    return view;
  }