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_); } }
void GVRActivity::onSurfaceCreated(JNIEnv& env) { LOGV("GVRActivity::onSurfaceCreated"); initializeOculusJava(env, oculusJavaGlThread_); //must happen as soon as possible as it updates the java side wherever it has default values; e.g. //resolutionWidth -1 becomes whatever VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH is. configurationHelper_.getFramebufferConfiguration(env, mWidthConfiguration, mHeightConfiguration, vrapi_GetSystemPropertyInt(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH), vrapi_GetSystemPropertyInt(&oculusJavaGlThread_, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT), mMultisamplesConfiguration, mColorTextureFormatConfiguration, mResolveDepthConfiguration, mDepthTextureFormatConfiguration); }
int GVRActivity::initializeVrApi() { initializeOculusJava(*envMainThread_, oculusJavaMainThread_); const ovrInitParms initParms = vrapi_DefaultInitParms(&oculusJavaMainThread_); mVrapiInitResult = vrapi_Initialize(&initParms); if (VRAPI_INITIALIZE_UNKNOWN_ERROR == mVrapiInitResult) { LOGE("Oculus is probably not present on this device"); return mVrapiInitResult; } if (VRAPI_INITIALIZE_PERMISSIONS_ERROR == mVrapiInitResult) { char const * msg = mVrapiInitResult == VRAPI_INITIALIZE_PERMISSIONS_ERROR ? "Thread priority security exception. Make sure the APK is signed." : "VrApi initialization error."; vrapi_ShowFatalError(&oculusJavaMainThread_, nullptr, msg, __FILE__, __LINE__); } return mVrapiInitResult; }
int GVRActivity::initializeVrApi() { initializeOculusJava(*envMainThread_, oculusJavaMainThread_); const ovrInitParms initParms = vrapi_DefaultInitParms(&oculusJavaMainThread_); mVrapiInitResult = vrapi_Initialize(&initParms); if (VRAPI_INITIALIZE_UNKNOWN_ERROR == mVrapiInitResult) { LOGE("Oculus is probably not present on this device"); return mVrapiInitResult; } SystemActivities_Init(&oculusJavaMainThread_); if (VRAPI_INITIALIZE_PERMISSIONS_ERROR == mVrapiInitResult) { char const * msg = mVrapiInitResult == VRAPI_INITIALIZE_PERMISSIONS_ERROR ? "Thread priority security exception. Make sure the APK is signed." : "VrApi initialization error."; SystemActivities_DisplayError(&oculusJavaMainThread_, SYSTEM_ACTIVITIES_FATAL_ERROR_OSIG, __FILE__, msg); SystemActivities_Shutdown(&oculusJavaMainThread_); } return mVrapiInitResult; }
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_); } }