fix quest vr threading
This commit is contained in:
@@ -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<const float*>(&proj_ovr));
|
||||
auto view_ovr = ovrMatrix4f_Transpose(&tracking.Eye[eye].ViewMatrix);
|
||||
glm::mat4 view = glm::make_mat4(reinterpret_cast<const float*>(&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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1405,7 +1405,7 @@ Here's a list of what's available in this release.
|
||||
<text text="Save Version" grow="1" margin="0 0 0 5"/>
|
||||
<text text="Ctrl-Shift-S" color=".4" justify="flex-end" margin="0 10 0 10"/>
|
||||
</button-custom>
|
||||
<node dir="row">
|
||||
<border dir="row" flood-events="1">
|
||||
<button-custom id="file-export" height="40" align="center" color=".2" pad="0 0 0 10" dir="row" grow="1">
|
||||
<icon icon="picture_go" width="20"/>
|
||||
<text text="Export JPG" grow="1" margin="0 0 0 5"/>
|
||||
@@ -1413,7 +1413,7 @@ Here's a list of what's available in this release.
|
||||
<button-custom id="file-export-tick" height="40" width="40" align="center" justify="center" color=".2" dir="row">
|
||||
<icon icon="resultset_next" width="20"/>
|
||||
</button-custom>
|
||||
</node>
|
||||
</border>
|
||||
<button-custom id="file-share" os="osx,ios" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<icon icon="picture_go" width="20"/>
|
||||
<text text="Share" grow="1" margin="0 0 0 5"/>
|
||||
@@ -1485,22 +1485,22 @@ Here's a list of what's available in this release.
|
||||
<!-- MENU TOOLS -->
|
||||
<layout id="tools-menu">
|
||||
<popup-menu positioning="absolute" position="100 100" width="150" thickness="1" border-color=".1" color=".4 .4 .4 .8" dir="col">
|
||||
<node dir="row">
|
||||
<border dir="row" flood-events="1">
|
||||
<button-custom id="tools-timelapse" height="40" align="center" color=".2" pad="0 0 0 10" dir="row" grow="1">
|
||||
<text text="Timelapse" grow="1" margin="0 0 0 5"/>
|
||||
</button-custom>
|
||||
<button-custom id="tools-timelapse-tick" height="40" width="40" align="center" justify="center" color=".2" dir="row">
|
||||
<icon icon="resultset_next" width="20"/>
|
||||
</button-custom>
|
||||
</node>
|
||||
<node dir="row">
|
||||
</border>
|
||||
<border dir="row" flood-events="1" >
|
||||
<button-custom id="tools-panels" height="40" align="center" color=".2" pad="0 0 0 10" dir="row" grow="1">
|
||||
<text text="Panels" grow="1" margin="0 0 0 5"/>
|
||||
</button-custom>
|
||||
<button-custom id="tools-panels-tick" height="40" width="40" align="center" justify="center" color=".2" dir="row">
|
||||
<icon icon="resultset_next" width="20"/>
|
||||
</button-custom>
|
||||
</node>
|
||||
</border>
|
||||
<button-custom id="tools-rtl" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<checkbox id="tools-rtl-check" width="20" height="20"/>
|
||||
<text text="Left-handed UI" margin="0 0 0 5"/>
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user