コード例 #1
0
  /**
   * This is the code that needs to be executed before either eye is drawn.
   *
   * @return Current time, from {@link GVRTime#getCurrentTime()}
   */
  private long doMemoryManagementAndPerFrameCallbacks() {
    long currentTime = GVRTime.getCurrentTime();
    mFrameTime = (currentTime - mPreviousTimeNanos) / 1e9f;
    mPreviousTimeNanos = currentTime;

    /*
     * Without the sensor data, can't draw a scene properly.
     */
    if (!(mSensoredScene == null || !mMainScene.equals(mSensoredScene))) {
      Runnable runnable = null;
      while ((runnable = mRunnables.poll()) != null) {
        try {
          runnable.run();
        } catch (final Exception exc) {
          Log.e(TAG, "Runnable-on-GL %s threw %s", runnable, exc.toString());
          exc.printStackTrace();
        }
      }

      final List<GVRDrawFrameListener> frameListeners = mFrameListeners;
      for (GVRDrawFrameListener listener : frameListeners) {
        try {
          listener.onDrawFrame(mFrameTime);
        } catch (final Exception exc) {
          Log.e(TAG, "DrawFrameListener %s threw %s", listener, exc.toString());
          exc.printStackTrace();
        }
      }
    }
    NativeGLDelete.processQueues(mGlDeleterPtr);

    return currentTime;
  }
コード例 #2
0
  boolean updateSensoredScene() {
    if (mSensoredScene != null && mMainScene.equals(mSensoredScene)) {
      return true;
    }

    if (null != mMainScene) {
      final GVRCameraRig cameraRig = mMainScene.getMainCameraRig();

      if (null != cameraRig && (mSensoredScene == null || !mMainScene.equals(mSensoredScene))) {
        Log.i(TAG, "camera rig yaw reset");
        cameraRig.resetYaw();
        mSensoredScene = mMainScene;
        return true;
      }
    }
    return false;
  }
コード例 #3
0
  void onDrawEyeView(int eye, float fovDegrees) {
    mCurrentEye = eye;
    if (!(mSensoredScene == null || !mMainScene.equals(mSensoredScene))) {
      GVRCameraRig mainCameraRig = mMainScene.getMainCameraRig();

      if (eye == 1) {
        GVRCamera rightCamera = mainCameraRig.getRightCamera();
        renderCamera(mActivity.getAppPtr(), mMainScene, rightCamera, mRenderBundle);

        // if mScreenshotRightCallback is not null, capture right eye
        if (mScreenshotRightCallback != null) {
          readRenderResult();
          returnScreenshotToCaller(
              mScreenshotRightCallback, mReadbackBufferWidth, mReadbackBufferHeight);
          mScreenshotRightCallback = null;
        }

        mActivity.setCamera(rightCamera);
      } else {
        // if mScreenshotCenterCallback is not null, capture center eye
        if (mScreenshotCenterCallback != null) {
          GVRPerspectiveCamera centerCamera = mainCameraRig.getCenterCamera();

          renderCamera(mActivity.getAppPtr(), mMainScene, centerCamera, mRenderBundle);

          readRenderResult();
          returnScreenshotToCaller(
              mScreenshotCenterCallback, mReadbackBufferWidth, mReadbackBufferHeight);

          mScreenshotCenterCallback = null;
        }

        // if mScreenshot3DCallback is not null, capture 3D screenshot
        if (mScreenshot3DCallback != null) {
          byte[][] byteArrays = new byte[6][];
          renderSixCamerasAndReadback(mainCameraRig, byteArrays);
          returnScreenshot3DToCaller(
              mScreenshot3DCallback, byteArrays, mReadbackBufferWidth, mReadbackBufferHeight);

          mScreenshot3DCallback = null;
        }

        GVRCamera leftCamera = mainCameraRig.getLeftCamera();
        renderCamera(mActivity.getAppPtr(), mMainScene, leftCamera, mRenderBundle);

        // if mScreenshotLeftCallback is not null, capture left eye
        if (mScreenshotLeftCallback != null) {
          readRenderResult();
          returnScreenshotToCaller(
              mScreenshotLeftCallback, mReadbackBufferWidth, mReadbackBufferHeight);

          mScreenshotLeftCallback = null;
        }

        if (mScreenshotLeftCallback == null
            && mScreenshotRightCallback == null
            && mScreenshotCenterCallback == null
            && mScreenshot3DCallback == null) {
          mReadbackBuffer = null;
        }

        mActivity.setCamera(leftCamera);
      }
    }
  }