summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src')
-rw-r--r--3rdparty/bgfx/src/glcontext_egl.h4
-rw-r--r--3rdparty/bgfx/src/hmd_openvr.cpp95
-rw-r--r--3rdparty/bgfx/src/hmd_openvr.h18
-rw-r--r--3rdparty/bgfx/src/hmd_ovr.cpp3
-rw-r--r--3rdparty/bgfx/src/hmd_ovr.h4
-rw-r--r--3rdparty/bgfx/src/renderer_d3d11.cpp360
-rw-r--r--3rdparty/bgfx/src/renderer_d3d11.h7
-rw-r--r--3rdparty/bgfx/src/renderer_gl.cpp104
-rw-r--r--3rdparty/bgfx/src/renderer_gl.h15
9 files changed, 462 insertions, 148 deletions
diff --git a/3rdparty/bgfx/src/glcontext_egl.h b/3rdparty/bgfx/src/glcontext_egl.h
index 95323fe419a..767879c8349 100644
--- a/3rdparty/bgfx/src/glcontext_egl.h
+++ b/3rdparty/bgfx/src/glcontext_egl.h
@@ -10,6 +10,10 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
+#if defined(Success)
+// X11 defines Success
+# undef Success
+#endif // defined(Success)
namespace bgfx { namespace gl
{
diff --git a/3rdparty/bgfx/src/hmd_openvr.cpp b/3rdparty/bgfx/src/hmd_openvr.cpp
new file mode 100644
index 00000000000..8e873032154
--- /dev/null
+++ b/3rdparty/bgfx/src/hmd_openvr.cpp
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ */
+
+#include "hmd_openvr.h"
+
+BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-variable")
+#include <openvr/openvr_capi.h>
+
+namespace bgfx
+{
+#if BX_PLATFORM_WINDOWS
+# define VR_CALLTYPE __cdecl
+#else
+# define VR_CALLTYPE
+#endif
+
+ typedef uint32_t (VR_CALLTYPE *PFN_VR_INITINTERNAL)(EVRInitError* peError, EVRApplicationType eType);
+ typedef void (VR_CALLTYPE *PFN_VR_SHUTDOWNINTERNAL)();
+ typedef bool (VR_CALLTYPE *PFN_VR_ISHMDPRESENT)();
+ typedef void* (VR_CALLTYPE *PFN_VR_GETGENERICINTERFACE)(const char* pchInterfaceVersion, EVRInitError* peError);
+ typedef bool (VR_CALLTYPE *PFN_VR_ISRUNTIMEINSTALLED)();
+ typedef bool (VR_CALLTYPE *PFN_VR_ISINTERFACEVERSIONVALID)(const char *pchInterfaceVersion);
+ typedef uint32_t (VR_CALLTYPE *PFN_VR_GETINITTOKEN)();
+ typedef const char* (VR_CALLTYPE *PFN_VR_GETVRINITERRORASSYMBOL)(EVRInitError error);
+ typedef const char* (VR_CALLTYPE *PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION)(EVRInitError error);
+
+ PFN_VR_INITINTERNAL VR_InitInternal;
+ PFN_VR_SHUTDOWNINTERNAL VR_ShutdownInternal;
+ PFN_VR_ISHMDPRESENT VR_IsHmdPresent;
+ PFN_VR_GETGENERICINTERFACE VR_GetGenericInterface;
+ PFN_VR_ISRUNTIMEINSTALLED VR_IsRuntimeInstalled;
+ PFN_VR_ISINTERFACEVERSIONVALID VR_IsInterfaceVersionValid;
+ PFN_VR_GETINITTOKEN VR_GetInitToken;
+ PFN_VR_GETVRINITERRORASSYMBOL VR_GetVRInitErrorAsSymbol;
+ PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION VR_GetVRInitErrorAsEnglishDescription;
+
+ void* loadOpenVR()
+ {
+ void* openvrdll = bx::dlopen(
+#if BX_PLATFORM_LINUX
+ "libopenvr_api.so"
+#elif BX_PLATFORM_OSX
+ "libopenvr_api.dylib"
+#else
+ "openvr_api.dll"
+#endif // BX_PLATFORM_*
+ );
+ if (NULL != openvrdll)
+ {
+ VR_InitInternal = (PFN_VR_INITINTERNAL )bx::dlsym(openvrdll, "VR_InitInternal");
+ VR_ShutdownInternal = (PFN_VR_SHUTDOWNINTERNAL )bx::dlsym(openvrdll, "VR_ShutdownInternal");
+ VR_IsHmdPresent = (PFN_VR_ISHMDPRESENT )bx::dlsym(openvrdll, "VR_IsHmdPresent");
+ VR_GetGenericInterface = (PFN_VR_GETGENERICINTERFACE )bx::dlsym(openvrdll, "VR_GetGenericInterface");
+ VR_IsRuntimeInstalled = (PFN_VR_ISRUNTIMEINSTALLED )bx::dlsym(openvrdll, "VR_IsRuntimeInstalled");
+ VR_IsInterfaceVersionValid = (PFN_VR_ISINTERFACEVERSIONVALID)bx::dlsym(openvrdll, "VR_IsInterfaceVersionValid");
+ VR_GetInitToken = (PFN_VR_GETINITTOKEN )bx::dlsym(openvrdll, "VR_GetInitToken");
+ VR_GetVRInitErrorAsSymbol = (PFN_VR_GETVRINITERRORASSYMBOL )bx::dlsym(openvrdll, "VR_GetVRInitErrorAsSymbol");
+ VR_GetVRInitErrorAsEnglishDescription = (PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION)bx::dlsym(openvrdll, "VR_GetVRInitErrorAsEnglishDescription");
+
+ if (NULL == VR_InitInternal
+ && NULL == VR_ShutdownInternal
+ && NULL == VR_IsHmdPresent
+ && NULL == VR_GetGenericInterface
+ && NULL == VR_IsRuntimeInstalled
+ && NULL == VR_IsInterfaceVersionValid
+ && NULL == VR_GetInitToken
+ && NULL == VR_GetVRInitErrorAsSymbol
+ && NULL == VR_GetVRInitErrorAsEnglishDescription)
+ {
+ bx::dlclose(openvrdll);
+ return NULL;
+ }
+
+ EVRInitError err;
+ uint32_t token = VR_InitInternal(&err, EVRApplicationType_VRApplication_Scene);
+ BX_UNUSED(token);
+
+ BX_TRACE("OpenVR: HMD is %spresent, Runtime is %sinstalled."
+ , VR_IsHmdPresent() ? "" : "not "
+ , VR_IsRuntimeInstalled() ? "" : "not "
+ );
+ }
+
+ return openvrdll;
+ }
+
+ void unloadOpenVR(void* _openvrdll)
+ {
+ VR_ShutdownInternal();
+ bx::dlclose(_openvrdll);
+ }
+
+} // namespace bgfx
diff --git a/3rdparty/bgfx/src/hmd_openvr.h b/3rdparty/bgfx/src/hmd_openvr.h
new file mode 100644
index 00000000000..262f8c947a1
--- /dev/null
+++ b/3rdparty/bgfx/src/hmd_openvr.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ */
+
+#ifndef BGFX_OPENVR_H_HEADER_GUARD
+#define BGFX_OPENVR_H_HEADER_GUARD
+
+#include "bgfx_p.h"
+
+namespace bgfx
+{
+ void* loadOpenVR();
+ void unloadOpenVR(void*);
+
+} // namespace bgfx
+
+#endif // BGFX_OPENVR_H_HEADER_GUARD
diff --git a/3rdparty/bgfx/src/hmd_ovr.cpp b/3rdparty/bgfx/src/hmd_ovr.cpp
index a3befb6549c..7d3109dbd45 100644
--- a/3rdparty/bgfx/src/hmd_ovr.cpp
+++ b/3rdparty/bgfx/src/hmd_ovr.cpp
@@ -17,6 +17,8 @@ namespace bgfx
#if BGFX_CONFIG_DEBUG
# define OVR_CHECK(_call) _OVR_CHECK(_call)
+#else
+# define OVR_CHECK(_call) _call
#endif // BGFX_CONFIG_DEBUG
OVR::OVR()
@@ -152,6 +154,7 @@ 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);
if (!OVR_SUCCESS(result) )
{
diff --git a/3rdparty/bgfx/src/hmd_ovr.h b/3rdparty/bgfx/src/hmd_ovr.h
index e30aa878f52..675e711c01e 100644
--- a/3rdparty/bgfx/src/hmd_ovr.h
+++ b/3rdparty/bgfx/src/hmd_ovr.h
@@ -31,10 +31,10 @@ namespace bgfx
struct OVRBufferI
{
virtual ~OVRBufferI() {};
- virtual void create(const ovrSession& _session, int _eyeIdx) = 0;
+ virtual void create(const ovrSession& _session, int _eyeIdx, int _msaaSamples) = 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;
};
diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp
index 539ab426f71..140f6a344c1 100644
--- a/3rdparty/bgfx/src/renderer_d3d11.cpp
+++ b/3rdparty/bgfx/src/renderer_d3d11.cpp
@@ -1076,13 +1076,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
DX_RELEASE(device, 2);
}
+ memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) );
hr = adapter->GetDesc(&m_adapterDesc);
- if (FAILED(hr) )
- {
- BX_TRACE("Unable to create Direct3D11 device.");
- DX_RELEASE(adapter, 2);
- goto error;
- }
+ BX_WARN(SUCCEEDED(hr), "Adapter GetDesc failed 0x%08x.", hr);
g_caps.vendorId = 0 == m_adapterDesc.VendorId
? BGFX_PCI_ID_SOFTWARE_RASTERIZER
@@ -1354,140 +1350,168 @@ BX_PRAGMA_DIAGNOSTIC_POP();
if (DXGI_FORMAT_UNKNOWN != fmt)
{
- struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
+ if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) )
{
- DXGI_FORMAT InFormat;
- UINT OutFormatSupport;
- };
+ struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
+ {
+ DXGI_FORMAT InFormat;
+ UINT OutFormatSupport;
+ };
- D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2
- data.InFormat = fmt;
- hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) );
- if (SUCCEEDED(hr) )
- {
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURE2D
- | D3D11_FORMAT_SUPPORT_TEXTURE3D
- | D3D11_FORMAT_SUPPORT_TEXTURECUBE
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_2D
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2
+ data.InFormat = fmt;
+ hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) );
+ if (SUCCEEDED(hr) )
+ {
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_TEXTURE2D
+ | D3D11_FORMAT_SUPPORT_TEXTURE3D
+ | D3D11_FORMAT_SUPPORT_TEXTURECUBE
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_2D
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURE3D
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_3D
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_TEXTURE3D
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_3D
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURECUBE
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_CUBE
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_TEXTURECUBE
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_CUBE
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_BUFFER
- | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER
- | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_BUFFER
+ | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER
+ | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_SHADER_LOAD
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_SHADER_LOAD
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_RENDER_TARGET
- | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_RENDER_TARGET
+ | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_MSAA
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_MSAA
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
+ }
+ else
+ {
+ BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) );
+ }
+
+ if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) )
+ {
+ // clear image flag for additional testing
+ support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE;
+
+ data.InFormat = s_textureFormat[ii].m_fmt;
+ hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) );
+ if (SUCCEEDED(hr) )
+ {
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD
+ | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
+ }
+ }
}
else
{
- BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) );
+ support |= 0
+ | BGFX_CAPS_FORMAT_TEXTURE_2D
+ | BGFX_CAPS_FORMAT_TEXTURE_3D
+ | BGFX_CAPS_FORMAT_TEXTURE_CUBE
+ | BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ | BGFX_CAPS_FORMAT_TEXTURE_VERTEX
+ | BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
+ | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA
+ | BGFX_CAPS_FORMAT_TEXTURE_MSAA
+ ;
}
+ }
- if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) )
+ if (DXGI_FORMAT_UNKNOWN != fmtSrgb)
+ {
+ if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) )
{
- // clear image flag for additional testing
- support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE;
+ struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
+ {
+ DXGI_FORMAT InFormat;
+ UINT OutFormatSupport;
+ };
- data.InFormat = s_textureFormat[ii].m_fmt;
- hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) );
+ D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2
+ data.InFormat = fmtSrgb;
+ hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) );
if (SUCCEEDED(hr) )
{
support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD
- | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE
+ | D3D11_FORMAT_SUPPORT_TEXTURE2D
) )
- ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE
+ ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
- }
- }
- }
-
- if (DXGI_FORMAT_UNKNOWN != fmtSrgb)
- {
- struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
- {
- DXGI_FORMAT InFormat;
- UINT OutFormatSupport;
- };
- D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2
- data.InFormat = fmtSrgb;
- hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) );
- if (SUCCEEDED(hr) )
- {
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURE2D
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
-
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURE3D
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_TEXTURE3D
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
- support |= 0 != (data.OutFormatSupport & (0
- | D3D11_FORMAT_SUPPORT_TEXTURECUBE
- ) )
- ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
- : BGFX_CAPS_FORMAT_TEXTURE_NONE
- ;
+ support |= 0 != (data.OutFormatSupport & (0
+ | D3D11_FORMAT_SUPPORT_TEXTURECUBE
+ ) )
+ ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
+ : BGFX_CAPS_FORMAT_TEXTURE_NONE
+ ;
+ }
+ else
+ {
+ BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) );
+ }
}
else
{
- BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) );
+ support |= 0
+ | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB
+ | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB
+ | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
+ ;
}
}
@@ -2132,7 +2156,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
ovrPostReset();
// If OVR doesn't create separate depth stencil view, create default one.
- if (NULL == m_backBufferDepthStencil)
+ if (!m_ovr.isEnabled() && NULL == m_backBufferDepthStencil)
{
D3D11_TEXTURE2D_DESC dsd;
dsd.Width = getBufferWidth();
@@ -3096,13 +3120,15 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{
if (m_ovr.postReset() )
{
+ const uint32_t msaaSamples = 1 << ((m_resolution.m_flags&BGFX_RESET_MSAA_MASK) >> BGFX_RESET_MSAA_SHIFT);
+
for (uint32_t ii = 0; ii < 2; ++ii)
{
// eye buffers need to be initialized only once during application lifetime
if (NULL == m_ovr.m_eyeBuffers[ii])
{
m_ovr.m_eyeBuffers[ii] = &m_ovrBuffers[ii];
- m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii);
+ m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii, msaaSamples);
}
}
@@ -3566,10 +3592,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
#if BGFX_CONFIG_USE_OVR
- void OVRBufferD3D11::create(const ovrSession& _session, int _eyeIdx)
+ void OVRBufferD3D11::create(const ovrSession& _session, int _eyeIdx, int _msaaSamples)
{
ovrHmdDesc hmdDesc = ovr_GetHmdDesc(_session);
m_eyeTextureSize = ovr_GetFovTextureSize(_session, (ovrEyeType)_eyeIdx, hmdDesc.DefaultEyeFov[_eyeIdx], 1.0f);
+ m_msaaTexture = NULL;
+ m_msaaRtv = NULL;
+ m_msaaSv = NULL;
ovrTextureSwapChainDesc desc = {};
desc.Type = ovrTexture_2D;
@@ -3617,7 +3646,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
dbDesc.MipLevels = 1;
dbDesc.ArraySize = 1;
dbDesc.Format = DXGI_FORMAT_D32_FLOAT;
- dbDesc.SampleDesc.Count = 1;
+ dbDesc.SampleDesc.Count = _msaaSamples;
dbDesc.SampleDesc.Quality = 0;
dbDesc.Usage = D3D11_USAGE_DEFAULT;
dbDesc.CPUAccessFlags = 0;
@@ -3627,29 +3656,74 @@ BX_PRAGMA_DIAGNOSTIC_POP();
DX_CHECK(device->CreateTexture2D(&dbDesc, NULL, &tex) );
DX_CHECK(device->CreateDepthStencilView(tex, NULL, &m_depthBuffer) );
DX_RELEASE(tex, 0);
+
+ // create MSAA render target
+ if (_msaaSamples > 1)
+ {
+ D3D11_TEXTURE2D_DESC dsDesc;
+ dsDesc.Width = m_eyeTextureSize.w;
+ dsDesc.Height = m_eyeTextureSize.h;
+ dsDesc.MipLevels = 1;
+ dsDesc.ArraySize = 1;
+ dsDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ dsDesc.SampleDesc.Count = _msaaSamples;
+ dsDesc.SampleDesc.Quality = 0;
+ dsDesc.Usage = D3D11_USAGE_DEFAULT;
+ dsDesc.CPUAccessFlags = 0;
+ dsDesc.MiscFlags = 0;
+ dsDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
+
+ ID3D11Device* device = s_renderD3D11->m_device;
+ DX_CHECK(device->CreateTexture2D(&dsDesc, NULL, &m_msaaTexture));
+ DX_CHECK(device->CreateShaderResourceView(m_msaaTexture, NULL, &m_msaaSv));
+ DX_CHECK(device->CreateRenderTargetView(m_msaaTexture, NULL, &m_msaaRtv));
+ }
}
void OVRBufferD3D11::render(const ovrSession& _session)
{
- // Clear and set up rendertarget
- int texIndex = 0;
- ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &texIndex);
-
ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
-
float black[] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Important that alpha=0, if want pixels to be transparent, for manual layers
- deviceCtx->OMSetRenderTargets(1, &m_eyeRtv[texIndex], m_depthBuffer);
- deviceCtx->ClearRenderTargetView(m_eyeRtv[texIndex], black);
- deviceCtx->ClearDepthStencilView(m_depthBuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
-
- D3D11_VIEWPORT D3Dvp;
- D3Dvp.TopLeftX = 0;
- D3Dvp.TopLeftY = 0;
- D3Dvp.Width = (FLOAT)m_eyeTextureSize.w;
- D3Dvp.Height = (FLOAT)m_eyeTextureSize.h;
- D3Dvp.MinDepth = 0;
- D3Dvp.MaxDepth = 1;
- deviceCtx->RSSetViewports(1, &D3Dvp);
+
+ // render to MSAA target
+ if (NULL != m_msaaTexture)
+ {
+ deviceCtx->OMSetRenderTargets(1, &m_msaaRtv, m_depthBuffer);
+ deviceCtx->ClearRenderTargetView(m_msaaRtv, black);
+ deviceCtx->ClearDepthStencilView(m_depthBuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
+ }
+ else // MSAA disabled? render directly to eye buffer
+ {
+ int texIndex = 0;
+ ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &texIndex);
+
+ deviceCtx->OMSetRenderTargets(1, &m_eyeRtv[texIndex], m_depthBuffer);
+ deviceCtx->ClearRenderTargetView(m_eyeRtv[texIndex], black);
+ deviceCtx->ClearDepthStencilView(m_depthBuffer, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
+
+ D3D11_VIEWPORT D3Dvp;
+ D3Dvp.TopLeftX = 0;
+ D3Dvp.TopLeftY = 0;
+ D3Dvp.Width = (FLOAT)m_eyeTextureSize.w;
+ D3Dvp.Height = (FLOAT)m_eyeTextureSize.h;
+ D3Dvp.MinDepth = 0;
+ D3Dvp.MaxDepth = 1;
+ deviceCtx->RSSetViewports(1, &D3Dvp);
+ }
+ }
+
+ void OVRBufferD3D11::postRender(const ovrSession& _session)
+ {
+ if (NULL != m_msaaTexture)
+ {
+ ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx;
+ int destIndex = 0;
+ ovr_GetTextureSwapChainCurrentIndex(_session, m_textureSwapChain, &destIndex);
+ ID3D11Resource* dstTex = NULL;
+ ovr_GetTextureSwapChainBufferDX(_session, m_textureSwapChain, destIndex, IID_PPV_ARGS(&dstTex));
+ deviceCtx->ResolveSubresource(dstTex, 0, m_msaaTexture, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
+ dstTex->Release();
+ }
}
void OVRBufferD3D11::destroy(const ovrSession& _session)
@@ -3661,6 +3735,24 @@ BX_PRAGMA_DIAGNOSTIC_POP();
ovr_DestroyTextureSwapChain(_session, m_textureSwapChain);
m_depthBuffer->Release();
+
+ if (NULL != m_msaaTexture)
+ {
+ m_msaaTexture->Release();
+ m_msaaTexture = NULL;
+ }
+
+ if (NULL != m_msaaSv)
+ {
+ m_msaaSv->Release();
+ m_msaaSv = NULL;
+ }
+
+ if (NULL != m_msaaRtv)
+ {
+ m_msaaRtv->Release();
+ m_msaaRtv = NULL;
+ }
}
void OVRMirrorD3D11::create(const ovrSession& _session, int _width, int _height)
diff --git a/3rdparty/bgfx/src/renderer_d3d11.h b/3rdparty/bgfx/src/renderer_d3d11.h
index f69bbef515d..84dd0c61981 100644
--- a/3rdparty/bgfx/src/renderer_d3d11.h
+++ b/3rdparty/bgfx/src/renderer_d3d11.h
@@ -33,6 +33,7 @@ BX_PRAGMA_DIAGNOSTIC_POP()
#include "renderer_d3d.h"
#include "shader_dxbc.h"
#include "hmd_ovr.h"
+#include "hmd_openvr.h"
#include "debug_renderdoc.h"
#ifndef D3DCOLOR_ARGB
@@ -62,12 +63,16 @@ namespace bgfx { namespace d3d11
#if BGFX_CONFIG_USE_OVR
struct OVRBufferD3D11 : public OVRBufferI
{
- virtual void create(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
+ virtual void create(const ovrSession& _session, int _eyeIdx, int _msaaSamples) BX_OVERRIDE;
virtual void destroy(const ovrSession& _session) BX_OVERRIDE;
virtual void render(const ovrSession& _session) BX_OVERRIDE;
+ virtual void postRender(const ovrSession& _session) BX_OVERRIDE;
ID3D11RenderTargetView* m_eyeRtv[4];
ID3D11DepthStencilView* m_depthBuffer;
+ ID3D11Texture2D* m_msaaTexture;
+ ID3D11ShaderResourceView* m_msaaSv;
+ ID3D11RenderTargetView* m_msaaRtv;
};
struct OVRMirrorD3D11 : public OVRMirrorI
diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp
index 288f479bd45..10f5a1c3fd9 100644
--- a/3rdparty/bgfx/src/renderer_gl.cpp
+++ b/3rdparty/bgfx/src/renderer_gl.cpp
@@ -2864,13 +2864,15 @@ namespace bgfx { namespace gl
{
if (m_ovr.postReset() )
{
+ const uint32_t msaaSamples = 1 << ((m_resolution.m_flags&BGFX_RESET_MSAA_MASK) >> BGFX_RESET_MSAA_SHIFT);
+
for (uint32_t ii = 0; ii < 2; ++ii)
{
// eye buffers need to be initialized only once during application lifetime
if (NULL == m_ovr.m_eyeBuffers[ii])
{
m_ovr.m_eyeBuffers[ii] = &m_ovrBuffers[ii];
- m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii);
+ m_ovr.m_eyeBuffers[ii]->create(m_ovr.m_hmd, ii, msaaSamples);
}
}
@@ -3332,8 +3334,15 @@ namespace bgfx { namespace gl
}
#if BGFX_CONFIG_USE_OVR
- void OVRBufferGL::create(const ovrSession& _session, int _eyeIdx)
+ void OVRBufferGL::create(const ovrSession& _session, int _eyeIdx, int _msaaSamples)
{
+ m_eyeFbo = 0;
+ m_eyeTexId = 0;
+ m_depthBuffer = 0;
+ m_msaaEyeFbo = 0;
+ m_msaaEyeTexId = 0;
+ m_msaaDepthBuffer = 0;
+
ovrHmdDesc hmdDesc = ovr_GetHmdDesc(_session);
m_eyeTextureSize = ovr_GetFovTextureSize(_session, ovrEyeType(_eyeIdx), hmdDesc.DefaultEyeFov[_eyeIdx], 1.0f);
@@ -3375,6 +3384,35 @@ namespace bgfx { namespace gl
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) );
+
+ // create MSAA buffers
+ if (_msaaSamples > 1)
+ {
+ GL_CHECK(glGenFramebuffers(1, &m_msaaEyeFbo) );
+
+ // create color MSAA texture
+ GL_CHECK(glGenTextures(1, &m_msaaEyeTexId) );
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_msaaEyeTexId) );
+
+ GL_CHECK(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaSamples, GL_RGBA, m_eyeTextureSize.w, m_eyeTextureSize.h, false) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAX_LEVEL, 0) );
+
+ // create MSAA depth buffer
+ GL_CHECK(glGenTextures(1, &m_msaaDepthBuffer) );
+ GL_CHECK(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_msaaDepthBuffer) );
+
+ GL_CHECK(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaSamples, GL_DEPTH_COMPONENT, m_eyeTextureSize.w, m_eyeTextureSize.h, false) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) );
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
+
+ GL_CHECK(glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAX_LEVEL, 0) );
+ }
}
void OVRBufferGL::render(const ovrSession& _session)
@@ -3384,20 +3422,74 @@ namespace bgfx { namespace gl
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) );
-
+ if (0 != m_msaaEyeFbo)
+ {
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaEyeFbo) );
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_msaaEyeTexId, 0) );
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, m_msaaDepthBuffer, 0) );
+ }
+ else // MSAA disabled? render directly to eye buffer
+ {
+ 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) );
}
+ void OVRBufferGL::postRender(const ovrSession& /*_sesion*/)
+ {
+ if (0 != m_msaaEyeFbo && 0 != m_eyeTexId)
+ {
+ // blit the contents of MSAA FBO to the regular eye buffer "connected" to the HMD
+ GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_msaaEyeFbo));
+ GL_CHECK(glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_msaaEyeTexId, 0) );
+ GL_CHECK(glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0) );
+
+ BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_READ_FRAMEBUFFER)
+ , "glCheckFramebufferStatus failed 0x%08x"
+ , glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) );
+
+ GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_eyeFbo));
+ GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_eyeTexId, 0) );
+ GL_CHECK(glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0) );
+
+ BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)
+ , "glCheckFramebufferStatus failed 0x%08x"
+ , glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) );
+
+ GL_CHECK(glBlitFramebuffer(0, 0, m_eyeTextureSize.w, m_eyeTextureSize.h,
+ 0, 0, m_eyeTextureSize.w, m_eyeTextureSize.h, GL_COLOR_BUFFER_BIT, GL_NEAREST) );
+
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
+ }
+ }
+
void OVRBufferGL::destroy(const ovrSession& _session)
{
GL_CHECK(glDeleteFramebuffers(1, &m_eyeFbo) );
GL_CHECK(glDeleteTextures(1, &m_depthBuffer) );
ovr_DestroyTextureSwapChain(_session, m_textureSwapChain);
+
+ if (0 != m_msaaEyeFbo)
+ {
+ GL_CHECK(glDeleteFramebuffers(1, &m_msaaEyeFbo) );
+ m_msaaEyeFbo = 0;
+ }
+
+ if (0 != m_msaaEyeTexId)
+ {
+ GL_CHECK(glDeleteTextures(1, &m_msaaEyeTexId));
+ m_msaaEyeTexId = 0;
+ }
+
+ if (0 != m_msaaDepthBuffer)
+ {
+ GL_CHECK(glDeleteTextures(1, &m_msaaDepthBuffer));
+ m_msaaDepthBuffer = 0;
+ }
}
void OVRMirrorGL::create(const ovrSession& _session, int _width, int _height)
diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h
index 015e74147ca..527910e559e 100644
--- a/3rdparty/bgfx/src/renderer_gl.h
+++ b/3rdparty/bgfx/src/renderer_gl.h
@@ -108,6 +108,7 @@ typedef uint64_t GLuint64;
#include "renderer.h"
#include "hmd_ovr.h"
+#include "hmd_openvr.h"
#include "debug_renderdoc.h"
#ifndef GL_LUMINANCE
@@ -904,13 +905,17 @@ namespace bgfx { namespace gl
#if BGFX_CONFIG_USE_OVR
struct OVRBufferGL : public OVRBufferI
{
- virtual void create(const ovrSession& _session, int _eyeIdx) BX_OVERRIDE;
+ virtual void create(const ovrSession& _session, int _eyeIdx, int _msaaSamples) BX_OVERRIDE;
virtual void destroy(const ovrSession& _session) BX_OVERRIDE;
virtual void render(const ovrSession& _session) BX_OVERRIDE;
+ virtual void postRender(const ovrSession& _sesion) BX_OVERRIDE;
GLuint m_eyeFbo;
GLuint m_eyeTexId;
GLuint m_depthBuffer;
+ GLuint m_msaaEyeFbo;
+ GLuint m_msaaEyeTexId;
+ GLuint m_msaaDepthBuffer;
};
struct OVRMirrorGL : public OVRMirrorI
@@ -1284,8 +1289,8 @@ namespace bgfx { namespace gl
void create(const ShaderGL& _vsh, const ShaderGL& _fsh);
void destroy();
- void init();
- void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const;
+ void init();
+ void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const;
void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const;
void add(uint32_t _hash)
@@ -1299,8 +1304,8 @@ namespace bgfx { namespace gl
GLint m_attributes[Attrib::Count]; // sparse
GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1];
- GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
- uint8_t m_numSamplers;
+ GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+ uint8_t m_numSamplers;
UniformBuffer* m_constantBuffer;
PredefinedUniform m_predefined[PredefinedUniform::Count];