mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-04-24 04:53:28 -04:00
OVR: Support for multiple SDK versions.
This commit is contained in:
parent
9b2ca73de4
commit
08d97d8c4b
5 changed files with 105 additions and 52 deletions
|
@ -18,7 +18,7 @@ Supported rendering backends:
|
|||
|
||||
Supported HMD:
|
||||
|
||||
* OculusVR (0.4.4)
|
||||
* OculusVR (0.4.2+)
|
||||
|
||||
Supported platforms:
|
||||
|
||||
|
|
34
src/ovr.cpp
34
src/ovr.cpp
|
@ -48,7 +48,11 @@ namespace bgfx
|
|||
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
|
||||
|
@ -57,7 +61,11 @@ namespace bgfx
|
|||
case ovrRenderAPI_D3D11:
|
||||
{
|
||||
ovrD3D11ConfigData* data = (ovrD3D11ConfigData*)_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_DIRECT3D11
|
||||
|
@ -66,7 +74,11 @@ namespace bgfx
|
|||
case ovrRenderAPI_OpenGL:
|
||||
{
|
||||
ovrGLConfigData* data = (ovrGLConfigData*)_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_OPENGL
|
||||
|
@ -96,6 +108,13 @@ namespace bgfx
|
|||
}
|
||||
}
|
||||
|
||||
BX_TRACE("HMD: %s, %s, firmware: %d.%d"
|
||||
, m_hmd->ProductName
|
||||
, m_hmd->Manufacturer
|
||||
, m_hmd->FirmwareMajor
|
||||
, m_hmd->FirmwareMinor
|
||||
);
|
||||
|
||||
ovrBool result;
|
||||
result = ovrHmd_AttachToWindow(m_hmd, _nwh, NULL, NULL);
|
||||
if (!result) { goto ovrError; }
|
||||
|
@ -197,8 +216,13 @@ ovrError:
|
|||
|
||||
m_timing = ovrHmd_BeginFrame(m_hmd, 0);
|
||||
|
||||
#if OVR_VERSION > OVR_VERSION_042
|
||||
m_pose[0] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Left);
|
||||
m_pose[1] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Right);
|
||||
#else
|
||||
m_pose[0] = ovrHmd_GetEyePose(m_hmd, ovrEye_Left);
|
||||
m_pose[1] = ovrHmd_GetEyePose(m_hmd, ovrEye_Right);
|
||||
#endif // OVR_VERSION > OVR_VERSION_042
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -219,7 +243,11 @@ ovrError:
|
|||
for (int ii = 0; ii < 2; ++ii)
|
||||
{
|
||||
ovrPosef& pose = m_pose[ii];
|
||||
#if OVR_VERSION > OVR_VERSION_042
|
||||
pose = ovrHmd_GetHmdPosePerEye(m_hmd, eye[ii]);
|
||||
#else
|
||||
pose = ovrHmd_GetEyePose(m_hmd, eye[ii]);
|
||||
#endif // OVR_VERSION > OVR_VERSION_042
|
||||
|
||||
HMD::Eye& eye = _hmd.eye[ii];
|
||||
eye.rotation[0] = pose.Orientation.x;
|
||||
|
@ -235,9 +263,15 @@ ovrError:
|
|||
eye.fov[1] = erd.Fov.DownTan;
|
||||
eye.fov[2] = erd.Fov.LeftTan;
|
||||
eye.fov[3] = erd.Fov.RightTan;
|
||||
#if OVR_VERSION > OVR_VERSION_042
|
||||
eye.viewOffset[0] = erd.HmdToEyeViewOffset.x;
|
||||
eye.viewOffset[1] = erd.HmdToEyeViewOffset.y;
|
||||
eye.viewOffset[2] = erd.HmdToEyeViewOffset.z;
|
||||
#else
|
||||
eye.viewOffset[0] = erd.ViewAdjust.x;
|
||||
eye.viewOffset[1] = erd.ViewAdjust.y;
|
||||
eye.viewOffset[2] = erd.ViewAdjust.z;
|
||||
#endif // OVR_VERSION > OVR_VERSION_042
|
||||
eye.pixelsPerTanAngle[0] = erd.PixelsPerTanAngleAtCenter.x;
|
||||
eye.pixelsPerTanAngle[1] = erd.PixelsPerTanAngleAtCenter.y;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
|
||||
# include <OVR.h>
|
||||
|
||||
# define OVR_VERSION_(_a, _b, _c) (_a * 10000 + _b * 100 + _c)
|
||||
# define OVR_VERSION OVR_VERSION_(OVR_MAJOR_VERSION, OVR_MINOR_VERSION, OVR_BUILD_VERSION)
|
||||
# define OVR_VERSION_042 OVR_VERSION_(0, 4, 2)
|
||||
# define OVR_VERSION_043 OVR_VERSION_(0, 4, 3)
|
||||
# define OVR_VERSION_044 OVR_VERSION_(0, 4, 4)
|
||||
|
||||
# if BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||
# define OVR_D3D_VERSION 9
|
||||
# include <OVR_D3D.h>
|
||||
|
|
|
@ -481,7 +481,6 @@ namespace bgfx
|
|||
#endif // USE_D3D11_DYNAMIC_LIB
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
IDXGIFactory* factory;
|
||||
#if BX_PLATFORM_WINRT
|
||||
// WinRT requires the IDXGIFactory2 interface, which isn't supported on older platforms
|
||||
|
@ -539,10 +538,12 @@ namespace bgfx
|
|||
D3D_FEATURE_LEVEL_10_0,
|
||||
D3D_FEATURE_LEVEL_9_3,
|
||||
D3D_FEATURE_LEVEL_9_2,
|
||||
D3D_FEATURE_LEVEL_9_1
|
||||
D3D_FEATURE_LEVEL_9_1,
|
||||
};
|
||||
|
||||
uint32_t flags = D3D11_CREATE_DEVICE_SINGLETHREADED
|
||||
uint32_t flags = 0
|
||||
| D3D11_CREATE_DEVICE_SINGLETHREADED
|
||||
| D3D11_CREATE_DEVICE_BGRA_SUPPORT
|
||||
| (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0)
|
||||
;
|
||||
|
||||
|
@ -593,13 +594,13 @@ namespace bgfx
|
|||
m_scd.Height = BGFX_DEFAULT_HEIGHT;
|
||||
m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
m_scd.Stereo = false;
|
||||
m_scd.SampleDesc.Count = 1;
|
||||
m_scd.SampleDesc.Count = 1;
|
||||
m_scd.SampleDesc.Quality = 0;
|
||||
m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
m_scd.BufferCount = 2;
|
||||
m_scd.Scaling = DXGI_SCALING_NONE;
|
||||
m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
||||
m_scd.Scaling = DXGI_SCALING_NONE;
|
||||
m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
||||
|
||||
hr = m_factory->CreateSwapChainForCoreWindow(m_device
|
||||
, g_bgfxCoreWindow
|
||||
|
@ -615,20 +616,20 @@ namespace bgfx
|
|||
memset(&m_scd, 0, sizeof(m_scd) );
|
||||
m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH;
|
||||
m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT;
|
||||
m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
m_scd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
m_scd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
m_scd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
m_scd.SampleDesc.Count = 1;
|
||||
m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
m_scd.SampleDesc.Count = 1;
|
||||
m_scd.SampleDesc.Quality = 0;
|
||||
m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
m_scd.BufferCount = 1;
|
||||
m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
m_scd.BufferCount = 1;
|
||||
m_scd.OutputWindow = g_bgfxHwnd;
|
||||
m_scd.Windowed = true;
|
||||
m_scd.Windowed = true;
|
||||
|
||||
hr = m_factory->CreateSwapChain(m_device
|
||||
, &m_scd
|
||||
, &m_swapChain
|
||||
);
|
||||
, &m_scd
|
||||
, &m_swapChain
|
||||
);
|
||||
#endif // BX_PLATFORM_WINRT
|
||||
BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain.");
|
||||
|
||||
|
@ -1090,23 +1091,23 @@ namespace bgfx
|
|||
DX_CHECK(m_device->CreateRenderTargetView(color, NULL, &m_backBufferColor) );
|
||||
DX_RELEASE(color, 0);
|
||||
|
||||
D3D11_TEXTURE2D_DESC dsd;
|
||||
dsd.Width = getBufferWidth();
|
||||
dsd.Height = getBufferHeight();
|
||||
dsd.MipLevels = 1;
|
||||
dsd.ArraySize = 1;
|
||||
dsd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
dsd.SampleDesc = m_scd.SampleDesc;
|
||||
dsd.Usage = D3D11_USAGE_DEFAULT;
|
||||
dsd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
dsd.CPUAccessFlags = 0;
|
||||
dsd.MiscFlags = 0;
|
||||
|
||||
ovrPostReset();
|
||||
|
||||
// If OVR doesn't create separate depth stencil view, create default one.
|
||||
if (NULL == m_backBufferDepthStencil)
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC dsd;
|
||||
dsd.Width = getBufferWidth();
|
||||
dsd.Height = getBufferHeight();
|
||||
dsd.MipLevels = 1;
|
||||
dsd.ArraySize = 1;
|
||||
dsd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
dsd.SampleDesc = m_scd.SampleDesc;
|
||||
dsd.Usage = D3D11_USAGE_DEFAULT;
|
||||
dsd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
dsd.CPUAccessFlags = 0;
|
||||
dsd.MiscFlags = 0;
|
||||
|
||||
ID3D11Texture2D* depthStencil;
|
||||
DX_CHECK(m_device->CreateTexture2D(&dsd, NULL, &depthStencil) );
|
||||
DX_CHECK(m_device->CreateDepthStencilView(depthStencil, NULL, &m_backBufferDepthStencil) );
|
||||
|
@ -1721,10 +1722,10 @@ namespace bgfx
|
|||
void setBufferSize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
#if BX_PLATFORM_WINRT
|
||||
m_scd.Width = _width;
|
||||
m_scd.Width = _width;
|
||||
m_scd.Height = _height;
|
||||
#else
|
||||
m_scd.BufferDesc.Width = _width;
|
||||
m_scd.BufferDesc.Width = _width;
|
||||
m_scd.BufferDesc.Height = _height;
|
||||
#endif
|
||||
}
|
||||
|
@ -1748,10 +1749,16 @@ namespace bgfx
|
|||
{
|
||||
ovrD3D11Config config;
|
||||
config.D3D11.Header.API = ovrRenderAPI_D3D11;
|
||||
# if OVR_VERSION > OVR_VERSION_043
|
||||
config.D3D11.Header.BackBufferSize.w = m_scd.BufferDesc.Width;
|
||||
config.D3D11.Header.BackBufferSize.h = m_scd.BufferDesc.Height;
|
||||
config.D3D11.pBackBufferUAV = NULL;
|
||||
# else
|
||||
config.D3D11.Header.RTSize.w = m_scd.BufferDesc.Width;
|
||||
config.D3D11.Header.RTSize.h = m_scd.BufferDesc.Height;
|
||||
# endif // OVR_VERSION > OVR_VERSION_042
|
||||
config.D3D11.Header.Multisample = 0;
|
||||
config.D3D11.pDevice = m_device;
|
||||
config.D3D11.pDevice = m_device;
|
||||
config.D3D11.pDeviceContext = m_deviceCtx;
|
||||
config.D3D11.pBackBufferRT = m_backBufferColor;
|
||||
config.D3D11.pSwapChain = m_swapChain;
|
||||
|
@ -1805,10 +1812,10 @@ namespace bgfx
|
|||
texture.D3D11.pSRView = m_ovrRT.m_srv;
|
||||
m_ovr.postReset(texture.Texture);
|
||||
|
||||
std::swap(m_ovrRtv, m_backBufferColor);
|
||||
bx::swap(m_ovrRtv, m_backBufferColor);
|
||||
|
||||
BX_CHECK(NULL == m_backBufferDepthStencil, "");
|
||||
std::swap(m_ovrDsv, m_backBufferDepthStencil);
|
||||
bx::swap(m_ovrDsv, m_backBufferDepthStencil);
|
||||
}
|
||||
}
|
||||
#endif // BGFX_CONFIG_USE_OVR
|
||||
|
@ -1820,8 +1827,8 @@ namespace bgfx
|
|||
m_ovr.preReset();
|
||||
if (NULL != m_ovrRtv)
|
||||
{
|
||||
std::swap(m_ovrRtv, m_backBufferColor);
|
||||
std::swap(m_ovrDsv, m_backBufferDepthStencil);
|
||||
bx::swap(m_ovrRtv, m_backBufferColor);
|
||||
bx::swap(m_ovrDsv, m_backBufferDepthStencil);
|
||||
BX_CHECK(NULL == m_backBufferDepthStencil, "");
|
||||
|
||||
DX_RELEASE(m_ovrRtv, 0);
|
||||
|
@ -1843,7 +1850,7 @@ namespace bgfx
|
|||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
memcpy(&desc, &backBufferDesc, sizeof(desc) );
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
|
@ -2663,13 +2670,13 @@ namespace bgfx
|
|||
case TextureCube:
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = textureWidth;
|
||||
desc.Width = textureWidth;
|
||||
desc.Height = textureHeight;
|
||||
desc.MipLevels = numMips;
|
||||
desc.Format = format;
|
||||
desc.MipLevels = numMips;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc = msaa;
|
||||
desc.Usage = kk == 0 ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
|
||||
desc.BindFlags = bufferOnly ? 0 : D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.Usage = kk == 0 ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
|
||||
desc.BindFlags = bufferOnly ? 0 : D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
|
||||
if (isDepth( (TextureFormat::Enum)m_textureFormat) )
|
||||
|
@ -2711,15 +2718,15 @@ namespace bgfx
|
|||
case Texture3D:
|
||||
{
|
||||
D3D11_TEXTURE3D_DESC desc;
|
||||
desc.Width = textureWidth;
|
||||
desc.Width = textureWidth;
|
||||
desc.Height = textureHeight;
|
||||
desc.Depth = imageContainer.m_depth;
|
||||
desc.Depth = imageContainer.m_depth;
|
||||
desc.MipLevels = imageContainer.m_numMips;
|
||||
desc.Format = format;
|
||||
desc.Usage = kk == 0 ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
|
||||
desc.Format = format;
|
||||
desc.Usage = kk == 0 ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
if (computeWrite)
|
||||
{
|
||||
|
@ -3308,11 +3315,12 @@ namespace bgfx
|
|||
|
||||
const uint64_t pt = newFlags&BGFX_STATE_PT_MASK;
|
||||
primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT);
|
||||
if (prim.m_type != s_primInfo[primIndex].m_type)
|
||||
{
|
||||
prim = s_primInfo[primIndex];
|
||||
deviceCtx->IASetPrimitiveTopology(prim.m_type);
|
||||
}
|
||||
}
|
||||
|
||||
if (prim.m_type != s_primInfo[primIndex].m_type)
|
||||
{
|
||||
prim = s_primInfo[primIndex];
|
||||
deviceCtx->IASetPrimitiveTopology(prim.m_type);
|
||||
}
|
||||
|
||||
uint16_t scissor = draw.m_scissor;
|
||||
|
|
|
@ -1969,8 +1969,13 @@ namespace bgfx
|
|||
{
|
||||
ovrGLConfig config;
|
||||
config.OGL.Header.API = ovrRenderAPI_OpenGL;
|
||||
# if OVR_VERSION > OVR_VERSION_043
|
||||
config.OGL.Header.BackBufferSize.w = m_resolution.m_width;
|
||||
config.OGL.Header.BackBufferSize.h = m_resolution.m_height;
|
||||
# else
|
||||
config.OGL.Header.RTSize.w = m_resolution.m_width;
|
||||
config.OGL.Header.RTSize.h = m_resolution.m_height;
|
||||
# endif // OVR_VERSION > OVR_VERSION_043
|
||||
config.OGL.Header.Multisample = 0;
|
||||
config.OGL.Window = g_bgfxHwnd;
|
||||
config.OGL.DC = GetDC(g_bgfxHwnd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue