diff --git a/CMakeLists.txt b/CMakeLists.txt index b271664c35..58dee5ab27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,7 @@ option(GET_GVERB "Get Gverb library automatically as external project" 1) option(GET_SOXR "Get Soxr library automatically as external project" 1) option(GET_TBB "Get Threading Building Blocks library automatically as external project" 1) option(GET_LIBOVR "Get LibOVR library automatically as external project" 1) +option(GET_OPENVR "Get OpenVR library automatically as external project" 1) option(USE_NSIGHT "Attempt to find the nSight libraries" 1) option(GET_VHACD "Get V-HACD library automatically as external project" 1) diff --git a/cmake/externals/openvr/CMakeLists.txt b/cmake/externals/openvr/CMakeLists.txt new file mode 100644 index 0000000000..c5b15f4ea3 --- /dev/null +++ b/cmake/externals/openvr/CMakeLists.txt @@ -0,0 +1,38 @@ +include(ExternalProject) +include(SelectLibraryConfigurations) + +set(EXTERNAL_NAME OpenVR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) + +ExternalProject_Add( + ${EXTERNAL_NAME} + URL https://github.com/ValveSoftware/openvr/archive/0.9.0.zip + URL_MD5 4fbde7759f604aaa68b9c40d628cc34a + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/openvr-0.9.0/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) + +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) + +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) + +endif() + diff --git a/cmake/modules/FindOpenVR.cmake b/cmake/modules/FindOpenVR.cmake new file mode 100644 index 0000000000..9104fc514f --- /dev/null +++ b/cmake/modules/FindOpenVR.cmake @@ -0,0 +1,24 @@ +# +# FindLibOVR.cmake +# +# Try to find the LibOVR library to use the Oculus + +# Once done this will define +# +# OPENVR_FOUND - system found LibOVR +# OPENVR_INCLUDE_DIRS - the LibOVR include directory +# OPENVR_LIBRARIES - Link this to use LibOVR +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + + +if (NOT ANDROID) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(OPENVR DEFAULT_MSG OPENVR_INCLUDE_DIRS OPENVR_LIBRARIES) + +endif (NOT ANDROID) + +mark_as_advanced(OPENVR_INCLUDE_DIRS OPENVR_LIBRARIES OPENVR_SEARCH_DIRS) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 4b989ec6c1..0b2cfa5427 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -136,6 +136,11 @@ 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 ${LIBOVR_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) + find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4348f50f25..d514ee2837 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -114,6 +114,8 @@ #include "gpu/Batch.h" #include "gpu/GLBackend.h" +#include "plugins/render/RenderPlugin.h" + #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" @@ -584,7 +586,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()); + //_glWidget->installEventFilter(DependencyManager::get().data()); } @@ -726,7 +728,7 @@ void Application::initializeGL() { // texture resources initializeUi(); qCDebug(interfaceapp, "Initialized Offscreen UI."); - _glWidget->makeCurrent(); + _offscreenContext->makeCurrent(); // call Menu getInstance static method to set up the menu // Needs to happen AFTER the QML UI initialization @@ -770,30 +772,24 @@ void Application::initializeUi() { VrMenu::registerType(); auto offscreenUi = DependencyManager::get(); - offscreenUi->create(_glWidget->context()->contextHandle()); - offscreenUi->resize(_glWidget->size()); + offscreenUi->create(_offscreenContext->getContext()); + offscreenUi->resize(fromGlm(getActiveRenderPlugin()->getCanvasSize())); offscreenUi->setProxyWindow(_window->windowHandle()); offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); offscreenUi->load("Root.qml"); offscreenUi->load("RootMenu.qml"); VrMenu::load(); VrMenu::executeQueuedLambdas(); - offscreenUi->setMouseTranslator([this](const QPointF& p){ - if (OculusManager::isConnected()) { - glm::vec2 pos = _applicationOverlay.screenToOverlay(toGlm(p)); - return QPointF(pos.x, pos.y); - } - return QPointF(p); - }); + offscreenUi->setMouseTranslator(getActiveRenderPlugin()->getMouseTranslator()); offscreenUi->resume(); connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect & r){ static qreal oldDevicePixelRatio = 0; - qreal devicePixelRatio = _glWidget->devicePixelRatio(); + qreal devicePixelRatio = getActiveRenderPlugin()->devicePixelRatio(); if (devicePixelRatio != oldDevicePixelRatio) { oldDevicePixelRatio = devicePixelRatio; qDebug() << "Device pixel ratio changed, triggering GL resize"; - resizeGL(_glWidget->width(), - _glWidget->height()); + auto canvasSize = getActiveRenderPlugin()->getCanvasSize(); + resizeGL(canvasSize.x, canvasSize.y); } }); } @@ -846,8 +842,9 @@ void Application::paintGL() { DependencyManager::get()->prepare(); // Primary rendering pass - auto primaryFbo = DependencyManager::get()->getPrimaryFramebufferObject(); - primaryFbo->bind(); + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + auto finalFbo = primaryFbo; + glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo)); { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -864,32 +861,18 @@ void Application::paintGL() { if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { _rearMirrorTools->render(true); } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { -<<<<<<< HEAD renderRearViewMirror(_mirrorViewRect); -======= - renderRearViewMirror(_mirrorViewRect); } - DependencyManager::get()->render(); - + finalFbo = DependencyManager::get()->render(); { PerformanceTimer perfTimer("renderOverlay"); _applicationOverlay.renderOverlay(); + glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); _applicationOverlay.displayOverlayTexture(); ->>>>>>> master + glBindFramebuffer(GL_FRAMEBUFFER, 0); } } - primaryFbo->release(); - - QOpenGLFramebufferObject * finalFbo = DependencyManager::get()->render(); - - finalFbo->bind(); - { - PerformanceTimer perfTimer("renderOverlay"); - _applicationOverlay.renderOverlay(); - _applicationOverlay.displayOverlayTexture(); - } - finalFbo->release(); // This might not be needed *right now*. We want to ensure that the FBO rendering // has completed before we start trying to read from it in another context. However @@ -899,7 +882,7 @@ void Application::paintGL() { _offscreenContext->doneCurrent(); Q_ASSERT(!QOpenGLContext::currentContext()); - getActiveRenderPlugin()->render(finalFbo->texture()); + getActiveRenderPlugin()->render(gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0))); Q_ASSERT(!QOpenGLContext::currentContext()); _offscreenContext->makeCurrent(); _frameCount++; @@ -951,8 +934,9 @@ void Application::resizeGL(int width, int height) { updateProjectionMatrix(); glLoadIdentity(); + auto canvasSize = getActiveRenderPlugin()->getCanvasSize(); auto offscreenUi = DependencyManager::get(); - offscreenUi->resize(_glWidget->size()); + offscreenUi->resize(fromGlm(canvasSize)); // update Stats width // let's set horizontal offset to give stats some margin to mirror @@ -1003,43 +987,6 @@ bool Application::importSVOFromURL(const QString& urlString) { bool Application::event(QEvent* event) { switch (event->type()) { -<<<<<<< HEAD - case QEvent::MouseMove: - mouseMoveEvent((QMouseEvent*)event); - return true; - - case QEvent::MouseButtonPress: - mousePressEvent((QMouseEvent*)event); - return true; - - case QEvent::MouseButtonRelease: - mouseReleaseEvent((QMouseEvent*)event); - return true; - - case QEvent::KeyPress: - keyPressEvent((QKeyEvent*)event); - return true; - - case QEvent::KeyRelease: - keyReleaseEvent((QKeyEvent*)event); - return true; - - case QEvent::FocusIn: - //focusInEvent((QFocusEvent*)event); - //return true; - break; - - case QEvent::FocusOut: - focusOutEvent((QFocusEvent*)event); - return true; - - case QEvent::Resize: - resizeEvent((QResizeEvent *)event); - return true; - - default: - break; -======= case Lambda: ((LambdaEvent*)event)->call(); return true; @@ -1080,7 +1027,6 @@ bool Application::event(QEvent* event) { return true; default: break; ->>>>>>> master } // handle custom URL @@ -2990,13 +2936,7 @@ void Application::updateShadowMap() { glMatrixMode(GL_MODELVIEW); } -<<<<<<< HEAD - fbo->release(); -======= - // fbo->release(); - - glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); ->>>>>>> master +// glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); activeRenderingThread = nullptr; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 507cd0e77c..6e4cb524e6 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -74,9 +74,8 @@ #include "octree/OctreeFade.h" #include "octree/OctreePacketProcessor.h" #include "UndoStackScriptingInterface.h" -#include "plugins/render/RenderPlugin.h" - +class RenderPlugin; class QGLWidget; class QKeyEvent; class QMouseEvent; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 487f507ee2..6eb46071b8 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -115,7 +115,10 @@ int main(int argc, const char* argv[]) { exitCode = app.exec(); } +#if 0 OculusManager::deinit(); +#endif + #ifdef Q_OS_WIN ReleaseMutex(mutex); #endif diff --git a/interface/src/plugins/render/RenderPlugin.h b/interface/src/plugins/render/RenderPlugin.h index 3f8de27a7b..6a8328ee48 100644 --- a/interface/src/plugins/render/RenderPlugin.h +++ b/interface/src/plugins/render/RenderPlugin.h @@ -13,6 +13,8 @@ #include +#include + #include #include #include @@ -46,6 +48,8 @@ public: return trueMouseToUiMouse(getTrueMousePosition()); } + 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; }; @@ -69,6 +73,7 @@ public: } virtual void abandonCalibration() {} virtual void resetSensors() {} + virtual float devicePixelRatio() { return 1.0; } signals: void recommendedFramebufferSizeChanged(const QSize & size); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index a260a1b452..adb6492964 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -27,6 +27,7 @@ #include "Application.h" #include "ApplicationOverlay.h" #include "devices/OculusManager.h" +#include "plugins/render/RenderPlugin.h" #include "Util.h" #include "ui/Stats.h" @@ -934,7 +935,6 @@ void ApplicationOverlay::renderAudioMeter() { } void ApplicationOverlay::renderStatsAndLogs() { -#if 0 Application* application = Application::getInstance(); QSharedPointer bandwidthRecorder = DependencyManager::get(); @@ -972,7 +972,6 @@ void ApplicationOverlay::renderStatsAndLogs() { 0.30f, 0.0f, 0, frameTimer.toUtf8().constData(), WHITE_TEXT); } nodeBoundsDisplay.drawOverlay(); -#endif } void ApplicationOverlay::renderDomainConnectionStatusBorder() { diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp index 33a91829f5..8672bfa7fc 100644 --- a/libraries/render-utils/src/GlowEffect.cpp +++ b/libraries/render-utils/src/GlowEffect.cpp @@ -139,7 +139,7 @@ gpu::FramebufferPointer GlowEffect::render() { glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); - gpu::FramebufferPointer destFBO = textureCache->getSecondaryFramebuffer() + gpu::FramebufferPointer destFBO = textureCache->getSecondaryFramebuffer(); if (!_enabled || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { @@ -147,13 +147,13 @@ gpu::FramebufferPointer GlowEffect::render() { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); glBlitFramebuffer(0, 0, framebufferSize.width(), framebufferSize.height(), 0, 0, framebufferSize.width(), framebufferSize.height(), GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { - destFBO->bind(); + glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); renderFullscreenQuad(); glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); - destFBO->release(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } } else { // diffuse into the secondary/tertiary (alternating between frames) @@ -188,11 +188,11 @@ gpu::FramebufferPointer GlowEffect::render() { glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(newDiffusedFBO->getRenderBuffer(0))); destFBO = oldDiffusedFBO; - destFBO->bind(); + glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); _addSeparateProgram->bind(); renderFullscreenQuad(); _addSeparateProgram->release(); - destFBO->release(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); glActiveTexture(GL_TEXTURE0); diff --git a/libraries/render-utils/src/OffscreenGlContext.h b/libraries/render-utils/src/OffscreenGlContext.h index ef67a7fc9a..c0d22b268f 100644 --- a/libraries/render-utils/src/OffscreenGlContext.h +++ b/libraries/render-utils/src/OffscreenGlContext.h @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #pragma once -#ifndef hifi_OffscreenGlCanvas_h -#define hifi_OffscreenGlCanvas_h +#ifndef hifi_OffscreenGlContext_h +#define hifi_OffscreenGlContext_h #include #include diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 63ca43725b..c7aa4b586c 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -32,8 +32,7 @@ TextureCache::TextureCache() : _permutationNormalTexture(0), _whiteTexture(0), _blueTexture(0), - _frameBufferSize(100, 100), - _associatedWidget(NULL) + _frameBufferSize(100, 100) { const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE; setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE); @@ -290,24 +289,6 @@ GLuint TextureCache::getShadowDepthTextureID() { return gpu::GLBackend::getTextureID(_shadowTexture); } -bool TextureCache::eventFilter(QObject* watched, QEvent* event) { - if (event->type() == QEvent::Resize) { - QSize size = static_cast(event)->size(); - if (_frameBufferSize != size) { - _primaryFramebuffer.reset(); - _primaryColorTexture.reset(); - _primaryDepthTexture.reset(); - _primaryNormalTexture.reset(); - _primarySpecularTexture.reset(); - - _secondaryFramebuffer.reset(); - - _tertiaryFramebuffer.reset(); - } - } - return false; -} - QSharedPointer TextureCache::createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra) { const TextureExtra* textureExtra = static_cast(extra); @@ -315,14 +296,6 @@ QSharedPointer TextureCache::createResource(const QUrl& url, &Resource::allReferencesCleared); } -void TextureCache::associateWithWidget(QGLWidget* widget) { - if (_associatedWidget) { - _associatedWidget->removeEventFilter(this); - } - _associatedWidget = widget; - _associatedWidget->installEventFilter(this); -} - Texture::Texture() { } diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 5d1b70275c..89fd15e179 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -336,6 +336,10 @@ QMatrix4x4 fromGlm(const glm::mat4 & m) { return QMatrix4x4(&m[0][0]).transposed(); } +QSize fromGlm(const glm::ivec2 & v) { + return QSize(v.x, v.y); +} + QRectF glmToRect(const glm::vec2 & pos, const glm::vec2 & size) { QRectF result(pos.x, pos.y, size.x, size.y); return result; diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index dda57a9cd9..a710ba759b 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -112,6 +112,7 @@ glm::vec2 toGlm(const QPointF & pt); glm::vec3 toGlm(const xColor & color); glm::vec4 toGlm(const QColor & color); +QSize fromGlm(const glm::ivec2 & v); QMatrix4x4 fromGlm(const glm::mat4 & m); QRectF glmToRect(const glm::vec2 & pos, const glm::vec2 & size);