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; }
public void onFovChanged( final HeadMountedDisplay hmd, final FieldOfView leftFov, final FieldOfView rightFov, final float virtualEyeToScreenDistance) { if (this.mDrawingFrame) { throw new IllegalStateException("Cannot change FOV while rendering a frame."); } this.mHmd = new HeadMountedDisplay(hmd); this.mLeftEyeViewport = this.initViewportForEye(leftFov, 0.0f); this.mRightEyeViewport = this.initViewportForEye(rightFov, this.mLeftEyeViewport.width); this.mMetersPerTanAngle = virtualEyeToScreenDistance; final ScreenParams screen = this.mHmd.getScreenParams(); this.mXPxPerTanAngle = screen.getWidth() / (screen.getWidthMeters() / this.mMetersPerTanAngle); this.mYPxPerTanAngle = screen.getHeight() / (screen.getHeightMeters() / this.mMetersPerTanAngle); this.mFovsChanged = true; this.mViewportsChanged = true; }