void GVRActivity::onSurfaceChanged(JNIEnv& env) { LOGV("GVRActivityT::onSurfaceChanged"); initializeOculusJava(env, oculusJavaGlThread_); if (nullptr == oculusMobile_) { ovrModeParms parms = vrapi_DefaultModeParms(&oculusJavaGlThread_); configurationHelper_.getModeConfiguration(env, parms.AllowPowerSave, parms.ResetWindowFullscreen); oculusMobile_ = vrapi_EnterVrMode(&parms); oculusPerformanceParms_ = vrapi_DefaultPerformanceParms(); configurationHelper_.getPerformanceConfiguration(env, oculusPerformanceParms_); oculusHeadModelParms_ = vrapi_DefaultHeadModelParms(); configurationHelper_.getHeadModelConfiguration(env, oculusHeadModelParms_); for (int eye = 0; eye < VRAPI_FRAME_LAYER_EYE_MAX; eye++) { bool b = frameBuffer_[eye].create(mColorTextureFormatConfiguration, mWidthConfiguration, mHeightConfiguration, mMultisamplesConfiguration, mResolveDepthConfiguration, mDepthTextureFormatConfiguration); } projectionMatrix_ = ovrMatrix4f_CreateProjectionFov( vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X), vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_Y), 0.0f, 0.0f, 1.0f, 0.0f); texCoordsTanAnglesMatrix_ = ovrMatrix4f_TanAngleMatrixFromProjection(&projectionMatrix_); } }
void GVRActivity::onSurfaceChanged(JNIEnv& env) { int maxSamples = MSAA::getMaxSampleCount(); LOGV("GVRActivityT::onSurfaceChanged"); initializeOculusJava(env, oculusJavaGlThread_); if (nullptr == oculusMobile_) { ovrModeParms parms = vrapi_DefaultModeParms(&oculusJavaGlThread_); bool AllowPowerSave, ResetWindowFullscreen; configurationHelper_.getModeConfiguration(env, AllowPowerSave, ResetWindowFullscreen); parms.Flags |=AllowPowerSave; parms.Flags |=ResetWindowFullscreen; oculusMobile_ = vrapi_EnterVrMode(&parms); oculusPerformanceParms_ = vrapi_DefaultPerformanceParms(); configurationHelper_.getPerformanceConfiguration(env, oculusPerformanceParms_); oculusHeadModelParms_ = vrapi_DefaultHeadModelParms(); configurationHelper_.getHeadModelConfiguration(env, oculusHeadModelParms_); if (mMultisamplesConfiguration > maxSamples) mMultisamplesConfiguration = maxSamples; bool multiview; configurationHelper_.getMultiviewConfiguration(env,multiview); const char* extensions = (const char*)glGetString(GL_EXTENSIONS); if(multiview && std::strstr(extensions, "GL_OVR_multiview2")!= NULL){ use_multiview = true; } if(multiview && !use_multiview){ std::string error = "Multiview is not supported by your device"; LOGE(" Multiview is not supported by your device"); throw error; } for (int eye = 0; eye < (use_multiview ? 1 :VRAPI_FRAME_LAYER_EYE_MAX); eye++) { bool b = frameBuffer_[eye].create(mColorTextureFormatConfiguration, mWidthConfiguration, mHeightConfiguration, mMultisamplesConfiguration, mResolveDepthConfiguration, mDepthTextureFormatConfiguration); } // default viewport same as window size x = 0; y = 0; width = mWidthConfiguration; height = mHeightConfiguration; configurationHelper_.getSceneViewport(env, x, y, width, height); projectionMatrix_ = ovrMatrix4f_CreateProjectionFov( vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X), vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_Y), 0.0f, 0.0f, 1.0f, 0.0f); texCoordsTanAnglesMatrix_ = ovrMatrix4f_TanAngleMatrixFromProjection(&projectionMatrix_); } }
Matrix4f OvrSceneView::GetEyeProjectionMatrix( const int eye, const float fovDegreesX, const float fovDegreesY ) const { OVR_UNUSED( eye ); // We may want to make per-eye projection matrices if we move away from nearly-centered lenses. // Use an infinite projection matrix because, except for things right up against the near plane, // it provides better precision: // "Tightening the Precision of Perspective Rendering" // Paul Upchurch, Mathieu Desbrun // Journal of Graphics Tools, Volume 16, Issue 1, 2012 return ovrMatrix4f_CreateProjectionFov( fovDegreesX, fovDegreesY, 0.0f, 0.0f, Znear, 0.0f ); }
Matrix4f MeganekkoActivity::DrawEyeView(const int eye, const float fovDegreesX, const float fovDegreesY, ovrFrameParms & frameParms) { Scene* scene = GetScene(); ovrMatrix4f centerViewMatrix = scene->GetCenterViewMatrix(); const Matrix4f eyeViewMatrix = vrapi_GetEyeViewMatrix( &app->GetHeadModelParms(), ¢erViewMatrix, eye ); const Matrix4f eyeProjectionMatrix = ovrMatrix4f_CreateProjectionFov( fovDegreesX, fovDegreesY, 0.0f, 0.0f, 1.0f, 0.0f ); scene->SetViewMatrix(eyeViewMatrix); scene->SetProjectionMatrix(eyeProjectionMatrix); const Matrix4f eyeViewProjection = scene->Render(eye); GuiSys->RenderEyeView(centerViewMatrix, eyeViewMatrix, eyeProjectionMatrix); return eyeViewProjection; }
void GVRActivity::onSurfaceChanged(JNIEnv& env) { int maxSamples = MSAA::getMaxSampleCount(); LOGV("GVRActivityT::onSurfaceChanged"); initializeOculusJava(env, oculusJavaGlThread_); if (nullptr == oculusMobile_) { ovrModeParms parms = vrapi_DefaultModeParms(&oculusJavaGlThread_); bool allowPowerSave, resetWindowFullscreen; configurationHelper_.getModeConfiguration(env, allowPowerSave, resetWindowFullscreen); if (allowPowerSave) { parms.Flags |= VRAPI_MODE_FLAG_ALLOW_POWER_SAVE; } if (resetWindowFullscreen) { parms.Flags |= VRAPI_MODE_FLAG_RESET_WINDOW_FULLSCREEN; } oculusMobile_ = vrapi_EnterVrMode(&parms); if (gearController != nullptr) { gearController->setOvrMobile(oculusMobile_); } oculusPerformanceParms_ = vrapi_DefaultPerformanceParms(); env.ExceptionClear(); //clear a weird GearVrRemoteForBatteryWorkAround raised by Oculus configurationHelper_.getPerformanceConfiguration(env, oculusPerformanceParms_); oculusPerformanceParms_.MainThreadTid = mainThreadId_; oculusPerformanceParms_.RenderThreadTid = gettid(); oculusHeadModelParms_ = vrapi_DefaultHeadModelParms(); configurationHelper_.getHeadModelConfiguration(env, oculusHeadModelParms_); if (mMultisamplesConfiguration > maxSamples) mMultisamplesConfiguration = maxSamples; bool multiview; configurationHelper_.getMultiviewConfiguration(env,multiview); const char* extensions = (const char*)glGetString(GL_EXTENSIONS); if(multiview && std::strstr(extensions, "GL_OVR_multiview2")!= NULL){ use_multiview = true; } if(multiview && !use_multiview){ std::string error = "Multiview is not supported by your device"; LOGE(" Multiview is not supported by your device"); throw error; } clampToBorderSupported_ = nullptr != std::strstr(extensions, "GL_EXT_texture_border_clamp"); for (int eye = 0; eye < (use_multiview ? 1 :VRAPI_FRAME_LAYER_EYE_MAX); eye++) { frameBuffer_[eye].create(mColorTextureFormatConfiguration, mWidthConfiguration, mHeightConfiguration, mMultisamplesConfiguration, mResolveDepthConfiguration, mDepthTextureFormatConfiguration); } // default viewport same as window size x = 0; y = 0; width = mWidthConfiguration; height = mHeightConfiguration; configurationHelper_.getSceneViewport(env, x, y, width, height); projectionMatrix_ = ovrMatrix4f_CreateProjectionFov( vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X), vrapi_GetSystemPropertyFloat(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_Y), 0.0f, 0.0f, 1.0f, 0.0f); texCoordsTanAnglesMatrix_ = ovrMatrix4f_TanAngleMatrixFromProjection(&projectionMatrix_); } }