diff --git a/android/quest/src/main/cpp/oculus_vr.cpp b/android/quest/src/main/cpp/oculus_vr.cpp index 5e322d0..9d7631d 100644 --- a/android/quest/src/main/cpp/oculus_vr.cpp +++ b/android/quest/src/main/cpp/oculus_vr.cpp @@ -97,31 +97,36 @@ void oculus_init(JavaVM* vm, JNIEnv* jni, jobject activity_class) void oculus_init_vr(EGLDisplay display, EGLContext context, ANativeWindow* surface) { - LOG("init swapchain"); - int rtt_w = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH); - int rtt_h = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT); - LOG("ovr suggested texture size %d %d", rtt_w, rtt_h); - for (int eye = 0; eye < 2; eye++) - { - swap_chain[eye] = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, rtt_w, rtt_h, 1, 3); - swap_chain_count = vrapi_GetTextureSwapChainLength(swap_chain[eye]); - for (int i = 0; i < swap_chain_count; i++) + App::I->render_task([&]{ + LOG("init swapchain"); + int rtt_w = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH); + int rtt_h = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT); + LOG("ovr suggested texture size %d %d", rtt_w, rtt_h); + for (int eye = 0; eye < 2; eye++) { - auto texid = vrapi_GetTextureSwapChainHandle(swap_chain[eye], i); - if (ovr_eyes[i][eye].create(rtt_w, rtt_h, texid, GL_RGBA8, true)) + swap_chain[eye] = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, rtt_w, rtt_h, 1, 3); + swap_chain_count = vrapi_GetTextureSwapChainLength(swap_chain[eye]); + for (int i = 0; i < swap_chain_count; i++) { - ovr_eyes[i][eye].bindTexture(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - ovr_eyes[i][eye].unbindTexture(); - LOG("create eye %d", eye); - } - else - { - LOG("FAILED create fb for eye %d", eye); + auto texid = vrapi_GetTextureSwapChainHandle(swap_chain[eye], i); + if (ovr_eyes[i][eye].create(rtt_w, rtt_h, texid, GL_RGBA8, true)) + { + App::I->render_task([&] + { + ovr_eyes[i][eye].bindTexture(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + ovr_eyes[i][eye].unbindTexture(); + LOG("create eye %d", eye); + }); + } + else + { + LOG("FAILED create fb for eye %d", eye); + } } } - } + }); LOG("vrapi_DefaultModeParms"); ovrModeParms parms = vrapi_DefaultModeParms( &java ); @@ -207,7 +212,7 @@ void oculus_draw(float dt) controllers[0].update_state(predictedDisplayTime, head_pos); App::I->vr_controllers[0] = controllers[0]; } - App::I->vr_head = pose; + App::I->vr_head = glm::translate(head_pos) * pose; App::I->vr_update(dt); // update hmd @@ -225,7 +230,7 @@ void oculus_draw(float dt) glm::mat4 proj = glm::make_mat4(reinterpret_cast(&proj_ovr)); auto view_ovr = ovrMatrix4f_Transpose(&tracking.Eye[eye].ViewMatrix); glm::mat4 view = glm::make_mat4(reinterpret_cast(&view_ovr)); - App::I->vr_draw(proj, view, pose); + App::I->vr_draw(proj, view, glm::translate(head_pos) * pose); rtt.unbindFramebuffer(); layer.Textures[eye].ColorSwapChain = swap_chain[eye]; layer.Textures[eye].SwapChainIndex = swap_chain_index; diff --git a/android/src/cpp/main.cpp b/android/src/cpp/main.cpp index 16e8ac7..c2003fd 100644 --- a/android/src/cpp/main.cpp +++ b/android/src/cpp/main.cpp @@ -383,11 +383,21 @@ static void engine_vr_loop() LOG("hmd renderer terminated"); } -static void engine_start_vr() +static void engine_start_vr_thread() { std::thread(engine_vr_loop).detach(); } +static void engine_start_vr_mode() +{ +#ifdef __QUEST__ + LOG("QUEST init VR"); + oculus_init_vr(g_engine.display, g_engine.context, g_engine.app->window); +#elif __FOCUS__ + wave_init_vr(g_engine.display, g_engine.context, g_engine.app->window); +#endif +} + /** * Initialize an EGL context for the current display. */ @@ -569,14 +579,6 @@ static int engine_init_display(struct engine* engine) { g_display = display; g_context = context; -#ifdef __QUEST__ - App::I->render_thread_id = std::this_thread::get_id(); - LOG("QUEST init VR"); - oculus_init_vr(display, context, engine->app->window); -#elif __FOCUS__ - wave_init_vr(display, context, engine->app->window); -#endif - if (resuming_context) { LOG("RESUME APP"); @@ -584,6 +586,7 @@ static int engine_init_display(struct engine* engine) { LOG("release egl context"); eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); mutex.unlock(); + engine_start_vr_mode(); return 0; } @@ -702,12 +705,13 @@ static int engine_init_display(struct engine* engine) { LOG("start render threads"); App::I->render_thread_start(); + LOG("start ui thread"); App::I->ui_thread_start(); - App::I->ui_sync(); LOG("start vr thread"); - engine_start_vr(); + engine_start_vr_mode(); + engine_start_vr_thread(); #else float density = get_display_density(); LOG("density %f", density); diff --git a/data/layout.xml b/data/layout.xml index 73b3134..38744fd 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -1405,7 +1405,7 @@ Here's a list of what's available in this release. - + @@ -1413,7 +1413,7 @@ Here's a list of what's available in this release. - + @@ -1485,22 +1485,22 @@ Here's a list of what's available in this release. - + - - + + - + diff --git a/src/app.cpp b/src/app.cpp index 29b5108..ada24ba 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -405,6 +405,8 @@ void App::init() initLayout(); title_update(); + uirtt.create(width, height, -1, GL_RGBA8, true); + if (!check_license()) { message_box("License", "Could not validate this license, running in demo mode."); diff --git a/src/app_vr.cpp b/src/app_vr.cpp index 7581006..4fe555c 100644 --- a/src/app_vr.cpp +++ b/src/app_vr.cpp @@ -35,9 +35,6 @@ void App::vr_stop() void App::vr_draw_ui() { - if (auto* main = layout[main_id]) - main->update(width, height, zoom); - uirtt.bindFramebuffer(); uirtt.clear(); glViewport(0, 0, uirtt.getWidth(), uirtt.getHeight());