fix quest vr threading

This commit is contained in:
2019-08-01 18:22:31 +02:00
parent 945028f171
commit 32667b709e
5 changed files with 51 additions and 43 deletions

View File

@@ -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;