Moved HMD tracking into flip. Removed unnecessary frame data when using single-threaded renderer.

This commit is contained in:
Branimir Karadžić 2015-04-15 20:59:00 -07:00
parent 4098dbb8fb
commit 66edb6c566
8 changed files with 44 additions and 65 deletions

View file

@ -934,14 +934,13 @@ namespace bgfx
m_exit = false;
m_frames = 0;
m_render = &m_frame[0];
m_submit = &m_frame[1];
m_debug = BGFX_DEBUG_NONE;
m_submit->create();
m_render->create();
#if BGFX_CONFIG_MULTITHREADED
m_render->create();
if (s_renderFrameCalled)
{
// When bgfx::renderFrame is called before init render thread
@ -1029,9 +1028,12 @@ namespace bgfx
m_clearQuad.shutdown();
frame();
destroyTransientVertexBuffer(m_submit->m_transientVb);
destroyTransientIndexBuffer(m_submit->m_transientIb);
frame();
if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) )
{
destroyTransientVertexBuffer(m_submit->m_transientVb);
destroyTransientIndexBuffer(m_submit->m_transientIb);
frame();
}
frame(); // If any VertexDecls needs to be destroyed.
@ -1054,10 +1056,11 @@ namespace bgfx
{
m_thread.shutdown();
}
m_render->destroy();
#endif // BGFX_CONFIG_MULTITHREADED
m_submit->destroy();
m_render->destroy();
if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
{
@ -1159,10 +1162,6 @@ namespace bgfx
// release render thread
gameSemPost();
#if !BGFX_CONFIG_MULTITHREADED
renderFrame();
#endif // BGFX_CONFIG_MULTITHREADED
}
void Context::swap()
@ -1186,9 +1185,12 @@ namespace bgfx
}
m_submit->finish();
Frame* temp = m_render;
m_render = m_submit;
m_submit = temp;
bx::xchg(m_render, m_submit);
if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) )
{
renderFrame();
}
m_frames++;
m_submit->start();
@ -1208,7 +1210,7 @@ namespace bgfx
if (m_rendererInitialized
&& !m_flipAfterRender)
{
m_renderCtx->flip();
m_renderCtx->flip(m_render->m_hmd);
}
gameSemWait();
@ -1225,7 +1227,7 @@ namespace bgfx
if (m_rendererInitialized
&& m_flipAfterRender)
{
m_renderCtx->flip();
m_renderCtx->flip(m_render->m_hmd);
}
return m_exit;

View file

@ -1830,7 +1830,7 @@ namespace bgfx
virtual ~RendererContextI() = 0;
virtual RendererType::Enum getRendererType() const = 0;
virtual const char* getRendererName() const = 0;
virtual void flip() = 0;
virtual void flip(HMD& _hmd) = 0;
virtual void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) = 0;
virtual void destroyIndexBuffer(IndexBufferHandle _handle) = 0;
virtual void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) = 0;
@ -1883,7 +1883,7 @@ namespace bgfx
{
Context()
: m_render(&m_frame[0])
, m_submit(&m_frame[1])
, m_submit(&m_frame[BGFX_CONFIG_MULTITHREADED ? 1 : 0])
, m_numFreeDynamicIndexBufferHandles(0)
, m_numFreeDynamicVertexBufferHandles(0)
, m_clearColorDirty(0)
@ -3425,7 +3425,7 @@ namespace bgfx
}
#endif // BGFX_CONFIG_MULTITHREADED
Frame m_frame[2];
Frame m_frame[1+(BGFX_CONFIG_MULTITHREADED ? 1 : 0)];
Frame* m_render;
Frame* m_submit;

View file

