merge with hifi/plugins

This commit is contained in:
Sam Gondelman 2015-07-02 10:13:28 -07:00
commit 81efd99ae4
24 changed files with 276 additions and 280 deletions

View file

@ -7,8 +7,8 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
ExternalProject_Add(
${EXTERNAL_NAME}
URL https://github.com/ValveSoftware/openvr/archive/0.9.1.zip
URL_MD5 f986f5a6815e9454c53c5bf58ce02fdc
URL https://github.com/ValveSoftware/openvr/archive/0.9.2.zip
URL_MD5 3ff7b67861b63ef673014e353f2c1bf6
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""

View file

@ -12,7 +12,6 @@
#ifndef interface__InterfaceConfig__
#define interface__InterfaceConfig__
#define GL_GLEXT_PROTOTYPES 1
@GL_HEADERS@
#include <gpu/GPUConfig.h>
#endif

View file

@ -4844,6 +4844,8 @@ const DisplayPlugin * Application::getActiveDisplayPlugin() const {
return ((Application*)this)->getActiveDisplayPlugin();
}
static QVector<QPair<QString, QString>> _currentDisplayPluginActions;
void Application::updateDisplayMode() {
auto menu = Menu::getInstance();
auto displayPlugins = getDisplayPlugins();
@ -4867,6 +4869,14 @@ void Application::updateDisplayMode() {
oldDisplayPlugin->removeEventFilter(qApp);
}
if (!_currentDisplayPluginActions.isEmpty()) {
auto menu = Menu::getInstance();
foreach(auto itemInfo, _currentDisplayPluginActions) {
menu->removeMenuItem(itemInfo.first, itemInfo.second);
}
_currentDisplayPluginActions.clear();
}
if (newDisplayPlugin) {
_offscreenContext->makeCurrent();
newDisplayPlugin->activate(this);
@ -4895,8 +4905,14 @@ void Application::updateDisplayMode() {
Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");
}
void Application::addMenuItem(const QString& path, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
auto menu = Menu::getInstance();
MenuWrapper* parentItem = menu->getMenu(path);
QAction* action = parentItem->addAction(name);
connect(action, &QAction::triggered, [=] {
onClicked();
});
_currentDisplayPluginActions.push_back({ path, name });
}
GlWindow* Application::getVisibleWindow() {

View file

@ -294,7 +294,7 @@ public:
virtual qreal getDevicePixelRatio();
// Plugin container support
virtual void addMenuItem(const QString& path, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName);
virtual void addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName);
virtual GlWindow* getVisibleWindow();
private:

View file

@ -17,8 +17,9 @@
#include <display-plugins/Basic2DWindowOpenGLDisplayPlugin.h>
#ifdef Q_OS_WIN
#include <display-plugins/oculus/OculusWin32DisplayPlugin.h>
#include <display-plugins/oculus/Oculus_0_6_DisplayPlugin.h>
#else
#include <display-plugins/oculus/Oculus_0_5_DisplayPlugin.h>
#endif
#include <display-plugins/openvr/OpenVrDisplayPlugin.h>
@ -56,8 +57,15 @@ const DisplayPluginList& getDisplayPlugins() {
new NullDisplayPlugin(),
new SideBySideStereoDisplayPlugin(),
// new InterleavedStereoDisplayPlugin(),
new OculusWin32DisplayPlugin(),
#ifdef Q_OS_WIN
new Oculus_0_6_DisplayPlugin(),
#else
new Oculus_0_5_DisplayPlugin(),
#endif
#ifndef Q_OS_MAC
new OpenVrDisplayPlugin(),
#endif
nullptr
};
for (int i = 0; PLUGIN_POOL[i]; ++i) {

View file

@ -1,165 +0,0 @@
//
// GLCanvas.cpp
// interface/src
//
// Created by Stephen Birarda on 8/14/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#if 0
#include "Application.h"
#include "GLCanvas.h"
const int MSECS_PER_FRAME_WHEN_THROTTLED = 66;
GLCanvas::GLCanvas() : QGLWidget(QGL::NoDepthBuffer | QGL::NoStencilBuffer),
_throttleRendering(false),
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
{
#ifdef Q_OS_LINUX
// Cause GLCanvas::eventFilter to be called.
// It wouldn't hurt to do this on Mac and PC too; but apparently it's only needed on linux.
qApp->installEventFilter(this);
#endif
}
void GLCanvas::stopFrameTimer() {
_frameTimer.stop();
}
bool GLCanvas::isThrottleRendering() const {
return _throttleRendering || parentWidget()->isMinimized();
}
int GLCanvas::getDeviceWidth() const {
return width() * (windowHandle() ? (float)windowHandle()->devicePixelRatio() : 1.0f);
}
int GLCanvas::getDeviceHeight() const {
return height() * (windowHandle() ? (float)windowHandle()->devicePixelRatio() : 1.0f);
}
void GLCanvas::initializeGL() {
setAttribute(Qt::WA_AcceptTouchEvents);
setAcceptDrops(true);
connect(Application::getInstance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeChanged(Qt::ApplicationState)));
connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(throttleRender()));
// Note, we *DO NOT* want Qt to automatically swap buffers for us. This results in the "ringing" bug mentioned in WL#19514 when we're throttling the framerate.
setAutoBufferSwap(false);
}
void GLCanvas::paintGL() {
if (!isThrottleRendering()) {
Application::getInstance()->paintGL();
}
}
void GLCanvas::resizeGL(int width, int height) {
Application::getInstance()->resizeGL();
}
void GLCanvas::activeChanged(Qt::ApplicationState state) {
switch (state) {
case Qt::ApplicationActive:
// If we're active, stop the frame timer and the throttle.
_frameTimer.stop();
_throttleRendering = false;
break;
case Qt::ApplicationSuspended:
case Qt::ApplicationHidden:
// If we're hidden or are about to suspend, don't render anything.
_throttleRendering = false;
_frameTimer.stop();
break;
default:
// Otherwise, throttle.
if (!_throttleRendering && !Application::getInstance()->isAboutToQuit()) {
_frameTimer.start(_idleRenderInterval);
_throttleRendering = true;
}
break;
}
}
void GLCanvas::throttleRender() {
_frameTimer.start(_idleRenderInterval);
if (!parentWidget()->isMinimized()) {
Application::getInstance()->paintGL();
}
}
int updateTime = 0;
bool GLCanvas::event(QEvent* event) {
switch (event->type()) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::FocusIn:
case QEvent::FocusOut:
case QEvent::Resize:
case QEvent::TouchBegin:
case QEvent::TouchEnd:
case QEvent::TouchUpdate:
case QEvent::Wheel:
case QEvent::DragEnter:
case QEvent::Drop:
if (QCoreApplication::sendEvent(QCoreApplication::instance(), event)) {
return true;
}
break;
case QEvent::Paint:
// Ignore paint events that occur after we've decided to quit
if (Application::getInstance()->isAboutToQuit()) {
return true;
}
break;
default:
break;
}
return QGLWidget::event(event);
}
// Pressing Alt (and Meta) key alone activates the menubar because its style inherits the
// SHMenuBarAltKeyNavigation from QWindowsStyle. This makes it impossible for a scripts to
// receive keyPress events for the Alt (and Meta) key in a reliable manner.
//
// This filter catches events before QMenuBar can steal the keyboard focus.
// The idea was borrowed from
// http://www.archivum.info/qt-interest@trolltech.com/2006-09/00053/Re-(Qt4)-Alt-key-focus-QMenuBar-(solved).html
bool GLCanvas::eventFilter(QObject*, QEvent* event) {
switch (event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::ShortcutOverride:
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Alt || keyEvent->key() == Qt::Key_Meta) {
if (event->type() == QEvent::KeyPress) {
keyPressEvent(keyEvent);
} else if (event->type() == QEvent::KeyRelease) {
keyReleaseEvent(keyEvent);
} else {
QGLWidget::event(event);
}
return true;
}
}
default:
break;
}
return false;
}
#endif

