display-plugins: Pulled getHeadPose into common base class.

* Moved getHeadPose and _headPoseCache out of each derived class and into HmdDisplayPlugin.
* updated comment in application.
This commit is contained in:
Anthony Thibault 2016-03-20 14:08:35 -07:00
parent e1d47e7028
commit 5b2a050df7
9 changed files with 13 additions and 27 deletions

View file

@ -1418,10 +1418,6 @@ void Application::paintGL() {
// FIXME not needed anymore?
_offscreenContext->makeCurrent();
// Tell the plugin what pose we're using to render. In this case we're just using the
// unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
// for rotational timewarp. If we move to support positonal timewarp, we need to
// ensure this contains the full pose composed with the eye offsets.
displayPlugin->updateHeadPose(_frameCount);
// update the avatar with a fresh HMD pose
@ -1621,6 +1617,10 @@ void Application::paintGL() {
mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
eyeOffsets[eye] = eyeOffsetTransform;
// Tell the plugin what pose we're using to render. In this case we're just using the
// unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
// for rotational timewarp. If we move to support positonal timewarp, we need to
// ensure this contains the full pose composed with the eye offsets.
displayPlugin->setEyeRenderPose(_frameCount, eye, headPose * glm::inverse(eyeOffsetTransform));
eyeProjections[eye] = displayPlugin->getEyeProjection(eye, baseProjection);

View file

@ -160,4 +160,8 @@ void HmdDisplayPlugin::updateFrameData() {
Parent::updateFrameData();
Lock lock(_mutex);
_currentRenderEyePoses = _renderEyePoses[_currentRenderFrameIndex];
}
}
glm::mat4 HmdDisplayPlugin::getHeadPose() const {
return _headPoseCache.get();
}

View file

@ -7,6 +7,8 @@
//
#pragma once
#include <ThreadSafeValueCache.h>
#include <QtGlobal>
#include "../OpenGLDisplayPlugin.h"
@ -24,7 +26,7 @@ public:
void setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) override final;
bool isDisplayVisible() const override { return isHmdMounted(); }
virtual glm::mat4 getHeadPose() const override;
protected:
virtual void hmdPresent() = 0;
@ -46,6 +48,7 @@ protected:
using EyePoses = std::array<glm::mat4, 2>;
QMap<uint32_t, EyePoses> _renderEyePoses;
EyePoses _currentRenderEyePoses;
ThreadSafeValueCache<glm::mat4> _headPoseCache { glm::mat4() };
private:
bool _enablePreview { false };

View file

@ -22,10 +22,6 @@ void OculusBaseDisplayPlugin::updateHeadPose(uint32_t frameIndex) {
_headPoseCache.set(headPose);
}
glm::mat4 OculusBaseDisplayPlugin::getHeadPose() const {
return _headPoseCache.get();
}
bool OculusBaseDisplayPlugin::isSupported() const {
return oculusAvailable();
}

View file

@ -8,7 +8,6 @@
#pragma once
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include <ThreadSafeValueCache.h>
#include <QTimer>
@ -22,7 +21,6 @@ public:
// Stereo specific methods
virtual void resetSensors() override final;
virtual void updateHeadPose(uint32_t frameIndex) override;
virtual glm::mat4 getHeadPose() const override;
protected:
void customizeContext() override;
@ -38,5 +36,4 @@ protected:
ovrHmdDesc _hmdDesc;
ovrLayerEyeFov _sceneLayer;
ovrViewScaleDesc _viewScaleDesc;
ThreadSafeValueCache<glm::mat4> _headPoseCache { glm::mat4() };
};

View file

@ -41,10 +41,6 @@ void OculusLegacyDisplayPlugin::updateHeadPose(uint32_t frameIndex) {
_headPoseCache.set(toGlm(_trackingState.HeadPose.ThePose));
}
glm::mat4 OculusLegacyDisplayPlugin::getHeadPose() const {
return _headPoseCache.get();
}
bool OculusLegacyDisplayPlugin::isSupported() const {
if (!ovr_Initialize(nullptr)) {
return false;

View file

@ -8,7 +8,6 @@
#pragma once
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include <ThreadSafeValueCache.h>
#include <QTimer>
@ -28,7 +27,6 @@ public:
// Stereo specific methods
virtual void resetSensors() override;
virtual void updateHeadPose(uint32_t frameIndex) override;
virtual glm::mat4 getHeadPose() const override;
virtual float getTargetFrameRate() override;
@ -54,7 +52,6 @@ private:
//ovrTexture _eyeTextures[2]; // FIXME - not currently in use
mutable int _hmdScreen { -1 };
bool _hswDismissed { false };
ThreadSafeValueCache<glm::mat4> _headPoseCache { glm::mat4() };
};

View file

@ -143,10 +143,6 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) {
_headPoseCache.set(_trackedDevicePoseMat4[0]);
}
glm::mat4 OpenVrDisplayPlugin::getHeadPose() const {
return _headPoseCache.get();
}
void OpenVrDisplayPlugin::hmdPresent() {
// Flip y-axis since GL UV coords are backwards.
static vr::VRTextureBounds_t leftBounds{ 0, 0, 0.5f, 1 };

View file

@ -12,7 +12,6 @@
#include <openvr.h>
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include <ThreadSafeValueCache.h>
const float TARGET_RATE_OpenVr = 90.0f; // FIXME: get from sdk tracked device property? This number is vive-only.
@ -29,7 +28,6 @@ public:
// Stereo specific methods
virtual void resetSensors() override;
virtual void updateHeadPose(uint32_t frameIndex) override;
virtual glm::mat4 getHeadPose() const override;
protected:
void internalActivate() override;
@ -43,5 +41,4 @@ private:
std::atomic<vr::EDeviceActivityLevel> _hmdActivityLevel { vr::k_EDeviceActivityLevel_Unknown };
static const QString NAME;
mutable Mutex _poseMutex;
ThreadSafeValueCache<glm::mat4> _headPoseCache { glm::mat4() };
};