implement tasks for update windows vr

This commit is contained in:
2019-07-27 15:52:15 +02:00
parent 5fc27ebb14
commit ae5da7139c
3 changed files with 37 additions and 33 deletions

View File

@@ -81,9 +81,9 @@ void App::vr_update(float dt)
controller_cursor.y = (-plane_local.y * 0.5f + 0.5f) * height; controller_cursor.y = (-plane_local.y * 0.5f + 0.5f) * height;
if (!down_controller && ui_visible) if (!down_controller && ui_visible)
{ {
async_start(); ui_task_async([this,p=controller_cursor] {
mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false); mouse_move(p.x, p.y, 1.f, kEventSource::Mouse, false);
async_end(); });
ui_inside = true; ui_inside = true;
} }
} }
@@ -97,10 +97,10 @@ void App::vr_update(float dt)
auto p = controller_points.average(); auto p = controller_points.average();
if (glm::distance(p, controller_last_point) > 1) if (glm::distance(p, controller_last_point) > 1)
{ {
async_start(); render_task_async([p, c=down_controller]{
Canvas::I->stroke_update(p, down_controller->get_trigger_value()); Canvas::I->stroke_update(p, c->get_trigger_value());
Canvas::I->stroke_draw(); Canvas::I->stroke_draw();
async_end(); });
controller_last_point = p; controller_last_point = p;
redraw = true; 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) if (!down_controller && (ui_inside || ui_capture) && ui_visible)
{ {
async_start();
if (a == VRController::kAction::Press) 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; ui_capture = true;
} }
else 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; ui_capture = false;
} }
async_end();
} }
else 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 head_position = vr_head[3];
glm::vec3 c_pos = glm::normalize(c.get_pos() - head_position) * 800.f; glm::vec3 c_pos = glm::normalize(c.get_pos() - head_position) * 800.f;
async_start(); render_task_async([=] {
Canvas::I->stroke_start(c_pos, force.x); Canvas::I->stroke_start(c_pos, force.x);
async_end(); });
controller_last_point = c_pos; controller_last_point = c_pos;
controller_points.clear(); controller_points.clear();
down_controller = &c; down_controller = &c;
@@ -142,9 +144,9 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController
if (a == VRController::kAction::Release) if (a == VRController::kAction::Release)
{ {
down_controller = nullptr; down_controller = nullptr;
async_start(); render_task_async([this] {
Canvas::I->stroke_end(); Canvas::I->stroke_end();
async_end(); });
} }
} }
} }
@@ -159,7 +161,9 @@ void App::vr_digital(const VRController& c, VRController::kButton b, VRControlle
{ {
if (!ui_visible) if (!ui_visible)
Canvas::I->m_cam_rot = vr_rot; Canvas::I->m_cam_rot = vr_rot;
toggle_ui(); ui_task_async([this] {
toggle_ui();
});
} }
} }
} }

View File

@@ -24,13 +24,15 @@ bool Vive::Initialize()
m_settings = vr::VRSettings(); m_settings = vr::VRSettings();
m_hmd->GetRecommendedRenderTargetSize(&m_eye_width, &m_eye_height); m_hmd->GetRecommendedRenderTargetSize(&m_eye_width, &m_eye_height);
for (int eye = 0; eye < 2; ++eye) 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].create(m_eye_width, m_eye_height);
m_eyes[eye].clear({ 1, 0, 0, 1 }); m_eyes[eye].bindFramebuffer();
m_eyes[eye].unbindFramebuffer(); m_eyes[eye].clear({ 1, 0, 0, 1 });
} m_eyes[eye].unbindFramebuffer();
}
});
vr::CVRSettingHelper s(m_settings); vr::CVRSettingHelper s(m_settings);
float timeout = s.GetFloat(vr::k_pch_Power_Section, vr::k_pch_Power_TurnOffScreensTimeout_Float); float timeout = s.GetFloat(vr::k_pch_Power_Section, vr::k_pch_Power_TurnOffScreensTimeout_Float);

View File

@@ -579,6 +579,8 @@ bool win32_vr_start()
return false; return false;
} }
if (hmd_renderer.joinable())
hmd_renderer.join();
hmd_renderer = std::thread([&] { hmd_renderer = std::thread([&] {
if (!vive) if (!vive)
return; return;
@@ -620,9 +622,9 @@ bool win32_vr_start()
if (vr_running && vive->m_active) if (vr_running && vive->m_active)
{ {
async_lock(); App::I->render_task([] {
vive->Draw(); vive->Draw();
async_unlock(); });
} }
const int framerate = (1.f / target_tick_rate) * 1000; const int framerate = (1.f / target_tick_rate) * 1000;
@@ -633,11 +635,7 @@ bool win32_vr_start()
App::I->vr_active = false; App::I->vr_active = false;
App::I->has_vr = false; App::I->has_vr = false;
vr_running = false; vr_running = false;
if (async_lock_try()) vive->Terminate();
{
vive->Terminate();
async_unlock();
}
LOG("hmd renderer terminated"); LOG("hmd renderer terminated");
}); });
return true; return true;