@ -39,19 +39,6 @@ namespace bgfx
{
switch (_config->Header.API)
{
#if BGFX_CONFIG_RENDERER_DIRECT3D9
case ovrRenderAPI_D3D9:
{
ovrD3D9ConfigData* data = (ovrD3D9ConfigData*)_config;
# if OVR_VERSION > OVR_VERSION_043
m_rtSize = data->Header.BackBufferSize;
# else
m_rtSize = data->Header.RTSize;
# endif // OVR_VERSION > OVR_VERSION_043
}
break;
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9
#if BGFX_CONFIG_RENDERER_DIRECT3D11
case ovrRenderAPI_D3D11:
{
@ -202,7 +189,7 @@ ovrError:
m_debug = false;
}
bool OVR::swap()
bool OVR::swap(HMD& _hmd)
{
if (NULL == m_hmd)
{
@ -216,6 +203,8 @@ ovrError:
m_warning = !ovrHmd_DismissHSWDisplay(m_hmd);
}
getEyePose(_hmd);
m_timing = ovrHmd_BeginFrame(m_hmd, 0);
#if OVR_VERSION > OVR_VERSION_042

View file

@ -25,22 +25,9 @@
# include <OVR_CAPI.h>
# endif // OVR_VERSION < OVR_VERSION_050
# if BGFX_CONFIG_RENDERER_DIRECT3D9
# define OVR_D3D_VERSION 9
# if OVR_VERSION < OVR_VERSION_050
# include <OVR_D3D.h>
# else
# include <OVR_CAPI_D3D.h>
# endif
# endif // BGFX_CONFIG_RENDERER_DIRECT3D9
# if BGFX_CONFIG_RENDERER_DIRECT3D11
# ifdef OVR_CAPI_D3D_h
# undef OVR_CAPI_D3D_h
# undef OVR_D3D_VERSION
# endif // OVR_CAPI_D3D_h
# define OVR_D3D_VERSION 11
# if OVR_VERSION < OVR_VERSION_050
# define OVR_D3D_VERSION 11
# include <OVR_D3D.h>
# else
# include <OVR_CAPI_D3D.h>
@ -83,7 +70,7 @@ namespace bgfx
bool postReset(void* _nwh, ovrRenderAPIConfig* _config, bool _debug = false);
void postReset(const ovrTexture& _texture);
void preReset();
bool swap();
bool swap(HMD& _hmd);
void recenter();
void getEyePose(HMD& _hmd);
void getSize(uint32_t& _width, uint32_t& _height) const
@ -143,8 +130,9 @@ namespace bgfx
return false;
}
bool swap()
bool swap(HMD& _hmd)
{
getEyePose(_hmd);
return false;
}

View file

@ -1297,7 +1297,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
;
}
void flip() BX_OVERRIDE
void flip(HMD& _hmd) BX_OVERRIDE
{
if (NULL != m_swapChain)
{
@ -1314,7 +1314,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
if (SUCCEEDED(hr) )
{
if (!m_ovr.swap() )
if (!m_ovr.swap(_hmd) )
{
hr = m_swapChain->Present(syncInterval, 0);
}
@ -3205,11 +3205,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug();
_render->m_hmdEnabled = hmdEnabled;
if (hmdEnabled)
{
HMD& hmd = _render->m_hmd;
m_ovr.getEyePose(hmd);
}
// if (hmdEnabled)
// {
// HMD& hmd = _render->m_hmd;
// m_ovr.getEyePose(hmd);
// }
ViewState viewState(_render, hmdEnabled);

View file

@ -1144,7 +1144,7 @@ namespace bgfx { namespace d3d9
;
}
void flip() BX_OVERRIDE
void flip(HMD& /*_hmd*/) BX_OVERRIDE
{
if (NULL != m_device)
{

View file

@ -1600,7 +1600,7 @@ namespace bgfx { namespace gl
return BGFX_RENDERER_OPENGL_NAME;
}
void flip()
void flip(HMD& _hmd)
{
if (m_flip)
{
@ -1609,7 +1609,7 @@ namespace bgfx { namespace gl
m_glctx.swap(m_frameBuffers[m_windows[ii].idx].m_swapChain);
}
if (!m_ovr.swap() )
if (!m_ovr.swap(_hmd) )
{
m_glctx.swap();
}
@ -4553,11 +4553,11 @@ namespace bgfx { namespace gl
const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug();
_render->m_hmdEnabled = hmdEnabled;
if (hmdEnabled)
{
HMD& hmd = _render->m_hmd;
m_ovr.getEyePose(hmd);
}
// if (hmdEnabled)
// {
// HMD& hmd = _render->m_hmd;
// m_ovr.getEyePose(hmd);
// }
ViewState viewState(_render, hmdEnabled);

View file

@ -29,7 +29,7 @@ namespace bgfx { namespace noop
return BGFX_RENDERER_NULL_NAME;
}
void flip() BX_OVERRIDE
void flip(HMD& /*_hmd*/) BX_OVERRIDE
{
}