01-24-2015 04:53 PM
01-24-2015 05:31 PM
01-27-2015 04:12 PM
01-27-2015 05:07 PM
01-27-2015 07:57 PM
01-29-2015 05:46 PM
01-29-2015 06:04 PM
01-30-2015 02:35 PM
01-30-2015 03:38 PM
01-30-2015 04:48 PM
ovr_Initialize();
...
if (m_hmd)
return true;
m_hmd = ovrHmd_Create(0);
if (!m_hmd)
m_hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
...
HWND window = CreateWindow(m_appName,
m_appName,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
m_type == Compute ? CW_USEDEFAULT : rect.left,
m_type == Compute ? SW_MINIMIZE : rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
wc.hInstance,
NULL);
...
UINT flags = 0;//D3D10_CREATE_DEVICE_SINGLETHREADED;
if (debug)
flags |= D3D10_CREATE_DEVICE_DEBUG;
for (UINT i = 0; ; i++) {
res = m_factory->EnumAdapters(i, &m_adapter);
if (res == S_OK) {
res = D3D10CreateDevice1(m_adapter,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
flags,
D3D10_FEATURE_LEVEL_10_0,
D3D10_1_SDK_VERSION,
&m_device);
if (res == S_OK)
break;
m_adapter->Release();
}
...
ovrBool attachRet = ovrHmd_AttachToWindow(hmd, window, NULL, NULL);
coAssert(attachRet != 0);
//Configure Stereo settings.
OVR::Sizei recommendedTex0Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0f);
OVR::Sizei recommendedTex1Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0f);
OVR::Sizei RenderTargetSize;
RenderTargetSize.w = recommendedTex0Size.w + recommendedTex1Size.w;
RenderTargetSize.h = max(recommendedTex0Size.h, recommendedTex1Size.h);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = rect.left + RenderTargetSize.w;
rect.bottom = rect.top + RenderTargetSize.h;
BOOL ret = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
coAssertAlways(ret == TRUE);
ret = SetWindowPos(window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, /*SWP_NOMOVE |*/ SWP_NOOWNERZORDER | SWP_NOZORDER);
coAssertAlways(ret == TRUE);
m_camera = new grVRCamera(window, true, RenderTargetSize.w, RenderTargetSize.h);
m_eyeRenderViewport[0].Pos = Vector2i(0,0);
m_eyeRenderViewport[0].Size = Sizei(RenderTargetSize.w / 2, RenderTargetSize.h);
m_eyeRenderViewport[1].Pos = Vector2i((RenderTargetSize.w + 1) / 2, 0);
m_eyeRenderViewport[1].Size = m_eyeRenderViewport[0].Size;
// Query D3D texture data.
m_eyeTexture[0].D3D10.Header.API = ovrRenderAPI_D3D10;
m_eyeTexture[0].D3D10.Header.TextureSize = RenderTargetSize;
m_eyeTexture[0].D3D10.Header.RenderViewport = m_eyeRenderViewport[0];
m_eyeTexture[0].D3D10.pTexture = m_camera->m_texture->m_texture;
m_eyeTexture[0].D3D10.pSRView = m_camera->m_texture->m_srv;
// Right eye uses the same texture, but different rendering viewport.
m_eyeTexture[1] = m_eyeTexture[0];
m_eyeTexture[1].D3D10.Header.RenderViewport = m_eyeRenderViewport[1];
// Configure d3d10.
ovrD3D10Config d3d10cfg;
d3d10cfg.D3D10.Header.API = ovrRenderAPI_D3D10;
d3d10cfg.D3D10.Header.RTSize = Sizei(hmd->Resolution.w, hmd->Resolution.h);
d3d10cfg.D3D10.Header.Multisample = m_camera->getNumMultiSamples();
d3d10cfg.D3D10.pDevice = grGraphics::getDevice();
d3d10cfg.D3D10.pBackBufferRT = m_camera->m_rtv;
d3d10cfg.D3D10.pSwapChain = m_camera->m_swapChain;
if (!ovrHmd_ConfigureRendering(hmd, &d3d10cfg.Config,
ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette |
ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive,
hmd->DefaultEyeFov, m_eyeRenderDesc)) return;
ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
// Start the sensor which informs of the Rift's pose and motion
ovrHmd_ConfigureTracking(hmd,
ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position,
0);