mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
Oculus update
This commit is contained in:
parent
19ad4314ca
commit
166a419e90
5 changed files with 97 additions and 36 deletions
|
@ -13,7 +13,7 @@ if (WIN32)
|
||||||
|
|
||||||
set(TARGET_NAME oculus)
|
set(TARGET_NAME oculus)
|
||||||
setup_hifi_plugin()
|
setup_hifi_plugin()
|
||||||
link_hifi_libraries(shared gl plugins gpu display-plugins input-plugins)
|
link_hifi_libraries(shared gl gpu controllers plugins display-plugins input-plugins)
|
||||||
|
|
||||||
include_hifi_library_headers(octree)
|
include_hifi_library_headers(octree)
|
||||||
|
|
||||||
|
|
|
@ -26,31 +26,7 @@ glm::mat4 OculusBaseDisplayPlugin::getHeadPose(uint32_t frameIndex) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OculusBaseDisplayPlugin::isSupported() const {
|
bool OculusBaseDisplayPlugin::isSupported() const {
|
||||||
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
return oculusAvailable();
|
||||||
qDebug() << "OculusBaseDisplayPlugin : ovr_Initialize() failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ovrSession session { nullptr };
|
|
||||||
ovrGraphicsLuid luid;
|
|
||||||
auto result = ovr_Create(&session, &luid);
|
|
||||||
if (!OVR_SUCCESS(result)) {
|
|
||||||
ovrErrorInfo error;
|
|
||||||
ovr_GetLastErrorInfo(&error);
|
|
||||||
qDebug() << "OculusBaseDisplayPlugin : ovr_Create() failed" << result << error.Result << error.ErrorString;
|
|
||||||
ovr_Shutdown();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto hmdDesc = ovr_GetHmdDesc(session);
|
|
||||||
if (hmdDesc.Type == ovrHmd_None) {
|
|
||||||
ovr_Destroy(session);
|
|
||||||
ovr_Shutdown();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ovr_Shutdown();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DLL based display plugins MUST initialize GLEW inside the DLL code.
|
// DLL based display plugins MUST initialize GLEW inside the DLL code.
|
||||||
|
@ -68,13 +44,7 @@ void OculusBaseDisplayPlugin::deinit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OculusBaseDisplayPlugin::activate() {
|
void OculusBaseDisplayPlugin::activate() {
|
||||||
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
_session = acquireOculusSession();
|
||||||
qFatal("Could not init OVR");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!OVR_SUCCESS(ovr_Create(&_session, &_luid))) {
|
|
||||||
qFatal("Failed to acquire HMD");
|
|
||||||
}
|
|
||||||
|
|
||||||
_hmdDesc = ovr_GetHmdDesc(_session);
|
_hmdDesc = ovr_GetHmdDesc(_session);
|
||||||
|
|
||||||
|
@ -130,7 +100,6 @@ void OculusBaseDisplayPlugin::activate() {
|
||||||
|
|
||||||
void OculusBaseDisplayPlugin::deactivate() {
|
void OculusBaseDisplayPlugin::deactivate() {
|
||||||
HmdDisplayPlugin::deactivate();
|
HmdDisplayPlugin::deactivate();
|
||||||
ovr_Destroy(_session);
|
releaseOculusSession();
|
||||||
_session = nullptr;
|
_session = nullptr;
|
||||||
ovr_Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,62 @@
|
||||||
|
|
||||||
#include "OculusHelpers.h"
|
#include "OculusHelpers.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <QtCore/QLoggingCategory>
|
||||||
|
using Mutex = std::mutex;
|
||||||
|
using Lock = std::unique_lock<Mutex>;
|
||||||
|
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(oculus)
|
||||||
|
Q_LOGGING_CATEGORY(oculus, "hifi.plugins.oculus")
|
||||||
|
|
||||||
|
static std::atomic<uint32_t> refCount { 0 };
|
||||||
|
static ovrSession session { nullptr };
|
||||||
|
|
||||||
|
bool oculusAvailable() {
|
||||||
|
ovrDetectResult detect = ovr_Detect(0);
|
||||||
|
return (detect.IsOculusServiceRunning && detect.IsOculusHMDConnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
ovrSession acquireOculusSession() {
|
||||||
|
if (!session && !oculusAvailable()) {
|
||||||
|
qCDebug(oculus) << "oculus: no runtime or HMD present";
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
ovrInitParams init = {};
|
||||||
|
init.Flags = 0;
|
||||||
|
init.ConnectionTimeoutMS = 0;
|
||||||
|
init.LogCallback = nullptr;
|
||||||
|
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
||||||
|
qCWarning(oculus) << "Failed to initialize Oculus SDK";
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(0 == refCount);
|
||||||
|
ovrGraphicsLuid luid;
|
||||||
|
if (!OVR_SUCCESS(ovr_Create(&session, &luid))) {
|
||||||
|
qCWarning(oculus) << "Failed to acquire Oculus session";
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++refCount;
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
void releaseOculusSession() {
|
||||||
|
Q_ASSERT(refCount > 0 && session);
|
||||||
|
if (!--refCount) {
|
||||||
|
qCDebug(oculus) << "oculus: zero refcount, shutdown SDK and session";
|
||||||
|
ovr_Destroy(session);
|
||||||
|
ovr_Shutdown();
|
||||||
|
session = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// A wrapper for constructing and using a swap texture set,
|
// A wrapper for constructing and using a swap texture set,
|
||||||
// where each frame you draw to a texture via the FBO,
|
// where each frame you draw to a texture via the FBO,
|
||||||
// then submit it and increment to the next texture.
|
// then submit it and increment to the next texture.
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
#include <gl/OglplusHelpers.h>
|
#include <gl/OglplusHelpers.h>
|
||||||
|
|
||||||
|
bool oculusAvailable();
|
||||||
|
ovrSession acquireOculusSession();
|
||||||
|
void releaseOculusSession();
|
||||||
|
|
||||||
// Convenience method for looping over each eye with a lambda
|
// Convenience method for looping over each eye with a lambda
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
inline void ovr_for_each_eye(Function function) {
|
inline void ovr_for_each_eye(Function function) {
|
||||||
|
@ -24,6 +28,19 @@ inline void ovr_for_each_eye(Function function) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Function>
|
||||||
|
inline void ovr_for_each_hand(Function function) {
|
||||||
|
for (ovrHandType hand = ovrHandType::ovrHand_Left;
|
||||||
|
hand <= ovrHandType::ovrHand_Right;
|
||||||
|
hand = static_cast<ovrHandType>(hand + 1)) {
|
||||||
|
function(hand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline glm::mat4 toGlm(const ovrMatrix4f & om) {
|
inline glm::mat4 toGlm(const ovrMatrix4f & om) {
|
||||||
return glm::transpose(glm::make_mat4(&om.M[0][0]));
|
return glm::transpose(glm::make_mat4(&om.M[0][0]));
|
||||||
}
|
}
|
||||||
|
@ -86,6 +103,7 @@ inline ovrPosef ovrPoseFromGlm(const glm::mat4 & m) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A wrapper for constructing and using a swap texture set,
|
// A wrapper for constructing and using a swap texture set,
|
||||||
// where each frame you draw to a texture via the FBO,
|
// where each frame you draw to a texture via the FBO,
|
||||||
// then submit it and increment to the next texture.
|
// then submit it and increment to the next texture.
|
||||||
|
|
|
@ -14,15 +14,18 @@
|
||||||
|
|
||||||
#include <plugins/RuntimePlugin.h>
|
#include <plugins/RuntimePlugin.h>
|
||||||
#include <plugins/DisplayPlugin.h>
|
#include <plugins/DisplayPlugin.h>
|
||||||
|
#include <plugins/InputPlugin.h>
|
||||||
|
|
||||||
#include "OculusDisplayPlugin.h"
|
#include "OculusDisplayPlugin.h"
|
||||||
#include "OculusDebugDisplayPlugin.h"
|
#include "OculusDebugDisplayPlugin.h"
|
||||||
|
|
||||||
class OculusProvider : public QObject, public DisplayProvider
|
class OculusProvider : public QObject, public DisplayProvider, InputProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID DisplayProvider_iid FILE "oculus.json")
|
Q_PLUGIN_METADATA(IID DisplayProvider_iid FILE "oculus.json")
|
||||||
Q_INTERFACES(DisplayProvider)
|
Q_INTERFACES(DisplayProvider)
|
||||||
|
Q_PLUGIN_METADATA(IID InputProvider_iid FILE "oculus.json")
|
||||||
|
Q_INTERFACES(InputProvider)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OculusProvider(QObject* parent = nullptr) : QObject(parent) {}
|
OculusProvider(QObject* parent = nullptr) : QObject(parent) {}
|
||||||
|
@ -47,8 +50,23 @@ public:
|
||||||
return _displayPlugins;
|
return _displayPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual InputPluginList getInputPlugins() override {
|
||||||
|
// FIXME pending full oculus input API and hardware
|
||||||
|
#if 0
|
||||||
|
static std::once_flag once;
|
||||||
|
std::call_once(once, [&] {
|
||||||
|
InputPluginPointer plugin(new OculusControllerManager());
|
||||||
|
if (plugin->isSupported()) {
|
||||||
|
_inputPlugins.push_back(plugin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
return _inputPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DisplayPluginList _displayPlugins;
|
DisplayPluginList _displayPlugins;
|
||||||
|
InputPluginList _inputPlugins;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "OculusProvider.moc"
|
#include "OculusProvider.moc"
|
||||||
|
|
Loading…
Reference in a new issue