Skip to content

Commit

Permalink
Combine OVRBufferI and OVRMirrorI into a single interface
Browse files Browse the repository at this point in the history
Simplify the renderer interface for VR to separate the OVR
implementation from the overall HMD foundation.

Part of merging OpenVR back upstream.
  • Loading branch information
mendsley committed Sep 15, 2016
1 parent 2703ff8 commit eec95ae
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 396 deletions.
39 changes: 14 additions & 25 deletions src/hmd_ovr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ namespace bgfx
OVR::OVR()
: m_hmd(NULL)
, m_enabled(false)
, m_mirror(NULL)
, m_render(NULL)
, m_frameIndex(0)
, m_sensorSampleTime(0)
{
memset(m_eyeBuffers, 0, sizeof(m_eyeBuffers));
}

OVR::~OVR()
Expand Down Expand Up @@ -73,19 +72,10 @@ namespace bgfx
{
BX_CHECK(!m_enabled, "HMD not disabled.");

for (uint32_t ii = 0; ii < 2; ++ii)
{
if (NULL != m_eyeBuffers[ii])
{
m_eyeBuffers[ii]->destroy(m_hmd);
m_eyeBuffers[ii] = NULL;
}
}

if (NULL != m_mirror)
if (NULL != m_render)
{
m_mirror->destroy(m_hmd);
m_mirror = NULL;
m_render->destroy(m_hmd);
m_render = NULL;
}

ovr_Destroy(m_hmd);
Expand All @@ -97,13 +87,13 @@ namespace bgfx
{
_viewport->m_x = 0;
_viewport->m_y = 0;
_viewport->m_width = m_eyeBuffers[_eye]->m_eyeTextureSize.w;
_viewport->m_height = m_eyeBuffers[_eye]->m_eyeTextureSize.h;
_viewport->m_width = m_render->m_eyeTextureSize[_eye].w;
_viewport->m_height = m_render->m_eyeTextureSize[_eye].h;
}

void OVR::renderEyeStart(uint8_t _eye)
{
m_eyeBuffers[_eye]->render(m_hmd);
m_render->startEyeRender(m_hmd, _eye);
}

bool OVR::postReset()
Expand All @@ -128,8 +118,7 @@ namespace bgfx
if (m_enabled)
{
// on window resize this will recreate the mirror texture in ovrPostReset
m_mirror->destroy(m_hmd);
m_mirror = NULL;
m_render->preReset(m_hmd);
m_enabled = false;
}
}
Expand All @@ -154,8 +143,8 @@ namespace bgfx

for (uint32_t ii = 0; ii < 2; ++ii)
{
m_eyeBuffers[ii]->postRender(m_hmd);
result = ovr_CommitTextureSwapChain(m_hmd, m_eyeBuffers[ii]->m_textureSwapChain);
m_render->postRender(m_hmd, ii);
result = ovr_CommitTextureSwapChain(m_hmd, m_render->m_textureSwapChain[ii]);
if (!OVR_SUCCESS(result) )
{
return DeviceLost;
Expand All @@ -177,11 +166,11 @@ namespace bgfx

for (uint32_t ii = 0; ii < 2; ++ii)
{
eyeLayer.ColorTexture[ii] = m_eyeBuffers[ii]->m_textureSwapChain;
eyeLayer.ColorTexture[ii] = m_render->m_textureSwapChain[ii];
eyeLayer.Viewport[ii].Pos.x = 0;
eyeLayer.Viewport[ii].Pos.y = 0;
eyeLayer.Viewport[ii].Size.w = m_eyeBuffers[ii]->m_eyeTextureSize.w;
eyeLayer.Viewport[ii].Size.h = m_eyeBuffers[ii]->m_eyeTextureSize.h;
eyeLayer.Viewport[ii].Size.w = m_render->m_eyeTextureSize[ii].w;
eyeLayer.Viewport[ii].Size.h = m_render->m_eyeTextureSize[ii].h;
eyeLayer.Fov[ii] = m_hmdDesc.DefaultEyeFov[ii];
eyeLayer.RenderPose[ii] = m_pose[ii];
eyeLayer.SensorSampleTime = m_sensorSampleTime;
Expand All @@ -199,7 +188,7 @@ namespace bgfx
// perform mirror texture blit right after the entire frame is submitted to HMD
if (result != ovrSuccess_NotVisible)
{
m_mirror->blit(m_hmd);
m_render->blitMirror(m_hmd);
}

m_hmdToEyeOffset[0] = m_erd[0].HmdToEyeOffset;
Expand Down
36 changes: 16 additions & 20 deletions src/hmd_ovr.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,26 @@

namespace bgfx
{
// single eye buffer
struct OVRBufferI
// render data for both eyes and mirrored output
struct BX_NO_VTABLE OVRRenderI
{
virtual ~OVRBufferI() {};
virtual void create(const ovrSession& _session, int _eyeIdx, int _msaaSamples) = 0;
virtual ~OVRRenderI() = 0;
virtual void create(const ovrSession& _session, int _msaaSamples, int _mirrorWidth, int _mirrorHeight) = 0;
virtual void destroy(const ovrSession& _session) = 0;
virtual void render(const ovrSession& _session) = 0;
virtual void postRender(const ovrSession& _session) = 0;
ovrSizei m_eyeTextureSize;
ovrTextureSwapChain m_textureSwapChain;
virtual void preReset(const ovrSession& _session) = 0;
virtual void startEyeRender(const ovrSession& _session, int _eyeIdx) = 0;
virtual void postRender(const ovrSession& _session, int _eyeIdx) = 0;
virtual void blitMirror(const ovrSession& _session) = 0;

ovrSizei m_eyeTextureSize[2];
ovrTextureSwapChain m_textureSwapChain[2];
ovrMirrorTexture m_mirrorTexture;
ovrMirrorTextureDesc m_mirrorTextureDesc;
};

// mirrored window output
struct OVRMirrorI
inline OVRRenderI::~OVRRenderI()
{
virtual ~OVRMirrorI() {};
virtual void create(const ovrSession& _session, int windowWidth, int windowHeight) = 0;
virtual void destroy(const ovrSession& _session) = 0;
virtual void blit(const ovrSession& _session) = 0;

ovrMirrorTexture m_mirrorTexture;
ovrMirrorTextureDesc m_mirrorTextureDesc;
};
}

struct OVR
{
Expand Down Expand Up @@ -93,8 +90,7 @@ namespace bgfx
ovrPosef m_pose[2];
ovrVector3f m_hmdToEyeOffset[2];
ovrSizei m_hmdSize;
OVRBufferI *m_eyeBuffers[2];
OVRMirrorI *m_mirror;
OVRRenderI *m_render;
uint64_t m_frameIndex;
double m_sensorSampleTime;
bool m_enabled;
Expand Down
Loading

0 comments on commit eec95ae

Please sign in to comment.