diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 5b3941d8..e11d6aac 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -118,6 +118,7 @@ namespace entry { entry::Key::F3, entry::Modifier::None, 1, cmd, "graphics wireframe" }, { entry::Key::F4, entry::Modifier::None, 1, cmd, "graphics hmd" }, { entry::Key::F4, entry::Modifier::LeftShift, 1, cmd, "graphics hmdrecenter" }, + { entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" }, { entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" }, { entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" }, { entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" }, diff --git a/src/ovr.cpp b/src/ovr.cpp index 52255fb3..f70f3e5d 100644 --- a/src/ovr.cpp +++ b/src/ovr.cpp @@ -12,6 +12,7 @@ namespace bgfx OVR::OVR() : m_hmd(NULL) , m_initialized(false) + , m_debug(false) { } @@ -39,6 +40,46 @@ namespace bgfx return false; } + if (_debug) + { + switch (_config->Header.API) + { +#if BGFX_CONFIG_RENDERER_DIRECT3D9 + case ovrRenderAPI_D3D9: + { + ovrD3D9ConfigData* data = (ovrD3D9ConfigData*)_config; + m_rtSize = data->Header.RTSize; + } + break; +#endif // BGFX_CONFIG_RENDERER_DIRECT3D9 + +#if BGFX_CONFIG_RENDERER_DIRECT3D11 + case ovrRenderAPI_D3D11: + { + ovrD3D11ConfigData* data = (ovrD3D11ConfigData*)_config; + m_rtSize = data->Header.RTSize; + } + break; +#endif // BGFX_CONFIG_RENDERER_DIRECT3D11 + +#if BGFX_CONFIG_RENDERER_OPENGL + case ovrRenderAPI_OpenGL: + { + ovrGLConfigData* data = (ovrGLConfigData*)_config; + m_rtSize = data->Header.RTSize; + } + break; +#endif // BGFX_CONFIG_RENDERER_OPENGL + + default: + BX_CHECK(false, "You should not be here!"); + break; + } + + m_debug = true; + return false; + } + if (!_debug) { m_hmd = ovrHmd_Create(0); @@ -67,6 +108,7 @@ namespace bgfx | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive + | ovrDistortionCap_NoRestore , eyeFov , m_erd ); @@ -135,6 +177,8 @@ ovrError: ovrHmd_Destroy(m_hmd); m_hmd = NULL; } + + m_debug = false; } bool OVR::swap() @@ -197,15 +241,32 @@ ovrError: eye.pixelsPerTanAngle[0] = erd.PixelsPerTanAngleAtCenter.x; eye.pixelsPerTanAngle[1] = erd.PixelsPerTanAngleAtCenter.y; } - - _hmd.width = uint16_t(m_rtSize.w); - _hmd.height = uint16_t(m_rtSize.h); } else { - _hmd.width = 0; - _hmd.height = 0; + for (int ii = 0; ii < 2; ++ii) + { + _hmd.eye[ii].rotation[0] = 0.0f; + _hmd.eye[ii].rotation[1] = 0.0f; + _hmd.eye[ii].rotation[2] = 0.0f; + _hmd.eye[ii].rotation[3] = 1.0f; + _hmd.eye[ii].translation[0] = 0.0f; + _hmd.eye[ii].translation[1] = 0.0f; + _hmd.eye[ii].translation[2] = 0.0f; + _hmd.eye[ii].fov[0] = 1.32928634f; + _hmd.eye[ii].fov[1] = 1.32928634f; + _hmd.eye[ii].fov[2] = 0 == ii ? 1.05865765f : 1.09236801f; + _hmd.eye[ii].fov[3] = 0 == ii ? 1.09236801f : 1.05865765f; + _hmd.eye[ii].viewOffset[0] = 0 == ii ? 0.0355070010f : -0.0375000015f; + _hmd.eye[ii].viewOffset[1] = 0.0f; + _hmd.eye[ii].viewOffset[2] = 0 == ii ? 0.00150949787f : -0.00150949787f; + _hmd.eye[ii].pixelsPerTanAngle[0] = 1; + _hmd.eye[ii].pixelsPerTanAngle[1] = 1; + } } + + _hmd.width = uint16_t(m_rtSize.w); + _hmd.height = uint16_t(m_rtSize.h); } } // namespace bgfx diff --git a/src/ovr.h b/src/ovr.h index 5fc18ef6..e08da30f 100644 --- a/src/ovr.h +++ b/src/ovr.h @@ -44,6 +44,11 @@ namespace bgfx return NULL != m_hmd; } + bool isDebug() const + { + return m_debug; + } + void init(); void shutdown(); @@ -68,6 +73,7 @@ namespace bgfx ovrSizei m_rtSize; bool m_warning; bool m_initialized; + bool m_debug; }; } // namespace bgfx @@ -104,6 +110,11 @@ namespace bgfx return false; } + bool isDebug() const + { + return false; + } + bool swap() { return false; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 288dfcdb..e935f8c4 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1833,9 +1833,9 @@ RENDERDOC_IMPORT void ovrPreReset() { #if BGFX_CONFIG_USE_OVR + m_ovr.preReset(); if (NULL != m_ovrRtv) { - m_ovr.preReset(); std::swap(m_ovrRtv, m_backBufferColor); std::swap(m_ovrDsv, m_backBufferDepthStencil); BX_CHECK(NULL == m_backBufferDepthStencil, ""); @@ -2952,7 +2952,7 @@ RENDERDOC_IMPORT Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] }; Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS]; - const bool hmdEnabled = m_ovr.isEnabled(); + const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug(); _render->m_hmdEnabled = hmdEnabled; if (hmdEnabled) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d988eeea..ae9bae09 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2017,9 +2017,9 @@ namespace bgfx void ovrPreReset() { #if BGFX_CONFIG_USE_OVR + m_ovr.preReset(); if (m_ovr.isEnabled() ) { - m_ovr.preReset(); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); GL_CHECK(glDeleteFramebuffers(1, &m_msaaBackBufferFbo) ); m_msaaBackBufferFbo = m_ovrFbo; @@ -4121,7 +4121,7 @@ namespace bgfx Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] }; Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS]; - const bool hmdEnabled = m_ovr.isEnabled(); + const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug(); _render->m_hmdEnabled = hmdEnabled; if (hmdEnabled)