From 09085f1cd93318d402871b6d2d435723a47f98f9 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 26 May 2015 18:42:38 -0700 Subject: [PATCH] Working towards display plugins --- CMakeLists.txt | 6 +- cmake/externals/boostconfig/CMakeLists.txt | 18 +++++ cmake/externals/oglplus/CMakeLists.txt | 18 +++++ cmake/externals/openvr/CMakeLists.txt | 4 +- cmake/modules/FindBoostConfig.cmake | 24 ++++++ cmake/modules/FindOGLPLUS.cmake | 24 ++++++ libraries/octree/src/ViewFrustum.cpp | 9 ++- libraries/octree/src/ViewFrustum.h | 10 +-- libraries/render-utils/src/GlWindow.cpp | 78 +++++++++++++++++++ libraries/render-utils/src/GlWindow.h | 34 ++++++++ .../render-utils/src/OffscreenGlCanvas.cpp | 22 +++++- .../render-utils/src/OffscreenGlCanvas.h | 8 ++ .../render-utils/src/OffscreenGlContext.cpp | 43 ---------- .../render-utils/src/OffscreenGlContext.h | 33 -------- 14 files changed, 243 insertions(+), 88 deletions(-) create mode 100644 cmake/externals/boostconfig/CMakeLists.txt create mode 100644 cmake/externals/oglplus/CMakeLists.txt create mode 100644 cmake/modules/FindBoostConfig.cmake create mode 100644 cmake/modules/FindOGLPLUS.cmake create mode 100644 libraries/render-utils/src/GlWindow.cpp create mode 100644 libraries/render-utils/src/GlWindow.h delete mode 100644 libraries/render-utils/src/OffscreenGlContext.cpp delete mode 100644 libraries/render-utils/src/OffscreenGlContext.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 347341efa0..f1f83f063a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,8 +177,12 @@ 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(USE_NSIGHT "Attempt to find the nSight libraries" 1) option(GET_VHACD "Get V-HACD library automatically as external project" 1) +option(GET_OPENVR "Get OpenVR library automatically as external project" 1) +option(GET_BOOSTCONFIG "Get Boost-config library automatically as external project" 1) +option(GET_OGLPLUS "Get OGLplus library automatically as external project" 1) + +option(USE_NSIGHT "Attempt to find the nSight libraries" 1) if (WIN32) option(GET_GLEW "Get GLEW library automatically as external project" 1) diff --git a/cmake/externals/boostconfig/CMakeLists.txt b/cmake/externals/boostconfig/CMakeLists.txt new file mode 100644 index 0000000000..8785e0d7c7 --- /dev/null +++ b/cmake/externals/boostconfig/CMakeLists.txt @@ -0,0 +1,18 @@ +set(EXTERNAL_NAME boostconfig) +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + URL https://github.com/boostorg/config/archive/boost-1.58.0.zip + URL_MD5 42fa673bae2b7645a22736445e80eb8d + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE INTERNAL) + diff --git a/cmake/externals/oglplus/CMakeLists.txt b/cmake/externals/oglplus/CMakeLists.txt new file mode 100644 index 0000000000..1413edce34 --- /dev/null +++ b/cmake/externals/oglplus/CMakeLists.txt @@ -0,0 +1,18 @@ +set(EXTERNAL_NAME oglplus) +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + URL http://softlayer-dal.dl.sourceforge.net/project/oglplus/oglplus-0.61.x/oglplus-0.61.0.zip + URL_MD5 bb55038c36c660d2b6c7be380414fa60 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include ${SOURCE_DIR}/implement CACHE TYPE INTERNAL) + diff --git a/cmake/externals/openvr/CMakeLists.txt b/cmake/externals/openvr/CMakeLists.txt index b5cd477c02..826c3dbb13 100644 --- a/cmake/externals/openvr/CMakeLists.txt +++ b/cmake/externals/openvr/CMakeLists.txt @@ -7,8 +7,8 @@ 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 + URL https://github.com/ValveSoftware/openvr/archive/0.9.1.zip + URL_MD5 f986f5a6815e9454c53c5bf58ce02fdc CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" diff --git a/cmake/modules/FindBoostConfig.cmake b/cmake/modules/FindBoostConfig.cmake new file mode 100644 index 0000000000..90682d2425 --- /dev/null +++ b/cmake/modules/FindBoostConfig.cmake @@ -0,0 +1,24 @@ +# +# Try to find BOOSTCONFIG include path. +# Once done this will define +# +# BOOSTCONFIG_INCLUDE_DIRS +# +# Created by Bradley Austin Davis on 2015/05/22 +# 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 +# + +# setup hints for BOOSTCONFIG search +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("BOOSTCONFIG") + +# locate header +find_path(BOOSTCONFIG_INCLUDE_DIRS "boost/config.hpp" HINTS ${BOOSTCONFIG_SEARCH_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BOOSTCONFIG DEFAULT_MSG BOOSTCONFIG_INCLUDE_DIRS) + +mark_as_advanced(BOOSTCONFIG_INCLUDE_DIRS BOOSTCONFIG_SEARCH_DIRS) \ No newline at end of file diff --git a/cmake/modules/FindOGLPLUS.cmake b/cmake/modules/FindOGLPLUS.cmake new file mode 100644 index 0000000000..6ba883ee2c --- /dev/null +++ b/cmake/modules/FindOGLPLUS.cmake @@ -0,0 +1,24 @@ +# +# Try to find OGLPLUS include path. +# Once done this will define +# +# OGLPLUS_INCLUDE_DIRS +# +# Created by Bradley Austin Davis on 2015/05/22 +# 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 +# + +# setup hints for OGLPLUS search +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("oglplus") + +# locate header +find_path(OGLPLUS_INCLUDE_DIRS "oglplus/fwd.hpp" HINTS ${OGLPLUS_SEARCH_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OGLPLUS DEFAULT_MSG OGLPLUS_INCLUDE_DIRS) + +mark_as_advanced(OGLPLUS_INCLUDE_DIRS OGLPLUS_SEARCH_DIRS) \ No newline at end of file diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 2694314b57..80f0023970 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -27,14 +27,17 @@ using namespace std; -ViewFrustum::ViewFrustum() { -} - void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) { _orientation = orientationAsQuaternion; _right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f)); _up = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_UP, 0.0f)); _direction = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_FRONT, 0.0f)); + _view = glm::translate(mat4(), _position) * glm::mat4_cast(_orientation); +} + +void ViewFrustum::setPosition(const glm::vec3& position) { + _position = position; + _view = glm::translate(mat4(), _position) * glm::mat4_cast(_orientation); } // Order cooresponds to the order defined in the BoxVertex enum. diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index 0422120e51..43bc1d992e 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -36,11 +36,9 @@ const float DEFAULT_FAR_CLIP = (float)TREE_SCALE; class ViewFrustum { public: - ViewFrustum(); - // setters for camera attributes - void setPosition(const glm::vec3& p) { _position = p; } - void setOrientation(const glm::quat& orientationAsQuaternion); + void setPosition(const glm::vec3& position); + void setOrientation(const glm::quat& orientation); // getters for camera attributes const glm::vec3& getPosition() const { return _position; } @@ -54,7 +52,8 @@ public: void getFocalLength(float focalLength) { _focalLength = focalLength; } // getters for lens attributes - const glm::mat4 getProjection() const { return _projection; }; + const glm::mat4& getProjection() const { return _projection; }; + const glm::mat4& getView() const { return _view; }; float getWidth() const { return _width; } float getHeight() const { return _height; } float getFieldOfView() const { return _fieldOfView; } @@ -120,6 +119,7 @@ private: // camera location/orientation attributes glm::vec3 _position; // the position in world-frame glm::quat _orientation; + glm::mat4 _view; // Lens attributes glm::mat4 _projection; diff --git a/libraries/render-utils/src/GlWindow.cpp b/libraries/render-utils/src/GlWindow.cpp new file mode 100644 index 0000000000..b395140518 --- /dev/null +++ b/libraries/render-utils/src/GlWindow.cpp @@ -0,0 +1,78 @@ +// +// Created by Bradley Austin Davis on 2015/05/21 +// 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 +// + +#include "GlWindow.h" + +#include +#include + +static QSurfaceFormat getDefaultFormat() { + QSurfaceFormat format; + // Qt Quick may need a depth and stencil buffer. Always make sure these are available. + format.setDepthBufferSize(16); + format.setStencilBufferSize(8); + format.setVersion(4, 1); +#ifdef DEBUG + format.setOption(QSurfaceFormat::DebugContext); +#endif + format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); + return format; +} + +GlWindow::GlWindow(QOpenGLContext * shareContext) : GlWindow(getDefaultFormat(), shareContext) { +} + +GlWindow::GlWindow(const QSurfaceFormat& format, QOpenGLContext * shareContext) { + setSurfaceType(QSurface::OpenGLSurface); + setFormat(format); + _context = new QOpenGLContext; + _context->setFormat(format); + if (shareContext) { + _context->setShareContext(shareContext); + } + _context->create(); +} + +GlWindow::~GlWindow() { +#ifdef DEBUG + if (_logger) { + makeCurrent(); + delete _logger; + _logger = nullptr; + } +#endif + _context->doneCurrent(); + _context->deleteLater(); + _context = nullptr; +} + + +void GlWindow::makeCurrent() { + _context->makeCurrent(this); +#ifdef DEBUG + if (!_logger) { + _logger = new QOpenGLDebugLogger(this); + if (_logger->initialize()) { + connect(_logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message) { + qDebug() << message; + }); + _logger->disableMessages(QOpenGLDebugMessage::AnySource, QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity); + _logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging); + } + } +#endif +} + +void GlWindow::doneCurrent() { + _context->doneCurrent(); +} + +void GlWindow::swapBuffers() { + _context->swapBuffers(this); +} + diff --git a/libraries/render-utils/src/GlWindow.h b/libraries/render-utils/src/GlWindow.h new file mode 100644 index 0000000000..69fb09932e --- /dev/null +++ b/libraries/render-utils/src/GlWindow.h @@ -0,0 +1,34 @@ +// +// Created by Bradley Austin Davis on 2015/05/21 +// 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 +// + +#pragma once +#ifndef hifi_GlWindow_h +#define hifi_GlWindow_h + +#include +#include + +class QOpenGLContext; +class QOpenGLDebugLogger; + +class GlWindow : public QWindow { +public: + GlWindow(QOpenGLContext * shareContext = nullptr); + GlWindow(const QSurfaceFormat& format, QOpenGLContext * shareContext = nullptr); + virtual ~GlWindow(); + void makeCurrent(); + void doneCurrent(); + void swapBuffers(); +private: + QOpenGLContext * _context{ nullptr }; +#ifdef DEBUG + QOpenGLDebugLogger * _logger{ nullptr }; +#endif +}; + +#endif \ No newline at end of file diff --git a/libraries/render-utils/src/OffscreenGlCanvas.cpp b/libraries/render-utils/src/OffscreenGlCanvas.cpp index 0e5d4928d8..a3025bc3f6 100644 --- a/libraries/render-utils/src/OffscreenGlCanvas.cpp +++ b/libraries/render-utils/src/OffscreenGlCanvas.cpp @@ -11,6 +11,7 @@ #include "OffscreenGlCanvas.h" +#include OffscreenGlCanvas::OffscreenGlCanvas() { } @@ -27,16 +28,35 @@ void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) { format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); +#ifdef DEBUG + format.setOption(QSurfaceFormat::DebugContext); +#endif _context.setFormat(format); } _context.create(); _offscreenSurface.setFormat(_context.format()); _offscreenSurface.create(); + } bool OffscreenGlCanvas::makeCurrent() { - return _context.makeCurrent(&_offscreenSurface); + bool result = _context.makeCurrent(&_offscreenSurface); + +#ifdef DEBUG + if (result && !_logger) { + _logger = new QOpenGLDebugLogger(this); + if (_logger->initialize()) { + connect(_logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message) { + qDebug() << message; + }); + _logger->disableMessages(QOpenGLDebugMessage::AnySource, QOpenGLDebugMessage::AnyType, QOpenGLDebugMessage::NotificationSeverity); + _logger->startLogging(QOpenGLDebugLogger::LoggingMode::SynchronousLogging); + } + } +#endif + + return result; } void OffscreenGlCanvas::doneCurrent() { diff --git a/libraries/render-utils/src/OffscreenGlCanvas.h b/libraries/render-utils/src/OffscreenGlCanvas.h index 5a64a4cf10..c9578f5a7c 100644 --- a/libraries/render-utils/src/OffscreenGlCanvas.h +++ b/libraries/render-utils/src/OffscreenGlCanvas.h @@ -15,16 +15,24 @@ #include #include +class QOpenGLDebugLogger; + class OffscreenGlCanvas : public QObject { public: OffscreenGlCanvas(); void create(QOpenGLContext* sharedContext = nullptr); bool makeCurrent(); void doneCurrent(); + QOpenGLContext* getContext() { + return &_context; + } protected: QOpenGLContext _context; QOffscreenSurface _offscreenSurface; +#ifdef DEBUG + QOpenGLDebugLogger * _logger{ nullptr }; +#endif }; diff --git a/libraries/render-utils/src/OffscreenGlContext.cpp b/libraries/render-utils/src/OffscreenGlContext.cpp deleted file mode 100644 index 96f0a93c3a..0000000000 --- a/libraries/render-utils/src/OffscreenGlContext.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// -// OffscreenGlCanvas.cpp -// interface/src/renderer -// -// Created by Bradley Austin Davis on 2014/04/09. -// 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 "OffscreenGlContext.h" - -OffscreenGlContext::OffscreenGlContext() { -} - -void OffscreenGlContext::create(QOpenGLContext * sharedContext) { - QSurfaceFormat format; - format.setDepthBufferSize(16); - format.setStencilBufferSize(8); - format.setMajorVersion(4); - format.setMinorVersion(1); - format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); - - _context.setFormat(format); - if (nullptr != sharedContext) { - _context.setShareContext(sharedContext); - } - _context.create(); - - _offscreenSurface.setFormat(_context.format()); - _offscreenSurface.create(); -} - -bool OffscreenGlContext::makeCurrent() { - return _context.makeCurrent(&_offscreenSurface); -} - -void OffscreenGlContext::doneCurrent() { - _context.doneCurrent(); -} - diff --git a/libraries/render-utils/src/OffscreenGlContext.h b/libraries/render-utils/src/OffscreenGlContext.h deleted file mode 100644 index c0d22b268f..0000000000 --- a/libraries/render-utils/src/OffscreenGlContext.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// OffscreenGlCanvas.h -// interface/src/renderer -// -// Created by Bradley Austin Davis on 2014/04/09. -// 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 -#ifndef hifi_OffscreenGlContext_h -#define hifi_OffscreenGlContext_h - -#include -#include - -class OffscreenGlContext : public QObject { -public: - OffscreenGlContext(); - void create(QOpenGLContext * sharedContext = nullptr); - bool makeCurrent(); - void doneCurrent(); - QOpenGLContext * getContext() { - return &_context; - } - -protected: - QOpenGLContext _context; - QOffscreenSurface _offscreenSurface; -}; - -#endif // hifi_OffscreenGlCanvas_h