From c70f37e0baf8818a087040323b8980dfc848ef2d Mon Sep 17 00:00:00 2001 From: Krzysztof Kondrak Date: Mon, 4 Apr 2016 20:08:06 +0200 Subject: [PATCH 1/2] Remove commitEye() and fix extra frame of latency in OpenGL as well --- src/hmd_ovr.cpp | 22 ++++++---------------- src/hmd_ovr.h | 6 ------ src/renderer_gl.cpp | 2 -- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/hmd_ovr.cpp b/src/hmd_ovr.cpp index d5008df04..93733442a 100644 --- a/src/hmd_ovr.cpp +++ b/src/hmd_ovr.cpp @@ -13,7 +13,6 @@ namespace bgfx : m_hmd(NULL) , m_isenabled(false) , m_mirror(NULL) - , m_hmdFrameReady(-1) , m_frameIndex(0) , m_sensorSampleTime(0) { @@ -125,14 +124,6 @@ namespace bgfx } } - void OVR::commitEye(uint8_t _eye) - { - if (m_isenabled) - { - m_hmdFrameReady = ovr_CommitTextureSwapChain(m_hmd, m_eyeBuffers[_eye]->m_swapTextureChain); - } - } - bool OVR::swap(HMD& _hmd, bool originBottomLeft) { _hmd.flags = BGFX_HMD_NONE; @@ -144,16 +135,15 @@ namespace bgfx _hmd.deviceHeight = m_hmdDesc.Resolution.h; } + if (!m_isenabled) + { + return false; + } + // commit eyes to HMD for (int eye = 0; eye < 2; eye++) { - commitEye(eye); - } - - // check that eyes committed successfully - if (!m_isenabled || !OVR_SUCCESS(m_hmdFrameReady)) - { - return false; + ovr_CommitTextureSwapChain(m_hmd, m_eyeBuffers[eye]->m_swapTextureChain); } _hmd.flags |= BGFX_HMD_RENDERING; diff --git a/src/hmd_ovr.h b/src/hmd_ovr.h index f8d414495..525dcac90 100644 --- a/src/hmd_ovr.h +++ b/src/hmd_ovr.h @@ -72,7 +72,6 @@ namespace bgfx void renderEyeStart(uint8_t _eye); bool postReset(); void preReset(); - void commitEye(uint8_t _eye); bool swap(HMD& _hmd, bool originBottomLeft); void recenter(); void getEyePose(HMD& _hmd); @@ -84,7 +83,6 @@ namespace bgfx ovrPosef m_pose[2]; ovrVector3f m_hmdToEyeOffset[2]; ovrSizei m_hmdSize; - ovrResult m_hmdFrameReady; OVRBufferI *m_eyeBuffers[2]; OVRMirrorI *m_mirror; long long m_frameIndex; @@ -139,10 +137,6 @@ namespace bgfx _viewport->m_height = 0; } - void commitEye(uint8_t /*_eye*/) - { - } - void renderEyeStart(uint8_t /*_eye*/) { } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 84afafbd5..edeabab46 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -5658,8 +5658,6 @@ namespace bgfx { namespace gl if (m_ovr.isEnabled() ) { m_ovr.getViewport(eye, &viewState.m_rect); - // commit previous eye to HMD and start rendering new frame - m_ovr.commitEye(eye); m_ovr.renderEyeStart(eye); } else From 76a46af41833df8e3ab6d86e910b2eb0255a2930 Mon Sep 17 00:00:00 2001 From: Krzysztof Kondrak Date: Mon, 4 Apr 2016 21:27:49 +0200 Subject: [PATCH 2/2] use separate projection matrices for left/right eyes in HMD demos --- examples/01-cubes/cubes.cpp | 2 +- examples/02-metaballs/metaballs.cpp | 2 +- examples/04-mesh/mesh.cpp | 2 +- examples/05-instancing/instancing.cpp | 2 +- examples/06-bump/bump.cpp | 2 +- examples/12-lod/lod.cpp | 2 +- examples/24-nbody/nbody.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/01-cubes/cubes.cpp b/examples/01-cubes/cubes.cpp index 97cf60529..6854b4725 100644 --- a/examples/01-cubes/cubes.cpp +++ b/examples/01-cubes/cubes.cpp @@ -143,7 +143,7 @@ class ExampleCubes : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/02-metaballs/metaballs.cpp b/examples/02-metaballs/metaballs.cpp index f0f20e39c..f26e9e5af 100644 --- a/examples/02-metaballs/metaballs.cpp +++ b/examples/02-metaballs/metaballs.cpp @@ -577,7 +577,7 @@ class ExampleMetaballs : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/04-mesh/mesh.cpp b/examples/04-mesh/mesh.cpp index f7f8b7e96..d40df05a1 100644 --- a/examples/04-mesh/mesh.cpp +++ b/examples/04-mesh/mesh.cpp @@ -91,7 +91,7 @@ class ExampleMesh : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/05-instancing/instancing.cpp b/examples/05-instancing/instancing.cpp index 1a0f0b69c..342687629 100644 --- a/examples/05-instancing/instancing.cpp +++ b/examples/05-instancing/instancing.cpp @@ -160,7 +160,7 @@ class ExampleInstancing : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/06-bump/bump.cpp b/examples/06-bump/bump.cpp index da6cff3d7..2d9589231 100644 --- a/examples/06-bump/bump.cpp +++ b/examples/06-bump/bump.cpp @@ -225,7 +225,7 @@ class ExampleBump : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index c66db5a24..7e79c36b2 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -174,7 +174,7 @@ class ExampleLod : public entry::AppI { float view[16]; bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - bgfx::setViewTransform(0, view, hmd->eye[0].projection); + bgfx::setViewTransform(0, view, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. // diff --git a/examples/24-nbody/nbody.cpp b/examples/24-nbody/nbody.cpp index f04766a58..636d8f525 100644 --- a/examples/24-nbody/nbody.cpp +++ b/examples/24-nbody/nbody.cpp @@ -305,7 +305,7 @@ int _main_(int _argc, char** _argv) float tmp[16]; bx::mtxMul(tmp, view, viewHead); - bgfx::setViewTransform(0, tmp, hmd->eye[0].projection); + bgfx::setViewTransform(0, tmp, hmd->eye[0].projection, BGFX_VIEW_STEREO, hmd->eye[1].projection); // Set view 0 default viewport. //