diff --git a/src/app_vr.cpp b/src/app_vr.cpp index f25358e..7581006 100644 --- a/src/app_vr.cpp +++ b/src/app_vr.cpp @@ -81,9 +81,9 @@ void App::vr_update(float dt) controller_cursor.y = (-plane_local.y * 0.5f + 0.5f) * height; if (!down_controller && ui_visible) { - async_start(); - mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false); - async_end(); + ui_task_async([this,p=controller_cursor] { + mouse_move(p.x, p.y, 1.f, kEventSource::Mouse, false); + }); ui_inside = true; } } @@ -97,10 +97,10 @@ void App::vr_update(float dt) auto p = controller_points.average(); if (glm::distance(p, controller_last_point) > 1) { - async_start(); - Canvas::I->stroke_update(p, down_controller->get_trigger_value()); - Canvas::I->stroke_draw(); - async_end(); + render_task_async([p, c=down_controller]{ + Canvas::I->stroke_update(p, c->get_trigger_value()); + Canvas::I->stroke_draw(); + }); controller_last_point = p; redraw = true; } @@ -113,18 +113,20 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController { if (!down_controller && (ui_inside || ui_capture) && ui_visible) { - async_start(); if (a == VRController::kAction::Press) { - mouse_down(0, controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false); + ui_task_async([this, p=controller_cursor] { + mouse_down(0, p.x, p.y, 1.f, kEventSource::Mouse, false); + }); ui_capture = true; } else { - mouse_up(0, controller_cursor.x, controller_cursor.y, kEventSource::Mouse, false); + ui_task_async([this, p=controller_cursor] { + mouse_up(0, p.x, p.y, kEventSource::Mouse, false); + }); ui_capture = false; } - async_end(); } else { @@ -132,9 +134,9 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController { glm::vec3 head_position = vr_head[3]; glm::vec3 c_pos = glm::normalize(c.get_pos() - head_position) * 800.f; - async_start(); - Canvas::I->stroke_start(c_pos, force.x); - async_end(); + render_task_async([=] { + Canvas::I->stroke_start(c_pos, force.x); + }); controller_last_point = c_pos; controller_points.clear(); down_controller = &c; @@ -142,9 +144,9 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController if (a == VRController::kAction::Release) { down_controller = nullptr; - async_start(); - Canvas::I->stroke_end(); - async_end(); + render_task_async([this] { + Canvas::I->stroke_end(); + }); } } } @@ -159,7 +161,9 @@ void App::vr_digital(const VRController& c, VRController::kButton b, VRControlle { if (!ui_visible) Canvas::I->m_cam_rot = vr_rot; - toggle_ui(); + ui_task_async([this] { + toggle_ui(); + }); } } } diff --git a/src/hmd.cpp b/src/hmd.cpp index 6a21598..bfa0bf2 100644 --- a/src/hmd.cpp +++ b/src/hmd.cpp @@ -24,13 +24,15 @@ bool Vive::Initialize() m_settings = vr::VRSettings(); m_hmd->GetRecommendedRenderTargetSize(&m_eye_width, &m_eye_height); - for (int eye = 0; eye < 2; ++eye) - { - m_eyes[eye].create(m_eye_width, m_eye_height); - m_eyes[eye].bindFramebuffer(); - m_eyes[eye].clear({ 1, 0, 0, 1 }); - m_eyes[eye].unbindFramebuffer(); - } + App::I->render_task([&]{ + for (int eye = 0; eye < 2; ++eye) + { + m_eyes[eye].create(m_eye_width, m_eye_height); + m_eyes[eye].bindFramebuffer(); + m_eyes[eye].clear({ 1, 0, 0, 1 }); + m_eyes[eye].unbindFramebuffer(); + } + }); vr::CVRSettingHelper s(m_settings); float timeout = s.GetFloat(vr::k_pch_Power_Section, vr::k_pch_Power_TurnOffScreensTimeout_Float); diff --git a/src/main.cpp b/src/main.cpp index 8adba61..eecab7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -579,6 +579,8 @@ bool win32_vr_start() return false; } + if (hmd_renderer.joinable()) + hmd_renderer.join(); hmd_renderer = std::thread([&] { if (!vive) return; @@ -620,9 +622,9 @@ bool win32_vr_start() if (vr_running && vive->m_active) { - async_lock(); - vive->Draw(); - async_unlock(); + App::I->render_task([] { + vive->Draw(); + }); } const int framerate = (1.f / target_tick_rate) * 1000; @@ -633,11 +635,7 @@ bool win32_vr_start() App::I->vr_active = false; App::I->has_vr = false; vr_running = false; - if (async_lock_try()) - { - vive->Terminate(); - async_unlock(); - } + vive->Terminate(); LOG("hmd renderer terminated"); }); return true;