public void beforeDrawFrame() {
   this.mDrawingFrame = true;
   if (this.mFovsChanged || this.mTextureFormatChanged) {
     this.updateTextureAndDistortionMesh();
   }
   GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, this.mOriginalFramebufferId);
   GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, this.mFramebufferId);
 }
 private void updateTextureAndDistortionMesh() {
   final ScreenParams screen = this.mHmd.getScreenParams();
   final CardboardDeviceParams cdp = this.mHmd.getCardboardDeviceParams();
   if (this.mProgramHolder == null) {
     this.mProgramHolder = this.createProgramHolder();
   }
   if (this.mProgramHolderAberration == null) {
     this.mProgramHolderAberration = (ProgramHolderAberration) this.createProgramHolder(true);
   }
   final float textureWidthTanAngle = this.mLeftEyeViewport.width + this.mRightEyeViewport.width;
   final float textureHeightTanAngle =
       Math.max(this.mLeftEyeViewport.height, this.mRightEyeViewport.height);
   final int[] maxTextureSize = {0};
   GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
   final int textureWidthPx =
       Math.min(Math.round(textureWidthTanAngle * this.mXPxPerTanAngle), maxTextureSize[0]);
   final int textureHeightPx =
       Math.min(Math.round(textureHeightTanAngle * this.mYPxPerTanAngle), maxTextureSize[0]);
   float xEyeOffsetTanAngleScreen =
       (screen.getWidthMeters() / 2.0f - cdp.getInterLensDistance() / 2.0f)
           / this.mMetersPerTanAngle;
   final float yEyeOffsetTanAngleScreen =
       (cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters())
           / this.mMetersPerTanAngle;
   this.mLeftEyeDistortionMesh =
       this.createDistortionMesh(
           this.mLeftEyeViewport,
           textureWidthTanAngle,
           textureHeightTanAngle,
           xEyeOffsetTanAngleScreen,
           yEyeOffsetTanAngleScreen);
   xEyeOffsetTanAngleScreen =
       screen.getWidthMeters() / this.mMetersPerTanAngle - xEyeOffsetTanAngleScreen;
   this.mRightEyeDistortionMesh =
       this.createDistortionMesh(
           this.mRightEyeViewport,
           textureWidthTanAngle,
           textureHeightTanAngle,
           xEyeOffsetTanAngleScreen,
           yEyeOffsetTanAngleScreen);
   this.setupRenderTextureAndRenderbuffer(textureWidthPx, textureHeightPx);
   this.mFovsChanged = false;
 }