This commit is contained in:
Branimir Karadžić 2016-04-04 23:04:46 -07:00
parent ace7083efa
commit 35efaf8751
6 changed files with 80 additions and 80 deletions

View File

@ -91,7 +91,7 @@ namespace bgfx
void OVR::renderEyeStart(uint8_t _eye)
{
m_eyeBuffers[_eye]->onRender(m_hmd);
m_eyeBuffers[_eye]->render(m_hmd);
}
bool OVR::postReset()
@ -142,7 +142,7 @@ namespace bgfx
// commit eyes to HMD
for (uint32_t ii = 0; ii < 2; ++ii)
{
ovr_CommitTextureSwapChain(m_hmd, m_eyeBuffers[ii]->m_swapTextureChain);
ovr_CommitTextureSwapChain(m_hmd, m_eyeBuffers[ii]->m_textureSwapChain);
}
_hmd.flags |= BGFX_HMD_RENDERING;
@ -160,7 +160,7 @@ namespace bgfx
for (uint32_t ii = 0; ii < 2; ++ii)
{
eyeLayer.ColorTexture[ii] = m_eyeBuffers[ii]->m_swapTextureChain;
eyeLayer.ColorTexture[ii] = m_eyeBuffers[ii]->m_textureSwapChain;
eyeLayer.Viewport[ii].Pos.x = 0;
eyeLayer.Viewport[ii].Pos.y = 0;
eyeLayer.Viewport[ii].Size.w = m_eyeBuffers[ii]->m_eyeTextureSize.w;

View File

@ -31,24 +31,24 @@ namespace bgfx
struct OVRBufferI
{
virtual ~OVRBufferI() {};
virtual void init(const ovrSession& _session, int _eyeIdx) = 0;
virtual void onRender(const ovrSession& _session) = 0;
virtual void create(const ovrSession& _session, int _eyeIdx) = 0;
virtual void destroy(const ovrSession& _session) = 0;
virtual void render(const ovrSession& _session) = 0;
ovrSizei m_eyeTextureSize;
ovrTextureSwapChain m_swapTextureChain;
ovrSizei m_eyeTextureSize;
ovrTextureSwapChain m_textureSwapChain;
};
// mirrored window output
struct OVRMirrorI
{
virtual ~OVRMirrorI() {};
virtual void init(const ovrSession& _session, int windowWidth, int windowHeight) = 0;
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_mirrorDesc;
ovrMirrorTextureDesc m_mirrorTextureDesc;
};
struct OVR

View File

@ -3087,13 +3087,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
if (!m_ovr.m_eyeBuffers[eyeIdx])
{
m_ovr.m_eyeBuffers[eyeIdx] = BX_NEW(g_allocator, OVRBufferD3D11);
m_ovr.m_eyeBuffers[eyeIdx]->init(m_ovr.m_hmd, eyeIdx);
m_ovr.m_eyeBuffers[eyeIdx]->create(m_ovr.m_hmd, eyeIdx);
}
}
// recreate mirror texture
m_ovr.m_mirror = BX_NEW(g_allocator, OVRMirrorD3D11);
m_ovr.m_mirror->init(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height);
m_ovr.m_mirror->create(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height);
}
}
#endif // BGFX_CONFIG_USE_OVR
@ -3547,7 +3547,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
#if BGFX_CONFIG_USE_OVR
void OVRBufferD3D11::init(const ovrSession& _session, int _eyeIdx)
void OVRBufferD3D11::create(const ovrSession& _session, int _eyeIdx)
{
ovrHmdDesc hmdDesc = ovr_GetHmdDesc(_session);
m_eyeTextureSize = ovr_GetFovTextureSize(_session, (ovrEyeType)_eyeIdx, hmdDesc.DefaultEyeFov[_eyeIdx], 1.0f);
@ -3564,7 +3564,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
desc.BindFlags = ovrTextureBind_DX_RenderTarget;
desc.StaticImage = ovrFalse;
ovrResult result = ovr_CreateTextureSwapChainDX(_session, s_renderD3D11->m_device, &desc, &m_swapTextureChain);
ovrResult result = ovr_CreateTextureSwapChainDX(_session, s_renderD3D11->m_device, &desc, &m_textureSwapChain);
if (!OVR_SUCCESS(result) )
{
@ -3573,12 +3573,12 @@ BX_PRAGMA_DIAGNOSTIC_POP();
memset(m_eyeRtv, 0, sizeof(m_eyeRtv) );
int textureCount = 0;
ovr_GetTextureSwapChainLength(_session, m_swapTextureChain, &textureCount);
ovr_GetTextureSwapChainLength(_session, m_textureSwapChain, &textureCount);
for (int ii = 0; ii < textureCount; ++ii)
{
ID3D11Texture2D* tex = NULL;
ovr_GetTextureSwapChainBufferDX(_session, m_swapTextureChain, ii, IID_PPV_ARGS(&tex) );
ovr_GetTextureSwapChainBufferDX(_session, m_textureSwapChain, ii, IID_PPV_ARGS(&tex) );
D3D11_RENDER_TARGET_VIEW_DESC rtvd = {};
rtvd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
@ -3608,11 +3608,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
DX_RELEASE(tex, 0);
}
void OVRBufferD3D11::onRender(const ovrSession& _session)
void OVRBufferD3D11::render(const ovrSession& _session)
{
// Clear and set up rendertarget
int texIndex = 0;
ovr_GetTextureSwapChainCurrentIndex(_session, m_swapTextureChain, &texIndex);
ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &texIndex);
float black[] = { 0.f, 0.f, 0.f, 0.f }; // Important that alpha=0, if want pixels to be transparent, for manual layers
s_renderD3D11->m_deviceCtx->OMSetRenderTargets(1, &m_eyeRtv[texIndex], m_depthBuffer);
@ -3636,16 +3636,16 @@ BX_PRAGMA_DIAGNOSTIC_POP();
DX_RELEASE(m_eyeRtv[ii], 0);
}
ovr_DestroyTextureSwapChain(_session, m_swapTextureChain);
ovr_DestroyTextureSwapChain(_session, m_textureSwapChain);
m_depthBuffer->Release();
}
void OVRMirrorD3D11::init(const ovrSession& _session, int _width, int _height)
void OVRMirrorD3D11::create(const ovrSession& _session, int _width, int _height)
{
m_mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
m_mirrorDesc.Width = _width;
m_mirrorDesc.Height = _height;
ovrResult result = ovr_CreateMirrorTextureDX(_session, s_renderD3D11->m_device, &m_mirrorDesc, &m_mirrorTexture);
m_mirrorTextureDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
m_mirrorTextureDesc.Width = _width;
m_mirrorTextureDesc.Height = _height;
ovrResult result = ovr_CreateMirrorTextureDX(_session, s_renderD3D11->m_device, &m_mirrorTextureDesc, &m_mirrorTexture);
if (!OVR_SUCCESS(result) )
{

View File

@ -62,9 +62,9 @@ namespace bgfx { namespace d3d11
#if BGFX_CONFIG_USE_OVR
struct OVRBufferD3D11 : public OVRBufferI
{
virtual void init(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
virtual void create(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
virtual void destroy(const ovrSession& _session) BX_OVERRIDE;
virtual void onRender(const ovrSession& _session) BX_OVERRIDE;
virtual void render(const ovrSession& _session) BX_OVERRIDE;
ID3D11RenderTargetView* m_eyeRtv[4];
ID3D11DepthStencilView* m_depthBuffer;
@ -72,7 +72,7 @@ namespace bgfx { namespace d3d11
struct OVRMirrorD3D11 : public OVRMirrorI
{
virtual void init(const ovrSession& _session, int _width, int _height) BX_OVERRIDE;
virtual void create(const ovrSession& _session, int _width, int _height) BX_OVERRIDE;
virtual void destroy(const ovrSession& session) BX_OVERRIDE;
virtual void blit(const ovrSession& session) BX_OVERRIDE;
};

View File

@ -2851,9 +2851,9 @@ 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())
if (m_ovr.postReset() )
{
for (int eyeIdx = 0; eyeIdx < ovrEye_Count; eyeIdx++)
{
@ -2861,13 +2861,13 @@ namespace bgfx { namespace gl
if (!m_ovr.m_eyeBuffers[eyeIdx])
{
m_ovr.m_eyeBuffers[eyeIdx] = BX_NEW(g_allocator, OVRBufferGL);
m_ovr.m_eyeBuffers[eyeIdx]->init(m_ovr.m_hmd, eyeIdx);
m_ovr.m_eyeBuffers[eyeIdx]->create(m_ovr.m_hmd, eyeIdx);
}
}
// recreate mirror texture
m_ovr.m_mirror = BX_NEW(g_allocator, OVRMirrorGL);
m_ovr.m_mirror->init(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height);
m_ovr.m_mirror->create(m_ovr.m_hmd, m_resolution.m_width, m_resolution.m_height);
}
}
#endif // BGFX_CONFIG_USE_OVR
@ -3319,7 +3319,7 @@ namespace bgfx { namespace gl
}
#if BGFX_CONFIG_USE_OVR
void OVRBufferGL::init(const ovrSession& session, int eyeIdx)
void OVRBufferGL::create(const ovrSession& session, int eyeIdx)
{
ovrHmdDesc hmdDesc = ovr_GetHmdDesc(session);
m_eyeTextureSize = ovr_GetFovTextureSize(session, (ovrEyeType)eyeIdx, hmdDesc.DefaultEyeFov[eyeIdx], 1.0f);
@ -3334,67 +3334,67 @@ namespace bgfx { namespace gl
desc.SampleCount = 1;
desc.StaticImage = ovrFalse;
ovr_CreateTextureSwapChainGL(session, &desc, &m_swapTextureChain);
ovr_CreateTextureSwapChainGL(session, &desc, &m_textureSwapChain);
int textureCount = 0;
ovr_GetTextureSwapChainLength(session, m_swapTextureChain, &textureCount);
ovr_GetTextureSwapChainLength(session, m_textureSwapChain, &textureCount);
for (int j = 0; j < textureCount; ++j)
{
GLuint chainTexId;
ovr_GetTextureSwapChainBufferGL(session, m_swapTextureChain, j, &chainTexId);
GL_CHECK(glBindTexture(GL_TEXTURE_2D, chainTexId));
ovr_GetTextureSwapChainBufferGL(session, m_textureSwapChain, j, &chainTexId);
GL_CHECK(glBindTexture(GL_TEXTURE_2D, chainTexId) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) );
}
GL_CHECK(glGenFramebuffers(1, &m_eyeFbo));
GL_CHECK(glGenFramebuffers(1, &m_eyeFbo) );
// create depth buffer
GL_CHECK(glGenTextures(1, &m_depthBuffer));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_depthBuffer));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GL_CHECK(glGenTextures(1, &m_depthBuffer) );
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_depthBuffer) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) );
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) );
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_eyeTextureSize.w, m_eyeTextureSize.h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_eyeTextureSize.w, m_eyeTextureSize.h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL) );
}
void OVRBufferGL::onRender(const ovrSession& session)
void OVRBufferGL::render(const ovrSession& session)
{
// set the current eye texture in swap chain
int curIndex;
ovr_GetTextureSwapChainCurrentIndex(session, m_swapTextureChain, &curIndex);
ovr_GetTextureSwapChainBufferGL(session, m_swapTextureChain, curIndex, &m_eyeTexId);
ovr_GetTextureSwapChainCurrentIndex(session, m_textureSwapChain, &curIndex);
ovr_GetTextureSwapChainBufferGL(session, m_textureSwapChain, curIndex, &m_eyeTexId);
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_eyeFbo));
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_eyeTexId, 0));
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthBuffer, 0));
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_eyeFbo) );
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_eyeTexId, 0) );
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthBuffer, 0) );
GL_CHECK(glViewport(0, 0, m_eyeTextureSize.w, m_eyeTextureSize.h));
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
GL_CHECK(glViewport(0, 0, m_eyeTextureSize.w, m_eyeTextureSize.h) );
GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
}
void OVRBufferGL::destroy(const ovrSession& session)
{
GL_CHECK(glDeleteFramebuffers(1, &m_eyeFbo));
GL_CHECK(glDeleteTextures(1, &m_depthBuffer));
GL_CHECK(glDeleteFramebuffers(1, &m_eyeFbo) );
GL_CHECK(glDeleteTextures(1, &m_depthBuffer) );
ovr_DestroyTextureSwapChain(session, m_swapTextureChain);
ovr_DestroyTextureSwapChain(session, m_textureSwapChain);
}
void OVRMirrorGL::init(const ovrSession& session, int windowWidth, int windowHeight)
void OVRMirrorGL::create(const ovrSession& session, int windowWidth, int windowHeight)
{
memset(&m_mirrorDesc, 0, sizeof(m_mirrorDesc));
m_mirrorDesc.Width = windowWidth;
m_mirrorDesc.Height = windowHeight;
m_mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
memset(&m_mirrorTextureDesc, 0, sizeof(m_mirrorTextureDesc) );
m_mirrorTextureDesc.Width = windowWidth;
m_mirrorTextureDesc.Height = windowHeight;
m_mirrorTextureDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
ovr_CreateMirrorTextureGL(session, &m_mirrorDesc, &m_mirrorTexture);
ovr_CreateMirrorTextureGL(session, &m_mirrorTextureDesc, &m_mirrorTexture);
// Fallback to doing nothing if mirror was not created. This is to prevent errors with fast window resizes
if (!m_mirrorTexture)
@ -3403,15 +3403,15 @@ namespace bgfx { namespace gl
// Configure the mirror read buffer
GLuint texId;
ovr_GetMirrorTextureBufferGL(session, m_mirrorTexture, &texId);
GL_CHECK(glGenFramebuffers(1, &m_mirrorFBO));
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO));
GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0));
GL_CHECK(glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0));
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0));
GL_CHECK(glGenFramebuffers(1, &m_mirrorFBO) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0) );
GL_CHECK(glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO));
GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO) );
BX_CHECK(false, "Could not initialize VR buffers!");
}
}
@ -3421,7 +3421,7 @@ namespace bgfx { namespace gl
if (!m_mirrorTexture)
return;
GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO));
GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFBO) );
ovr_DestroyMirrorTexture(session, m_mirrorTexture);
m_mirrorTexture = NULL;
}
@ -3432,12 +3432,12 @@ namespace bgfx { namespace gl
return;
// Blit mirror texture to back buffer
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO));
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
GLint w = m_mirrorDesc.Width;
GLint h = m_mirrorDesc.Height;
GL_CHECK(glBlitFramebuffer(0, h, w, 0, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST));
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0));
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFBO) );
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
GLint width = m_mirrorTextureDesc.Width;
GLint height = m_mirrorTextureDesc.Height;
GL_CHECK(glBlitFramebuffer(0, height, width, 0, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
}
#endif // BGFX_CONFIG_USE_OVR

View File

@ -904,9 +904,9 @@ namespace bgfx { namespace gl
#if BGFX_CONFIG_USE_OVR
struct OVRBufferGL : public OVRBufferI
{
virtual void init(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
virtual void create(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
virtual void destroy(const ovrSession& _session) BX_OVERRIDE;
virtual void onRender(const ovrSession& _session) BX_OVERRIDE;
virtual void render(const ovrSession& _session) BX_OVERRIDE;
GLuint m_eyeFbo;
GLuint m_eyeTexId;
@ -915,7 +915,7 @@ namespace bgfx { namespace gl
struct OVRMirrorGL : public OVRMirrorI
{
virtual void init(const ovrSession& _session, int _width, int _height) BX_OVERRIDE;
virtual void create(const ovrSession& _session, int _width, int _height) BX_OVERRIDE;
virtual void destroy(const ovrSession& _session) BX_OVERRIDE;
virtual void blit(const ovrSession& _session) BX_OVERRIDE;