View file

@ -1,55 +0,0 @@
//
// GLCanvas.h
// interface/src
//
// Created by Stephen Birarda on 8/14/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#if 0
#ifndef hifi_GLCanvas_h
#define hifi_GLCanvas_h
#include <QDebug>
#include <QGLWidget>
#include <QTimer>
/// customized canvas that simply forwards requests/events to the singleton application
class GLCanvas : public QGLWidget {
Q_OBJECT
public:
GLCanvas();
void stopFrameTimer();
bool isThrottleRendering() const;
int getDeviceWidth() const;
int getDeviceHeight() const;
QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); }
protected:
QTimer _frameTimer;
bool _throttleRendering;
int _idleRenderInterval;
virtual void initializeGL();
virtual void paintGL();
virtual void resizeGL(int width, int height);
virtual bool event(QEvent* event);
private slots:
void activeChanged(Qt::ApplicationState state);
void throttleRender();
bool eventFilter(QObject*, QEvent* event);
};
#endif // hifi_GLCanvas_h
#endif

View file

@ -12,8 +12,6 @@
#include <QStyle>
#include <QStyleOptionTitleBar>
#include "GLCanvas.h"
#include "UIUtil.h"
int UIUtil::getWindowTitleBarHeight(const QWidget* window) {

View file

@ -11,7 +11,6 @@
#include <avatar/AvatarManager.h>
#include <avatar/MyAvatar.h>
#include <GLCanvas.h>
#include <HandData.h>
#include <HFBackEvent.h>

View file

@ -22,7 +22,6 @@
#include <avatar/AvatarManager.h>
#include <avatar/MyAvatar.h>
#include <FileUtils.h>
#include <GLCanvas.h>
#include <NodeList.h>
#include "Application.h"

View file

@ -21,7 +21,6 @@
#include <avatar/AvatarManager.h>
#include <Application.h>
#include <GeometryCache.h>
#include <GLCanvas.h>
#include <LODManager.h>
#include <PerfStat.h>

View file

@ -14,7 +14,7 @@ find_package(GLM REQUIRED)
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(boostconfig)
find_package(BOOSTCONFIG REQUIRED)
find_package(BoostConfig REQUIRED)
target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS})
add_dependency_external_projects(oglplus)
@ -26,7 +26,9 @@ find_package(LibOVR REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES})
add_dependency_external_projects(OpenVR)
find_package(OpenVR REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${OPENVR_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${OPENVR_LIBRARIES})
if (NOT(APPLE))
add_dependency_external_projects(OpenVR)
find_package(OpenVR REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${OPENVR_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${OPENVR_LIBRARIES})
endif()

View file

@ -39,30 +39,30 @@ void WindowOpenGLDisplayPlugin::initSurfaceFormat(QSurfaceFormat& format) {
void WindowOpenGLDisplayPlugin::activate(PluginContainer * container) {
OpenGLDisplayPlugin::activate(container);
_window = createWindow(container);
QSurfaceFormat format;
initSurfaceFormat(format);
_window->setFormat(format);
_window->create();
_window->installEventFilter(this);
customizeWindow(container);
makeCurrent();
_window->makeCurrent();
customizeContext(container);
}
void WindowOpenGLDisplayPlugin::deactivate() {
OpenGLDisplayPlugin::deactivate();
destroyWindow();
_window = nullptr;
}
GlWindow* WindowOpenGLDisplayPlugin::createWindow(PluginContainer * container) {
return new GlWindow(QOpenGLContext::currentContext());
GlWindow* result = new GlWindow(QOpenGLContext::currentContext());
QSurfaceFormat format;
initSurfaceFormat(format);
result->setFormat(format);
result->create();
result->installEventFilter(this);
return result;
}
void WindowOpenGLDisplayPlugin::destroyWindow() {
_window->deleteLater();
_window = nullptr;
}

View file

@ -30,11 +30,13 @@ void OculusBaseDisplayPlugin::activate(PluginContainer * container) {
eyeSizes[0].x + eyeSizes[1].x,
std::max(eyeSizes[0].y, eyeSizes[1].y));
_frameIndex = 0;
if (!OVR_SUCCESS(ovrHmd_ConfigureTracking(_hmd,
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) {
qFatal("Could not attach to sensor device");
}
_frameIndex = 0;
MainWindowOpenGLDisplayPlugin::activate(container);
}

View file

@ -36,3 +36,7 @@ protected:
mat4 _compositeEyeProjections[2];
uvec2 _desiredFramebufferSize;
};
#if (OVR_MAJOR_VERSION < 6)
#define OVR_SUCCESS(x) x
#endif

View file

@ -0,0 +1,107 @@
//
// Created by Bradley Austin Davis on 2014/04/13.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Oculus_0_5_DisplayPlugin.h"
#if (OVR_MAJOR_VERSION == 5)
#include <memory>
#include <QMainWindow>
#include <QGLWidget>
#include <GLMHelpers.h>
#include <GlWindow.h>
#include <QEvent>
#include <QResizeEvent>
#include <QOpenGLContext>
#include <OVR_CAPI_GL.h>
#include <PerfStat.h>
#include "plugins/PluginContainer.h"
#include "OculusHelpers.h"
#include <oglplus/opt/list_init.hpp>
#include <oglplus/shapes/vector.hpp>
#include <oglplus/opt/list_init.hpp>
#include <oglplus/shapes/obj_mesh.hpp>
#include "../OglplusHelpers.h"
const QString Oculus_0_5_DisplayPlugin::NAME("Oculus Rift (0.5)");
const QString & Oculus_0_5_DisplayPlugin::getName() const {
return NAME;
}
bool Oculus_0_5_DisplayPlugin::isSupported() const {
if (!ovr_Initialize(nullptr)) {
return false;
}
bool result = false;
if (ovrHmd_Detect() > 0) {
result = true;
}
ovr_Shutdown();
return result;
}
void Oculus_0_5_DisplayPlugin::activate(PluginContainer * container) {
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
Q_ASSERT(false);
qFatal("Failed to Initialize SDK");
}
_hmd = ovrHmd_Create(0);
if (!_hmd) {
qFatal("Failed to acquire HMD");
}
OculusBaseDisplayPlugin::activate(container);
_window->makeCurrent();
_hmdWindow = new GlWindow(QOpenGLContext::currentContext());
QSurfaceFormat format;
initSurfaceFormat(format);
_hmdWindow->setFormat(format);
_hmdWindow->create();
_hmdWindow->installEventFilter(this);
_hmdWindow->makeCurrent();
}
void Oculus_0_5_DisplayPlugin::deactivate() {
_hmdWindow->deleteLater();
_hmdWindow = nullptr;
OculusBaseDisplayPlugin::deactivate();
ovrHmd_Destroy(_hmd);
_hmd = nullptr;
ovr_Shutdown();
}
void Oculus_0_5_DisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
++_frameIndex;
}
// Pass input events on to the application
bool Oculus_0_5_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
return OculusBaseDisplayPlugin::eventFilter(receiver, event);
}
/*
The swapbuffer call here is only required if we want to mirror the content to the screen.
However, it should only be done if we can reliably disable v-sync on the mirror surface,
otherwise the swapbuffer delay will interefere with the framerate of the headset
*/
void Oculus_0_5_DisplayPlugin::finishFrame() {
swapBuffers();
doneCurrent();
};
#endif

