This commit is contained in:
Branimir Karadžić 2018-07-19 20:29:03 -07:00
parent db0ec1f5db
commit 7612f88426
6 changed files with 0 additions and 665 deletions

View File

@ -94,27 +94,6 @@ function bgfxProjectBase(_kind, _defines)
}
end
if _OPTIONS["with-ovr"] then
defines {
-- "BGFX_CONFIG_MULTITHREADED=0",
"BGFX_CONFIG_USE_OVR=1",
}
includedirs {
"$(OVR_DIR)/LibOVR/Include",
}
configuration { "x32" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/Win32/Release", _ACTION) }
configuration { "x64" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/x64/Release", _ACTION) }
configuration { "x32 or x64" }
links { "libovr" }
configuration {}
end
configuration { "Debug" }
defines {
"BGFX_CONFIG_DEBUG=1",

View File

@ -8,11 +8,6 @@ newoption {
description = "Enable amalgamated build.",
}
newoption {
trigger = "with-ovr",
description = "Enable OculusVR integration.",
}
newoption {
trigger = "with-sdl",
description = "Enable SDL entry.",
@ -184,19 +179,6 @@ function exampleProjectDefaults()
configuration {}
end
if _OPTIONS["with-ovr"] then
configuration { "x32" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/Win32/Release", _ACTION) }
configuration { "x64" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/x64/Release", _ACTION) }
configuration { "x32 or x64" }
links { "libovr" }
configuration {}
end
configuration { "vs*", "x32 or x64" }
linkoptions {
"/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll

View File

@ -63,52 +63,6 @@ project ("texturev")
configuration {}
end
if _OPTIONS["with-ovr"] then
links {
"winmm",
"ws2_32",
}
-- Check for LibOVR 5.0+
if os.isdir(path.join(os.getenv("OVR_DIR"), "LibOVR/Lib/Windows/Win32/Debug/VS2012")) then
configuration { "x32", "Debug" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/Win32/Debug", _ACTION) }
configuration { "x32", "Release" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/Win32/Release", _ACTION) }
configuration { "x64", "Debug" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/x64/Debug", _ACTION) }
configuration { "x64", "Release" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Windows/x64/Release", _ACTION) }
configuration { "x32 or x64" }
links { "libovr" }
else
configuration { "x32" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/Win32", _ACTION) }
configuration { "x64" }
libdirs { path.join("$(OVR_DIR)/LibOVR/Lib/x64", _ACTION) }
configuration { "x32", "Debug" }
links { "libovrd" }
configuration { "x32", "Release" }
links { "libovr" }
configuration { "x64", "Debug" }
links { "libovr64d" }
configuration { "x64", "Release" }
links { "libovr64" }
end
configuration {}
end
configuration { "vs*" }
linkoptions {
"/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll

View File

@ -143,11 +143,6 @@
# define BGFX_CONFIG_USE_TINYSTL 1
#endif // BGFX_CONFIG_USE_TINYSTL
/// Enable OculusVR integration.
#ifndef BGFX_CONFIG_USE_OVR
# define BGFX_CONFIG_USE_OVR 0
#endif // BGFX_CONFIG_USE_OVR
/// Enable nVidia PerfHUD integration.
#ifndef BGFX_CONFIG_DEBUG_PERFHUD
# define BGFX_CONFIG_DEBUG_PERFHUD 0

View File

@ -635,29 +635,6 @@ namespace bgfx { namespace d3d11
int WINAPI d3d11Annotation_EndEvent();
void WINAPI d3d11Annotation_SetMarker(DWORD _color, LPCWSTR _name);
#if BGFX_CONFIG_USE_OVR
class VRImplOVRD3D11 : public VRImplOVR
{
public:
VRImplOVRD3D11();
virtual bool createSwapChain(const VRDesc& _desc, int _msaaSamples, int _mirrorWidth, int _mirrorHeight) override;
virtual void destroySwapChain() override;
virtual void destroyMirror() override;
virtual void makeRenderTargetActive(const VRDesc& _desc) override;
virtual bool submitSwapChain(const VRDesc& _desc) override;
private:
ID3D11DepthStencilView* m_depthBuffer;
ID3D11RenderTargetView* m_eyeRtv[4];
ID3D11RenderTargetView* m_msaaRtv;
ID3D11Texture2D* m_msaaTexture;
ovrTextureSwapChain m_textureSwapChain;
ovrMirrorTexture m_mirrorTexture;
};
#endif // BGFX_CONFIG_USE_OVR
struct RendererContextD3D11 : public RendererContextI
{
RendererContextD3D11()
@ -2055,8 +2032,6 @@ namespace bgfx { namespace d3d11
{
m_needPresent = false;
ovrPreReset();
if (m_timerQuerySupport)
{
m_gpuTimer.preReset();
@ -2111,8 +2086,6 @@ namespace bgfx { namespace d3d11
}
m_occlusionQuery.postReset();
ovrPostReset();
if (NULL == m_backBufferDepthStencil)
{
D3D11_TEXTURE2D_DESC dsd;
@ -3033,24 +3006,6 @@ namespace bgfx { namespace d3d11
return srv;
}
void ovrPostReset()
{
#if BGFX_CONFIG_USE_OVR
if (m_resolution.reset & (BGFX_RESET_HMD|BGFX_RESET_HMD_DEBUG) )
{
const uint32_t msaaSamples = 1 << ((m_resolution.reset&BGFX_RESET_MSAA_MASK) >> BGFX_RESET_MSAA_SHIFT);
m_ovr.postReset(msaaSamples, m_resolution.width, m_resolution.height);
}
#endif // BGFX_CONFIG_USE_OVR
}
void ovrPreReset()
{
#if BGFX_CONFIG_USE_OVR
m_ovr.preReset();
#endif // BGFX_CONFIG_USE_OVR
}
void capturePostReset()
{
if (m_resolution.reset&BGFX_RESET_CAPTURE)
@ -3509,229 +3464,6 @@ namespace bgfx { namespace d3d11
s_renderD3D11->m_annotation->SetMarker(_name);
}
#if BGFX_CONFIG_USE_OVR
VRImplOVRD3D11::VRImplOVRD3D11()
: m_depthBuffer(NULL)
, m_msaaRtv(NULL)
, m_msaaTexture(NULL)
, m_textureSwapChain(NULL)
, m_mirrorTexture(NULL)
{
bx::memSet(m_eyeRtv, 0, sizeof(m_eyeRtv));
}
bool VRImplOVRD3D11::createSwapChain(const VRDesc& _desc, int _msaaSamples, int _mirrorWidth, int _mirrorHeight)
{
if (!m_session)
{
return false;
}
ID3D11Device* device = s_renderD3D11->m_device;
if (NULL == m_textureSwapChain)
{
ovrTextureSwapChainDesc swapchainDesc = {};
swapchainDesc.Type = ovrTexture_2D;
swapchainDesc.Width = _desc.m_eyeSize[0].m_w + _desc.m_eyeSize[1].m_w;
swapchainDesc.Height = bx::uint32_max(_desc.m_eyeSize[0].m_h, _desc.m_eyeSize[1].m_h);
swapchainDesc.MipLevels = 1;
swapchainDesc.ArraySize = 1;
swapchainDesc.SampleCount = 1;
swapchainDesc.MiscFlags = ovrTextureMisc_DX_Typeless;
swapchainDesc.BindFlags = ovrTextureBind_DX_RenderTarget;
swapchainDesc.StaticImage = ovrFalse;
swapchainDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
ovrResult result = ovr_CreateTextureSwapChainDX(m_session, device, &swapchainDesc, &m_textureSwapChain);
if (!OVR_SUCCESS(result) )
{
return false;
}
for (int eye = 0; eye < 2; ++eye)
{
m_renderLayer.ColorTexture[eye] = m_textureSwapChain;
}
// create MSAA target
if (_msaaSamples > 1)
{
D3D11_TEXTURE2D_DESC msDesc;
msDesc.Width = swapchainDesc.Width;
msDesc.Height = swapchainDesc.Height;
msDesc.MipLevels = 1;
msDesc.ArraySize = 1;
msDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
msDesc.SampleDesc.Count = _msaaSamples;
msDesc.SampleDesc.Quality = 0;
msDesc.Usage = D3D11_USAGE_DEFAULT;
msDesc.CPUAccessFlags = 0;
msDesc.MiscFlags = 0;
msDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
DX_CHECK(device->CreateTexture2D(&msDesc, NULL, &m_msaaTexture) );
DX_CHECK(device->CreateRenderTargetView(m_msaaTexture, NULL, &m_msaaRtv) );
}
else
{
int swapchainSize;
result = ovr_GetTextureSwapChainLength(m_session, m_textureSwapChain, &swapchainSize);
if (!OVR_SUCCESS(result) )
{
destroySwapChain();
return false;
}
BX_CHECK(swapchainSize <= BX_COUNTOF(m_eyeRtv), "Too many OVR swap chain entries %d", swapchainSize);
for (int ii = 0; ii < swapchainSize; ++ii)
{
ID3D11Texture2D* texture;
ovr_GetTextureSwapChainBufferDX(m_session, m_textureSwapChain, ii, IID_PPV_ARGS(&texture) );
D3D11_RENDER_TARGET_VIEW_DESC viewDesc;
viewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
viewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
viewDesc.Texture2D.MipSlice = 0;
DX_CHECK(device->CreateRenderTargetView(texture, &viewDesc, &m_eyeRtv[ii]) );
DX_RELEASE(texture, 1);
}
}
// create depth buffer
D3D11_TEXTURE2D_DESC dbDesc = {};
dbDesc.Width = swapchainDesc.Width;
dbDesc.Height = swapchainDesc.Height;
dbDesc.MipLevels = 1;
dbDesc.ArraySize = 1;
dbDesc.Format = DXGI_FORMAT_D32_FLOAT;
dbDesc.SampleDesc.Count = _msaaSamples;
dbDesc.SampleDesc.Quality = 0;
dbDesc.Usage = D3D11_USAGE_DEFAULT;
dbDesc.CPUAccessFlags = 0;
dbDesc.MiscFlags = 0;
dbDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ID3D11Texture2D* depthTexture;
DX_CHECK(device->CreateTexture2D(&dbDesc, NULL, &depthTexture) );
DX_CHECK(device->CreateDepthStencilView(depthTexture, NULL, &m_depthBuffer) );
DX_RELEASE(depthTexture, 0);
}
if (NULL == m_mirrorTexture)
{
ovrMirrorTextureDesc mirrorDesc = {};
mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
mirrorDesc.Width = _mirrorWidth;
mirrorDesc.Height = _mirrorHeight;
ovrResult result = ovr_CreateMirrorTextureDX(m_session, device, &mirrorDesc, &m_mirrorTexture);
BX_WARN(OVR_SUCCESS(result), "Could not create D3D11 OVR mirror texture");
BX_UNUSED(result);
}
return true;
}
void VRImplOVRD3D11::destroySwapChain()
{
if (NULL != m_textureSwapChain)
{
BX_CHECK(m_session, "VRSWapChain destroyed without valid OVR session");
ovr_DestroyTextureSwapChain(m_session, m_textureSwapChain);
m_textureSwapChain = NULL;
}
for (int ii = 0, nn = BX_COUNTOF(m_eyeRtv); ii < nn; ++ii)
{
DX_RELEASE(m_eyeRtv[ii], 0);
}
DX_RELEASE(m_msaaRtv, 0);
DX_RELEASE(m_msaaTexture, 0);
DX_RELEASE(m_depthBuffer, 0);
destroyMirror();
}
void VRImplOVRD3D11::destroyMirror()
{
if (NULL != m_mirrorTexture)
{
ovr_DestroyMirrorTexture(m_session, m_mirrorTexture);
m_mirrorTexture = NULL;
}
}
void VRImplOVRD3D11::makeRenderTargetActive(const VRDesc& /*_desc*/)
{
if (NULL != m_msaaRtv)
{
s_renderD3D11->m_currentColor = m_msaaRtv;
}
else
{
int index;
ovr_GetTextureSwapChainCurrentIndex(m_session, m_textureSwapChain, &index);
s_renderD3D11->m_currentColor = m_eyeRtv[index];
}
s_renderD3D11->m_currentDepthStencil = m_depthBuffer;
}
bool VRImplOVRD3D11::submitSwapChain(const VRDesc& /* _desc */)
{
BX_CHECK(NULL != m_session, "No session in VRImplOVRD3D11::submitSwapChain. Usage error");
BX_CHECK(NULL != m_textureSwapChain, "VRImplOVRD3D11 submitted without a valid swap chain");
ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
int index;
ovr_GetTextureSwapChainCurrentIndex(m_session, m_textureSwapChain, &index);
ID3D11Texture2D* eyeTexture;
ovr_GetTextureSwapChainBufferDX(m_session, m_textureSwapChain, index, IID_PPV_ARGS(&eyeTexture));
if (NULL != m_msaaRtv)
{
deviceCtx->ResolveSubresource(eyeTexture, 0, m_msaaTexture, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
}
ovrResult result = ovr_CommitTextureSwapChain(m_session, m_textureSwapChain);
if (!OVR_SUCCESS(result) )
{
DX_RELEASE(eyeTexture, 1);
return false;
}
ovrLayerHeader* layerList = &m_renderLayer.Header;
result = ovr_SubmitFrame(m_session, 0, NULL, &layerList, 1);
if (!OVR_SUCCESS(result) )
{
DX_RELEASE(eyeTexture, 1);
return false;
}
if (result != ovrSuccess_NotVisible && NULL != m_mirrorTexture)
{
Dxgi::SwapChainI* swapChain = s_renderD3D11->m_swapChain;
ID3D11Texture2D* tex = NULL;
ovr_GetMirrorTextureBufferDX(m_session, m_mirrorTexture, IID_PPV_ARGS(&tex));
ID3D11Texture2D* backBuffer;
DX_CHECK(swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)));
deviceCtx->CopyResource(backBuffer, tex);
DX_CHECK(swapChain->Present(0, 0));
DX_RELEASE(tex, 1);
DX_RELEASE(backBuffer, 0);
}
DX_RELEASE(eyeTexture, 1);
return true;
}
#endif // BGFX_CONFIG_USE_OVR
struct UavFormat
{
DXGI_FORMAT format[3];

View File

@ -1685,32 +1685,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
BX_UNUSED(supported);
}
#if BGFX_CONFIG_USE_OVR
class VRImplOVRGL : public VRImplOVR
{
public:
VRImplOVRGL();
virtual bool createSwapChain(const VRDesc& _desc, int _msaaSamples, int _mirrorWidth, int _mirrorHeight) override;
virtual void destroySwapChain() override;
virtual void destroyMirror() override;
virtual void makeRenderTargetActive(const VRDesc& _desc) override;
virtual bool submitSwapChain(const VRDesc& _desc) override;
private:
GLuint m_eyeTarget[4];
GLuint m_depthRbo;
GLuint m_msaaTexture;
GLuint m_msaaTarget;
GLuint m_mirrorFbo;
GLint m_mirrorWidth;
GLint m_mirrorHeight;
ovrTextureSwapChain m_textureSwapChain;
ovrMirrorTexture m_mirrorTexture;
};
#endif // BGFX_CONFIG_USE_OVR
struct VendorId
{
const char* name;
@ -2572,8 +2546,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d ", ii);
}
ovrPostReset();
m_needPresent = false;
}
@ -2586,8 +2558,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
break;
}
ovrPreReset();
m_glctx.destroy();
unloadRenderDoc(m_renderdocdll);
@ -2596,8 +2566,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
void shutdown()
{
ovrPreReset();
if (m_vaoSupport)
{
GL_CHECK(glBindVertexArray(0) );
@ -2666,8 +2634,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
// Ensure the back buffer is bound as the source of the flip
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo));
// need to swap GL render context even if OVR is enabled to get
// the mirror texture in the output
m_glctx.swap();
m_needPresent = false;
}
@ -3155,9 +3121,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
m_frameBuffers[ii].postReset();
}
ovrPreReset();
ovrPostReset();
m_currentFbo = 0;
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_currentFbo) );
@ -3483,24 +3446,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
return _visible == (0 != _render->m_occlusion[_handle.idx]);
}
void ovrPostReset()
{
#if BGFX_CONFIG_USE_OVR
if (m_resolution.reset & (BGFX_RESET_HMD|BGFX_RESET_HMD_DEBUG) )
{
const uint32_t msaaSamples = 1 << ( (m_resolution.reset&BGFX_RESET_MSAA_MASK) >> BGFX_RESET_MSAA_SHIFT);
m_ovr.postReset(msaaSamples, m_resolution.width, m_resolution.height);
}
#endif // BGFX_CONFIG_USE_OVR
}
void ovrPreReset()
{
#if BGFX_CONFIG_USE_OVR
m_ovr.preReset();
#endif // BGFX_CONFIG_USE_OVR
}
void updateCapture()
{
if (m_resolution.reset&BGFX_RESET_CAPTURE)
@ -3965,258 +3910,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) );
BX_UNUSED(complete);
}
#if BGFX_CONFIG_USE_OVR
VRImplOVRGL::VRImplOVRGL()
: m_depthRbo(0)
, m_msaaTexture(0)
, m_msaaTarget(0)
, m_textureSwapChain(NULL)
, m_mirrorTexture(NULL)
{
bx::memSet(&m_eyeTarget, 0, sizeof(m_eyeTarget) );
}
static void setDefaultSamplerState()
{
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) );
}
bool VRImplOVRGL::createSwapChain(const VRDesc& _desc, int _msaaSamples, int _mirrorWidth, int _mirrorHeight)
{
if (!m_session)
{
return false;
}
if (NULL == m_textureSwapChain)
{
const GLsizei width = _desc.m_eyeSize[0].m_w + _desc.m_eyeSize[1].m_w;
const GLsizei height = bx::uint32_max(_desc.m_eyeSize[0].m_h, _desc.m_eyeSize[1].m_h);
ovrTextureSwapChainDesc swapchainDesc = {};
swapchainDesc.Type = ovrTexture_2D;
swapchainDesc.Width = width;
swapchainDesc.Height = height;
swapchainDesc.MipLevels = 1;
swapchainDesc.ArraySize = 1;
swapchainDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
swapchainDesc.SampleCount = 1;
swapchainDesc.StaticImage = ovrFalse;
ovrResult result = ovr_CreateTextureSwapChainGL(m_session, &swapchainDesc, &m_textureSwapChain);
if (!OVR_SUCCESS(result) )
{
destroySwapChain();
return false;
}
m_renderLayer.Header.Flags |= ovrLayerFlag_TextureOriginAtBottomLeft;
for (int eye = 0; eye < 2; ++eye)
{
m_renderLayer.ColorTexture[eye] = m_textureSwapChain;
}
// create depth buffer
GL_CHECK(glGenRenderbuffers(1, &m_depthRbo));
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthRbo));
if (_msaaSamples > 1)
{
GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaaSamples, GL_DEPTH_COMPONENT32F, width, height));
}
else
{
GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, width, height));
}
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0));
int count;
result = ovr_GetTextureSwapChainLength(m_session, m_textureSwapChain, &count);
if (!OVR_SUCCESS(result) )
{
destroySwapChain();
return false;
}
BX_CHECK(count <= BX_COUNTOF(m_eyeTarget), "Too many OVR swap chain textures. %d", count);
for (int ii = 0; ii < count; ++ii)
{
GLuint texture;
ovr_GetTextureSwapChainBufferGL(m_session, m_textureSwapChain, ii, &texture);
// create eye target
GL_CHECK(glGenFramebuffers(1, &m_eyeTarget[ii]) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_eyeTarget[ii]) );
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0) );
if (2 > _msaaSamples && 0 != m_depthRbo)
{
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRbo) );
}
frameBufferValidate();
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
}
// create MSAA target
if (1 < _msaaSamples)
{
GL_CHECK(glGenTextures(1, &m_msaaTexture) );
GL_CHECK(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_msaaTexture) );
GL_CHECK(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaSamples, GL_RGBA, width, height, GL_TRUE) );
setDefaultSamplerState();
GL_CHECK(glGenFramebuffers(1, &m_msaaTarget) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaTarget) );
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_msaaTexture, 0) );
if (0 != m_depthRbo)
{
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRbo) );
}
frameBufferValidate();
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
}
}
if (NULL == m_mirrorTexture)
{
m_mirrorFbo = 0;
ovrMirrorTextureDesc mirrorDesc = {};
mirrorDesc.Width = _mirrorWidth;
mirrorDesc.Height = _mirrorHeight;
mirrorDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
// Fallback to doing nothing if mirror was not created. This is to prevent errors with fast window resizes
ovr_CreateMirrorTextureGL(m_session, &mirrorDesc, &m_mirrorTexture);
if (m_mirrorTexture)
{
m_mirrorWidth = _mirrorWidth;
m_mirrorHeight = _mirrorHeight;
// Configure the mirror read buffer
GLuint texId;
ovr_GetMirrorTextureBufferGL(m_session, m_mirrorTexture, &texId);
GL_CHECK(glGenFramebuffers(1, &m_mirrorFbo) );
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_mirrorFbo) );
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0) );
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0) );
frameBufferValidate();
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
}
}
return true;
}
void VRImplOVRGL::destroySwapChain()
{
destroyMirror();
if (0 != m_msaaTarget)
{
GL_CHECK(glDeleteFramebuffers(1, &m_msaaTarget) );
m_msaaTarget = 0;
}
if (0 != m_msaaTexture)
{
GL_CHECK(glDeleteTextures(1, &m_msaaTexture) );
m_msaaTexture = 0;
}
if (0 != m_depthRbo)
{
GL_CHECK(glDeleteRenderbuffers(1, &m_depthRbo) );
m_depthRbo = 0;
}
for (int ii = 0, nn = BX_COUNTOF(m_eyeTarget); ii < nn; ++ii)
{
if (0 != m_eyeTarget[ii])
{
GL_CHECK(glDeleteFramebuffers(1, &m_eyeTarget[ii]) );
m_eyeTarget[ii] = 0;
}
}
if (NULL != m_textureSwapChain)
{
ovr_DestroyTextureSwapChain(m_session, m_textureSwapChain);
m_textureSwapChain = NULL;
}
}
void VRImplOVRGL::destroyMirror()
{
if (NULL != m_mirrorTexture)
{
GL_CHECK(glDeleteFramebuffers(1, &m_mirrorFbo) );
ovr_DestroyMirrorTexture(m_session, m_mirrorTexture);
m_mirrorTexture = NULL;
}
}
void VRImplOVRGL::makeRenderTargetActive(const VRDesc& /*_desc*/)
{
if (0 != m_msaaTarget)
{
s_renderGL->m_currentFbo = m_msaaTarget;
}
else
{
int index;
ovr_GetTextureSwapChainCurrentIndex(m_session, m_textureSwapChain, &index);
s_renderGL->m_currentFbo = m_eyeTarget[index];
}
}
bool VRImplOVRGL::submitSwapChain(const VRDesc& _desc)
{
BX_CHECK(NULL != m_textureSwapChain, "VRImplOVRGL submitted without a valid swap chain");
if (0 != m_msaaTarget)
{
const uint32_t width = _desc.m_eyeSize[0].m_w+_desc.m_eyeSize[1].m_w;
const uint32_t height = _desc.m_eyeSize[0].m_h;
int index;
ovr_GetTextureSwapChainCurrentIndex(m_session, m_textureSwapChain, &index);
// resolve MSAA
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_msaaTarget) );
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_eyeTarget[index]) );
GL_CHECK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
}
ovrResult result = ovr_CommitTextureSwapChain(m_session, m_textureSwapChain);
if (!OVR_SUCCESS(result) )
{
return false;
}
ovrLayerHeader* layerList = &m_renderLayer.Header;
result = ovr_SubmitFrame(m_session, 0, &m_viewScale, &layerList, 1);
if (!OVR_SUCCESS(result) )
{
return false;
}
if (result != ovrSuccess_NotVisible && NULL != m_mirrorTexture)
{
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_mirrorFbo) );
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
GL_CHECK(glBlitFramebuffer(0, m_mirrorHeight, m_mirrorWidth, 0, 0, 0, m_mirrorWidth, m_mirrorHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) );
}
return true;
}
#endif // BGFX_CONFIG_USE_OVR
const char* glslTypeName(GLuint _type)
{
#define GLSL_TYPE(_ty) case _ty: return #_ty