add openvr support, switch to 8.1 sdk, prepare for vr ui
This commit is contained in:
47
src/main.cpp
47
src/main.cpp
@@ -6,6 +6,7 @@
|
||||
#include "image.h"
|
||||
#include "app.h"
|
||||
#include "keymap.h"
|
||||
#include "hmd.h"
|
||||
#include "../resource.h"
|
||||
|
||||
#include <shellscalingapi.h>
|
||||
@@ -564,6 +565,21 @@ int main(int argc, char** argv)
|
||||
LOG("init app");
|
||||
App::I.init();
|
||||
|
||||
Vive* vive = nullptr;
|
||||
if (!sandboxed)
|
||||
{
|
||||
vive = new Vive;
|
||||
vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view) { App::I.vr_draw(proj, view); };
|
||||
async_lock();
|
||||
if (!vive->Initialize())
|
||||
{
|
||||
delete vive;
|
||||
vive = nullptr;
|
||||
LOG("VR: failed to initialize vive");
|
||||
}
|
||||
async_unlock();
|
||||
}
|
||||
|
||||
LOG("show main window");
|
||||
ShowWindow(hWnd, SW_NORMAL);
|
||||
|
||||
@@ -689,6 +705,35 @@ int main(int argc, char** argv)
|
||||
}
|
||||
});
|
||||
|
||||
std::mutex hmd_render_mutex;
|
||||
std::condition_variable hmd_render_cv;
|
||||
|
||||
std::thread hmd_renderer([&] {
|
||||
BT_SetTerminate();
|
||||
LOG("start hmd render thread");
|
||||
|
||||
const float target_tick_rate = 90;
|
||||
unsigned long t0 = GetTickCount();
|
||||
while (running && vive->Valid())
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(hmd_render_mutex);
|
||||
unsigned long t1 = GetTickCount();
|
||||
float dt = (float)(t1 - t0) / 1000.0f;
|
||||
|
||||
async_lock();
|
||||
vive->Draw();
|
||||
async_unlock();
|
||||
|
||||
const int framerate = (1.f / target_tick_rate) * 1000;
|
||||
const int diff = framerate - (t1 - t0);
|
||||
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
|
||||
}
|
||||
async_lock();
|
||||
vive->Terminate();
|
||||
async_unlock();
|
||||
});
|
||||
|
||||
|
||||
MSG msg;
|
||||
LOG("start main loop");
|
||||
while (running)
|
||||
@@ -710,6 +755,8 @@ int main(int argc, char** argv)
|
||||
render_cv.notify_all();
|
||||
if (renderer.joinable())
|
||||
renderer.join();
|
||||
if (hmd_renderer.joinable())
|
||||
hmd_renderer.join();
|
||||
App::I.terminate();
|
||||
// Clean up
|
||||
WacomTablet::I.terminate();
|
||||
|
||||
Reference in New Issue
Block a user