From b73ce81a2d3eb4cd811d1fd7a3a48cc01cff8645 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 6 May 2015 22:28:34 -0700 Subject: [PATCH] Working on plugin architecture --- interface/CMakeLists.txt | 6 +- interface/src/Application.cpp | 127 +++++------------- interface/src/Application.h | 21 +-- interface/src/plugins/render/DisplayPlugin.h | 4 +- .../plugins/render/LegacyDisplayPlugin.cpp | 2 +- .../src/plugins/render/LegacyDisplayPlugin.h | 4 +- .../src/plugins/render/NullDisplayPlugin.cpp | 2 +- .../src/plugins/render/NullDisplayPlugin.h | 4 +- 8 files changed, 56 insertions(+), 114 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 9dbed9a6ee..84079dc3b4 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -74,8 +74,6 @@ find_package(Qt5 COMPONENTS Gui Multimedia Network OpenGL Qml Quick Script Svg W file (GLOB_RECURSE QT_UI_FILES ui/*.ui) source_group("UI Files" FILES ${QT_UI_FILES}) - - # have qt5 wrap them and generate the appropriate header files qt5_wrap_ui(QT_UI_HEADERS "${QT_UI_FILES}") @@ -138,8 +136,8 @@ target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) add_dependency_external_projects(OpenVR) find_package(OpenVR REQUIRED) -target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS}) -target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) +target_include_directories(${TARGET_NAME} PRIVATE ${OPENVR_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${OPENVR_LIBRARIES}) find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 781d4d31ed..6b60c3b437 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -290,7 +290,6 @@ bool setupEssentials(int& argc, char** argv) { Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QApplication(argc, argv), _dependencyManagerIsSetup(setupEssentials(argc, argv)), - _offscreenContext(new OffscreenGlContext()), _window(new MainWindow(desktop())), _toolWindow(NULL), _friendsWindow(NULL), @@ -319,8 +318,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _cursorVisible(true), _lastMouseMove(usecTimestampNow()), _lastMouseMoveWasSimulated(false), - _touchAvgX(0.0f), - _touchAvgY(0.0f), _isTouchPressed(false), _mousePressed(false), _enableProcessOctreeThread(true), @@ -501,7 +498,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ResourceCache::setRequestLimit(3); _window->setCentralWidget(new QWidget()); + _window->restoreGeometry(); + _window->setVisible(true); #if 0 @@ -592,7 +591,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : this->installEventFilter(this); // The offscreen UI needs to intercept the mouse and keyboard // events coming from the onscreen window - _glWidget->installEventFilter(DependencyManager::get().data()); + this->installEventFilter(DependencyManager::get().data()); // initialize our face trackers after loading the menu settings auto faceshiftTracker = DependencyManager::get(); @@ -810,18 +809,14 @@ void Application::initializeUi() { void Application::paintGL() { PROFILE_RANGE(__FUNCTION__); - _glWidget->makeCurrent(); + _offscreenContext->makeCurrent(); PerformanceTimer perfTimer("paintGL"); - //Need accurate frame timing for the oculus rift - if (OculusManager::isConnected()) { - OculusManager::beginFrameTiming(); - } + getActiveDisplayPlugin()->preDisplay(); PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::paintGL()"); - _offscreenContext->makeCurrent(); QSize fbSize = getActiveDisplayPlugin()->getRecommendedFramebufferSize() * getRenderResolutionScale(); DependencyManager::get()->setFrameBufferSize(fbSize); @@ -888,7 +883,8 @@ void Application::paintGL() { glPopMatrix(); if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { - _rearMirrorTools->render(true, _glWidget->mapFromGlobal(QCursor::pos())); + glm::vec2 mpos = getActiveDisplayPlugin()->getUiMousePosition(); + _rearMirrorTools->render(true, QPoint(mpos.x, mpos.y)); } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { renderRearViewMirror(_mirrorViewRect); } @@ -1460,8 +1456,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { _keyboardMouseDevice.mousePressEvent(event); if (event->button() == Qt::LeftButton) { - _mouseDragStartedX = getTrueMouseX(); - _mouseDragStartedY = getTrueMouseY(); + _mouseDragStarted = getTrueMousePosition(); _mousePressed = true; if (mouseOnScreen()) { @@ -1563,22 +1558,18 @@ void Application::touchUpdateEvent(QTouchEvent* event) { bool validTouch = false; if (activeWindow() == _window) { const QList& tPoints = event->touchPoints(); - _touchAvgX = 0.0f; - _touchAvgY = 0.0f; + _touchAvg = glm::vec2(0); int numTouches = tPoints.count(); if (numTouches > 1) { for (int i = 0; i < numTouches; ++i) { - _touchAvgX += tPoints[i].pos().x(); - _touchAvgY += tPoints[i].pos().y(); + _touchAvg += toGlm(tPoints[i].pos()); } - _touchAvgX /= (float)(numTouches); - _touchAvgY /= (float)(numTouches); + _touchAvg /= numTouches; validTouch = true; } } if (!_isTouchPressed) { - _touchDragStartedAvgX = _touchAvgX; - _touchDragStartedAvgY = _touchAvgY; + _touchDragStartedAvg = _touchAvg; } _isTouchPressed = validTouch; } @@ -1614,8 +1605,7 @@ void Application::touchEndEvent(QTouchEvent* event) { _keyboardMouseDevice.touchEndEvent(event); // put any application specific touch behavior below here.. - _touchDragStartedAvgX = _touchAvgX; - _touchDragStartedAvgY = _touchAvgY; + _touchDragStartedAvg = _touchAvg; _isTouchPressed = false; } @@ -1736,13 +1726,11 @@ void Application::idle() { const float BIGGEST_DELTA_TIME_SECS = 0.25f; update(glm::clamp((float)timeSinceLastUpdate / 1000.0f, 0.0f, BIGGEST_DELTA_TIME_SECS)); } - { PerformanceTimer perfTimer("updateGL"); PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); getActiveDisplayPlugin()->idle(); } - { PerformanceTimer perfTimer("rest"); PerformanceWarning warn(showWarnings, "Application::idle()... rest of it"); @@ -1822,15 +1810,12 @@ void Application::setFullscreen(bool fullscreen) { } } - -void Application::setEnable3DTVMode(bool enable3DTVMode) { #if 0 +void Application::setEnable3DTVMode(bool enable3DTVMode) { resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); -#endif } void Application::setEnableVRMode(bool enableVRMode) { -#if 0 if (Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode) != enableVRMode) { Menu::getInstance()->getActionForOption(MenuOption::EnableVRMode)->setChecked(enableVRMode); } @@ -1855,8 +1840,8 @@ void Application::setEnableVRMode(bool enableVRMode) { resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); updateCursorVisibility(); -#endif } +#endif void Application::setLowVelocityFilter(bool lowVelocityFilter) { SixenseManager::getInstance().setLowVelocityFilter(lowVelocityFilter); @@ -1875,16 +1860,15 @@ int Application::getMouseY() const { } ivec2 Application::getMouseDragStarted() const { - return getActiveDisplaylugin()->trueMouseToUiMouse( - glm::ivec2(getTrueMouseDragStartedX(), getTrueMouseDragStartedY())); + return getActiveDisplayPlugin()->trueMouseToUiMouse(getTrueMouseDragStarted()); } int Application::getMouseDragStartedX() const { - return getMouseDragStarted().x; + return getMouseDragStarted().x; } int Application::getMouseDragStartedY() const { - return getMouseDragStarted().y; + return getMouseDragStarted().y; } FaceTracker* Application::getActiveFaceTracker() { @@ -2221,9 +2205,8 @@ void Application::updateMyAvatarLookAtPosition() { bool isLookingAtSomeone = false; glm::vec3 lookAtSpot; if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { -#if 0 // When I am in mirror mode, just look right at the camera (myself) - if (!OculusManager::isConnected()) { + if (!isHMDMode()) { lookAtSpot = _myCamera.getPosition(); } else { if (_myAvatar->isLookingAtLeftEye()) { @@ -2232,7 +2215,7 @@ void Application::updateMyAvatarLookAtPosition() { lookAtSpot = OculusManager::getRightEyePosition(); } } -#endif + } else { AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().toStrongRef(); if (lookingAt && _myAvatar != lookingAt.data()) { @@ -3190,12 +3173,12 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha); } - // draw the sky dome - if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { - PerformanceTimer perfTimer("atmosphere"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::displaySide() ... atmosphere..."); - _environment.renderAtmospheres(theCamera); + // draw the sky dome + if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { + PerformanceTimer perfTimer("atmosphere"); + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), + "Application::displaySide() ... atmosphere..."); + _environment.renderAtmospheres(theCamera); } } @@ -3444,7 +3427,8 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { glPopMatrix(); if (!billboard) { - _rearMirrorTools->render(false, _glWidget->mapFromGlobal(QCursor::pos())); + glm::vec2 mpos = getActiveDisplayPlugin()->getUiMousePosition(); + _rearMirrorTools->render(false, QPoint(mpos.x, mpos.y)); } // reset Viewport and projection matrix @@ -4320,6 +4304,7 @@ void Application::skipVersion(QString latestVersion) { } void Application::takeSnapshot() { +#if 0 QMediaPlayer* player = new QMediaPlayer(); QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); @@ -4336,6 +4321,8 @@ void Application::takeSnapshot() { _snapshotShareDialog = new SnapshotShareDialog(fileName, desktop()); } _snapshotShareDialog->show(); +#endif + } void Application::setVSyncEnabled() { @@ -4524,7 +4511,7 @@ glm::uvec2 Application::getCanvasSize() const { } QSize Application::getDeviceSize() const { - return getActiveDisplayPlugin()->getRecommendedFramebufferSize(); // _glWidget->getDeviceSize(); + return getActiveDisplayPlugin()->getDeviceSize(); } void Application::resizeGL() { @@ -4544,21 +4531,15 @@ glm::vec2 Application::getViewportDimensions() const { glm::ivec2 Application::getTrueMousePosition() const { return getActiveDisplayPlugin()->getTrueMousePosition(); } + glm::quat Application::getHeadOrientation() const { return getActiveDisplayPlugin()->headOrientation(); } + glm::vec3 Application::getHeadPosition() const { return getActiveDisplayPlugin()->headTranslation(); } -int Application::getTrueMouseX() const { - return getActiveDisplayPlugin()->getTrueMousePosition().x; -} - -int Application::getTrueMouseY() const { - return getActiveDisplayPlugin()->getTrueMousePosition().y; -} - bool Application::isThrottleRendering() const { return getActiveDisplayPlugin()->isThrottled(); } @@ -4659,43 +4640,3 @@ void Application::initPlugins() { void Application::shutdownPlugins() { OculusManager::deinit(); } - -glm::vec3 Application::getHeadPosition() const { - return OculusManager::getRelativePosition(); -} - -glm::quat Application::getHeadOrientation() const { - return OculusManager::getOrientation(); -} - -glm::uvec2 Application::getCanvasSize() const { - return glm::uvec2(_glWidget->width(), _glWidget->height()); -} - -QSize Application::getDeviceSize() const { - return _glWidget->getDeviceSize(); -} - -int Application::getTrueMouseX() const { - return _glWidget->mapFromGlobal(QCursor::pos()).x(); -} - -int Application::getTrueMouseY() const { - return _glWidget->mapFromGlobal(QCursor::pos()).y(); -} - -bool Application::isThrottleRendering() const { - return _glWidget->isThrottleRendering(); -} - -PickRay Application::computePickRay() const { - return computePickRay(getTrueMouseX(), getTrueMouseY()); -} - -bool Application::hasFocus() const { - return _glWidget->hasFocus(); -} - -void Application::resizeGL() { - this->resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); -} diff --git a/interface/src/Application.h b/interface/src/Application.h index 84231f1bd5..990ccdbd6a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -40,7 +40,6 @@ #include #include - #include "AudioClient.h" #include "Bookmarks.h" #include "Camera.h" @@ -221,14 +220,19 @@ public: const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } bool mouseOnScreen() const; - glm::ivec2 getMouse(); - int getMouseX() const; - int getMouseY() const; + + glm::ivec2 getMouse() const; + int getMouseX() const { return getMouse().x; } + int getMouseY() const { return getMouse().y; } + glm::ivec2 getTrueMousePosition() const; int getTrueMouseX() const { return getTrueMousePosition().x; } int getTrueMouseY() const { return getTrueMousePosition().y; } + + glm::ivec2 getMouseDragStarted() const; int getMouseDragStartedX() const; int getMouseDragStartedY() const; + const glm::ivec2 & getTrueMouseDragStarted() const { return _mouseDragStarted; } int getTrueMouseDragStartedX() const { return getTrueMouseDragStarted().x; } int getTrueMouseDragStartedY() const { return getTrueMouseDragStarted().y; } @@ -586,18 +590,15 @@ private: Environment _environment; bool _cursorVisible; - int _mouseDragStartedX; - int _mouseDragStartedY; + glm::ivec2 _mouseDragStarted; quint64 _lastMouseMove; bool _lastMouseMoveWasSimulated; glm::vec3 _mouseRayOrigin; glm::vec3 _mouseRayDirection; - float _touchAvgX; - float _touchAvgY; - float _touchDragStartedAvgX; - float _touchDragStartedAvgY; + glm::vec2 _touchAvg; + glm::vec2 _touchDragStartedAvg; bool _isTouchPressed; // true if multitouch has been pressed (clear when finished) bool _mousePressed; // true if mouse has been pressed (clear when finished) diff --git a/interface/src/plugins/render/DisplayPlugin.h b/interface/src/plugins/render/DisplayPlugin.h index a0a409bd7e..3c1f710354 100644 --- a/interface/src/plugins/render/DisplayPlugin.h +++ b/interface/src/plugins/render/DisplayPlugin.h @@ -36,7 +36,9 @@ public: // Does the rendering surface have current focus? virtual bool hasFocus() const = 0; // The size of the rendering surface - virtual QSize getRecommendedFramebufferSize() const = 0; + virtual QSize getDeviceSize() const = 0; + // The size of the rendering target (may be larger than the device size due to distortion) + virtual QSize getRecommendedFramebufferSize() const { return getDeviceSize(); }; // The size of the window (differs from the framebuffers size in instances like Retina macs) virtual glm::ivec2 getCanvasSize() const = 0; diff --git a/interface/src/plugins/render/LegacyDisplayPlugin.cpp b/interface/src/plugins/render/LegacyDisplayPlugin.cpp index 79cc433543..30c42d29c3 100644 --- a/interface/src/plugins/render/LegacyDisplayPlugin.cpp +++ b/interface/src/plugins/render/LegacyDisplayPlugin.cpp @@ -48,7 +48,7 @@ void LegacyDisplayPlugin::deactivate() { _window = nullptr; } -QSize LegacyDisplayPlugin::getRecommendedFramebufferSize() const { +QSize LegacyDisplayPlugin::getDeviceSize() const { return _window->getDeviceSize(); } diff --git a/interface/src/plugins/render/LegacyDisplayPlugin.h b/interface/src/plugins/render/LegacyDisplayPlugin.h index 9654278dcd..2565554297 100644 --- a/interface/src/plugins/render/LegacyDisplayPlugin.h +++ b/interface/src/plugins/render/LegacyDisplayPlugin.h @@ -21,12 +21,12 @@ public: virtual void activate(); virtual void deactivate(); - virtual QSize getRecommendedFramebufferSize() const; + virtual QSize getDeviceSize() const; virtual glm::ivec2 getCanvasSize() const; virtual bool hasFocus() const; virtual PickRay computePickRay(const glm::vec2 & pos) const; virtual bool isMouseOnScreen() const { return true; } - virtual bool isThrottled(); + virtual bool isThrottled() const; protected: virtual void makeCurrent(); diff --git a/interface/src/plugins/render/NullDisplayPlugin.cpp b/interface/src/plugins/render/NullDisplayPlugin.cpp index 97683a1100..0bd964f34b 100644 --- a/interface/src/plugins/render/NullDisplayPlugin.cpp +++ b/interface/src/plugins/render/NullDisplayPlugin.cpp @@ -15,7 +15,7 @@ const QString & NullDisplayPlugin::getName() { return NAME; } -QSize NullDisplayPlugin::getRecommendedFramebufferSize() const { +QSize NullDisplayPlugin::getDeviceSize() const { return QSize(100, 100); } diff --git a/interface/src/plugins/render/NullDisplayPlugin.h b/interface/src/plugins/render/NullDisplayPlugin.h index c434ddd3f5..47f5dc7288 100644 --- a/interface/src/plugins/render/NullDisplayPlugin.h +++ b/interface/src/plugins/render/NullDisplayPlugin.h @@ -18,12 +18,12 @@ public: virtual ~NullDisplayPlugin() final {} virtual const QString & getName(); - virtual QSize getRecommendedFramebufferSize() const; + virtual QSize getDeviceSize() const; virtual glm::ivec2 getCanvasSize() const; virtual bool hasFocus() const; virtual glm::ivec2 getRelativeMousePosition() const; virtual glm::ivec2 getTrueMousePosition() const; virtual PickRay computePickRay(const glm::vec2 & pos) const; - virtual bool isMouseOnScreen(); + virtual bool isMouseOnScreen() const; };