diff --git a/cmake/externals/openvr/CMakeLists.txt b/cmake/externals/openvr/CMakeLists.txt index c5b15f4ea3..b5cd477c02 100644 --- a/cmake/externals/openvr/CMakeLists.txt +++ b/cmake/externals/openvr/CMakeLists.txt @@ -17,22 +17,22 @@ ExternalProject_Add( ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) -set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/openvr-0.9.0/headers CACHE TYPE INTERNAL) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/headers CACHE TYPE INTERNAL) if (WIN32) # FIXME need to account for different architectures - set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/openvr-0.9.0/lib/win32/openvr_api.lib CACHE TYPE INTERNAL) + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/win32/openvr_api.lib CACHE TYPE INTERNAL) elseif(APPLE) # FIXME need to account for different architectures - set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/openvr-0.9.0/lib/osx32/libopenvr_api.dylib CACHE TYPE INTERNAL) + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/osx32/libopenvr_api.dylib CACHE TYPE INTERNAL) elseif(NOT ANDROID) # FIXME need to account for different architectures - set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/openvr-0.9.0/lib/linux32/libopenvr_api.so CACHE TYPE INTERNAL) + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/linux32/libopenvr_api.so CACHE TYPE INTERNAL) endif() diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0b98fdae6b..8f47962b24 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -109,8 +109,6 @@ #include "devices/Leapmotion.h" #include "devices/RealSense.h" #include "devices/MIDIManager.h" -#include "devices/OculusManager.h" -#include "devices/TV3DManager.h" #include "gpu/Batch.h" #include "gpu/GLBackend.h" @@ -589,9 +587,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : #endif this->installEventFilter(this); - // The offscreen UI needs to intercept the mouse and keyboard - // events coming from the onscreen window - this->installEventFilter(DependencyManager::get().data()); // initialize our face trackers after loading the menu settings auto faceshiftTracker = DependencyManager::get(); @@ -808,14 +803,18 @@ void Application::initializeUi() { void Application::paintGL() { PROFILE_RANGE(__FUNCTION__); - _offscreenContext->makeCurrent(); + auto displayPlugin = getActiveDisplayPlugin(); + displayPlugin->preRender(); PerformanceTimer perfTimer("paintGL"); - getActiveDisplayPlugin()->preDisplay(); + + _offscreenContext->makeCurrent(); + Q_ASSERT(_offscreenContext->getContext() == QOpenGLContext::currentContext()); PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::paintGL()"); resizeGL(); + Q_ASSERT(_offscreenContext->getContext() == QOpenGLContext::currentContext()); glEnable(GL_LINE_SMOOTH); @@ -850,9 +849,10 @@ void Application::paintGL() { (_myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); } + Q_ASSERT(_offscreenContext->getContext() == QOpenGLContext::currentContext()); // Update camera position - if (!OculusManager::isConnected()) { + if (!isHMDMode()) { _myCamera.update(1.0f / _fps); } @@ -887,19 +887,9 @@ void Application::paintGL() { } finalFbo = DependencyManager::get()->render(); - - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); - glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y, - 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(), - GL_COLOR_BUFFER_BIT, GL_NEAREST); - { PerformanceTimer perfTimer("renderOverlay"); _applicationOverlay.renderOverlay(); - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); - _applicationOverlay.displayOverlayTexture(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); } } @@ -909,9 +899,14 @@ void Application::paintGL() { // but may be better handled with a fence object glFinish(); + _offscreenContext->doneCurrent(); Q_ASSERT(!QOpenGLContext::currentContext()); - getActiveDisplayPlugin()->display(gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0))); + displayPlugin->preDisplay(); + + displayPlugin->display(gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0)), finalFbo->getSize(), + _applicationOverlay.getOverlayTexture(), getCanvasSize()); + displayPlugin->finishFrame(); Q_ASSERT(!QOpenGLContext::currentContext()); _offscreenContext->makeCurrent(); _frameCount++; @@ -944,32 +939,32 @@ void Application::showEditEntitiesHelp() { } void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) { +#if 0 if (OculusManager::isConnected()) { OculusManager::configureCamera(camera, size.x, size.y); } else if (TV3DManager::isConnected()) { TV3DManager::configureCamera(camera, size.x, size.y); } else { - camera.setAspectRatio(aspect(size)); +#endif + camera.setAspectRatio(aspect(size)); camera.setFieldOfView(_fieldOfView.get()); +#if 0 } +#endif } void Application::resizeEvent(QResizeEvent * event) { - const QSize & newSize = event->size(); - resizeGL(newSize.width(), newSize.height()); + resizeGL(); } void Application::resizeGL() { // Set the desired FBO texture size. If it hasn't changed, this does nothing. // Otherwise, it must rebuild the FBOs - QSize renderSize; - if (OculusManager::isConnected()) { - renderSize = OculusManager::getRenderTargetSize(); - } else { - renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale(); - } + QSize framebufferSize = getActiveDisplayPlugin()->getRecommendedFramebufferSize(); + QSize renderSize = framebufferSize * getRenderResolutionScale(); + if (_renderResolution == toGlm(renderSize)) { - return; + return; } _renderResolution = toGlm(renderSize); @@ -981,10 +976,9 @@ void Application::resizeGL() { updateProjectionMatrix(); glLoadIdentity(); - auto canvasSize = getActiveDisplayPlugin()->getCanvasSize(); auto offscreenUi = DependencyManager::get(); - offscreenUi->resize(fromGlm(canvasSize)); - _glWidget->makeCurrent(); + offscreenUi->resize(fromGlm(getCanvasSize())); + _offscreenContext->makeCurrent(); // update Stats width // let's set horizontal offset to give stats some margin to mirror @@ -1865,14 +1859,6 @@ bool Application::mouseOnScreen() const { return getActiveDisplayPlugin()->isMouseOnScreen(); } -int Application::getMouseX() const { - return getActiveDisplayPlugin()->getUiMousePosition().x; -} - -int Application::getMouseY() const { - return getActiveDisplayPlugin()->getUiMousePosition().x; -} - ivec2 Application::getMouseDragStarted() const { return getActiveDisplayPlugin()->trueMouseToUiMouse(getTrueMouseDragStarted()); } @@ -2050,6 +2036,7 @@ void Application::init() { DependencyManager::get()->toggleLoginDialog(); _environment.init(); + Q_ASSERT(_offscreenContext->getContext() == QOpenGLContext::currentContext()); DependencyManager::get()->init(this); DependencyManager::get()->init(this); @@ -2220,15 +2207,17 @@ void Application::updateMyAvatarLookAtPosition() { glm::vec3 lookAtSpot; if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { // When I am in mirror mode, just look right at the camera (myself) - if (!isHMDMode()) { - lookAtSpot = _myCamera.getPosition(); - } else { + lookAtSpot = _myCamera.getPosition(); +#if 0 + // FIXME is this really necessary? + if (isHMDMode()) { if (_myAvatar->isLookingAtLeftEye()) { lookAtSpot = OculusManager::getLeftEyePosition(); } else { lookAtSpot = OculusManager::getRightEyePosition(); } } +#endif } else { AvatarSharedPointer lookingAt = _myAvatar->getLookAtTargetAvatar().toStrongRef(); @@ -3279,6 +3268,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs PROFILE_RANGE("DeferredLighting"); PerformanceTimer perfTimer("lighting"); + Q_ASSERT(_offscreenContext->getContext() == QOpenGLContext::currentContext()); DependencyManager::get()->render(); } @@ -4533,11 +4523,6 @@ QSize Application::getDeviceSize() const { return getActiveDisplayPlugin()->getDeviceSize(); } -void Application::resizeGL() { - auto size = getCanvasSize(); - return resizeGL(size.x, size.y); -} - bool Application::hasFocus() const { return getActiveDisplayPlugin()->hasFocus(); } @@ -4546,7 +4531,6 @@ glm::vec2 Application::getViewportDimensions() const { return toGlm(getDeviceSize()); } - glm::ivec2 Application::getTrueMousePosition() const { return getActiveDisplayPlugin()->getTrueMousePosition(); } @@ -4569,7 +4553,7 @@ using DisplayPluginPointer = QSharedPointer; #include "plugins/render/NullDisplayPlugin.h" #include "plugins/render/WindowDisplayPlugin.h" #include "plugins/render/LegacyDisplayPlugin.h" -#include "plugins/render/OculusDirectD3DDisplayPlugin.h" +#include "plugins/render/OculusDisplayPlugin.h" static DisplayPluginPointer _displayPlugin{ nullptr }; @@ -4610,7 +4594,7 @@ static const DisplayPluginList & getDisplayPlugins() { }); QObject::connect(displayPlugin.data(), &DisplayPlugin::recommendedFramebufferSizeChanged, [](const QSize & size) { DependencyManager::get()->setFrameBufferSize(size * qApp->getRenderResolutionScale()); - qApp->resizeGL(size.width(), size.height()); + qApp->resizeGL(); }); addDisplayPluginToMenu(displayPlugin, true); } @@ -4653,9 +4637,18 @@ void Application::updateDisplayMode() { } void Application::initPlugins() { +#if 0 OculusManager::init(); +#endif } void Application::shutdownPlugins() { +#if 0 OculusManager::deinit(); +#endif } + + +glm::ivec2 Application::getMouse() const { + return getActiveDisplayPlugin()->getUiMousePosition(); +} \ No newline at end of file diff --git a/interface/src/Application.h b/interface/src/Application.h index 0626a8ae43..1eed6140d5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -57,7 +57,6 @@ #include "scripting/ControllerScriptingInterface.h" #include "scripting/WebWindowClass.h" #include "ui/BandwidthDialog.h" -#include "ui/HMDToolsDialog.h" #include "ui/ModelsBrowser.h" #include "ui/NodeBounds.h" #include "ui/OctreeStatsDialog.h" @@ -453,8 +452,6 @@ private slots: friend class HMDToolsDialog; void setFullscreen(bool fullscreen); - void setEnable3DTVMode(bool enable3DTVMode); - void setEnableVRMode(bool enableVRMode); void cameraMenuChanged(); void closeMirrorView(); diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index 995e1908a9..066ae97ebf 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -47,7 +47,6 @@ int GLCanvas::getDeviceHeight() const { } void GLCanvas::initializeGL() { - Application::getInstance()->initializeGL(); setAttribute(Qt::WA_AcceptTouchEvents); setAcceptDrops(true); connect(Application::getInstance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeChanged(Qt::ApplicationState))); diff --git a/interface/src/devices/OculusManager.h b/interface/src/devices/OculusManager.h index e41c6e8f9b..a4b73344a2 100644 --- a/interface/src/devices/OculusManager.h +++ b/interface/src/devices/OculusManager.h @@ -13,6 +13,7 @@ #ifndef hifi_OculusManager_h #define hifi_OculusManager_h +#if 0 #include #include @@ -215,5 +216,6 @@ inline ovrSizei ovrFromGlm(const glm::uvec2 & v) { inline ovrQuatf ovrFromGlm(const glm::quat & q) { return{ q.x, q.y, q.z, q.w }; } +#endif #endif // hifi_OculusManager_h diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index f1a762e64f..9d146b10f2 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -487,8 +487,7 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { triggerButton = Qt::LeftButton; } - if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers) - || Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) { + if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers) || qApp->isHMDMode()) { pos = qApp->getApplicationOverlay().getPalmClickLocation(palm); } else { // Get directon relative to avatar orientation diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index bb715ba6e4..95e3da8375 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -130,7 +130,9 @@ void TV3DManager::display(Camera& whichCamera) { eyeCamera.setEyeOffsetPosition(glm::vec3(-_activeEye->modelTranslation,0,0)); Application::getInstance()->displaySide(eyeCamera, false, RenderArgs::MONO); +#if 0 applicationOverlay.displayOverlayTextureStereo(whichCamera, _aspect, fov); +#endif _activeEye = NULL; } glPopMatrix(); @@ -158,8 +160,9 @@ void TV3DManager::display(Camera& whichCamera) { glLoadIdentity(); eyeCamera.setEyeOffsetPosition(glm::vec3(-_activeEye->modelTranslation,0,0)); Application::getInstance()->displaySide(eyeCamera, false, RenderArgs::MONO); - +#if 0 applicationOverlay.displayOverlayTextureStereo(whichCamera, _aspect, fov); +#endif _activeEye = NULL; } glPopMatrix(); diff --git a/interface/src/plugins/render/DisplayPlugin.h b/interface/src/plugins/render/DisplayPlugin.h index 3c1f710354..7229a3dcef 100644 --- a/interface/src/plugins/render/DisplayPlugin.h +++ b/interface/src/plugins/render/DisplayPlugin.h @@ -12,9 +12,11 @@ #include "plugins/Plugin.h" #include - +#include #include +#include "gpu/GPUConfig.h" + #include #include #include @@ -27,11 +29,16 @@ public: virtual bool isThrottled() const { return false; } // Rendering support - virtual void preDisplay() {}; - virtual void display(int finalSceneTexture) {}; - virtual void postDisplay() {}; - - // Pointer support + virtual void preRender() {}; + virtual void preDisplay() { + makeCurrent(); + }; + virtual void display(GLuint sceneTexture, const glm::uvec2& sceneSize, + GLuint overlayTexture, const glm::uvec2& overlaySize) = 0; + virtual void finishFrame() { + swapBuffers(); + doneCurrent(); + }; // Does the rendering surface have current focus? virtual bool hasFocus() const = 0; @@ -50,7 +57,7 @@ public: return trueMouseToUiMouse(getTrueMousePosition()); } - virtual std::function getMouseTranslator() { return [](const QPointF& p) { return p; }; }; + virtual std::function getMouseTranslator() { return [](const QPointF& p) { return p; }; }; // Convert from screen mouse coordinates to UI mouse coordinates virtual glm::ivec2 trueMouseToUiMouse(const glm::ivec2 & position) const { return position; }; diff --git a/interface/src/plugins/render/LegacyDisplayPlugin.cpp b/interface/src/plugins/render/LegacyDisplayPlugin.cpp index 30c42d29c3..d5a3b2fc46 100644 --- a/interface/src/plugins/render/LegacyDisplayPlugin.cpp +++ b/interface/src/plugins/render/LegacyDisplayPlugin.cpp @@ -11,6 +11,7 @@ #include "LegacyDisplayPlugin.h" #include "MainWindow.h" #include +#include const QString LegacyDisplayPlugin::NAME("2D Monitor (GL Windgets)"); @@ -22,10 +23,17 @@ static QWidget * oldWidget = nullptr; void LegacyDisplayPlugin::activate() { _window = new GLCanvas(); - QGLFormat format(QGL::NoDepthBuffer | QGL::NoStencilBuffer); - _window->setContext(new QGLContext(format), - QGLContext::fromOpenGLContext(QOpenGLContext::currentContext())); + + QOpenGLContext * sourceContext = QOpenGLContext::currentContext(); + QSurfaceFormat format; + format.setOption(QSurfaceFormat::DebugContext); + QOpenGLContext * newContext = new QOpenGLContext(); + newContext->setFormat(format); + _window->setContext( + QGLContext::fromOpenGLContext(newContext), + QGLContext::fromOpenGLContext(sourceContext)); _window->makeCurrent(); + oldWidget = qApp->getWindow()->centralWidget(); qApp->getWindow()->setCentralWidget(_window); _window->doneCurrent(); @@ -35,12 +43,15 @@ void LegacyDisplayPlugin::activate() { _window->installEventFilter(qApp); _window->installEventFilter(DependencyManager::get().data()); + SimpleDisplayPlugin::activate(); } void LegacyDisplayPlugin::deactivate() { _window->removeEventFilter(DependencyManager::get().data()); _window->removeEventFilter(qApp); - qApp->getWindow()->setCentralWidget(oldWidget); + if (qApp->getWindow()) { + qApp->getWindow()->setCentralWidget(oldWidget); + } // stop the glWidget frame timer so it doesn't call paintGL _window->stopFrameTimer(); _window->doneCurrent(); @@ -54,8 +65,6 @@ QSize LegacyDisplayPlugin::getDeviceSize() const { void LegacyDisplayPlugin::makeCurrent() { _window->makeCurrent(); - QSize windowSize = _window->size(); - glViewport(0, 0, windowSize.width(), windowSize.height()); } void LegacyDisplayPlugin::doneCurrent() { @@ -64,7 +73,6 @@ void LegacyDisplayPlugin::doneCurrent() { void LegacyDisplayPlugin::swapBuffers() { _window->swapBuffers(); - glFinish(); } void LegacyDisplayPlugin::idle() { @@ -87,6 +95,12 @@ bool isMouseOnScreen() { return false; } -bool LegacyDisplayPlugin::isThrottled() { +void LegacyDisplayPlugin::preDisplay() { + SimpleDisplayPlugin::preDisplay(); + auto size = toGlm(_window->size()); + glViewport(0, 0, size.x, size.y); +} + +bool LegacyDisplayPlugin::isThrottled() const { return _window->isThrottleRendering(); } \ No newline at end of file diff --git a/interface/src/plugins/render/LegacyDisplayPlugin.h b/interface/src/plugins/render/LegacyDisplayPlugin.h index 2565554297..481667d3d4 100644 --- a/interface/src/plugins/render/LegacyDisplayPlugin.h +++ b/interface/src/plugins/render/LegacyDisplayPlugin.h @@ -27,6 +27,7 @@ public: virtual PickRay computePickRay(const glm::vec2 & pos) const; virtual bool isMouseOnScreen() const { return true; } virtual bool isThrottled() const; + virtual void preDisplay(); protected: virtual void makeCurrent(); diff --git a/interface/src/plugins/render/NullDisplayPlugin.cpp b/interface/src/plugins/render/NullDisplayPlugin.cpp index 0bd964f34b..9b5ab8ed0a 100644 --- a/interface/src/plugins/render/NullDisplayPlugin.cpp +++ b/interface/src/plugins/render/NullDisplayPlugin.cpp @@ -39,6 +39,6 @@ PickRay NullDisplayPlugin::computePickRay(const glm::vec2 & pos) const { return PickRay(); } -bool NullDisplayPlugin::isMouseOnScreen() { +bool NullDisplayPlugin::isMouseOnScreen() const { return false; } diff --git a/interface/src/plugins/render/NullDisplayPlugin.h b/interface/src/plugins/render/NullDisplayPlugin.h index 47f5dc7288..8a06febb7b 100644 --- a/interface/src/plugins/render/NullDisplayPlugin.h +++ b/interface/src/plugins/render/NullDisplayPlugin.h @@ -26,4 +26,7 @@ public: virtual PickRay computePickRay(const glm::vec2 & pos) const; virtual bool isMouseOnScreen() const; + virtual void display(GLuint sceneTexture, const glm::uvec2& sceneSize, + GLuint overlayTexture, const glm::uvec2& overlaySize) {}; + }; diff --git a/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.cpp b/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.cpp deleted file mode 100644 index ec1b9a1986..0000000000 --- a/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// OculusDirectD3DDisplayPlugin.cpp -// -// 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 "OculusDirectD3DDisplayPlugin.h" diff --git a/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.h b/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.h deleted file mode 100644 index 531e779a3b..0000000000 --- a/interface/src/plugins/render/OculusDirectD3DDisplayPlugin.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// OculusDirectD3DDisplayPlugin.h -// -// 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 -// -#pragma once - -#include "OculusBaseDisplayPlugin.h" diff --git a/interface/src/plugins/render/OculusDirectDisplayPlugin.cpp b/interface/src/plugins/render/OculusDirectDisplayPlugin.cpp deleted file mode 100644 index 569597f2cc..0000000000 --- a/interface/src/plugins/render/OculusDirectDisplayPlugin.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// OculusDirectDisplayPlugin.cpp -// -// 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 "OculusDirectDisplayPlugin.h" diff --git a/interface/src/plugins/render/OculusDirectDisplayPlugin.h b/interface/src/plugins/render/OculusDirectDisplayPlugin.h deleted file mode 100644 index 5f3fc911c7..0000000000 --- a/interface/src/plugins/render/OculusDirectDisplayPlugin.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// OculusDirectDisplayPlugin.h -// -// 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 -// -#pragma once - -#include "OculusBaseDisplayPlugin.h" diff --git a/interface/src/plugins/render/OculusBaseDisplayPlugin.cpp b/interface/src/plugins/render/OculusDisplayPlugin.cpp similarity index 69% rename from interface/src/plugins/render/OculusBaseDisplayPlugin.cpp rename to interface/src/plugins/render/OculusDisplayPlugin.cpp index 2d423424eb..d32af59ebf 100644 --- a/interface/src/plugins/render/OculusBaseDisplayPlugin.cpp +++ b/interface/src/plugins/render/OculusDisplayPlugin.cpp @@ -1,5 +1,5 @@ // -// OculusBaseDisplayPlugin.cpp +// OculusDisplayPlugin.cpp // // Created by Bradley Austin Davis on 2014/04/13. // Copyright 2015 High Fidelity, Inc. @@ -7,50 +7,42 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "OculusBaseDisplayPlugin.h" +#include "OculusDisplayPlugin.h" #include -bool OculusBaseDisplayPlugin::sdkInitialized = false; - -bool OculusBaseDisplayPlugin::enableSdk() { - sdkInitialized = ovr_Initialize(); - return sdkInitialized; -} - -void OculusBaseDisplayPlugin::disableSdk() { +bool OculusDisplayPlugin::isSupported() { + ovr_Initialize(); + bool result = false; + if (ovrHmd_Detect() != 0) { + result = true; + } ovr_Shutdown(); - sdkInitialized = false; + return result; } -void OculusBaseDisplayPlugin::withSdkActive(std::function f) { - bool activateSdk = !sdkInitialized; - if (activateSdk && !enableSdk()) { - return; - } - f(); - if (activateSdk) { - disableSdk(); - } +void OculusDisplayPlugin::activate() { } -bool OculusBaseDisplayPlugin::isSupported() { - bool attached = false; - withSdkActive([&] { - attached = ovrHmd_Detect(); - }); - return attached; +void OculusDisplayPlugin::deactivate() { } -void OculusBaseDisplayPlugin::activate() { - enableSdk(); +void OculusDisplayPlugin::init() { } -void OculusBaseDisplayPlugin::deactivate() { - disableSdk(); +void OculusDisplayPlugin::deinit() { } +void OculusDisplayPlugin::overrideOffAxisFrustum( + float& left, float& right, float& bottom, float& top, + float& nearVal, float& farVal, + glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { + +} + + + #if 0 // Set the desired FBO texture size. If it hasn't changed, this does nothing. // Otherwise, it must rebuild the FBOs diff --git a/interface/src/plugins/render/OculusBaseDisplayPlugin.h b/interface/src/plugins/render/OculusDisplayPlugin.h similarity index 71% rename from interface/src/plugins/render/OculusBaseDisplayPlugin.h rename to interface/src/plugins/render/OculusDisplayPlugin.h index 7eb0a42a19..7b846ae569 100644 --- a/interface/src/plugins/render/OculusBaseDisplayPlugin.h +++ b/interface/src/plugins/render/OculusDisplayPlugin.h @@ -12,7 +12,7 @@ #include "HmdDisplayPlugin.h" #include -class OculusBaseDisplayPlugin : public HmdDisplayPlugin { +class OculusDisplayPlugin : public HmdDisplayPlugin { public: virtual bool isSupported(); @@ -27,14 +27,4 @@ public: float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; - -protected: - virtual bool isRiftPresent(); - virtual bool isDirectMode(); - - static bool sdkInitialized; - - static void withSdkActive(std::function f); - static bool enableSdk(); - static void disableSdk(); }; diff --git a/interface/src/plugins/render/OculusExtendedDisplayPlugin.cpp b/interface/src/plugins/render/OculusExtendedDisplayPlugin.cpp deleted file mode 100644 index cbef7d11f3..0000000000 --- a/interface/src/plugins/render/OculusExtendedDisplayPlugin.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// OculusExtendedDisplayPlugin.cpp -// -// 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 "OculusExtendedDisplayPlugin.h" diff --git a/interface/src/plugins/render/OculusExtendedDisplayPlugin.h b/interface/src/plugins/render/OculusExtendedDisplayPlugin.h deleted file mode 100644 index 674a79bd5a..0000000000 --- a/interface/src/plugins/render/OculusExtendedDisplayPlugin.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// OculusExtendedDisplayPlugin.h -// -// 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 -// -#pragma once - -#include "OculusBaseDisplayPlugin.h" diff --git a/interface/src/plugins/render/SimpleDisplayPlugin.cpp b/interface/src/plugins/render/SimpleDisplayPlugin.cpp index d68a32b1ea..40e0ba4d87 100644 --- a/interface/src/plugins/render/SimpleDisplayPlugin.cpp +++ b/interface/src/plugins/render/SimpleDisplayPlugin.cpp @@ -8,6 +8,81 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "SimpleDisplayPlugin.h" -#include #include +#include +#include +#include "DependencyManager.h" +#include "TextureCache.h" +#include "gpu/GLBackend.h" + + +void SimpleGlDisplayPlugin::activate() { + makeCurrent(); + doneCurrent(); +} + +void SimpleGlDisplayPlugin::display(GLuint sceneTexture, const glm::uvec2& sceneSize, + GLuint overlayTexture, const glm::uvec2& overlaySize) { + makeCurrent(); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_TEXTURE_2D); + + if (sceneTexture) { + glBindTexture(GL_TEXTURE_2D, sceneTexture); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(+1, -1); + glTexCoord2f(1, 1); + glVertex2f(+1, +1); + glTexCoord2f(0, 1); + glVertex2f(-1, +1); + glEnd(); + } + + if (overlayTexture) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBindTexture(GL_TEXTURE_2D, overlayTexture); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(+1, -1); + glTexCoord2f(1, 1); + glVertex2f(+1, +1); + glTexCoord2f(0, 1); + glVertex2f(-1, +1); + glEnd(); + } + + + glDisable(GL_BLEND); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + Q_ASSERT(!glGetError()); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + + glFinish(); + doneCurrent(); +} diff --git a/interface/src/plugins/render/SimpleDisplayPlugin.h b/interface/src/plugins/render/SimpleDisplayPlugin.h index 55ce69b323..aca9366b24 100644 --- a/interface/src/plugins/render/SimpleDisplayPlugin.h +++ b/interface/src/plugins/render/SimpleDisplayPlugin.h @@ -10,43 +10,23 @@ #pragma once #include "DisplayPlugin.h" + +#include + #include #include #include -template -class SimpleDisplayPlugin : public DisplayPlugin { +class SimpleGlDisplayPlugin : public DisplayPlugin { public: - virtual void render(int finalSceneTexture) { - makeCurrent(); - - glDisable(GL_LIGHTING); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, finalSceneTexture); - renderFullscreenQuad(); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glEnable(GL_LIGHTING); - - swapBuffers(); - doneCurrent(); - } - - virtual glm::ivec2 getUiMousePosition() const { - return getTrueMousePosition(); - } + virtual void activate(); + virtual void display(GLuint sceneTexture, const glm::uvec2& sceneSize, + GLuint overlayTexture, const glm::uvec2& overlaySize); +}; +template +class SimpleDisplayPlugin : public SimpleGlDisplayPlugin { +public: virtual glm::ivec2 getTrueMousePosition() const { return toGlm(_window->mapFromGlobal(QCursor::pos())); } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f6724bb942..62cdf45be7 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -136,12 +136,9 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { } ApplicationOverlay::ApplicationOverlay() : - _textureFov(glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE)), - _textureAspectRatio(1.0f), _lastMouseMove(0), _magnifier(true), _alpha(1.0f), - _oculusUIRadius(1.0f), _trailingAudioLoudness(0.0f), _crosshairTexture(0), _previousBorderWidth(-1), @@ -184,25 +181,33 @@ ApplicationOverlay::ApplicationOverlay() : ApplicationOverlay::~ApplicationOverlay() { } +GLuint ApplicationOverlay::getOverlayTexture() { + if (!_framebufferObject) { + return 0; + } + return _framebufferObject->texture(); +} + // Renders the overlays either to a texture or to the screen void ApplicationOverlay::renderOverlay() { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); Overlays& overlays = qApp->getOverlays(); - _textureFov = glm::radians(_hmdUIAngularSize); - glm::vec2 size = qApp->getCanvasSize(); - _textureAspectRatio = aspect(size); + glm::uvec2 size = qApp->getCanvasSize(); + if (!_framebufferObject || size == toGlm(_framebufferObject->size())) { + if(_framebufferObject) { + delete _framebufferObject; + } + _framebufferObject = new QOpenGLFramebufferObject(QSize(size.x, size.y)); + } - //Handle fading and deactivation/activation of UI - // Render 2D overlay glMatrixMode(GL_PROJECTION); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - _overlays.buildFramebufferObject(); - _overlays.bind(); + _framebufferObject->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, size.x, size.y); @@ -227,6 +232,32 @@ void ApplicationOverlay::renderOverlay() { renderPointers(); renderDomainConnectionStatusBorder(); + static const glm::vec2 topLeft(-1, 1); + static const glm::vec2 bottomRight(1, -1); + static const glm::vec2 texCoordTopLeft(0.0f, 1.0f); + static const glm::vec2 texCoordBottomRight(1.0f, 0.0f); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + + + glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, _newUiTexture); +// glBegin(GL_QUADS); +// glVertex2f(0, 0); +// glVertex2f(1, 0); +// glVertex2f(1, 1); +// glVertex2f(0, 1); +// glEnd(); + DependencyManager::get()->renderQuad( + topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + + _framebufferObject->bindDefault(); glMatrixMode(GL_PROJECTION); } glPopMatrix(); @@ -235,8 +266,6 @@ void ApplicationOverlay::renderOverlay() { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); - - _overlays.release(); } // A quick and dirty solution for compositing the old overlay @@ -256,7 +285,7 @@ void with_each_texture(GLuint firstPassTexture, GLuint secondPassTexture, F f) { glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } - +#if 0 // Draws the FBO texture for the screen void ApplicationOverlay::displayOverlayTexture() { if (_alpha == 0.0f) { @@ -454,6 +483,8 @@ void ApplicationOverlay::displayOverlayTextureStereo(Camera& whichCamera, float glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); glEnable(GL_LIGHTING); } +#endif + void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) { const MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); @@ -473,7 +504,6 @@ void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origi //Caculate the click location using one of the sixense controllers. Scale is not applied QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); glm::vec3 eyePos = myAvatar->getHead()->getEyePosition(); glm::quat invOrientation = glm::inverse(myAvatar->getOrientation()); @@ -482,6 +512,7 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { glm::vec3 tipPos = invOrientation * (tip - eyePos); QPoint rv; +#if 0 auto canvasSize = qApp->getCanvasSize(); if (qApp->isHMDMode()) { float t; @@ -521,6 +552,7 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * canvasSize.x); rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * canvasSize.y); } +#endif return rv; } @@ -534,11 +566,13 @@ bool ApplicationOverlay::calculateRayUICollisionPoint(const glm::vec3& position, glm::vec3 relativeDirection = glm::normalize(inverseOrientation * direction); float t; +#if 0 if (raySphereIntersect(relativeDirection, relativePosition, _oculusUIRadius * myAvatar->getScale(), &t)){ result = position + direction * t; return true; } - +#endif + return false; } @@ -748,6 +782,7 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { //Renders a small magnification of the currently bound texture at the coordinates void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) { +#if 0 if (!_magnifier) { return; } @@ -813,6 +848,7 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool magnifierColor, _magnifierQuad); } glPopMatrix(); +#endif } const int AUDIO_METER_GAP = 5; @@ -1023,7 +1059,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { geometryCache->renderVertices(gpu::LINE_STRIP, _domainStatusBorder); } } - +#if 0 ApplicationOverlay::TexturedHemisphere::TexturedHemisphere() : _vertices(0), _indices(0), @@ -1186,6 +1222,7 @@ void ApplicationOverlay::TexturedHemisphere::render() { GLuint ApplicationOverlay::TexturedHemisphere::getTexture() { return _framebufferObject->texture(); } +#endif glm::vec2 ApplicationOverlay::directionToSpherical(const glm::vec3& direction) { glm::vec2 result; @@ -1230,6 +1267,7 @@ glm::vec2 ApplicationOverlay::sphericalToScreen(const glm::vec2& sphericalPos) { glm::vec2 ApplicationOverlay::sphericalToOverlay(const glm::vec2& sphericalPos) const { glm::vec2 result = sphericalPos; +#if 0 result.x *= -1.0; result /= _textureFov; result.x /= _textureAspectRatio; @@ -1237,16 +1275,19 @@ glm::vec2 ApplicationOverlay::sphericalToOverlay(const glm::vec2& sphericalPos) result.x = (-sphericalPos.x / (_textureFov * _textureAspectRatio) + 0.5f); result.y = (sphericalPos.y / _textureFov + 0.5f); result *= qApp->getCanvasSize(); +#endif return result; } glm::vec2 ApplicationOverlay::overlayToSpherical(const glm::vec2& overlayPos) const { glm::vec2 result = overlayPos; +#if 0 result.x *= -1.0; result /= qApp->getCanvasSize(); result -= 0.5f; result *= _textureFov; result.x *= _textureAspectRatio; +#endif return result; } diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 71a4876c67..45cf573a0e 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -34,19 +34,14 @@ public: ~ApplicationOverlay(); void renderOverlay(); - void displayOverlayTexture(); - void displayOverlayTextureStereo(Camera& whichCamera, float aspectRatio, float fov); - void displayOverlayTextureHmd(Camera& whichCamera); - + GLuint getOverlayTexture(); + QPoint getPalmClickLocation(const PalmData *palm) const; bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const; bool hasMagnifier() const { return _magnifier; } void toggleMagnifier() { _magnifier = !_magnifier; } - float getHmdUIAngularSize() const { return _hmdUIAngularSize; } - void setHmdUIAngularSize(float hmdUIAngularSize) { _hmdUIAngularSize = hmdUIAngularSize; } - // Converter from one frame of reference to another. // Frame of reference: // Direction: Ray that represents the spherical values @@ -67,36 +62,6 @@ public: static void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction); private: - // Interleaved vertex data - struct TextureVertex { - glm::vec3 position; - glm::vec2 uv; - }; - - typedef QPair VerticesIndices; - class TexturedHemisphere { - public: - TexturedHemisphere(); - ~TexturedHemisphere(); - - void bind(); - void release(); - GLuint getTexture(); - - void buildFramebufferObject(); - void buildVBO(const float fov, const float aspectRatio, const int slices, const int stacks); - void render(); - - private: - void cleanupVBO(); - - GLuint _vertices; - GLuint _indices; - QOpenGLFramebufferObject* _framebufferObject; - VerticesIndices _vbo; - }; - - float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE; void renderReticle(glm::quat orientation, float alpha); void renderPointers();; @@ -109,11 +74,6 @@ private: void renderCameraToggle(); void renderStatsAndLogs(); void renderDomainConnectionStatusBorder(); - - TexturedHemisphere _overlays; - - float _textureFov; - float _textureAspectRatio; enum Reticles { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_RETICLES }; bool _reticleActive[NUMBER_OF_RETICLES]; @@ -124,8 +84,8 @@ private: bool _magnifier; float _alpha = 1.0f; - float _oculusUIRadius; float _trailingAudioLoudness; + QOpenGLFramebufferObject* _framebufferObject{nullptr}; gpu::TexturePointer _crosshairTexture; GLuint _newUiTexture{ 0 }; @@ -145,7 +105,6 @@ private: glm::vec3 _previousMagnifierBottomRight; glm::vec3 _previousMagnifierTopLeft; glm::vec3 _previousMagnifierTopRight; - }; #endif // hifi_ApplicationOverlay_h diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index fe8afc5c0a..0455007ffc 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -24,7 +24,6 @@ #include "BandwidthDialog.h" #include "CachesSizeDialog.h" #include "DiskCacheEditor.h" -#include "HMDToolsDialog.h" #include "LodToolsDialog.h" #include "LoginDialog.h" #include "OctreeStatsDialog.h" diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index 2c8f77c4c6..83bfc05b6b 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -17,8 +17,6 @@ #include #include -#include "HMDToolsDialog.h" - class QAction; class AddressBarDialog; diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp deleted file mode 100644 index ef2c179eb0..0000000000 --- a/interface/src/ui/HMDToolsDialog.cpp +++ /dev/null @@ -1,347 +0,0 @@ -// -// HMDToolsDialog.cpp -// interface/src/ui -// -// Created by Brad Hefta-Gaub on 7/19/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 -#include -#include - -#include -#include -#include -#include -#include - -#include "MainWindow.h" -#include "Menu.h" -#include "ui/DialogsManager.h" -#include "ui/HMDToolsDialog.h" -#include "devices/OculusManager.h" - -HMDToolsDialog::HMDToolsDialog(QWidget* parent) : - QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) , - _previousScreen(NULL), - _hmdScreen(NULL), - _hmdScreenNumber(-1), - _switchModeButton(NULL), - _debugDetails(NULL), - _previousDialogScreen(NULL), - _inHDMMode(false) -{ - this->setWindowTitle("HMD Tools"); - - // Create layouter - QFormLayout* form = new QFormLayout(); - const int WIDTH = 350; - - // Add a button to enter - _switchModeButton = new QPushButton("Enter HMD Mode"); - _switchModeButton->setFixedWidth(WIDTH); - form->addRow("", _switchModeButton); - connect(_switchModeButton,SIGNAL(clicked(bool)),this,SLOT(switchModeClicked(bool))); - - // Create a label with debug details... - _debugDetails = new QLabel(); - _debugDetails->setText(getDebugDetails()); - const int HEIGHT = 100; - _debugDetails->setFixedSize(WIDTH, HEIGHT); - form->addRow("", _debugDetails); - - this->QDialog::setLayout(form); - - _wasMoved = false; - _previousRect = Application::getInstance()->getWindow()->rect(); - Application::getInstance()->getWindow()->activateWindow(); - - // watch for our application window moving screens. If it does we want to update our screen details - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged); - - // watch for our dialog window moving screens. If it does we want to enforce our rules about - // what screens we're allowed on - watchWindow(windowHandle()); - auto dialogsManager = DependencyManager::get(); - if (Application::getInstance()->getRunningScriptsWidget()) { - watchWindow(Application::getInstance()->getRunningScriptsWidget()->windowHandle()); - } - if (Application::getInstance()->getToolWindow()) { - watchWindow(Application::getInstance()->getToolWindow()->windowHandle()); - } - if (dialogsManager->getBandwidthDialog()) { - watchWindow(dialogsManager->getBandwidthDialog()->windowHandle()); - } - if (dialogsManager->getOctreeStatsDialog()) { - watchWindow(dialogsManager->getOctreeStatsDialog()->windowHandle()); - } - if (dialogsManager->getLodToolsDialog()) { - watchWindow(dialogsManager->getLodToolsDialog()->windowHandle()); - } - - // when the application is about to quit, leave HDM mode - connect(Application::getInstance(), SIGNAL(beforeAboutToQuit()), this, SLOT(aboutToQuit())); - - // keep track of changes to the number of screens - connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged); -} - -HMDToolsDialog::~HMDToolsDialog() { - foreach(HMDWindowWatcher* watcher, _windowWatchers) { - delete watcher; - } - _windowWatchers.clear(); -} - -void HMDToolsDialog::applicationWindowScreenChanged(QScreen* screen) { - _debugDetails->setText(getDebugDetails()); -} - -QString HMDToolsDialog::getDebugDetails() const { - QString results; - - int hmdScreenNumber = OculusManager::getHMDScreen(); - if (hmdScreenNumber >= 0) { - results += "HMD Screen: " + QGuiApplication::screens()[hmdScreenNumber]->name() + "\n"; - } else { - results += "HMD Screen Name: Unknown\n"; - } - - int desktopPrimaryScreenNumber = QApplication::desktop()->primaryScreen(); - QScreen* desktopPrimaryScreen = QGuiApplication::screens()[desktopPrimaryScreenNumber]; - results += "Desktop's Primary Screen: " + desktopPrimaryScreen->name() + "\n"; - - results += "Application Primary Screen: " + QGuiApplication::primaryScreen()->name() + "\n"; - QScreen* mainWindowScreen = Application::getInstance()->getWindow()->windowHandle()->screen(); - results += "Application Main Window Screen: " + mainWindowScreen->name() + "\n"; - results += "Total Screens: " + QString::number(QApplication::desktop()->screenCount()) + "\n"; - - return results; -} - -void HMDToolsDialog::switchModeClicked(bool checked) { - if (!_inHDMMode) { - enterHDMMode(); - } else { - leaveHDMMode(); - } -} - -void HMDToolsDialog::enterHDMMode() { - if (!_inHDMMode) { - _switchModeButton->setText("Leave HMD Mode"); - _debugDetails->setText(getDebugDetails()); - - _hmdScreenNumber = OculusManager::getHMDScreen(); - - if (_hmdScreenNumber >= 0) { - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - _hmdScreen = QGuiApplication::screens()[_hmdScreenNumber]; - - _previousRect = Application::getInstance()->getWindow()->rect(); - _previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()), - mainWindow->mapToGlobal(_previousRect.bottomRight())); - _previousScreen = mainWindow->screen(); - QRect rect = QApplication::desktop()->screenGeometry(_hmdScreenNumber); - mainWindow->setScreen(_hmdScreen); - mainWindow->setGeometry(rect); - - _wasMoved = true; - } - - - // if we're on a single screen setup, then hide our tools window when entering HMD mode - if (QApplication::desktop()->screenCount() == 1) { - close(); - } - - Application::getInstance()->setEnableVRMode(true); - - const int SLIGHT_DELAY = 500; - // If we go to fullscreen immediately, it ends up on the primary monitor, - // even though we've already moved the window. By adding this delay, the - // fullscreen target screen ends up correct. - QTimer::singleShot(SLIGHT_DELAY, this, [&]{ - Application::getInstance()->setFullscreen(true); - activateWindowAfterEnterMode(); - }); - - _inHDMMode = true; - } -} - -void HMDToolsDialog::activateWindowAfterEnterMode() { - Application::getInstance()->getWindow()->activateWindow(); - - // center the cursor on the main application window - centerCursorOnWidget(Application::getInstance()->getWindow()); -} - -void HMDToolsDialog::leaveHDMMode() { - if (_inHDMMode) { - _switchModeButton->setText("Enter HMD Mode"); - _debugDetails->setText(getDebugDetails()); - - Application::getInstance()->setEnableVRMode(false); - Application::getInstance()->setFullscreen(false); - Application::getInstance()->getWindow()->activateWindow(); - - if (_wasMoved) { - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - mainWindow->setScreen(_previousScreen); - mainWindow->setGeometry(_previousRect); - - const int SLIGHT_DELAY = 1500; - QTimer::singleShot(SLIGHT_DELAY, this, SLOT(moveWindowAfterLeaveMode())); - } - _wasMoved = false; - _inHDMMode = false; - } -} - -void HMDToolsDialog::moveWindowAfterLeaveMode() { - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - mainWindow->setScreen(_previousScreen); - mainWindow->setGeometry(_previousRect); - Application::getInstance()->getWindow()->activateWindow(); - Application::getInstance()->resetSensors(); -} - - -void HMDToolsDialog::reject() { - // Just regularly close upon ESC - close(); -} - -void HMDToolsDialog::closeEvent(QCloseEvent* event) { - // TODO: consider if we want to prevent closing of this window with event->ignore(); - this->QDialog::closeEvent(event); - emit closed(); -} - -void HMDToolsDialog::centerCursorOnWidget(QWidget* widget) { - QWindow* window = widget->windowHandle(); - QScreen* screen = window->screen(); - QPoint windowCenter = window->geometry().center(); - QCursor::setPos(screen, windowCenter); -} - -void HMDToolsDialog::showEvent(QShowEvent* event) { - // center the cursor on the hmd tools dialog - centerCursorOnWidget(this); -} - -void HMDToolsDialog::hideEvent(QHideEvent* event) { - // center the cursor on the main application window - centerCursorOnWidget(Application::getInstance()->getWindow()); -} - - -void HMDToolsDialog::aboutToQuit() { - if (_inHDMMode) { - leaveHDMMode(); - } -} - -void HMDToolsDialog::screenCountChanged(int newCount) { - if (!OculusManager::isConnected()) { - OculusManager::connect(); - } - int hmdScreenNumber = OculusManager::getHMDScreen(); - - if (_inHDMMode && _hmdScreenNumber != hmdScreenNumber) { - qDebug() << "HMD Display changed WHILE IN HMD MODE"; - leaveHDMMode(); - - // if there is a new best HDM screen then go back into HDM mode after done leaving - if (hmdScreenNumber >= 0) { - qDebug() << "Trying to go back into HDM Mode"; - const int SLIGHT_DELAY = 2000; - QTimer::singleShot(SLIGHT_DELAY, this, SLOT(enterHDMMode())); - } - } - _debugDetails->setText(getDebugDetails()); -} - -void HMDToolsDialog::watchWindow(QWindow* window) { - qDebug() << "HMDToolsDialog::watchWindow() window:" << window; - if (window && !_windowWatchers.contains(window)) { - HMDWindowWatcher* watcher = new HMDWindowWatcher(window, this); - _windowWatchers[window] = watcher; - } -} - - -HMDWindowWatcher::HMDWindowWatcher(QWindow* window, HMDToolsDialog* hmdTools) : - _window(window), - _hmdTools(hmdTools), - _previousScreen(NULL) -{ - connect(window, &QWindow::screenChanged, this, &HMDWindowWatcher::windowScreenChanged); - connect(window, &QWindow::xChanged, this, &HMDWindowWatcher::windowGeometryChanged); - connect(window, &QWindow::yChanged, this, &HMDWindowWatcher::windowGeometryChanged); - connect(window, &QWindow::widthChanged, this, &HMDWindowWatcher::windowGeometryChanged); - connect(window, &QWindow::heightChanged, this, &HMDWindowWatcher::windowGeometryChanged); -} - -HMDWindowWatcher::~HMDWindowWatcher() { -} - - -void HMDWindowWatcher::windowGeometryChanged(int arg) { - _previousRect = _window->geometry(); - _previousScreen = _window->screen(); -} - -void HMDWindowWatcher::windowScreenChanged(QScreen* screen) { - // if we have more than one screen, and a known hmdScreen then try to - // keep our dialog off of the hmdScreen - if (QApplication::desktop()->screenCount() > 1) { - - // we want to use a local variable here because we are not necesarily in HMD mode - int hmdScreenNumber = OculusManager::getHMDScreen(); - if (hmdScreenNumber >= 0) { - QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber]; - if (screen == hmdScreen) { - qDebug() << "HMD Tools: Whoa! What are you doing? You don't want to move me to the HMD Screen!"; - - // try to pick a better screen - QScreen* betterScreen = NULL; - - QScreen* lastApplicationScreen = _hmdTools->getLastApplicationScreen(); - QWindow* appWindow = Application::getInstance()->getWindow()->windowHandle(); - QScreen* appScreen = appWindow->screen(); - - if (_previousScreen && _previousScreen != hmdScreen) { - // first, if the previous dialog screen is not the HMD screen, then move it there. - betterScreen = _previousScreen; - } else if (appScreen != hmdScreen) { - // second, if the application screen is not the HMD screen, then move it there. - betterScreen = appScreen; - } else if (lastApplicationScreen && lastApplicationScreen != hmdScreen) { - // third, if the application screen is the HMD screen, we want to move it to - // the previous screen - betterScreen = lastApplicationScreen; - } else { - // last, if we can't use the previous screen the use the primary desktop screen - int desktopPrimaryScreenNumber = QApplication::desktop()->primaryScreen(); - QScreen* desktopPrimaryScreen = QGuiApplication::screens()[desktopPrimaryScreenNumber]; - betterScreen = desktopPrimaryScreen; - } - - if (betterScreen) { - _window->setScreen(betterScreen); - _window->setGeometry(_previousRect); - } - } - } - } -} - -#endif diff --git a/interface/src/ui/HMDToolsDialog.h b/interface/src/ui/HMDToolsDialog.h deleted file mode 100644 index 86bfc7bf1a..0000000000 --- a/interface/src/ui/HMDToolsDialog.h +++ /dev/null @@ -1,89 +0,0 @@ -// -// HMDToolsDialog.h -// interface/src/ui -// -// Created by Brad Hefta-Gaub on 7/19/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 -// - -#ifndef hifi_HMDToolsDialog_h -#define hifi_HMDToolsDialog_h -#if 0 -#include - -class HMDWindowWatcher; - -class HMDToolsDialog : public QDialog { - Q_OBJECT -public: - // Sets up the UI - HMDToolsDialog(QWidget* parent); - ~HMDToolsDialog(); - - QString getDebugDetails() const; - QScreen* getHMDScreen() const { return _hmdScreen; } - QScreen* getLastApplicationScreen() const { return _previousScreen; } - bool hasHMDScreen() const { return _hmdScreenNumber >= -1; } - void watchWindow(QWindow* window); - -signals: - void closed(); - -public slots: - void reject(); - void switchModeClicked(bool checked); - void activateWindowAfterEnterMode(); - void moveWindowAfterLeaveMode(); - void applicationWindowScreenChanged(QScreen* screen); - void aboutToQuit(); - void screenCountChanged(int newCount); - -protected: - virtual void closeEvent(QCloseEvent*); // Emits a 'closed' signal when this dialog is closed. - virtual void showEvent(QShowEvent* event); - virtual void hideEvent(QHideEvent* event); - -private: - void centerCursorOnWidget(QWidget* widget); - void enterHDMMode(); - void leaveHDMMode(); - - bool _wasMoved; - QRect _previousRect; - QScreen* _previousScreen; - QScreen* _hmdScreen; - int _hmdScreenNumber; - QPushButton* _switchModeButton; - QLabel* _debugDetails; - - QRect _previousDialogRect; - QScreen* _previousDialogScreen; - bool _inHDMMode; - - QHash _windowWatchers; -}; - - -class HMDWindowWatcher : public QObject { - Q_OBJECT -public: - // Sets up the UI - HMDWindowWatcher(QWindow* window, HMDToolsDialog* hmdTools); - ~HMDWindowWatcher(); - -public slots: - void windowScreenChanged(QScreen* screen); - void windowGeometryChanged(int arg); - -private: - QWindow* _window; - HMDToolsDialog* _hmdTools; - QRect _previousRect; - QScreen* _previousScreen; -}; -#endif - -#endif // hifi_HMDToolsDialog_h diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index ac436cbb10..20da050a8d 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -169,9 +169,9 @@ void PreferencesDialog::loadPreferences() { ui.avatarScaleSpin->setValue(myAvatar->getScale()); ui.maxOctreePPSSpin->setValue(qApp->getOctreeQuery().getMaxOctreePacketsPerSecond()); - +#if 0 ui.oculusUIAngularSizeSpin->setValue(qApp->getApplicationOverlay().getHmdUIAngularSize()); - +#endif SixenseManager& sixense = SixenseManager::getInstance(); ui.sixenseReticleMoveSpeedSpin->setValue(sixense.getReticleMoveSpeed()); ui.invertSixenseButtonsCheckBox->setChecked(sixense.getInvertButtons()); @@ -229,9 +229,9 @@ void PreferencesDialog::savePreferences() { faceshift->setHostname(ui.faceshiftHostnameEdit->text()); qApp->getOctreeQuery().setMaxOctreePacketsPerSecond(ui.maxOctreePPSSpin->value()); - +#if 0 qApp->getApplicationOverlay().setHmdUIAngularSize(ui.oculusUIAngularSizeSpin->value()); - +#endif SixenseManager& sixense = SixenseManager::getInstance(); sixense.setReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value()); sixense.setInvertButtons(ui.invertSixenseButtonsCheckBox->isChecked()); diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 8f96e63df3..192f782449 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include "BillboardOverlay.h" diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index bddb1815bf..324ed69a96 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -268,16 +268,16 @@ void DeferredLightingEffect::render() { program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i)); } } - - if (locations->lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + + if (locations->lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } if (_atmosphere && (locations->atmosphereBufferUnit >= 0)) { - gpu::Batch batch; - batch.setUniformBuffer(locations->atmosphereBufferUnit, _atmosphere->getDataBuffer()); + gpu::Batch batch; + batch.setUniformBuffer(locations->atmosphereBufferUnit, _atmosphere->getDataBuffer()); gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(locations->invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -334,11 +334,11 @@ void DeferredLightingEffect::render() { for (auto lightID : _pointLights) { auto light = _allocatedLights[lightID]; - - if (_pointLightLocations.lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + + if (_pointLightLocations.lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(_pointLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -380,10 +380,10 @@ void DeferredLightingEffect::render() { for (auto lightID : _spotLights) { auto light = _allocatedLights[lightID]; - if (_spotLightLocations.lightBufferUnit >= 0) { - gpu::Batch batch; - batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer()); - gpu::GLBackend::renderBatch(batch); + if (_spotLightLocations.lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); } glUniformMatrix4fv(_spotLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); @@ -482,6 +482,8 @@ void DeferredLightingEffect::render() { } void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations) { + qDebug() << (limited ? deferred_light_limited_vert : deferred_light_vert); + qDebug() << fragSource; program.addShaderFromSourceCode(QGLShader::Vertex, (limited ? deferred_light_limited_vert : deferred_light_vert)); program.addShaderFromSourceCode(QGLShader::Fragment, fragSource); program.link(); @@ -502,42 +504,42 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit locations.ambientSphere = program.uniformLocation("ambientSphere.L00"); locations.invViewMat = program.uniformLocation("invViewMat"); - GLint loc = -1; - -#if (GPU_FEATURE_PROFILE == GPU_CORE) - const GLint LIGHT_GPU_SLOT = 3; - loc = glGetUniformBlockIndex(program.programId(), "lightBuffer"); - if (loc >= 0) { - glUniformBlockBinding(program.programId(), loc, LIGHT_GPU_SLOT); - locations.lightBufferUnit = LIGHT_GPU_SLOT; - } else { - locations.lightBufferUnit = -1; - } -#else - loc = program.uniformLocation("lightBuffer"); - if (loc >= 0) { - locations.lightBufferUnit = loc; - } else { - locations.lightBufferUnit = -1; - } + GLint loc = -1; + +#if (GPU_FEATURE_PROFILE == GPU_CORE) + const GLint LIGHT_GPU_SLOT = 3; + loc = glGetUniformBlockIndex(program.programId(), "lightBuffer"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, LIGHT_GPU_SLOT); + locations.lightBufferUnit = LIGHT_GPU_SLOT; + } else { + locations.lightBufferUnit = -1; + } +#else + loc = program.uniformLocation("lightBuffer"); + if (loc >= 0) { + locations.lightBufferUnit = loc; + } else { + locations.lightBufferUnit = -1; + } #endif -#if (GPU_FEATURE_PROFILE == GPU_CORE) - const GLint ATMOSPHERE_GPU_SLOT = 4; - loc = glGetUniformBlockIndex(program.programId(), "atmosphereBufferUnit"); - if (loc >= 0) { - glUniformBlockBinding(program.programId(), loc, ATMOSPHERE_GPU_SLOT); - locations.atmosphereBufferUnit = ATMOSPHERE_GPU_SLOT; - } else { - locations.atmosphereBufferUnit = -1; - } -#else - loc = program.uniformLocation("atmosphereBufferUnit"); - if (loc >= 0) { - locations.atmosphereBufferUnit = loc; - } else { - locations.atmosphereBufferUnit = -1; - } +#if (GPU_FEATURE_PROFILE == GPU_CORE) + const GLint ATMOSPHERE_GPU_SLOT = 4; + loc = glGetUniformBlockIndex(program.programId(), "atmosphereBufferUnit"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, ATMOSPHERE_GPU_SLOT); + locations.atmosphereBufferUnit = ATMOSPHERE_GPU_SLOT; + } else { + locations.atmosphereBufferUnit = -1; + } +#else + loc = program.uniformLocation("atmosphereBufferUnit"); + if (loc >= 0) { + locations.atmosphereBufferUnit = loc; + } else { + locations.atmosphereBufferUnit = -1; + } #endif program.release();