Migrate to latest Oculus SDK (0.8)

This commit is contained in:
Bradley Austin Davis 2015-12-08 14:21:14 -08:00
parent fd5fb3096f
commit 1644bda908
4 changed files with 70 additions and 71 deletions

View file

@ -15,17 +15,16 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
# 0.6 public # 0.6 public
# URL http://static.oculus.com/sdk-downloads/0.6.0.1/Public/1435190862/ovr_sdk_win_0.6.0.1.zip # URL http://static.oculus.com/sdk-downloads/0.6.0.1/Public/1435190862/ovr_sdk_win_0.6.0.1.zip
# URL_MD5 4b3ef825f9a1d6d3035c9f6820687da9 # URL_MD5 4b3ef825f9a1d6d3035c9f6820687da9
# 0.7 alpha # 0.8 public
# URL https://s3.amazonaws.com/static.oculus.com/sdk-downloads/0.7.0.0/Public/Alpha/ovr_sdk_win_0.7.0.0_RC1.zip # URL http://static.oculus.com/sdk-downloads/0.8.0.0/Public/1445451746/ovr_sdk_win_0.8.0.0.zip
# URL_MD5 a562bb9d117087b2cf9d86653ea70fd8 # URL_MD5 54944b03b95149d6010f84eb701b9647
if (WIN32) if (WIN32)
ExternalProject_Add( ExternalProject_Add(
${EXTERNAL_NAME} ${EXTERNAL_NAME}
URL http://static.oculus.com/sdk-downloads/0.6.0.1/Public/1435190862/ovr_sdk_win_0.6.0.1.zip URL http://static.oculus.com/sdk-downloads/0.8.0.0/Public/1445451746/ovr_sdk_win_0.8.0.0.zip
URL_MD5 4b3ef825f9a1d6d3035c9f6820687da9 URL_MD5 54944b03b95149d6010f84eb701b9647
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND "" INSTALL_COMMAND ""

View file

@ -20,9 +20,7 @@ glm::mat4 OculusBaseDisplayPlugin::getProjection(Eye eye, const glm::mat4& baseP
} }
void OculusBaseDisplayPlugin::resetSensors() { void OculusBaseDisplayPlugin::resetSensors() {
#if (OVR_MAJOR_VERSION >= 6) ovr_RecenterPose(_session);
ovr_RecenterPose(_hmd);
#endif
} }
glm::mat4 OculusBaseDisplayPlugin::getEyeToHeadTransform(Eye eye) const { glm::mat4 OculusBaseDisplayPlugin::getEyeToHeadTransform(Eye eye) const {
@ -30,27 +28,39 @@ glm::mat4 OculusBaseDisplayPlugin::getEyeToHeadTransform(Eye eye) const {
} }
glm::mat4 OculusBaseDisplayPlugin::getHeadPose(uint32_t frameIndex) const { glm::mat4 OculusBaseDisplayPlugin::getHeadPose(uint32_t frameIndex) const {
#if (OVR_MAJOR_VERSION >= 6) static uint32_t lastFrameSeen = 0;
auto frameTiming = ovr_GetFrameTiming(_hmd, frameIndex); auto displayTime = ovr_GetPredictedDisplayTime(_session, frameIndex);
auto trackingState = ovr_GetTrackingState(_hmd, frameTiming.DisplayMidpointSeconds); auto trackingState = ovr_GetTrackingState(_session, displayTime, frameIndex > lastFrameSeen);
if (frameIndex > lastFrameSeen) {
lastFrameSeen = frameIndex;
}
return toGlm(trackingState.HeadPose.ThePose); return toGlm(trackingState.HeadPose.ThePose);
#endif
} }
bool OculusBaseDisplayPlugin::isSupported() const { bool OculusBaseDisplayPlugin::isSupported() const {
#if (OVR_MAJOR_VERSION >= 6)
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) { if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
return false; return false;
} }
bool result = false;
if (ovrHmd_Detect() > 0) { ovrSession session { nullptr };
result = true; ovrGraphicsLuid luid;
auto result = ovr_Create(&session, &luid);
if (!OVR_SUCCESS(result)) {
ovrErrorInfo error;
ovr_GetLastErrorInfo(&error);
ovr_Shutdown();
return false;
} }
auto hmdDesc = ovr_GetHmdDesc(session);
if (hmdDesc.Type == ovrHmd_None) {
ovr_Destroy(session);
ovr_Shutdown();
return false;
}
ovr_Shutdown(); ovr_Shutdown();
return result; return true;
#else
return false;
#endif
} }
// DLL based display plugins MUST initialize GLEW inside the DLL code. // DLL based display plugins MUST initialize GLEW inside the DLL code.
@ -69,28 +79,22 @@ void OculusBaseDisplayPlugin::deinit() {
void OculusBaseDisplayPlugin::activate() { void OculusBaseDisplayPlugin::activate() {
WindowOpenGLDisplayPlugin::activate(); WindowOpenGLDisplayPlugin::activate();
#if (OVR_MAJOR_VERSION >= 6)
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) { if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
qFatal("Could not init OVR"); qFatal("Could not init OVR");
} }
#if (OVR_MAJOR_VERSION == 6) if (!OVR_SUCCESS(ovr_Create(&_session, &_luid))) {
if (!OVR_SUCCESS(ovr_Create(0, &_hmd))) {
#elif (OVR_MAJOR_VERSION == 7)
if (!OVR_SUCCESS(ovr_Create(&_hmd, &_luid))) {
#endif
Q_ASSERT(false);
qFatal("Failed to acquire HMD"); qFatal("Failed to acquire HMD");
} }
_hmdDesc = ovr_GetHmdDesc(_hmd); _hmdDesc = ovr_GetHmdDesc(_session);
_ipd = ovr_GetFloat(_hmd, OVR_KEY_IPD, _ipd); _ipd = ovr_GetFloat(_session, OVR_KEY_IPD, _ipd);
glm::uvec2 eyeSizes[2]; glm::uvec2 eyeSizes[2];
ovr_for_each_eye([&](ovrEyeType eye) { ovr_for_each_eye([&](ovrEyeType eye) {
_eyeFovs[eye] = _hmdDesc.DefaultEyeFov[eye]; _eyeFovs[eye] = _hmdDesc.DefaultEyeFov[eye];
ovrEyeRenderDesc& erd = _eyeRenderDescs[eye] = ovr_GetRenderDesc(_hmd, eye, _eyeFovs[eye]); ovrEyeRenderDesc& erd = _eyeRenderDescs[eye] = ovr_GetRenderDesc(_session, eye, _eyeFovs[eye]);
ovrMatrix4f ovrPerspectiveProjection = ovrMatrix4f ovrPerspectiveProjection =
ovrMatrix4f_Projection(erd.Fov, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, ovrProjection_RightHanded); ovrMatrix4f_Projection(erd.Fov, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, ovrProjection_RightHanded);
_eyeProjections[eye] = toGlm(ovrPerspectiveProjection); _eyeProjections[eye] = toGlm(ovrPerspectiveProjection);
@ -100,7 +104,7 @@ void OculusBaseDisplayPlugin::activate() {
_compositeEyeProjections[eye] = toGlm(ovrPerspectiveProjection); _compositeEyeProjections[eye] = toGlm(ovrPerspectiveProjection);
_eyeOffsets[eye] = erd.HmdToEyeViewOffset; _eyeOffsets[eye] = erd.HmdToEyeViewOffset;
eyeSizes[eye] = toGlm(ovr_GetFovTextureSize(_hmd, eye, erd.Fov, 1.0f)); eyeSizes[eye] = toGlm(ovr_GetFovTextureSize(_session, eye, erd.Fov, 1.0f));
}); });
ovrFovPort combined = _eyeFovs[Left]; ovrFovPort combined = _eyeFovs[Left];
combined.LeftTan = std::max(_eyeFovs[Left].LeftTan, _eyeFovs[Right].LeftTan); combined.LeftTan = std::max(_eyeFovs[Left].LeftTan, _eyeFovs[Right].LeftTan);
@ -115,34 +119,33 @@ void OculusBaseDisplayPlugin::activate() {
eyeSizes[0].x + eyeSizes[1].x, eyeSizes[0].x + eyeSizes[1].x,
std::max(eyeSizes[0].y, eyeSizes[1].y)); std::max(eyeSizes[0].y, eyeSizes[1].y));
if (!OVR_SUCCESS(ovr_ConfigureTracking(_hmd, if (!OVR_SUCCESS(ovr_ConfigureTracking(_session,
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) { ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) {
qFatal("Could not attach to sensor device"); qFatal("Could not attach to sensor device");
} }
// Parent class relies on our _hmd intialization, so it must come after that. // Parent class relies on our _session intialization, so it must come after that.
memset(&_sceneLayer, 0, sizeof(ovrLayerEyeFov)); memset(&_sceneLayer, 0, sizeof(ovrLayerEyeFov));
_sceneLayer.Header.Type = ovrLayerType_EyeFov; _sceneLayer.Header.Type = ovrLayerType_EyeFov;
_sceneLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft; _sceneLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;
ovr_for_each_eye([&](ovrEyeType eye) { ovr_for_each_eye([&](ovrEyeType eye) {
ovrFovPort & fov = _sceneLayer.Fov[eye] = _eyeRenderDescs[eye].Fov; ovrFovPort & fov = _sceneLayer.Fov[eye] = _eyeRenderDescs[eye].Fov;
ovrSizei & size = _sceneLayer.Viewport[eye].Size = ovr_GetFovTextureSize(_hmd, eye, fov, 1.0f); ovrSizei & size = _sceneLayer.Viewport[eye].Size = ovr_GetFovTextureSize(_session, eye, fov, 1.0f);
_sceneLayer.Viewport[eye].Pos = { eye == ovrEye_Left ? 0 : size.w, 0 }; _sceneLayer.Viewport[eye].Pos = { eye == ovrEye_Left ? 0 : size.w, 0 };
}); });
if (!OVR_SUCCESS(ovr_ConfigureTracking(_hmd, if (!OVR_SUCCESS(ovr_ConfigureTracking(_session,
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) { ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) {
qFatal("Could not attach to sensor device"); qFatal("Could not attach to sensor device");
} }
#endif
} }
void OculusBaseDisplayPlugin::deactivate() { void OculusBaseDisplayPlugin::deactivate() {
WindowOpenGLDisplayPlugin::deactivate(); WindowOpenGLDisplayPlugin::deactivate();
#if (OVR_MAJOR_VERSION >= 6) #if (OVR_MAJOR_VERSION >= 6)
ovr_Destroy(_hmd); ovr_Destroy(_session);
_hmd = nullptr; _session = nullptr;
ovr_Shutdown(); ovr_Shutdown();
#endif #endif
} }
@ -151,7 +154,7 @@ void OculusBaseDisplayPlugin::deactivate() {
float OculusBaseDisplayPlugin::getIPD() const { float OculusBaseDisplayPlugin::getIPD() const {
float result = OVR_DEFAULT_IPD; float result = OVR_DEFAULT_IPD;
#if (OVR_MAJOR_VERSION >= 6) #if (OVR_MAJOR_VERSION >= 6)
result = ovr_GetFloat(_hmd, OVR_KEY_IPD, result); result = ovr_GetFloat(_session, OVR_KEY_IPD, result);
#endif #endif
return result; return result;
} }

View file

@ -43,17 +43,13 @@ protected:
mat4 _compositeEyeProjections[2]; mat4 _compositeEyeProjections[2];
uvec2 _desiredFramebufferSize; uvec2 _desiredFramebufferSize;
#if (OVR_MAJOR_VERSION >= 6) ovrSession _session;
ovrHmd _hmd; ovrGraphicsLuid _luid;
float _ipd{ OVR_DEFAULT_IPD }; float _ipd{ OVR_DEFAULT_IPD };
ovrEyeRenderDesc _eyeRenderDescs[2]; ovrEyeRenderDesc _eyeRenderDescs[2];
ovrFovPort _eyeFovs[2]; ovrFovPort _eyeFovs[2];
ovrHmdDesc _hmdDesc; ovrHmdDesc _hmdDesc;
ovrLayerEyeFov _sceneLayer; ovrLayerEyeFov _sceneLayer;
#endif
#if (OVR_MAJOR_VERSION == 7)
ovrGraphicsLuid _luid;
#endif
}; };
#if (OVR_MAJOR_VERSION == 6) #if (OVR_MAJOR_VERSION == 6)

View file

@ -23,12 +23,16 @@
// ovr_CreateMirrorTextureGL, etc // ovr_CreateMirrorTextureGL, etc
template <typename C> template <typename C>
struct RiftFramebufferWrapper : public FramebufferWrapper<C, char> { struct RiftFramebufferWrapper : public FramebufferWrapper<C, char> {
ovrHmd hmd; ovrSession session;
RiftFramebufferWrapper(const ovrHmd & hmd) : hmd(hmd) { RiftFramebufferWrapper(const ovrSession& session) : session(session) {
color = 0; color = 0;
depth = 0; depth = 0;
}; };
~RiftFramebufferWrapper() {
destroyColor();
}
void Resize(const uvec2 & size) { void Resize(const uvec2 & size) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oglplus::GetName(fbo)); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oglplus::GetName(fbo));
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
@ -39,6 +43,9 @@ struct RiftFramebufferWrapper : public FramebufferWrapper<C, char> {
} }
protected: protected:
virtual void destroyColor() {
}
virtual void initDepth() override final { virtual void initDepth() override final {
} }
}; };
@ -53,12 +60,6 @@ struct SwapFramebufferWrapper : public RiftFramebufferWrapper<ovrSwapTextureSet*
: RiftFramebufferWrapper(hmd) { : RiftFramebufferWrapper(hmd) {
} }
~SwapFramebufferWrapper() {
if (color) {
ovr_DestroySwapTextureSet(hmd, color);
color = nullptr;
}
}
void Increment() { void Increment() {
++color->CurrentIndex; ++color->CurrentIndex;
@ -66,13 +67,17 @@ struct SwapFramebufferWrapper : public RiftFramebufferWrapper<ovrSwapTextureSet*
} }
protected: protected:
virtual void initColor() override { virtual void destroyColor() override {
if (color) { if (color) {
ovr_DestroySwapTextureSet(hmd, color); ovr_DestroySwapTextureSet(session, color);
color = nullptr; color = nullptr;
} }
}
if (!OVR_SUCCESS(ovr_CreateSwapTextureSetGL(hmd, GL_RGBA, size.x, size.y, &color))) { virtual void initColor() override {
destroyColor();
if (!OVR_SUCCESS(ovr_CreateSwapTextureSetGL(session, GL_SRGB8_ALPHA8, size.x, size.y, &color))) {
qFatal("Unable to create swap textures"); qFatal("Unable to create swap textures");
} }
@ -107,20 +112,17 @@ struct MirrorFramebufferWrapper : public RiftFramebufferWrapper<ovrGLTexture*> {
MirrorFramebufferWrapper(const ovrHmd & hmd) MirrorFramebufferWrapper(const ovrHmd & hmd)
: RiftFramebufferWrapper(hmd) { } : RiftFramebufferWrapper(hmd) { }
virtual ~MirrorFramebufferWrapper() { private:
virtual void destroyColor() override {
if (color) { if (color) {
ovr_DestroyMirrorTexture(hmd, (ovrTexture*)color); ovr_DestroyMirrorTexture(session, (ovrTexture*)color);
color = nullptr; color = nullptr;
} }
} }
private:
void initColor() override { void initColor() override {
if (color) { destroyColor();
ovr_DestroyMirrorTexture(hmd, (ovrTexture*)color); ovrResult result = ovr_CreateMirrorTextureGL(session, GL_SRGB8_ALPHA8, size.x, size.y, (ovrTexture**)&color);
color = nullptr;
}
ovrResult result = ovr_CreateMirrorTextureGL(hmd, GL_RGBA, size.x, size.y, (ovrTexture**)&color);
Q_ASSERT(OVR_SUCCESS(result)); Q_ASSERT(OVR_SUCCESS(result));
} }
@ -154,8 +156,7 @@ void OculusDisplayPlugin::activate() {
void OculusDisplayPlugin::customizeContext() { void OculusDisplayPlugin::customizeContext() {
OculusBaseDisplayPlugin::customizeContext(); OculusBaseDisplayPlugin::customizeContext();
#if (OVR_MAJOR_VERSION >= 6) _sceneFbo = SwapFboPtr(new SwapFramebufferWrapper(_session));
_sceneFbo = SwapFboPtr(new SwapFramebufferWrapper(_hmd));
_sceneFbo->Init(getRecommendedRenderSize()); _sceneFbo->Init(getRecommendedRenderSize());
// We're rendering both eyes to the same texture, so only one of the // We're rendering both eyes to the same texture, so only one of the
@ -163,7 +164,7 @@ void OculusDisplayPlugin::customizeContext() {
_sceneLayer.ColorTexture[0] = _sceneFbo->color; _sceneLayer.ColorTexture[0] = _sceneFbo->color;
// not needed since the structure was zeroed on init, but explicit // not needed since the structure was zeroed on init, but explicit
_sceneLayer.ColorTexture[1] = nullptr; _sceneLayer.ColorTexture[1] = nullptr;
#endif
enableVsync(false); enableVsync(false);
// Only enable mirroring if we know vsync is disabled // Only enable mirroring if we know vsync is disabled
_enablePreview = !isVsyncEnabled(); _enablePreview = !isVsyncEnabled();
@ -177,7 +178,6 @@ void OculusDisplayPlugin::uncustomizeContext() {
} }
void OculusDisplayPlugin::internalPresent() { void OculusDisplayPlugin::internalPresent() {
#if (OVR_MAJOR_VERSION >= 6)
if (!_currentSceneTexture) { if (!_currentSceneTexture) {
return; return;
} }
@ -206,8 +206,10 @@ void OculusDisplayPlugin::internalPresent() {
auto size = _sceneFbo->size; auto size = _sceneFbo->size;
Context::Viewport(size.x, size.y); Context::Viewport(size.x, size.y);
glBindTexture(GL_TEXTURE_2D, _currentSceneTexture); glBindTexture(GL_TEXTURE_2D, _currentSceneTexture);
//glEnable(GL_FRAMEBUFFER_SRGB);
GLenum err = glGetError(); GLenum err = glGetError();
drawUnitQuad(); drawUnitQuad();
//glDisable(GL_FRAMEBUFFER_SRGB);
}); });
uint32_t frameIndex { 0 }; uint32_t frameIndex { 0 };
@ -230,13 +232,12 @@ void OculusDisplayPlugin::internalPresent() {
viewScaleDesc.HmdToEyeViewOffset[1] = _eyeOffsets[1]; viewScaleDesc.HmdToEyeViewOffset[1] = _eyeOffsets[1];
ovrLayerHeader* layers = &_sceneLayer.Header; ovrLayerHeader* layers = &_sceneLayer.Header;
ovrResult result = ovr_SubmitFrame(_hmd, frameIndex, &viewScaleDesc, &layers, 1); ovrResult result = ovr_SubmitFrame(_session, frameIndex, &viewScaleDesc, &layers, 1);
if (!OVR_SUCCESS(result)) { if (!OVR_SUCCESS(result)) {
qDebug() << result; qDebug() << result;
} }
} }
_sceneFbo->Increment(); _sceneFbo->Increment();
#endif
/* /*
The swapbuffer call here is only required if we want to mirror the content to the screen. The swapbuffer call here is only required if we want to mirror the content to the screen.