diff --git a/src/hmd_ovr.cpp b/src/hmd_ovr.cpp index 05ab81e60..a3befb654 100644 --- a/src/hmd_ovr.cpp +++ b/src/hmd_ovr.cpp @@ -73,17 +73,17 @@ namespace bgfx for (uint32_t ii = 0; ii < 2; ++ii) { - if (m_eyeBuffers[ii]) + if (NULL != m_eyeBuffers[ii]) { m_eyeBuffers[ii]->destroy(m_hmd); - BX_DELETE(g_allocator, m_eyeBuffers[ii]); + m_eyeBuffers[ii] = NULL; } } - if (m_mirror) + if (NULL != m_mirror) { m_mirror->destroy(m_hmd); - BX_DELETE(g_allocator, m_mirror); + m_mirror = NULL; } ovr_Destroy(m_hmd); @@ -127,7 +127,6 @@ namespace bgfx { // on window resize this will recreate the mirror texture in ovrPostReset m_mirror->destroy(m_hmd); - BX_DELETE(g_allocator, m_mirror); m_mirror = NULL; m_enabled = false; } diff --git a/src/hmd_ovr.h b/src/hmd_ovr.h index 99954a656..c35e11423 100644 --- a/src/hmd_ovr.h +++ b/src/hmd_ovr.h @@ -108,6 +108,15 @@ namespace bgfx { struct OVR { + enum Enum + { + NotEnabled, + DeviceLost, + Success, + + Count + }; + OVR() { } diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2756f2081..539ab426f 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -3096,18 +3096,18 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (m_ovr.postReset() ) { - for (int eyeIdx = 0; eyeIdx < ovrEye_Count; eyeIdx++) + for (uint32_t ii = 0; ii < 2; ++ii) { // eye buffers need to be initialized only once during application lifetime - if (!m_ovr.m_eyeBuffers[eyeIdx]) + if (NULL == m_ovr.m_eyeBuffers[ii]) { - m_ovr.m_eyeBuffers[eyeIdx] = BX_NEW(g_allocator, OVRBufferD3D11); - m_ovr.m_eyeBuffers[eyeIdx]->create(m_ovr.m_hmd, eyeIdx); + m_ovr.m_eyeBuffers[ii] = &m_ovrBuffers[ii]; + m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii); } } // recreate mirror texture - m_ovr.m_mirror = BX_NEW(g_allocator, OVRMirrorD3D11); + m_ovr.m_mirror = &m_ovrMirror; m_ovr.m_mirror->create(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height); } } @@ -3509,6 +3509,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); bool m_timerQuerySupport; OVR m_ovr; +#if BGFX_CONFIG_USE_OVR + OVRMirrorD3D11 m_ovrMirror; + OVRBufferD3D11 m_ovrBuffers[2]; +#endif // BGFX_CONFIG_USE_OVR }; static RendererContextD3D11* s_renderD3D11; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index de30bfd6f..288f479bd 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2860,22 +2860,22 @@ namespace bgfx { namespace gl void ovrPostReset() { #if BGFX_CONFIG_USE_OVR - if (m_resolution.m_flags & (BGFX_RESET_HMD | BGFX_RESET_HMD_DEBUG) ) + if (m_resolution.m_flags & (BGFX_RESET_HMD|BGFX_RESET_HMD_DEBUG) ) { if (m_ovr.postReset() ) { - for (int eyeIdx = 0; eyeIdx < ovrEye_Count; eyeIdx++) + for (uint32_t ii = 0; ii < 2; ++ii) { // eye buffers need to be initialized only once during application lifetime - if (!m_ovr.m_eyeBuffers[eyeIdx]) + if (NULL == m_ovr.m_eyeBuffers[ii]) { - m_ovr.m_eyeBuffers[eyeIdx] = BX_NEW(g_allocator, OVRBufferGL); - m_ovr.m_eyeBuffers[eyeIdx]->create(m_ovr.m_hmd, eyeIdx); + m_ovr.m_eyeBuffers[ii] = &m_ovrBuffers[ii]; + m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii); } } // recreate mirror texture - m_ovr.m_mirror = BX_NEW(g_allocator, OVRMirrorGL); + m_ovr.m_mirror = &m_ovrMirror; m_ovr.m_mirror->create(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height); } } @@ -3309,6 +3309,10 @@ namespace bgfx { namespace gl const char* m_glslVersion; OVR m_ovr; +#if BGFX_CONFIG_USE_OVR + OVRMirrorGL m_ovrMirror; + OVRBufferGL m_ovrBuffers[2]; +#endif // BGFX_CONFIG_USE_OVR }; RendererContextGL* s_renderGL;