View file

@ -0,0 +1,47 @@
//
// Created by Bradley Austin Davis on 2015/05/29
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#include "OculusBaseDisplayPlugin.h"
#if (OVR_MAJOR_VERSION == 5)
#include <QTimer>
class OffscreenGlCanvas;
struct SwapFramebufferWrapper;
struct MirrorFramebufferWrapper;
using SwapFboPtr = QSharedPointer<SwapFramebufferWrapper>;
using MirrorFboPtr = QSharedPointer<MirrorFramebufferWrapper>;
class Oculus_0_5_DisplayPlugin : public OculusBaseDisplayPlugin {
public:
virtual bool isSupported() const override;
virtual const QString & getName() const override;
virtual void activate(PluginContainer * container) override;
virtual void deactivate() override;
virtual bool eventFilter(QObject* receiver, QEvent* event) override;
protected:
virtual void display(GLuint finalTexture, const glm::uvec2& sceneSize) override;
// Do not perform swap in finish
virtual void finishFrame() override;
private:
static const QString NAME;
GlWindow* _hmdWindow;
};
#endif

View file

@ -5,7 +5,9 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "OculusWin32DisplayPlugin.h"
#include "Oculus_0_6_DisplayPlugin.h"
#if (OVR_MAJOR_VERSION == 6)
#include <memory>
@ -144,13 +146,13 @@ private:
}
};
const QString OculusWin32DisplayPlugin::NAME("Oculus Rift");
const QString Oculus_0_6_DisplayPlugin::NAME("Oculus Rift");
const QString & OculusWin32DisplayPlugin::getName() const {
const QString & Oculus_0_6_DisplayPlugin::getName() const {
return NAME;
}
bool OculusWin32DisplayPlugin::isSupported() const {
bool Oculus_0_6_DisplayPlugin::isSupported() const {
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
return false;
}
@ -162,13 +164,13 @@ bool OculusWin32DisplayPlugin::isSupported() const {
return result;
}
ovrLayerEyeFov& OculusWin32DisplayPlugin::getSceneLayer() {
ovrLayerEyeFov& Oculus_0_6_DisplayPlugin::getSceneLayer() {
return _sceneLayer;
}
//static gpu::TexturePointer _texture;
void OculusWin32DisplayPlugin::activate(PluginContainer * container) {
void Oculus_0_6_DisplayPlugin::activate(PluginContainer * container) {
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
Q_ASSERT(false);
qFatal("Failed to Initialize SDK");
@ -178,6 +180,8 @@ void OculusWin32DisplayPlugin::activate(PluginContainer * container) {
qFatal("Failed to acquire HMD");
}
OculusBaseDisplayPlugin::activate(container);
// Parent class relies on our _hmd intialization, so it must come after that.
ovrLayerEyeFov& sceneLayer = getSceneLayer();
memset(&sceneLayer, 0, sizeof(ovrLayerEyeFov));
@ -191,16 +195,14 @@ void OculusWin32DisplayPlugin::activate(PluginContainer * container) {
PerformanceTimer::setActive(true);
//ovrLayerQuad& uiLayer = getUiLayer();
//memset(&uiLayer, 0, sizeof(ovrLayerQuad));
//uiLayer.Header.Type = ovrLayerType_QuadInWorld;
//uiLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft | ovrLayerFlag_HighQuality;
//uiLayer.QuadPoseCenter.Orientation = { 0, 0, 0, 1 };
//uiLayer.QuadPoseCenter.Position = { 0, 0, -1 };
OculusBaseDisplayPlugin::activate(container);
if (!OVR_SUCCESS(ovrHmd_ConfigureTracking(_hmd,
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) {
qFatal("Could not attach to sensor device");
}
}
void OculusWin32DisplayPlugin::customizeContext(PluginContainer * container) {
void Oculus_0_6_DisplayPlugin::customizeContext(PluginContainer * container) {
OculusBaseDisplayPlugin::customizeContext(container);
//_texture = DependencyManager::get<TextureCache>()->
@ -220,7 +222,7 @@ void OculusWin32DisplayPlugin::customizeContext(PluginContainer * container) {
sceneLayer.ColorTexture[1] = nullptr;
}
void OculusWin32DisplayPlugin::deactivate() {
void Oculus_0_6_DisplayPlugin::deactivate() {
makeCurrent();
_sceneFbo.reset();
_mirrorFbo.reset();
@ -234,7 +236,7 @@ void OculusWin32DisplayPlugin::deactivate() {
ovr_Shutdown();
}
void OculusWin32DisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
void Oculus_0_6_DisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
using namespace oglplus;
// Need to make sure only the display plugin is responsible for
// controlling vsync
@ -297,7 +299,7 @@ void OculusWin32DisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sc
}
// Pass input events on to the application
bool OculusWin32DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
bool Oculus_0_6_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
if (event->type() == QEvent::Resize) {
QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
qDebug() << resizeEvent->size().width() << " x " << resizeEvent->size().height();
@ -314,7 +316,7 @@ bool OculusWin32DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
However, it should only be done if we can reliably disable v-sync on the mirror surface,
otherwise the swapbuffer delay will interefere with the framerate of the headset
*/
void OculusWin32DisplayPlugin::finishFrame() {
void Oculus_0_6_DisplayPlugin::finishFrame() {
swapBuffers();
doneCurrent();
};
@ -351,3 +353,5 @@ _uiFbo->Bound([&] {
Q_ASSERT(0 == glGetError());
});
#endif
#endif

View file

@ -11,6 +11,8 @@
#include <QTimer>
#if (OVR_MAJOR_VERSION == 6)
class OffscreenGlCanvas;
struct SwapFramebufferWrapper;
struct MirrorFramebufferWrapper;
@ -18,7 +20,7 @@ struct MirrorFramebufferWrapper;
using SwapFboPtr = QSharedPointer<SwapFramebufferWrapper>;
using MirrorFboPtr = QSharedPointer<MirrorFramebufferWrapper>;
class OculusWin32DisplayPlugin : public OculusBaseDisplayPlugin {
class Oculus_0_6_DisplayPlugin : public OculusBaseDisplayPlugin {
public:
virtual bool isSupported() const override;
virtual const QString & getName() const override;
@ -45,3 +47,5 @@ private:
MirrorFboPtr _mirrorFbo;
ovrLayerEyeFov _sceneLayer;
};
#endif

View file

@ -7,6 +7,8 @@
//
#include "OpenVrDisplayPlugin.h"
#if !defined(Q_OS_MAC)
#include <memory>
#include <QMainWindow>
@ -33,6 +35,7 @@ vr::IVRSystem *_hmd{ nullptr };
static vr::IVRCompositor* _compositor{ nullptr };
vr::TrackedDevicePose_t _trackedDevicePose[vr::k_unMaxTrackedDeviceCount];
mat4 _trackedDevicePoseMat4[vr::k_unMaxTrackedDeviceCount];
static mat4 _sensorResetMat;
static uvec2 _windowSize;
static ivec2 _windowPosition;
static uvec2 _renderTargetSize;
@ -130,7 +133,24 @@ mat4 OpenVrDisplayPlugin::getModelview(Eye eye, const mat4& baseModelview) const
}
void OpenVrDisplayPlugin::resetSensors() {
_hmd->ResetSeatedZeroPose();
// _hmd->ResetSeatedZeroPose(); AJT: not working
mat4 pose = _trackedDevicePoseMat4[0];
vec3 xAxis = vec3(pose[0]);
vec3 yAxis = vec3(pose[1]);
vec3 zAxis = vec3(pose[2]);
// cancel out the roll and pitch
vec3 newZ = (zAxis.x == 0 && zAxis.z == 0) ? vec3(1, 0, 0) : glm::normalize(vec3(zAxis.x, 0, zAxis.z));
vec3 newX = glm::cross(vec3(0, 1, 0), newZ);
vec3 newY = glm::cross(newZ, newX);
mat4 m;
m[0] = vec4(newX, 0);
m[1] = vec4(newY, 0);
m[2] = vec4(newZ, 0);
m[3] = pose[3];
_sensorResetMat = glm::inverse(m);
}
glm::mat4 OpenVrDisplayPlugin::getEyePose(Eye eye) const {
@ -138,7 +158,7 @@ glm::mat4 OpenVrDisplayPlugin::getEyePose(Eye eye) const {
}
glm::mat4 OpenVrDisplayPlugin::getHeadPose() const {
return _trackedDevicePoseMat4[0];
return _sensorResetMat * _trackedDevicePoseMat4[0];
}
void OpenVrDisplayPlugin::customizeContext(PluginContainer * container) {
@ -147,8 +167,8 @@ void OpenVrDisplayPlugin::customizeContext(PluginContainer * container) {
void OpenVrDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
// Flip y-axis since GL UV coords are backwards.
static vr::Compositor_TextureBounds leftBounds{ 0, 1, 0.5f, 0 };
static vr::Compositor_TextureBounds rightBounds{ 0.5f, 1, 1, 0 };
static vr::VRTextureBounds_t leftBounds{ 0, 1, 0.5f, 0 };
static vr::VRTextureBounds_t rightBounds{ 0.5f, 1, 1, 0 };
_compositor->Submit(vr::Eye_Left, (void*)finalTexture, &leftBounds);
_compositor->Submit(vr::Eye_Right, (void*)finalTexture, &rightBounds);
glFinish();
@ -157,12 +177,14 @@ void OpenVrDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSi
void OpenVrDisplayPlugin::finishFrame() {
// swapBuffers();
doneCurrent();
_compositor->WaitGetPoses(_trackedDevicePose, vr::k_unMaxTrackedDeviceCount);
_compositor->WaitGetPoses(_trackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0);
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) {
_trackedDevicePoseMat4[i] = toGlm(_trackedDevicePose[i].mDeviceToAbsoluteTracking);
}
openvr_for_each_eye([&](vr::Hmd_Eye eye) {
_eyesData[eye]._pose = _trackedDevicePoseMat4[0];
_eyesData[eye]._pose = _sensorResetMat * _trackedDevicePoseMat4[0];
});
};
#endif

View file

@ -7,6 +7,8 @@
//
#pragma once
#if !defined(Q_OS_MAC)
#include "../MainWindowOpenGLDisplayPlugin.h"
class OpenVrDisplayPlugin : public MainWindowOpenGLDisplayPlugin {
@ -38,3 +40,6 @@ protected:
private:
static const QString NAME;
};
#endif

View file

@ -7,8 +7,10 @@
//
#pragma once
#if !defined(Q_OS_MAC)
#include <openvr.h>
#include <GLMHelpers.h>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#endif

View file

@ -12,21 +12,20 @@
#ifndef gpu__GPUConfig__
#define gpu__GPUConfig__
#include <GL/glew.h>
#define GL_GLEXT_PROTOTYPES 1
#define GPU_CORE 1
#define GPU_LEGACY 0
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#define GPU_FEATURE_PROFILE GPU_LEGACY
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
#elif defined(WIN32)
#include <windowshacks.h>
#include <GL/glew.h>
#include <GL/wglew.h>
#define GPU_FEATURE_PROFILE GPU_CORE
@ -35,12 +34,12 @@
#elif defined(ANDROID)
#else
#include <GL/gl.h>
#include <GL/glext.h>
#define GPU_FEATURE_PROFILE GPU_LEGACY
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
#include <GL/glxew.h>
#endif
#endif

View file

@ -6,6 +6,6 @@ class GlWindow;
class PluginContainer {
public:
virtual void addMenuItem(const QString& path, std::function<void()> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
virtual void addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
virtual GlWindow* getVisibleWindow() = 0;
};