diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 78f4cbd6a6..a9688a5919 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -107,7 +107,8 @@ endif() add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # link required hifi libraries -link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics render-utils) +link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics + render-utils entities-renderer) # find any optional and required libraries find_package(ZLIB REQUIRED) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 864a12ea1d..c3ec763426 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,7 @@ #include #include #include +#include #include #include @@ -109,7 +111,6 @@ #include "ui/InfoView.h" #include "ui/Snapshot.h" #include "ui/Stats.h" -#include "ui/TextRenderer.h" @@ -142,7 +143,6 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QApplication(argc, argv), _window(new MainWindow(desktop())), - _glWidget(new GLCanvas()), _toolWindow(NULL), _nodeThread(new QThread(this)), _datagramProcessor(), @@ -155,9 +155,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _voxelImporter(), _importSucceded(false), _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard), - _entities(true), + _entities(true, this, this), _entityCollisionSystem(), - _entityClipboardRenderer(false), + _entityClipboardRenderer(false, this, this), _entityClipboard(), _wantToKillLocalVoxels(false), _viewFrustum(), @@ -191,8 +191,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { - Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us - + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + Model::setAbstractViewStateInterface(this); // The model class will sometimes need to know view state details from us + // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -362,16 +363,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ResourceCache::setRequestLimit(3); - _window->setCentralWidget(_glWidget); + _window->setCentralWidget(glCanvas.data()); restoreSizeAndPosition(); _window->setVisible(true); - _glWidget->setFocusPolicy(Qt::StrongFocus); - _glWidget->setFocus(); + glCanvas->setFocusPolicy(Qt::StrongFocus); + glCanvas->setFocus(); // enable mouse tracking; otherwise, we only get drag events - _glWidget->setMouseTracking(true); + glCanvas->setMouseTracking(true); _toolWindow = new ToolWindow(); _toolWindow->setWindowFlags(_toolWindow->windowFlags() | Qt::WindowStaysOnTopHint); @@ -390,7 +391,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : checkVersion(); - _overlays.init(_glWidget); // do this before scripts load + _overlays.init(glCanvas.data()); // do this before scripts load LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); @@ -439,6 +440,7 @@ void Application::aboutToQuit() { } Application::~Application() { + _entities.getTree()->setSimulation(NULL); qInstallMessageHandler(NULL); @@ -480,8 +482,6 @@ Application::~Application() { Menu::getInstance()->deleteLater(); _myAvatar = NULL; - - delete _glWidget; } void Application::saveSettings() { @@ -621,7 +621,7 @@ void Application::paintGL() { if (OculusManager::isConnected()) { DependencyManager::get()->setFrameBufferSize(OculusManager::getRenderTargetSize()); } else { - QSize fbSize = _glWidget->getDeviceSize() * getRenderResolutionScale(); + QSize fbSize = DependencyManager::get()->getDeviceSize() * getRenderResolutionScale(); DependencyManager::get()->setFrameBufferSize(fbSize); } @@ -1045,7 +1045,8 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); @@ -1057,7 +1058,8 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { @@ -1503,7 +1505,7 @@ void Application::idle() { { PerformanceTimer perfTimer("updateGL"); PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); - _glWidget->updateGL(); + DependencyManager::get()->updateGL(); } { PerformanceTimer perfTimer("rest"); @@ -1529,13 +1531,14 @@ void Application::idle() { void Application::checkBandwidthMeterClick() { // ... to be called upon button release + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) && glm::compMax(glm::abs(glm::ivec2(getMouseX() - getMouseDragStartedX(), getMouseY() - getMouseDragStartedY()))) <= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH - && _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), _glWidget->width(), _glWidget->height())) { + && _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), glCanvas->width(), glCanvas->height())) { // The bandwidth meter is visible, the click didn't get dragged too far and // we actually hit the bandwidth meter @@ -1564,7 +1567,8 @@ void Application::setFullscreen(bool fullscreen) { } void Application::setEnable3DTVMode(bool enable3DTVMode) { - resizeGL(_glWidget->getDeviceWidth(),_glWidget->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } void Application::setEnableVRMode(bool enableVRMode) { @@ -1589,7 +1593,8 @@ void Application::setEnableVRMode(bool enableVRMode) { _myCamera.setHmdRotation(glm::quat()); } - resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } void Application::setRenderVoxels(bool voxelRender) { @@ -1651,8 +1656,9 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox bool Application::mouseOnScreen() const { if (OculusManager::isConnected()) { - return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() && - getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + return getMouseX() >= 0 && getMouseX() <= glCanvas->getDeviceWidth() && + getMouseY() >= 0 && getMouseY() <= glCanvas->getDeviceHeight(); } return true; } @@ -1692,13 +1698,13 @@ int Application::getMouseDragStartedY() const { } FaceTracker* Application::getActiveFaceTracker() { - Faceshift* faceshift = DependencyManager::get(); - Visage* visage = DependencyManager::get(); - DdeFaceTracker* dde = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); + Visage::SharedPointer visage = DependencyManager::get(); + DdeFaceTracker::SharedPointer dde = DependencyManager::get(); - return (dde->isActive() ? static_cast(dde) : - (faceshift->isActive() ? static_cast(faceshift) : - (visage->isActive() ? static_cast(visage) : NULL))); + return (dde->isActive() ? static_cast(dde.data()) : + (faceshift->isActive() ? static_cast(faceshift.data()) : + (visage->isActive() ? static_cast(visage.data()) : NULL))); } struct SendVoxelsOperationArgs { @@ -1771,7 +1777,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QString suggestedName = desktopLocation.append("/voxels.svo"); - QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName, + QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get().data(), + tr("Export Voxels"), suggestedName, tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); @@ -2025,9 +2032,9 @@ void Application::init() { _metavoxels.init(); - _audio.init(_glWidget); - - _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + _audio.init(glCanvas.data()); + _rearMirrorTools = new RearMirrorTools(glCanvas.data(), _mirrorViewRect, _settings); connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); @@ -2040,11 +2047,12 @@ void Application::init() { // save settings when avatar changes connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings); - // make sure our texture cache knows about window size changes - DependencyManager::get()->associateWithWidget(getGLWidget()); + // make sure our texture cache knows about window size changes + DependencyManager::get()->associateWithWidget(glCanvas.data()); // initialize the GlowEffect with our widget - DependencyManager::get()->init(getGLWidget(), Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); + DependencyManager::get()->init(glCanvas.data(), + Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); } void Application::closeMirrorView() { @@ -2112,7 +2120,7 @@ void Application::updateMouseRay() { void Application::updateFaceshift() { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateFaceshift()"); - Faceshift* faceshift = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); // Update faceshift faceshift->update(); @@ -2916,8 +2924,9 @@ void Application::updateShadowMap() { } fbo->release(); - - glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f }; @@ -2944,6 +2953,18 @@ bool Application::shouldRenderMesh(float largestDimension, float distanceToCamer return Menu::getInstance()->shouldRenderMesh(largestDimension, distanceToCamera); } +float Application::getSizeScale() const { + return Menu::getInstance()->getVoxelSizeScale(); +} + +int Application::getBoundaryLevelAdjust() const { + return Menu::getInstance()->getBoundaryLevelAdjust(); +} + +PickRay Application::computePickRay(float x, float y) { + return getCamera()->computePickRay(x, y); +} + QImage Application::renderAvatarBillboard() { DependencyManager::get()->getPrimaryFramebufferObject()->bind(); @@ -2951,7 +2972,9 @@ QImage Application::renderAvatarBillboard() { Glower glower; const int BILLBOARD_SIZE = 64; - renderRearViewMirror(QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE, BILLBOARD_SIZE, BILLBOARD_SIZE), true); + renderRearViewMirror(QRect(0, DependencyManager::get()->getDeviceHeight() - BILLBOARD_SIZE, + BILLBOARD_SIZE, BILLBOARD_SIZE), + true); QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); @@ -3254,8 +3277,9 @@ bool Application::getCascadeShadowsEnabled() { } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { - float horizontalScale = _glWidget->getDeviceWidth() / 2.0f; - float verticalScale = _glWidget->getDeviceHeight() / 2.0f; + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + float horizontalScale = glCanvas->getDeviceWidth() / 2.0f; + float verticalScale = glCanvas->getDeviceHeight() / 2.0f; // -1,-1 is 0,windowHeight // 1,1 is windowWidth,0 @@ -3274,7 +3298,7 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { // -1,-1 1,-1 glm::vec2 screenPoint((projectedPoint.x + 1.0) * horizontalScale, - ((projectedPoint.y + 1.0) * -verticalScale) + _glWidget->getDeviceHeight()); + ((projectedPoint.y + 1.0) * -verticalScale) + glCanvas->getDeviceHeight()); return screenPoint; } @@ -3585,7 +3609,7 @@ void Application::resetSensors() { QScreen* currentScreen = _window->windowHandle()->screen(); QWindow* mainWindow = _window->windowHandle(); QPoint windowCenter = mainWindow->geometry().center(); - _glWidget->cursor().setPos(currentScreen, windowCenter); + DependencyManager::get()->cursor().setPos(currentScreen, windowCenter); _myAvatar->reset(); @@ -4021,7 +4045,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); - scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get()); + scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance()); scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels); @@ -4266,7 +4290,8 @@ void Application::setPreviousScriptLocation(const QString& previousScriptLocatio void Application::loadDialog() { - QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), + QString fileNameString = QFileDialog::getOpenFileName(DependencyManager::get().data(), + tr("Open Script"), getPreviousScriptLocation(), tr("JavaScript Files (*.js)")); if (!fileNameString.isEmpty()) { @@ -4302,7 +4327,7 @@ void Application::loadScriptURLDialog() { void Application::toggleLogDialog() { if (! _logDialog) { - _logDialog = new LogDialog(_glWidget, getLogger()); + _logDialog = new LogDialog(DependencyManager::get().data(), getLogger()); } if (_logDialog->isVisible()) { @@ -4362,7 +4387,7 @@ void Application::parseVersionXml() { } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); + new UpdateDialog(DependencyManager::get().data(), releaseNotes, latestVersion, downloadUrl); } sender->deleteLater(); } @@ -4395,7 +4420,7 @@ void Application::takeSnapshot() { } if (!_snapshotShareDialog) { - _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); + _snapshotShareDialog = new SnapshotShareDialog(fileName, DependencyManager::get().data()); } _snapshotShareDialog->show(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 9aca90fac8..111f03c7c6 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -12,28 +12,22 @@ #ifndef hifi_Application_h #define hifi_Application_h -#include -#include - #include #include -#include -#include #include #include -#include #include #include #include #include -#include -#include #include -#include +#include +#include #include #include +#include #include #include #include @@ -42,10 +36,8 @@ #include #include #include -#include #include -#include "MainWindow.h" #include "Audio.h" #include "Camera.h" #include "DatagramProcessor.h" @@ -61,7 +53,6 @@ #include "avatar/MyAvatar.h" #include "devices/PrioVR.h" #include "devices/SixenseManager.h" -#include "entities/EntityTreeRenderer.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" @@ -89,17 +80,19 @@ #include "UndoStackScriptingInterface.h" -class QAction; -class QActionGroup; class QGLWidget; class QKeyEvent; class QMouseEvent; class QSettings; +class QSystemTrayIcon; +class QTouchEvent; class QWheelEvent; class FaceTracker; +class MainWindow; class Node; class ProgramObject; +class ScriptEngine; static const float NODE_ADDED_RED = 0.0f; static const float NODE_ADDED_GREEN = 1.0f; @@ -127,7 +120,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; -class Application : public QApplication, public ViewStateInterface { +class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface { Q_OBJECT friend class OctreePacketProcessor; @@ -182,46 +175,50 @@ public: void removeVoxel(glm::vec3 position, float scale); glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel); + bool isThrottleRendering() const { return DependencyManager::get()->isThrottleRendering(); } - GLCanvas* getGLWidget() { return _glWidget; } - bool isThrottleRendering() const { return _glWidget->isThrottleRendering(); } MyAvatar* getAvatar() { return _myAvatar; } + const MyAvatar* getAvatar() const { return _myAvatar; } Audio* getAudio() { return &_audio; } Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } ViewFrustum* getDisplayViewFrustum() { return &_displayViewFrustum; } ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } - VoxelImporter* getVoxelImporter() { return &_voxelImporter; } VoxelSystem* getVoxels() { return &_voxels; } - VoxelTree* getVoxelTree() { return _voxels.getTree(); } const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; } EntityTreeRenderer* getEntities() { return &_entities; } - bool getImportSucceded() { return _importSucceded; } VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; } + Environment* getEnvironment() { return &_environment; } + PrioVR* getPrioVR() { return &_prioVR; } + QUndoStack* getUndoStack() { return &_undoStack; } + MainWindow* getWindow() { return _window; } + + VoxelImporter* getVoxelImporter() { return &_voxelImporter; } VoxelTree* getClipboard() { return &_clipboard; } EntityTree* getEntityClipboard() { return &_entityClipboard; } EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; } - Environment* getEnvironment() { return &_environment; } + VoxelTree* getVoxelTree() { return _voxels.getTree(); } + bool getImportSucceded() { return _importSucceded; } + bool isMousePressed() const { return _mousePressed; } - bool isMouseHidden() const { return _glWidget->cursor().shape() == Qt::BlankCursor; } + bool isMouseHidden() const { return DependencyManager::get()->cursor().shape() == Qt::BlankCursor; } void setCursorVisible(bool visible); const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } bool mouseOnScreen() const; int getMouseX() const; int getMouseY() const; - int getTrueMouseX() const { return _glWidget->mapFromGlobal(QCursor::pos()).x(); } - int getTrueMouseY() const { return _glWidget->mapFromGlobal(QCursor::pos()).y(); } + int getTrueMouseX() const { return DependencyManager::get()->mapFromGlobal(QCursor::pos()).x(); } + int getTrueMouseY() const { return DependencyManager::get()->mapFromGlobal(QCursor::pos()).y(); } int getMouseDragStartedX() const; int getMouseDragStartedY() const; int getTrueMouseDragStartedX() const { return _mouseDragStartedX; } int getTrueMouseDragStartedY() const { return _mouseDragStartedY; } bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; } + FaceTracker* getActiveFaceTracker(); - PrioVR* getPrioVR() { return &_prioVR; } BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } - QUndoStack* getUndoStack() { return &_undoStack; } QSystemTrayIcon* getTrayIcon() { return _trayIcon; } ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; } Overlays& getOverlays() { return _overlays; } @@ -241,14 +238,15 @@ public: void saveSettings(); - MainWindow* getWindow() { return _window; } NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; } void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); } void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); } ToolWindow* getToolWindow() { return _toolWindow ; } - ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } + virtual AbstractControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } + virtual void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); + AvatarManager& getAvatarManager() { return _avatarManager; } void resetProfile(const QString& username); @@ -285,12 +283,17 @@ public: virtual bool getShadowsEnabled(); virtual bool getCascadeShadowsEnabled(); virtual QThread* getMainThread() { return thread(); } + virtual float getSizeScale() const; + virtual int getBoundaryLevelAdjust() const; + virtual PickRay computePickRay(float x, float y); + virtual const glm::vec3& getAvatarPosition() const { return getAvatar()->getPosition(); } NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } FileLogger* getLogger() { return _logger; } - glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } + glm::vec2 getViewportDimensions() const { return glm::vec2(DependencyManager::get()->getDeviceWidth(), + DependencyManager::get()->getDeviceHeight()); } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination); @@ -309,9 +312,6 @@ public: bool isVSyncEditable() const; bool isAboutToQuit() const { return _aboutToQuit; } - - void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); - // the isHMDmode is true whenever we use the interface from an HMD and not a standard flat display // rendering of several elements depend on that // TODO: carry that information on the Camera as a setting @@ -468,7 +468,6 @@ private: int sendNackPackets(); MainWindow* _window; - GLCanvas* _glWidget; // our GLCanvas has a couple extra features ToolWindow* _toolWindow; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index d069afb96a..b2fd30a1a6 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -95,10 +95,8 @@ void Camera::setFarClip(float f) { } PickRay Camera::computePickRay(float x, float y) { - float screenWidth = Application::getInstance()->getGLWidget()->width(); - float screenHeight = Application::getInstance()->getGLWidget()->height(); - - return computeViewPickRay(x / screenWidth, y / screenHeight); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + return computeViewPickRay(x / glCanvas->width(), y / glCanvas->height()); } PickRay Camera::computeViewPickRay(float xRatio, float yRatio) { diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index cec3f62b7d..10090de51a 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -9,13 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include #include #include #include #include "Application.h" #include "GLCanvas.h" +#include "MainWindow.h" #include "devices/OculusManager.h" const int MSECS_PER_FRAME_WHEN_THROTTLED = 66; diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 0d381fa0bf..420bf77467 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -15,11 +15,14 @@ #include #include +#include + /// customized canvas that simply forwards requests/events to the singleton application class GLCanvas : public QGLWidget { Q_OBJECT + SINGLETON_DEPENDENCY(GLCanvas) + public: - GLCanvas(); bool isThrottleRendering() const; int getDeviceWidth() const; @@ -56,6 +59,12 @@ private slots: void activeChanged(Qt::ApplicationState state); void throttleRender(); bool eventFilter(QObject*, QEvent* event); + +private: + GLCanvas(); + ~GLCanvas() { + qDebug() << "Deleting GLCanvas"; + } }; #endif // hifi_GLCanvas_h diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 80fdec5202..f0c2a687a4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -426,7 +427,7 @@ Menu::Menu() : appInstance, SLOT(setRenderVoxels(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::EnableGlowEffect, 0, true, - DependencyManager::get(), SLOT(toggleGlowEffect(bool))); + DependencyManager::get().data(), SLOT(toggleGlowEffect(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, Qt::ALT | Qt::Key_W, false); addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools())); @@ -437,12 +438,12 @@ Menu::Menu() : MenuOption::Faceshift, 0, true, - DependencyManager::get(), + DependencyManager::get().data(), SLOT(setTCPEnabled(bool))); #endif #ifdef HAVE_VISAGE addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::Visage, 0, false, - DependencyManager::get(), SLOT(updateEnabled())); + DependencyManager::get().data(), SLOT(updateEnabled())); #endif addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSkeletonCollisionShapes); @@ -1051,11 +1052,11 @@ void Menu::bumpSettings() { void sendFakeEnterEvent() { QPoint lastCursorPosition = QCursor::pos(); - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - QPoint windowPosition = glWidget->mapFromGlobal(lastCursorPosition); + QPoint windowPosition = glCanvas->mapFromGlobal(lastCursorPosition); QEnterEvent enterEvent = QEnterEvent(windowPosition, windowPosition, lastCursorPosition); - QCoreApplication::sendEvent(glWidget, &enterEvent); + QCoreApplication::sendEvent(glCanvas.data(), &enterEvent); } const float DIALOG_RATIO_OF_WINDOW = 0.30f; @@ -1303,7 +1304,7 @@ void Menu::toggleLoginMenuItem() { void Menu::bandwidthDetails() { if (! _bandwidthDialog) { - _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), + _bandwidthDialog = new BandwidthDialog(DependencyManager::get().data(), Application::getInstance()->getBandwidthMeter()); connect(_bandwidthDialog, SIGNAL(closed()), SLOT(bandwidthDetailsClosed())); @@ -1414,7 +1415,7 @@ void Menu::bandwidthDetailsClosed() { void Menu::octreeStatsDetails() { if (!_octreeStatsDialog) { - _octreeStatsDialog = new OctreeStatsDialog(Application::getInstance()->getGLWidget(), + _octreeStatsDialog = new OctreeStatsDialog(DependencyManager::get().data(), Application::getInstance()->getOcteeSceneStats()); connect(_octreeStatsDialog, SIGNAL(closed()), SLOT(octreeStatsDetailsClosed())); _octreeStatsDialog->show(); @@ -1598,7 +1599,7 @@ bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) { void Menu::lodTools() { if (!_lodToolsDialog) { - _lodToolsDialog = new LodToolsDialog(Application::getInstance()->getGLWidget()); + _lodToolsDialog = new LodToolsDialog(DependencyManager::get().data()); connect(_lodToolsDialog, SIGNAL(closed()), SLOT(lodToolsClosed())); _lodToolsDialog->show(); if (_hmdToolsDialog) { @@ -1618,7 +1619,7 @@ void Menu::lodToolsClosed() { void Menu::hmdTools(bool showTools) { if (showTools) { if (!_hmdToolsDialog) { - _hmdToolsDialog = new HMDToolsDialog(Application::getInstance()->getGLWidget()); + _hmdToolsDialog = new HMDToolsDialog(DependencyManager::get().data()); connect(_hmdToolsDialog, SIGNAL(closed()), SLOT(hmdToolsClosed())); } _hmdToolsDialog->show(); diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 07c312bdfd..9a26ca6bb5 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -1178,7 +1178,7 @@ void VoxelBuffer::render(bool cursor) { if (!_materials.isEmpty()) { _networkTextures.resize(_materials.size()); - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); for (int i = 0; i < _materials.size(); i++) { const SharedObjectPointer material = _materials.at(i); if (material) { @@ -2233,7 +2233,7 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g const QVector& materials = node->getMaterial()->getMaterials(); _networkTextures.resize(materials.size()); - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); for (int i = 0; i < materials.size(); i++) { const SharedObjectPointer& material = materials.at(i); if (material) { diff --git a/interface/src/ModelUploader.cpp b/interface/src/ModelUploader.cpp index 6f582d60eb..29d1596809 100644 --- a/interface/src/ModelUploader.cpp +++ b/interface/src/ModelUploader.cpp @@ -472,7 +472,7 @@ void ModelUploader::processCheck() { QString("Your model is now available in the browser."), QMessageBox::Ok); DependencyManager::get()->refresh(_url); - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); foreach (const QByteArray& filename, _textureFilenames) { textureCache->refresh(_textureBase + filename); } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 6d40726f14..38f18e96d9 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -19,12 +19,12 @@ #include #include -#include - #include +#include +#include + #include "InterfaceConfig.h" -#include "ui/TextRenderer.h" #include "VoxelConstants.h" #include "world.h" #include "Application.h" @@ -71,7 +71,7 @@ void renderWorldBox() { glPushMatrix(); glTranslatef(MARKER_DISTANCE, 0, 0); glColor3fv(red); - GeometryCache* geometryCache = DependencyManager::get(); + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 51fde3df43..81d7920783 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "Application.h" @@ -42,7 +43,6 @@ #include "Recorder.h" #include "world.h" #include "devices/OculusManager.h" -#include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 5d84c2d939..9c02b0e380 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -72,20 +72,19 @@ void Head::reset() { } void Head::simulate(float deltaTime, bool isMine, bool billboard) { - if (isMine) { MyAvatar* myAvatar = static_cast(_owningAvatar); // Only use face trackers when not playing back a recording. if (!myAvatar->isPlaying()) { FaceTracker* faceTracker = Application::getInstance()->getActiveFaceTracker(); - DdeFaceTracker* dde = DependencyManager::get(); - Faceshift* faceshift = DependencyManager::get(); + DdeFaceTracker::SharedPointer dde = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); if ((_isFaceshiftConnected = (faceshift == faceTracker))) { _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); } else if (dde->isActive()) { - faceTracker = dde; + faceTracker = dde.data(); _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 6976e26e86..4e3a9c4ff4 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "Application.h" #include "Audio.h" @@ -41,7 +42,6 @@ #include "Recorder.h" #include "devices/Faceshift.h" #include "devices/OculusManager.h" -#include "ui/TextRenderer.h" using namespace std; @@ -422,7 +422,7 @@ void MyAvatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bo } void MyAvatar::renderHeadMouse(int screenWidth, int screenHeight) const { - Faceshift* faceshift = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); float pixelsPerDegree = screenHeight / Menu::getInstance()->getFieldOfView(); diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 42c74db143..b707861677 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -554,7 +554,7 @@ void SkeletonModel::renderRagdoll() { float radius1 = 0.008f; float radius2 = 0.01f; glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame(); - GeometryCache* geometryCache = DependencyManager::get(); + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); for (int i = 0; i < numPoints; ++i) { glPushMatrix(); // NOTE: ragdollPoints are in simulation-frame but we want them to be model-relative @@ -914,7 +914,7 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { endPoint = endPoint - _translation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); glColor4f(0.6f, 0.6f, 0.8f, alpha); - GeometryCache* geometryCache = DependencyManager::get(); + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); // draw a yellow sphere at the capsule startpoint @@ -950,7 +950,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { continue; } - GeometryCache* geometryCache = DependencyManager::get(); + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); glPushMatrix(); // shapes are stored in simulation-frame but we want position to be model-relative diff --git a/interface/src/devices/DdeFaceTracker.h b/interface/src/devices/DdeFaceTracker.h index d80aa043e4..23a5d1fcc8 100644 --- a/interface/src/devices/DdeFaceTracker.h +++ b/interface/src/devices/DdeFaceTracker.h @@ -18,8 +18,9 @@ #include "FaceTracker.h" -class DdeFaceTracker : public FaceTracker, public DependencyManager::Dependency { +class DdeFaceTracker : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY(DdeFaceTracker) public: //initialization @@ -58,7 +59,6 @@ private: DdeFaceTracker(); DdeFaceTracker(const QHostAddress& host, quint16 port); ~DdeFaceTracker(); - friend DependencyManager; float getBlendshapeCoefficient(int index) const; void decodePacket(const QByteArray& buffer); diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index 3cca8f2bb1..b6b942dfee 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -24,8 +24,9 @@ #include "FaceTracker.h" /// Handles interaction with the Faceshift software, which provides head position/orientation and facial features. -class Faceshift : public FaceTracker, public DependencyManager::Dependency { +class Faceshift : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY(Faceshift) public: void init(); @@ -89,7 +90,6 @@ private slots: private: Faceshift(); virtual ~Faceshift() {} - friend DependencyManager; float getBlendshapeCoefficient(int index) const; diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 96615112dd..1854c9539d 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -562,8 +562,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p } // restore our normal viewport - glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -581,8 +581,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); - gluOrtho2D(0, Application::getInstance()->getGLWidget()->getDeviceWidth(), 0, - Application::getInstance()->getGLWidget()->getDeviceHeight()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + gluOrtho2D(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight()); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index d3e985d259..70c668a162 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -14,11 +14,11 @@ #include #include +#include #include "Application.h" #include "PrioVR.h" #include "scripting/JoystickScriptingInterface.h" -#include "ui/TextRenderer.h" #ifdef HAVE_PRIOVR const unsigned int SERIAL_LIST[] = { 0x00000001, 0x00000000, 0x00000008, 0x00000009, 0x0000000A, @@ -215,8 +215,9 @@ void PrioVR::renderCalibrationCountdown() { static TextRenderer* textRenderer = TextRenderer::getInstance(MONO_FONT_FAMILY, 18, QFont::Bold, false, TextRenderer::OUTLINE_EFFECT, 2); QByteArray text = "Assume T-Pose in " + QByteArray::number(secondsRemaining) + "..."; - textRenderer->draw((Application::getInstance()->getGLWidget()->width() - - textRenderer->computeWidth(text.constData())) / 2, Application::getInstance()->getGLWidget()->height() / 2, - text); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + textRenderer->draw((glCanvas->width() - textRenderer->computeWidth(text.constData())) / 2, + glCanvas->height() / 2, + text); #endif } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 7a555eb902..e2b4fedd50 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -461,7 +461,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) void SixenseManager::emulateMouse(PalmData* palm, int index) { Application* application = Application::getInstance(); MyAvatar* avatar = application->getAvatar(); - GLCanvas* widget = application->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); QPoint pos; Qt::MouseButton bumperButton; @@ -489,10 +489,10 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = widget->width() * getCursorPixelRangeMult(); + float cursorRange = glCanvas->width() * getCursorPixelRangeMult(); - pos.setX(widget->width() / 2.0f + cursorRange * xAngle); - pos.setY(widget->height() / 2.0f + cursorRange * yAngle); + pos.setX(glCanvas->width() / 2.0f + cursorRange * xAngle); + pos.setY(glCanvas->height() / 2.0f + cursorRange * yAngle); } diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index f665765d70..ff40329b6c 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -35,10 +35,10 @@ bool TV3DManager::isConnected() { } void TV3DManager::connect() { - Application* app = Application::getInstance(); - int width = app->getGLWidget()->getDeviceWidth(); - int height = app->getGLWidget()->getDeviceHeight(); - Camera& camera = *app->getCamera(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + int width = glCanvas->getDeviceWidth(); + int height = glCanvas->getDeviceHeight(); + Camera& camera = *Application::getInstance()->getCamera(); configureCamera(camera, width, height); } @@ -93,7 +93,8 @@ void TV3DManager::display(Camera& whichCamera) { // left eye portal int portalX = 0; int portalY = 0; - QSize deviceSize = Application::getInstance()->getGLWidget()->getDeviceSize() * + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + QSize deviceSize = glCanvas->getDeviceSize() * Application::getInstance()->getRenderResolutionScale(); int portalW = deviceSize.width() / 2; int portalH = deviceSize.height(); diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp index 189ad90e12..bdb33cc092 100644 --- a/interface/src/devices/Visage.cpp +++ b/interface/src/devices/Visage.cpp @@ -122,7 +122,7 @@ static const QMultiHash >& getActionUnitNameMap() const float TRANSLATION_SCALE = 20.0f; void Visage::init() { - connect(DependencyManager::get(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled())); + connect(DependencyManager::get().data(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled())); updateEnabled(); } diff --git a/interface/src/devices/Visage.h b/interface/src/devices/Visage.h index 73edddc4d7..c12ce3aabd 100644 --- a/interface/src/devices/Visage.h +++ b/interface/src/devices/Visage.h @@ -26,8 +26,9 @@ namespace VisageSDK { } /// Handles input from the Visage webcam feature tracking software. -class Visage : public FaceTracker, public DependencyManager::Dependency { +class Visage : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY(Visage) public: void init(); @@ -44,7 +45,6 @@ public slots: private: Visage(); virtual ~Visage(); - friend DependencyManager; #ifdef HAVE_VISAGE VisageSDK::VisageTracker2* _tracker; diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index bcfe844668..545de00d7d 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -267,9 +267,9 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) { } } -glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { - GLCanvas* widget = Application::getInstance()->getGLWidget(); - return glm::vec2(widget->width(), widget->height()); +glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + return glm::vec2(glCanvas->width(), glCanvas->height()); } AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index bbb4e695e7..15372dc057 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -17,6 +17,7 @@ #include #include "Application.h" +#include "MainWindow.h" #include "Menu.h" #include "ui/ModelsBrowser.h" @@ -39,7 +40,7 @@ WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title } QScriptValue WindowScriptingInterface::hasFocus() { - return Application::getInstance()->getGLWidget()->hasFocus(); + return DependencyManager::get()->hasFocus(); } void WindowScriptingInterface::setCursorVisible(bool visible) { diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index 32161b018f..5f55aa5210 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -14,6 +14,7 @@ #include "AddressBarDialog.h" #include "AddressManager.h" #include "Application.h" +#include "MainWindow.h" const QString ADDRESSBAR_GO_BUTTON_ICON = "images/address-bar-submit.svg"; const QString ADDRESSBAR_GO_BUTTON_ACTIVE_ICON = "images/address-bar-submit-active.svg"; diff --git a/interface/src/ui/AnimationsDialog.cpp b/interface/src/ui/AnimationsDialog.cpp index c5ab826ebb..65e7cadc77 100644 --- a/interface/src/ui/AnimationsDialog.cpp +++ b/interface/src/ui/AnimationsDialog.cpp @@ -22,6 +22,7 @@ #include "AnimationsDialog.h" #include "Application.h" +#include "MainWindow.h" AnimationsDialog::AnimationsDialog() : QDialog(Application::getInstance()->getWindow()) { diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 32fffd3d40..ab85da125c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -147,11 +147,11 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); Application* application = Application::getInstance(); Overlays& overlays = application->getOverlays(); - GLCanvas* glWidget = application->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize()); - _textureAspectRatio = (float)application->getGLWidget()->getDeviceWidth() / (float)application->getGLWidget()->getDeviceHeight(); + _textureAspectRatio = (float)glCanvas->getDeviceWidth() / (float)glCanvas->getDeviceHeight(); //Handle fading and deactivation/activation of UI if (Menu::getInstance()->isOptionChecked(MenuOption::UserInterface)) { @@ -180,12 +180,12 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + gluOrtho2D(0, glCanvas->width(), glCanvas->height(), 0); renderAudioMeter(); if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - myAvatar->renderHeadMouse(glWidget->width(), glWidget->height()); + myAvatar->renderHeadMouse(glCanvas->width(), glCanvas->height()); } renderStatsAndLogs(); @@ -215,7 +215,7 @@ void ApplicationOverlay::displayOverlayTexture() { if (_alpha == 0.0f) { return; } - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -224,16 +224,16 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), 0); + gluOrtho2D(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBegin(GL_QUADS); { glColor4f(1.0f, 1.0f, 1.0f, _alpha); - glTexCoord2f(0, 0); glVertex2i(0, glWidget->getDeviceHeight()); - glTexCoord2f(1, 0); glVertex2i(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); - glTexCoord2f(1, 1); glVertex2i(glWidget->getDeviceWidth(), 0); + glTexCoord2f(0, 0); glVertex2i(0, glCanvas->getDeviceHeight()); + glTexCoord2f(1, 0); glVertex2i(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); + glTexCoord2f(1, 1); glVertex2i(glCanvas->getDeviceWidth(), 0); glTexCoord2f(0, 1); glVertex2i(0, 0); } glEnd(); } glPopMatrix(); @@ -380,18 +380,19 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glEnd(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); } //draw the mouse pointer glBindTexture(GL_TEXTURE_2D, _crosshairTexture); - const float reticleSize = 40.0f / application->getGLWidget()->width() * quadWidth; + const float reticleSize = 40.0f / glCanvas->width() * quadWidth; x -= reticleSize / 2.0f; y += reticleSize / 2.0f; - const float mouseX = (application->getMouseX() / (float)application->getGLWidget()->width()) * quadWidth; - const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->height())) * quadHeight; + const float mouseX = (application->getMouseX() / (float)glCanvas->width()) * quadWidth; + const float mouseY = (1.0 - (application->getMouseY() / (float)glCanvas->height())) * quadHeight; glBegin(GL_QUADS); @@ -433,7 +434,7 @@ void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& origi //Caculate the click location using one of the sixense controllers. Scale is not applied QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); @@ -464,8 +465,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { float u = asin(collisionPos.x) / (_textureFov)+0.5f; float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f); - rv.setX(u * glWidget->width()); - rv.setY(v * glWidget->height()); + rv.setX(u * glCanvas->width()); + rv.setY(v * glCanvas->height()); } } else { //if they did not click on the overlay, just set the coords to INT_MAX @@ -482,8 +483,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w; } - rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glWidget->width()); - rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glWidget->height()); + rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glCanvas->width()); + rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glCanvas->height()); } return rv; } @@ -512,10 +513,11 @@ bool ApplicationOverlay::calculateRayUICollisionPoint(const glm::vec3& position, //Renders optional pointers void ApplicationOverlay::renderPointers() { Application* application = Application::getInstance(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); //lazily load crosshair texture if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); } glEnable(GL_TEXTURE_2D); @@ -538,7 +540,7 @@ void ApplicationOverlay::renderPointers() { glm::vec2 screenPos = sphericalToScreen(glm::vec2(yaw, -pitch)); position = QPoint(screenPos.x, screenPos.y); - application->getGLWidget()->cursor().setPos(application->getGLWidget()->mapToGlobal(position)); + glCanvas->cursor().setPos(glCanvas->mapToGlobal(position)); } _reticlePosition[MOUSE] = position; @@ -559,7 +561,7 @@ void ApplicationOverlay::renderPointers() { void ApplicationOverlay::renderControllerPointers() { Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state @@ -637,14 +639,14 @@ void ApplicationOverlay::renderControllerPointers() { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = glWidget->width() * SixenseManager::getInstance().getCursorPixelRangeMult(); + float cursorRange = glCanvas->width() * SixenseManager::getInstance().getCursorPixelRangeMult(); - mouseX = (glWidget->width() / 2.0f + cursorRange * xAngle); - mouseY = (glWidget->height() / 2.0f + cursorRange * yAngle); + mouseX = (glCanvas->width() / 2.0f + cursorRange * xAngle); + mouseY = (glCanvas->height() / 2.0f + cursorRange * yAngle); } //If the cursor is out of the screen then don't render it - if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { + if (mouseX < 0 || mouseX >= glCanvas->width() || mouseY < 0 || mouseY >= glCanvas->height()) { _reticleActive[index] = false; continue; } @@ -704,11 +706,10 @@ 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) const { - Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - const int widgetWidth = glWidget->width(); - const int widgetHeight = glWidget->height(); + const int widgetWidth = glCanvas->width(); + const int widgetHeight = glCanvas->height(); const float halfWidth = (MAGNIFY_WIDTH / _textureAspectRatio) * sizeMult / 2.0f; const float halfHeight = MAGNIFY_HEIGHT * sizeMult / 2.0f; @@ -762,8 +763,8 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool void ApplicationOverlay::renderAudioMeter() { Application* application = Application::getInstance(); - - GLCanvas* glWidget = application->getGLWidget(); + + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); Audio* audio = application->getAudio(); // Display a single screen-size quad to create an alpha blended 'collision' flash @@ -771,7 +772,7 @@ void ApplicationOverlay::renderAudioMeter() { float collisionSoundMagnitude = audio->getCollisionSoundMagnitude(); const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { - renderCollisionOverlay(glWidget->width(), glWidget->height(), + renderCollisionOverlay(glCanvas->width(), glCanvas->height(), audio->getCollisionSoundMagnitude()); } } @@ -825,14 +826,14 @@ void ApplicationOverlay::renderAudioMeter() { if ((audio->getTimeSinceLastClip() > 0.0f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) { const float MAX_MAGNITUDE = 0.7f; float magnitude = MAX_MAGNITUDE * (1 - audio->getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME); - renderCollisionOverlay(glWidget->width(), glWidget->height(), magnitude, 1.0f); + renderCollisionOverlay(glCanvas->width(), glCanvas->height(), magnitude, 1.0f); } audio->renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, boxed); - audio->renderScope(glWidget->width(), glWidget->height()); + audio->renderScope(glCanvas->width(), glCanvas->height()); - audio->renderStats(WHITE_TEXT, glWidget->width(), glWidget->height()); + audio->renderStats(WHITE_TEXT, glCanvas->width(), glCanvas->height()); glBegin(GL_QUADS); if (isClipping) { @@ -893,8 +894,8 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - - GLCanvas* glWidget = application->getGLWidget(); + + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); @@ -912,8 +913,8 @@ void ApplicationOverlay::renderStatsAndLogs() { application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); // Bandwidth meter if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) { - Stats::drawBackground(0x33333399, glWidget->width() - 296, glWidget->height() - 68, 296, 68); - bandwidthMeter->render(glWidget->width(), glWidget->height()); + Stats::drawBackground(0x33333399, glCanvas->width() - 296, glCanvas->height() - 68, 296, 68); + bandwidthMeter->render(glCanvas->width(), glCanvas->height()); } } @@ -926,7 +927,7 @@ void ApplicationOverlay::renderStatsAndLogs() { (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) ? 80 : 20; - drawText(glWidget->width() - 100, glWidget->height() - timerBottom, + drawText(glCanvas->width() - 100, glCanvas->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); } nodeBoundsDisplay.drawOverlay(); @@ -936,9 +937,9 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { NodeList* nodeList = NodeList::getInstance(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int right = glWidget->width(); - int bottom = glWidget->height(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + int right = glCanvas->width(); + int bottom = glCanvas->height(); glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], CONNECTION_STATUS_BORDER_COLOR[1], @@ -1073,7 +1074,7 @@ void ApplicationOverlay::TexturedHemisphere::cleanupVBO() { } void ApplicationOverlay::TexturedHemisphere::buildFramebufferObject() { - QSize size = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize size = DependencyManager::get()->getDeviceSize(); if (_framebufferObject != NULL && size == _framebufferObject->size()) { // Already build return; @@ -1124,7 +1125,7 @@ void ApplicationOverlay::TexturedHemisphere::render() { glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float yaw = -(screenPos.x / screenSize.width() - 0.5f) * MOUSE_YAW_RANGE; float pitch = (screenPos.y / screenSize.height() - 0.5f) * MOUSE_PITCH_RANGE; @@ -1132,7 +1133,7 @@ glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const { } glm::vec2 ApplicationOverlay::sphericalToScreen(glm::vec2 sphericalPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float x = (-sphericalPos.x / MOUSE_YAW_RANGE + 0.5f) * screenSize.width(); float y = (sphericalPos.y / MOUSE_PITCH_RANGE + 0.5f) * screenSize.height(); @@ -1140,7 +1141,7 @@ glm::vec2 ApplicationOverlay::sphericalToScreen(glm::vec2 sphericalPos) const { } glm::vec2 ApplicationOverlay::sphericalToOverlay(glm::vec2 sphericalPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float x = (-sphericalPos.x / (_textureFov * _textureAspectRatio) + 0.5f) * screenSize.width(); float y = (sphericalPos.y / _textureFov + 0.5f) * screenSize.height(); @@ -1148,7 +1149,7 @@ glm::vec2 ApplicationOverlay::sphericalToOverlay(glm::vec2 sphericalPos) const { } glm::vec2 ApplicationOverlay::overlayToSpherical(glm::vec2 overlayPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float yaw = -(overlayPos.x / screenSize.width() - 0.5f) * _textureFov * _textureAspectRatio; float pitch = (overlayPos.y / screenSize.height() - 0.5f) * _textureFov; diff --git a/interface/src/ui/AttachmentsDialog.cpp b/interface/src/ui/AttachmentsDialog.cpp index 44dd2452e6..1209af580d 100644 --- a/interface/src/ui/AttachmentsDialog.cpp +++ b/interface/src/ui/AttachmentsDialog.cpp @@ -20,6 +20,7 @@ #include "Application.h" #include "AttachmentsDialog.h" +#include "MainWindow.h" AttachmentsDialog::AttachmentsDialog() : QDialog(Application::getInstance()->getWindow()) { diff --git a/interface/src/ui/BandwidthMeter.h b/interface/src/ui/BandwidthMeter.h index 09353512d1..9931355f8e 100644 --- a/interface/src/ui/BandwidthMeter.h +++ b/interface/src/ui/BandwidthMeter.h @@ -16,7 +16,7 @@ #include -#include "ui/TextRenderer.h" +#include class BandwidthMeter { diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 22ceb0d367..24653b7e8c 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -16,6 +16,8 @@ #include #include #include +#include "qtimespan.h" + #include #include @@ -24,7 +26,7 @@ #include "Application.h" #include "ChatMessageArea.h" #include "FlowLayout.h" -#include "qtimespan.h" +#include "MainWindow.h" #include "UIUtil.h" #include "XmppClient.h" diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index ab84980d80..23d6d5df2f 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -21,6 +21,7 @@ #include +#include "MainWindow.h" #include "Menu.h" #include "devices/OculusManager.h" #include "ui/HMDToolsDialog.h" diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 1a85e84b72..f0516ab955 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -38,6 +38,7 @@ #include #include "Application.h" +#include "MainWindow.h" #include "MetavoxelEditor.h" using namespace std; @@ -138,7 +139,7 @@ MetavoxelEditor::MetavoxelEditor() : connect(Application::getInstance()->getMetavoxels(), &MetavoxelSystem::rendering, this, &MetavoxelEditor::renderPreview); - Application::getInstance()->getGLWidget()->installEventFilter(this); + DependencyManager::get()->installEventFilter(this); show(); diff --git a/interface/src/ui/MetavoxelNetworkSimulator.cpp b/interface/src/ui/MetavoxelNetworkSimulator.cpp index aabee97636..7185524d6f 100644 --- a/interface/src/ui/MetavoxelNetworkSimulator.cpp +++ b/interface/src/ui/MetavoxelNetworkSimulator.cpp @@ -21,7 +21,7 @@ const int BYTES_PER_KILOBYTE = 1024; MetavoxelNetworkSimulator::MetavoxelNetworkSimulator() : - QWidget(Application::getInstance()->getGLWidget(), Qt::Dialog) { + QWidget(DependencyManager::get().data(), Qt::Dialog) { setWindowTitle("Metavoxel Network Simulator"); setAttribute(Qt::WA_DeleteOnClose); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 61cc9718b3..7baacd3d5a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -11,6 +11,7 @@ #include "Application.h" +#include "MainWindow.h" #include "Menu.h" #include "ModelsBrowser.h" #include "PreferencesDialog.h" @@ -214,8 +215,8 @@ void PreferencesDialog::savePreferences() { myAvatar->setClampedTargetScale(ui.avatarScaleSpin->value()); Application::getInstance()->getVoxels()->setMaxVoxels(ui.maxVoxelsSpin->value()); - Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(), - Application::getInstance()->getGLWidget()->height()); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Menu::getInstance()->setRealWorldFieldOfView(ui.realWorldFieldOfViewSpin->value()); @@ -247,8 +248,7 @@ void PreferencesDialog::savePreferences() { Menu::getInstance()->setReceivedAudioStreamSettings(streamSettings); Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings); - Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(), - Application::getInstance()->getGLWidget()->height()); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Application::getInstance()->bumpSettings(); } diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index d68920a5f5..e3b512adcc 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -83,9 +83,8 @@ QTemporaryFile* Snapshot::saveTempSnapshot() { } QFile* Snapshot::savedFileForSnapshot(bool isTemporary) { - - QGLWidget* widget = Application::getInstance()->getGLWidget(); - QImage shot = widget->grabFrameBuffer(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + QImage shot = glCanvas->grabFrameBuffer(); Avatar* avatar = Application::getInstance()->getAvatar(); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 27a34fe3d4..ab3927a3ab 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -56,8 +56,8 @@ Stats::Stats(): _metavoxelReceiveProgress(0), _metavoxelReceiveTotal(0) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - resetWidth(glWidget->width(), 0); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + resetWidth(glCanvas->width(), 0); } void Stats::toggleExpanded() { @@ -67,7 +67,7 @@ void Stats::toggleExpanded() { // called on mouse click release // check for clicks over stats in order to expand or contract them void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (0 != glm::compMax(glm::abs(glm::ivec2(mouseX - mouseDragStartedX, mouseY - mouseDragStartedY)))) { // not worried about dragging on stats @@ -114,7 +114,7 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD // top-right stats click lines = _expanded ? 11 : 3; statsHeight = lines * STATS_PELS_PER_LINE + 10; - statsWidth = glWidget->width() - statsX; + statsWidth = glCanvas->width() - statsX; if (mouseX > statsX && mouseX < statsX + statsWidth && mouseY > statsY && mouseY < statsY + statsHeight) { toggleExpanded(); return; @@ -122,8 +122,8 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD } void Stats::resetWidth(int width, int horizontalOffset) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int extraSpace = glWidget->width() - horizontalOffset -2 + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); + int extraSpace = glCanvas->width() - horizontalOffset -2 - STATS_GENERAL_MIN_WIDTH - (Menu::getInstance()->isOptionChecked(MenuOption::TestPing) ? STATS_PING_MIN_WIDTH -1 : 0) - STATS_GEO_MIN_WIDTH @@ -147,7 +147,7 @@ void Stats::resetWidth(int width, int horizontalOffset) { _pingStatsWidth += (int) extraSpace / panels; } _geoStatsWidth += (int) extraSpace / panels; - _voxelStatsWidth += glWidget->width() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); + _voxelStatsWidth += glCanvas->width() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); } } @@ -198,7 +198,7 @@ void Stats::display( int bytesPerSecond, int voxelPacketsToProcess) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); unsigned int backgroundColor = 0x33333399; int verticalOffset = 0, lines = 0; @@ -210,7 +210,7 @@ void Stats::display( std::stringstream voxelStats; if (_lastHorizontalOffset != horizontalOffset) { - resetWidth(glWidget->width(), horizontalOffset); + resetWidth(glCanvas->width(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; } @@ -478,7 +478,7 @@ void Stats::display( lines = _expanded ? 14 : 3; - drawBackground(backgroundColor, horizontalOffset, 0, glWidget->width() - horizontalOffset, + drawBackground(backgroundColor, horizontalOffset, 0, glCanvas->width() - horizontalOffset, lines * STATS_PELS_PER_LINE + 10); horizontalOffset += 5; diff --git a/interface/src/ui/ToolWindow.cpp b/interface/src/ui/ToolWindow.cpp index da1d2c68f4..8774bffc36 100644 --- a/interface/src/ui/ToolWindow.cpp +++ b/interface/src/ui/ToolWindow.cpp @@ -10,6 +10,7 @@ // #include "Application.h" +#include "MainWindow.h" #include "ToolWindow.h" #include "UIUtil.h" diff --git a/interface/src/ui/overlays/LocalModelsOverlay.h b/interface/src/ui/overlays/LocalModelsOverlay.h index 39465de7f9..a82943a4a0 100644 --- a/interface/src/ui/overlays/LocalModelsOverlay.h +++ b/interface/src/ui/overlays/LocalModelsOverlay.h @@ -12,10 +12,10 @@ #ifndef hifi_LocalModelsOverlay_h #define hifi_LocalModelsOverlay_h -#include "entities/EntityTreeRenderer.h" - #include "Volume3DOverlay.h" +class EntityTreeRenderer; + class LocalModelsOverlay : public Volume3DOverlay { Q_OBJECT public: diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 41e36cb396..9b80d873f9 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -11,9 +11,10 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" +#include + #include "Application.h" #include "Text3DOverlay.h" -#include "ui/TextRenderer.h" const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 }; const float DEFAULT_BACKGROUND_ALPHA = 0.7f; diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index ae8a7cbcfe..97d910eb64 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -13,9 +13,9 @@ #include #include +#include #include "TextOverlay.h" -#include "ui/TextRenderer.h" TextOverlay::TextOverlay() : _backgroundColor(DEFAULT_BACKGROUND_COLOR), diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 5f3f305461..4e67014822 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -24,8 +24,9 @@ class Animation; typedef QSharedPointer AnimationPointer; /// Scriptable interface for FBX animation loading. -class AnimationCache : public ResourceCache, public DependencyManager::Dependency { +class AnimationCache : public ResourceCache { Q_OBJECT + SINGLETON_DEPENDENCY(AnimationCache) public: Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); } @@ -38,7 +39,6 @@ protected: private: AnimationCache(QObject* parent = NULL); virtual ~AnimationCache() { } - friend class DependencyManager; }; diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt new file mode 100644 index 0000000000..5744ea0b7b --- /dev/null +++ b/libraries/entities-renderer/CMakeLists.txt @@ -0,0 +1,37 @@ +set(TARGET_NAME entities-renderer) + +# use setup_hifi_library macro to setup our project and link appropriate Qt modules +setup_hifi_library(Widgets OpenGL Network Script) + +include_glm() + +link_hifi_libraries(shared gpu) +if (APPLE) + # link in required OS X frameworks and include the right GL headers + find_library(OpenGL OpenGL) + + #target_link_libraries(${TARGET_NAME} ${OpenGL}) + +else (APPLE) + find_package(OpenGL REQUIRED) + + if (${OPENGL_INCLUDE_DIR}) + include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") + endif () + + # link target to external libraries + if (WIN32) + find_package(GLEW REQUIRED) + include_directories(${GLEW_INCLUDE_DIRS}) + + find_package(GLUT REQUIRED) + include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") + + # we're using static GLEW, so define GLEW_STATIC + add_definitions(-DGLEW_STATIC) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}") + endif() +endif (APPLE) + +# call macro to link our dependencies and bubble them up via a property on our target +link_shared_dependencies() diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp similarity index 86% rename from interface/src/entities/EntityTreeRenderer.cpp rename to libraries/entities-renderer/src/EntityTreeRenderer.cpp index 59b3f697c8..7253b96480 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -9,28 +9,24 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include +#include #include - -#include -#include "InterfaceConfig.h" - -#include +#include +#include +#include #include -#include -#include +#include +#include #include -#include +#include - -#include "Menu.h" -#include "NetworkAccessManager.h" #include "EntityTreeRenderer.h" -#include "devices/OculusManager.h" - #include "RenderableBoxEntityItem.h" #include "RenderableLightEntityItem.h" #include "RenderableModelEntityItem.h" @@ -38,15 +34,18 @@ #include "RenderableTextEntityItem.h" -QThread* EntityTreeRenderer::getMainThread() { - return Application::getInstance()->getEntities()->thread(); -} - -EntityTreeRenderer::EntityTreeRenderer(bool wantScripts) : +EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, + AbstractScriptingServicesInterface* scriptingServices) : OctreeRenderer(), _wantScripts(wantScripts), _entitiesScriptEngine(NULL), - _lastMouseEventValid(false) + _lastMouseEventValid(false), + _viewState(viewState), + _scriptingServices(scriptingServices), + _displayElementChildProxies(false), + _displayModelBounds(false), + _displayModelElementProxy(false), + _dontDoPrecisionPicking(false) { REGISTER_ENTITY_TYPE_WITH_FACTORY(Model, RenderableModelEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Box, RenderableBoxEntityItem::factory) @@ -76,14 +75,14 @@ void EntityTreeRenderer::init() { entityTree->setFBXService(this); if (_wantScripts) { - _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities", - Application::getInstance()->getControllerScriptingInterface()); - Application::getInstance()->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); + _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities", + _scriptingServices->getControllerScriptingInterface()); + _scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); } // make sure our "last avatar position" is something other than our current position, so that on our // first chance, we'll check for enter/leave entity events. - glm::vec3 avatarPosition = Application::getInstance()->getAvatar()->getPosition(); + glm::vec3 avatarPosition = _viewState->getAvatarPosition(); _lastAvatarPosition = avatarPosition + glm::vec3(1.0f, 1.0f, 1.0f); connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity); @@ -240,7 +239,7 @@ void EntityTreeRenderer::update() { void EntityTreeRenderer::checkEnterLeaveEntities() { if (_tree) { _tree->lockForWrite(); // so that our scripts can do edits if they want - glm::vec3 avatarPosition = Application::getInstance()->getAvatar()->getPosition() / (float) TREE_SCALE; + glm::vec3 avatarPosition = _viewState->getAvatarPosition() / (float) TREE_SCALE; if (avatarPosition != _lastAvatarPosition) { float radius = 1.0f / (float) TREE_SCALE; // for now, assume 1 meter radius @@ -289,44 +288,38 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { } void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) { - bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene); + if (_tree) { + Model::startScene(renderSide); + RenderArgs args = { this, _viewFrustum, getSizeScale(), getBoundaryLevelAdjust(), renderMode, renderSide, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + _tree->lockForRead(); + _tree->recurseTreeWithOperation(renderOperation, &args); + + Model::RenderMode modelRenderMode = renderMode == RenderArgs::SHADOW_RENDER_MODE + ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; + + // we must call endScene while we still have the tree locked so that no one deletes a model + // on us while rendering the scene + Model::endScene(modelRenderMode, &args); + _tree->unlock(); - if (dontRenderAsScene) { - OctreeRenderer::render(renderMode, renderSide); - } else { - if (_tree) { - Model::startScene(renderSide); - RenderArgs args = { this, _viewFrustum, getSizeScale(), getBoundaryLevelAdjust(), renderMode, renderSide, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - _tree->lockForRead(); - _tree->recurseTreeWithOperation(renderOperation, &args); + // stats... + _meshesConsidered = args._meshesConsidered; + _meshesRendered = args._meshesRendered; + _meshesOutOfView = args._meshesOutOfView; + _meshesTooSmall = args._meshesTooSmall; - Model::RenderMode modelRenderMode = renderMode == RenderArgs::SHADOW_RENDER_MODE - ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; + _elementsTouched = args._elementsTouched; + _itemsRendered = args._itemsRendered; + _itemsOutOfView = args._itemsOutOfView; + _itemsTooSmall = args._itemsTooSmall; - // we must call endScene while we still have the tree locked so that no one deletes a model - // on us while rendering the scene - Model::endScene(modelRenderMode, &args); - _tree->unlock(); - - // stats... - _meshesConsidered = args._meshesConsidered; - _meshesRendered = args._meshesRendered; - _meshesOutOfView = args._meshesOutOfView; - _meshesTooSmall = args._meshesTooSmall; + _materialSwitches = args._materialSwitches; + _trianglesRendered = args._trianglesRendered; + _quadsRendered = args._quadsRendered; - _elementsTouched = args._elementsTouched; - _itemsRendered = args._itemsRendered; - _itemsOutOfView = args._itemsOutOfView; - _itemsTooSmall = args._itemsTooSmall; - - _materialSwitches = args._materialSwitches; - _trianglesRendered = args._trianglesRendered; - _quadsRendered = args._quadsRendered; - - _translucentMeshPartsRendered = args._translucentMeshPartsRendered; - _opaqueMeshPartsRendered = args._opaqueMeshPartsRendered; - } + _translucentMeshPartsRendered = args._translucentMeshPartsRendered; + _opaqueMeshPartsRendered = args._opaqueMeshPartsRendered; } deleteReleasedModels(); // seems like as good as any other place to do some memory cleanup } @@ -358,75 +351,72 @@ const Model* EntityTreeRenderer::getModelForEntityItem(const EntityItem* entityI return result; } -void renderElementProxy(EntityTreeElement* entityTreeElement) { +void EntityTreeRenderer::renderElementProxy(EntityTreeElement* entityTreeElement) { glm::vec3 elementCenter = entityTreeElement->getAACube().calcCenter() * (float) TREE_SCALE; float elementSize = entityTreeElement->getScale() * (float) TREE_SCALE; glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x, elementCenter.y, elementCenter.z); - glutWireCube(elementSize); + DependencyManager::get()->renderWireCube(elementSize); glPopMatrix(); - bool displayElementChildProxies = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelElementChildProxies); - - if (displayElementChildProxies) { + if (_displayElementChildProxies) { // draw the children float halfSize = elementSize / 2.0f; float quarterSize = elementSize / 4.0f; glColor3f(1.0f, 1.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y - quarterSize, elementCenter.z - quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y - quarterSize, elementCenter.z - quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(0.0f, 1.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y + quarterSize, elementCenter.z - quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y - quarterSize, elementCenter.z + quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(1.0f, 1.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y + quarterSize, elementCenter.z + quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(0.0f, 0.5f, 0.5f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y + quarterSize, elementCenter.z + quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(0.5f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y - quarterSize, elementCenter.z + quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); glColor3f(0.0f, 0.5f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y + quarterSize, elementCenter.z - quarterSize); - glutWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize); glPopMatrix(); } } void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* args) { bool isShadowMode = args->_renderMode == RenderArgs::SHADOW_RENDER_MODE; - bool displayModelBounds = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelBounds); - if (!isShadowMode && displayModelBounds) { + if (!isShadowMode && _displayModelBounds) { PerformanceTimer perfTimer("renderProxies"); AACube maxCube = entity->getMaximumAACube(); @@ -446,14 +436,14 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glColor4f(1.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(maxCenter.x, maxCenter.y, maxCenter.z); - glutWireCube(maxCube.getScale()); + DependencyManager::get()->renderWireCube(maxCube.getScale()); glPopMatrix(); // draw the min bounding cube glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(minCenter.x, minCenter.y, minCenter.z); - glutWireCube(minCube.getScale()); + DependencyManager::get()->renderWireCube(minCube.getScale()); glPopMatrix(); // draw the entityBox bounding box @@ -461,7 +451,7 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glPushMatrix(); glTranslatef(entityBoxCenter.x, entityBoxCenter.y, entityBoxCenter.z); glScalef(entityBoxScale.x, entityBoxScale.y, entityBoxScale.z); - glutWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f); glPopMatrix(); @@ -479,15 +469,13 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - glutWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f); glPopMatrix(); glPopMatrix(); } } void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) { - bool wantDebug = false; - args->_elementsTouched++; // actually render it here... // we need to iterate the actual entityItems of the element @@ -499,11 +487,8 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) uint16_t numberOfEntities = entityItems.size(); bool isShadowMode = args->_renderMode == RenderArgs::SHADOW_RENDER_MODE; - bool displayElementProxy = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelElementProxy); - - - if (!isShadowMode && displayElementProxy && numberOfEntities > 0) { + if (!isShadowMode && _displayModelElementProxy && numberOfEntities > 0) { renderElementProxy(entityTreeElement); } @@ -520,23 +505,9 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) // when they are outside of the view frustum... float distance = args->_viewFrustum->distanceToCamera(entityBox.calcCenter()); - if (wantDebug) { - qDebug() << "------- renderElement() ----------"; - qDebug() << " type:" << EntityTypes::getEntityTypeName(entityItem->getType()); - if (entityItem->getType() == EntityTypes::Model) { - ModelEntityItem* modelEntity = static_cast(entityItem); - qDebug() << " url:" << modelEntity->getModelURL(); - } - qDebug() << " entityBox:" << entityItem->getAABox(); - qDebug() << " dimensions:" << entityItem->getDimensionsInMeters() << "in meters"; - qDebug() << " largestDimension:" << entityBox.getLargestDimension() << "in meters"; - qDebug() << " shouldRender:" << Menu::getInstance()->shouldRenderMesh(entityBox.getLargestDimension(), distance); - qDebug() << " in frustum:" << (args->_viewFrustum->boxInFrustum(entityBox) != ViewFrustum::OUTSIDE); - } - bool outOfView = args->_viewFrustum->boxInFrustum(entityBox) == ViewFrustum::OUTSIDE; if (!outOfView) { - bool bigEnoughToRender = Menu::getInstance()->shouldRenderMesh(entityBox.getLargestDimension(), distance); + bool bigEnoughToRender = _viewState->shouldRenderMesh(entityBox.getLargestDimension(), distance); if (bigEnoughToRender) { renderProxies(entityItem, args); @@ -561,11 +532,11 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } float EntityTreeRenderer::getSizeScale() const { - return Menu::getInstance()->getVoxelSizeScale(); + return _viewState->getSizeScale(); } int EntityTreeRenderer::getBoundaryLevelAdjust() const { - return Menu::getInstance()->getBoundaryLevelAdjust(); + return _viewState->getBoundaryLevelAdjust(); } @@ -640,11 +611,6 @@ void EntityTreeRenderer::deleteReleasedModels() { } } -PickRay EntityTreeRenderer::computePickRay(float x, float y) { - return Application::getInstance()->getCamera()->computePickRay(x, y); -} - - RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking) { RayToEntityIntersectionResult result; @@ -706,9 +672,9 @@ QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entity void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent"); - PickRay ray = computePickRay(event->x(), event->y()); + PickRay ray = _viewState->computePickRay(event->x(), event->y()); - bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking); + bool precisionPicking = !_dontDoPrecisionPicking; RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking); if (rayPickResult.intersects) { //qDebug() << "mousePressEvent over entity:" << rayPickResult.entityID; @@ -732,8 +698,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { PerformanceTimer perfTimer("EntityTreeRenderer::mouseReleaseEvent"); - PickRay ray = computePickRay(event->x(), event->y()); - bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking); + PickRay ray = _viewState->computePickRay(event->x(), event->y()); + bool precisionPicking = !_dontDoPrecisionPicking; RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking); if (rayPickResult.intersects) { //qDebug() << "mouseReleaseEvent over entity:" << rayPickResult.entityID; @@ -767,7 +733,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent"); - PickRay ray = computePickRay(event->x(), event->y()); + PickRay ray = _viewState->computePickRay(event->x(), event->y()); bool precisionPicking = false; // for mouse moves we do not do precision picking RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking); diff --git a/interface/src/entities/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h similarity index 84% rename from interface/src/entities/EntityTreeRenderer.h rename to libraries/entities-renderer/src/EntityTreeRenderer.h index 87f45d5f56..f23c5286c1 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -12,20 +12,17 @@ #ifndef hifi_EntityTreeRenderer_h #define hifi_EntityTreeRenderer_h -#include -#include - #include #include // for RayToEntityIntersectionResult -#include -#include -#include +#include #include -#include -#include -#include -#include +class Model; +class ScriptEngine; +class AbstractViewStateInterface; +class AbstractScriptingServicesInterface; + +class ScriptEngine; class EntityScriptDetails { public: @@ -37,7 +34,8 @@ public: class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService { Q_OBJECT public: - EntityTreeRenderer(bool wantScripts); + EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, + AbstractScriptingServicesInterface* scriptingServices); virtual ~EntityTreeRenderer(); virtual char getMyNodeType() const { return NodeType::EntityServer; } @@ -64,8 +62,6 @@ public: /// clears the tree virtual void clear(); - static QThread* getMainThread(); - /// if a renderable entity item needs a model, we will allocate it for them Q_INVOKABLE Model* allocateModel(const QString& url); @@ -109,17 +105,22 @@ public slots: void entityCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel, const Collision& collision); void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); + // optional slots that can be wired to menu items + void setDisplayElementChildProxies(bool value) { _displayElementChildProxies = value; } + void setDisplayModelBounds(bool value) { _displayModelBounds = value; } + void setDisplayModelElementProxy(bool value) { _displayModelElementProxy = value; } + void setDontDoPrecisionPicking(bool value) { _dontDoPrecisionPicking = value; } protected: virtual Octree* createTree() { return new EntityTree(true); } private: + void renderElementProxy(EntityTreeElement* entityTreeElement); void checkAndCallPreload(const EntityItemID& entityID); void checkAndCallUnload(const EntityItemID& entityID); QList _releasedModels; void renderProxies(const EntityItem* entity, RenderArgs* args); - PickRay computePickRay(float x, float y); RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking); @@ -145,6 +146,13 @@ private: bool _lastMouseEventValid; MouseEvent _lastMouseEvent; + AbstractViewStateInterface* _viewState; + AbstractScriptingServicesInterface* _scriptingServices; + bool _displayElementChildProxies; + bool _displayModelBounds; + bool _displayModelElementProxy; + bool _dontDoPrecisionPicking; + }; #endif // hifi_EntityTreeRenderer_h diff --git a/interface/src/entities/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp similarity index 96% rename from interface/src/entities/RenderableBoxEntityItem.cpp rename to libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index f7b403bff2..bb0de0ce6d 100644 --- a/interface/src/entities/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -11,21 +11,13 @@ #include -#include +#include -#include "InterfaceConfig.h" - -#include #include -#include #include - -#include "Menu.h" -#include "EntityTreeRenderer.h" #include "RenderableBoxEntityItem.h" - EntityItem* RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new RenderableBoxEntityItem(entityID, properties); } diff --git a/interface/src/entities/RenderableBoxEntityItem.h b/libraries/entities-renderer/src/RenderableBoxEntityItem.h similarity index 78% rename from interface/src/entities/RenderableBoxEntityItem.h rename to libraries/entities-renderer/src/RenderableBoxEntityItem.h index da4714f32b..c4495d2328 100644 --- a/interface/src/entities/RenderableBoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.h @@ -12,17 +12,6 @@ #ifndef hifi_RenderableBoxEntityItem_h #define hifi_RenderableBoxEntityItem_h -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include class RenderableBoxEntityItem : public BoxEntityItem { diff --git a/interface/src/entities/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp similarity index 69% rename from interface/src/entities/RenderableLightEntityItem.cpp rename to libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 58a3c3f18a..9097956c88 100644 --- a/interface/src/entities/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -11,21 +11,13 @@ #include -#include - -#include "InterfaceConfig.h" +#include #include #include -#include - -#include "Application.h" -#include "Menu.h" -#include "EntityTreeRenderer.h" #include "RenderableLightEntityItem.h" - EntityItem* RenderableLightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new RenderableLightEntityItem(entityID, properties); } @@ -61,17 +53,13 @@ void RenderableLightEntityItem::render(RenderArgs* args) { float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); - bool disableLights = Menu::getInstance()->isOptionChecked(MenuOption::DisableLightEntities); - - if (!disableLights) { - if (_isSpotlight) { - DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, - ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation, - direction, exponent, cutoff); - } else { - DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, - ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation); - } + if (_isSpotlight) { + DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, + ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation, + direction, exponent, cutoff); + } else { + DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, + ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation); } #ifdef WANT_DEBUG @@ -94,10 +82,11 @@ void RenderableLightEntityItem::render(RenderArgs* args) { bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { - - // TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's - // EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to - // use the ray intersection API there. Anyway... if you ever try to do ray intersection testing off of trees other - // than the main tree of the main entity renderer, then you'll need to fix this mechanism. - return Application::getInstance()->getEntities()->getTree()->getLightsArePickable(); + + // TODO: consider if this is really what we want to do. We've made it so that "lights are pickable" is a global state + // this is probably reasonable since there's typically only one tree you'd be picking on at a time. Technically we could + // be on the clipboard and someone might be trying to use the ray intersection API there. Anyway... if you ever try to + // do ray intersection testing off of trees other than the main tree of the main entity renderer, then we'll need to + // fix this mechanism. + return _lightsArePickable; } diff --git a/interface/src/entities/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h similarity index 84% rename from interface/src/entities/RenderableLightEntityItem.h rename to libraries/entities-renderer/src/RenderableLightEntityItem.h index 2113f486cc..cfafb85983 100644 --- a/interface/src/entities/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -12,17 +12,6 @@ #ifndef hifi_RenderableLightEntityItem_h #define hifi_RenderableLightEntityItem_h -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include class RenderableLightEntityItem : public LightEntityItem { diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp similarity index 90% rename from interface/src/entities/RenderableModelEntityItem.cpp rename to libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 13bc097f27..3e5118d203 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -11,17 +11,14 @@ #include -#include +#include -#include "InterfaceConfig.h" +#include -#include #include -#include +#include #include - -#include "Menu.h" #include "EntityTreeRenderer.h" #include "RenderableModelEntityItem.h" @@ -165,28 +162,11 @@ void RenderableModelEntityItem::render(RenderArgs* args) { _needsInitialSimulation = false; } - // TODO: should we allow entityItems to have alpha on their models? - Model::RenderMode modelRenderMode = args->_renderMode == RenderArgs::SHADOW_RENDER_MODE - ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; - if (_model->isActive()) { // TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render // is significantly more expensive. Is there a way to call this that doesn't cost us as much? PerformanceTimer perfTimer("model->render"); - bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene); - bool displayModelTriangles = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelTriangles); - bool rendered = false; - if (displayModelTriangles) { - rendered = _model->renderTriangleProxies(); - } - - if (!rendered) { - if (dontRenderAsScene) { - _model->render(alpha, modelRenderMode, args); - } else { - _model->renderInScene(alpha, args); - } - } + _model->renderInScene(alpha, args); } else { // if we couldn't get a model, then just draw a cube glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); diff --git a/interface/src/entities/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h similarity index 90% rename from interface/src/entities/RenderableModelEntityItem.h rename to libraries/entities-renderer/src/RenderableModelEntityItem.h index 2c194467d2..6f61a1b9db 100644 --- a/interface/src/entities/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -12,18 +12,13 @@ #ifndef hifi_RenderableModelEntityItem_h #define hifi_RenderableModelEntityItem_h -#include -#include +#include +#include -#include -#include #include -#include -#include -#include -#include -#include -#include + +class Model; +class EntityTreeRenderer; class RenderableModelEntityItem : public ModelEntityItem { public: diff --git a/interface/src/entities/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp similarity index 93% rename from interface/src/entities/RenderableSphereEntityItem.cpp rename to libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index db10edca73..97e3ee7869 100644 --- a/interface/src/entities/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -11,18 +11,12 @@ #include -#include - -#include "InterfaceConfig.h" +#include #include #include #include -#include - -#include "Menu.h" -#include "EntityTreeRenderer.h" #include "RenderableSphereEntityItem.h" EntityItem* RenderableSphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { diff --git a/interface/src/entities/RenderableSphereEntityItem.h b/libraries/entities-renderer/src/RenderableSphereEntityItem.h similarity index 79% rename from interface/src/entities/RenderableSphereEntityItem.h rename to libraries/entities-renderer/src/RenderableSphereEntityItem.h index 3c24889e79..3ed651b0ae 100644 --- a/interface/src/entities/RenderableSphereEntityItem.h +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.h @@ -12,17 +12,6 @@ #ifndef hifi_RenderableSphereEntityItem_h #define hifi_RenderableSphereEntityItem_h -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include class RenderableSphereEntityItem : public SphereEntityItem { diff --git a/interface/src/entities/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp similarity index 97% rename from interface/src/entities/RenderableTextEntityItem.cpp rename to libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 4059ee5751..24f4a71295 100644 --- a/interface/src/entities/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -11,13 +11,10 @@ #include -#include "InterfaceConfig.h" - -#include +#include #include +#include -#include "Menu.h" -#include "EntityTreeRenderer.h" #include "RenderableTextEntityItem.h" const int FIXED_FONT_POINT_SIZE = 40; diff --git a/interface/src/entities/RenderableTextEntityItem.h b/libraries/entities-renderer/src/RenderableTextEntityItem.h similarity index 80% rename from interface/src/entities/RenderableTextEntityItem.h rename to libraries/entities-renderer/src/RenderableTextEntityItem.h index 8760cb9df7..e57ab0538a 100644 --- a/interface/src/entities/RenderableTextEntityItem.h +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.h @@ -12,17 +12,6 @@ #ifndef hifi_RenderableTextEntityItem_h #define hifi_RenderableTextEntityItem_h -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include class RenderableTextEntityItem : public TextEntityItem { diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 26870ad9bb..6226012052 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -11,6 +11,7 @@ #include "EntityScriptingInterface.h" #include "EntityTree.h" +#include "LightEntityItem.h" #include "ModelEntityItem.h" EntityScriptingInterface::EntityScriptingInterface() : @@ -226,16 +227,11 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke } void EntityScriptingInterface::setLightsArePickable(bool value) { - if (_entityTree) { - _entityTree->setLightsArePickable(value); - } + LightEntityItem::setLightsArePickable(value); } bool EntityScriptingInterface::getLightsArePickable() const { - if (_entityTree) { - return _entityTree->getLightsArePickable(); - } - return false; + return LightEntityItem::getLightsArePickable(); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 17178ccbed..fb8e4345f4 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -22,7 +22,6 @@ EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage), _fbxService(NULL), - _lightsArePickable(true), _simulation(NULL) { _rootElement = createNewElement(); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 9a0fb43ecb..cfd08c3b5c 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -150,8 +150,6 @@ public: void emitEntityScriptChanging(const EntityItemID& entityItemID); - bool getLightsArePickable() const { return _lightsArePickable; } - void setLightsArePickable(bool value) { _lightsArePickable = value; } void setSimulation(EntitySimulation* simulation); signals: @@ -180,7 +178,6 @@ private: QHash _entityToElementMap; - bool _lightsArePickable; EntitySimulation* _simulation; }; diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a24fe58c2a..44b83bc94e 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -18,6 +18,7 @@ #include "EntityTreeElement.h" #include "LightEntityItem.h" +bool LightEntityItem::_lightsArePickable = false; EntityItem* LightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new LightEntityItem(entityID, properties); diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index eb9a2ed051..6ebb85beda 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -99,6 +99,9 @@ public: void setCutoff(float value) { _cutoff = value; } virtual const Shape& getCollisionShapeInMeters() const { return _emptyShape; } + + static bool getLightsArePickable() { return _lightsArePickable; } + static void setLightsArePickable(bool value) { _lightsArePickable = value; } protected: virtual void recalculateCollisionShape() { /* nothing to do */ } @@ -116,6 +119,8 @@ protected: // used for collision detection SphereShape _emptyShape; + + static bool _lightsArePickable; }; #endif // hifi_LightEntityItem_h diff --git a/libraries/gpu/src/gpu/GLUTConfig.h b/libraries/gpu/src/gpu/GLUTConfig.h new file mode 100644 index 0000000000..214f2bb2b0 --- /dev/null +++ b/libraries/gpu/src/gpu/GLUTConfig.h @@ -0,0 +1,25 @@ +// +// GPUConfig.h +// libraries/gpu/src/gpu +// +// Created by Brad Hefta-Gaub on 12/17/14. +// Copyright 2014 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 gpu__GLUTConfig__ +#define gpu__GLUTConfig__ + +// TODO: remove these once we migrate away from GLUT calls +#if defined(__APPLE__) +#include +#elif defined(WIN32) +#include +#else +#include +#endif + + +#endif // gpu__GLUTConfig__ diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/AbstractViewStateInterface.h similarity index 73% rename from libraries/render-utils/src/ViewStateInterface.h rename to libraries/render-utils/src/AbstractViewStateInterface.h index 9110eb8eb6..50a75c769a 100644 --- a/libraries/render-utils/src/ViewStateInterface.h +++ b/libraries/render-utils/src/AbstractViewStateInterface.h @@ -1,5 +1,5 @@ // -// ViewStateInterface.h +// AbstractViewStateInterface.h // interface/src/renderer // // Created by Brad Hefta-Gaub on 12/16/14. @@ -9,16 +9,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ViewStateInterface_h -#define hifi_ViewStateInterface_h +#ifndef hifi_AbstractViewStateInterface_h +#define hifi_AbstractViewStateInterface_h -#include +#include class Transform; class QThread; +class ViewFrustum; +class PickRay; /// Interface provided by Application to other objects that need access to the current view state details -class ViewStateInterface { +class AbstractViewStateInterface { public: /// Returns the shadow distances for the current view state @@ -38,7 +40,12 @@ public: virtual const Transform& getViewTransform() const = 0; virtual void setupWorldLight() = 0; virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera) = 0; + virtual float getSizeScale() const = 0; + virtual int getBoundaryLevelAdjust() const = 0; + virtual PickRay computePickRay(float x, float y) = 0; + + virtual const glm::vec3& getAvatarPosition() const = 0; }; -#endif // hifi_ViewStateInterface_h +#endif // hifi_AbstractViewStateInterface_h diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index b9289204c7..40a02a60a4 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -19,6 +19,7 @@ #include #include +#include "AbstractViewStateInterface.h" #include "AmbientOcclusionEffect.h" #include "GlowEffect.h" #include "ProgramObject.h" @@ -28,7 +29,7 @@ const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; -void AmbientOcclusionEffect::init(ViewStateInterface* viewState) { +void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) { _viewState = viewState; // we will use this for view state services _occlusionProgram = new ProgramObject(); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 1ee7269480..c5757f4baa 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -14,22 +14,22 @@ #include -#include "ViewStateInterface.h" - +class AbstractViewStateInterface; class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at /// http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html for reference. -class AmbientOcclusionEffect: public DependencyManager::Dependency { +class AmbientOcclusionEffect { + SINGLETON_DEPENDENCY(AmbientOcclusionEffect) + public: - void init(ViewStateInterface* viewState); + void init(AbstractViewStateInterface* viewState); void render(); private: AmbientOcclusionEffect() {} virtual ~AmbientOcclusionEffect() {} - friend class DependencyManager; ProgramObject* _occlusionProgram; int _nearLocation; @@ -44,7 +44,7 @@ private: int _blurScaleLocation; GLuint _rotationTextureID; - ViewStateInterface* _viewState; + AbstractViewStateInterface* _viewState; }; #endif // hifi_AmbientOcclusionEffect_h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 9f54b25441..14d383418f 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -12,22 +12,15 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include - -// TODO: remove these once we migrate away from GLUT calls -#if defined(__APPLE__) -#include -#elif defined(WIN32) -#include -#else -#include -#endif +#include // TODO - we need to get rid of this ASAP #include #include #include +#include - +#include "AbstractViewStateInterface.h" #include "DeferredLightingEffect.h" #include "GeometryCache.h" #include "GlowEffect.h" @@ -35,7 +28,7 @@ #include "TextureCache.h" -void DeferredLightingEffect::init(ViewStateInterface* viewState) { +void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { _viewState = viewState; _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/simple.frag"); @@ -135,7 +128,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu void DeferredLightingEffect::prepare() { // clear the normal and specular buffers - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); textureCache->setPrimaryDrawBuffers(false, true, false); glClear(GL_COLOR_BUFFER_BIT); textureCache->setPrimaryDrawBuffers(false, false, true); @@ -157,7 +150,7 @@ void DeferredLightingEffect::render() { glDisable(GL_COLOR_MATERIAL); glDepthMask(false); - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject(); primaryFBO->release(); @@ -254,7 +247,7 @@ void DeferredLightingEffect::render() { const glm::vec3& eyePoint = _viewState->getCurrentViewFrustum()->getPosition(); float nearRadius = glm::distance(eyePoint, _viewState->getCurrentViewFrustum()->getNearTopLeft()); - GeometryCache* geometryCache = DependencyManager::get(); + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); if (!_pointLights.isEmpty()) { _pointLight.bind(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 5dcd7d35f4..7ace3448d7 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -18,15 +18,17 @@ #include #include "ProgramObject.h" -#include "ViewStateInterface.h" +class AbstractViewStateInterface; class PostLightingRenderable; /// Handles deferred lighting for the bits that require it (voxels, metavoxels...) -class DeferredLightingEffect: public DependencyManager::Dependency { +class DeferredLightingEffect { + SINGLETON_DEPENDENCY(DeferredLightingEffect) + public: - void init(ViewStateInterface* viewState); + void init(AbstractViewStateInterface* viewState); /// Returns a reference to a simple program suitable for rendering static /// untextured geometry (such as that generated by glutSolidSphere, etc.) @@ -73,7 +75,6 @@ public: private: DeferredLightingEffect() { } virtual ~DeferredLightingEffect() { } - friend class DependencyManager; class LightLocations { public: @@ -125,7 +126,7 @@ private: QVector _spotLights; QVector _postLightingRenderables; - ViewStateInterface* _viewState; + AbstractViewStateInterface* _viewState; }; /// Simple interface for objects that require something to be rendered after deferred lighting. diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 54239f1678..56092945a2 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -699,7 +699,7 @@ void NetworkGeometry::clearLoadPriority(const QPointer& owner) { void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& url) { if (_meshes.size() > 0) { - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); for (int i = 0; i < _meshes.size(); i++) { NetworkMesh& mesh = _meshes[i]; for (int j = 0; j < mesh.parts.size(); j++) { @@ -914,7 +914,7 @@ void NetworkGeometry::reinsert() { void NetworkGeometry::setGeometry(const FBXGeometry& geometry) { _geometry = geometry; - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); foreach (const FBXMesh& mesh, _geometry.meshes) { NetworkMesh networkMesh; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 22857125af..97f24f94a3 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -32,8 +32,9 @@ class NetworkMesh; class NetworkTexture; /// Stores cached geometry. -class GeometryCache : public ResourceCache, public DependencyManager::Dependency { +class GeometryCache : public ResourceCache { Q_OBJECT + SINGLETON_DEPENDENCY(GeometryCache) public: void renderHemisphere(int slices, int stacks); @@ -56,7 +57,6 @@ protected: private: GeometryCache(); virtual ~GeometryCache(); - friend class DependencyManager; typedef QPair IntPair; typedef QPair VerticesIndices; diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp index 174436d155..fb7189f61e 100644 --- a/libraries/render-utils/src/GlowEffect.cpp +++ b/libraries/render-utils/src/GlowEffect.cpp @@ -12,7 +12,6 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include -#include #include #include @@ -139,7 +138,7 @@ static void maybeRelease(QOpenGLFramebufferObject* fbo) { QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { PerformanceTimer perfTimer("glowEffect"); - TextureCache* textureCache = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject(); primaryFBO->release(); glBindTexture(GL_TEXTURE_2D, primaryFBO->texture()); @@ -160,7 +159,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { if (!_enabled || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { - QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); + QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); } else { maybeBind(destFBO); if (!destFBO) { @@ -213,7 +212,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { if (!destFBO) { glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); } - _addSeparateProgram->bind(); + _addSeparateProgram->bind(); renderFullscreenQuad(); _addSeparateProgram->release(); maybeRelease(destFBO); diff --git a/libraries/render-utils/src/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h index cc3e6e5867..37f29afb62 100644 --- a/libraries/render-utils/src/GlowEffect.h +++ b/libraries/render-utils/src/GlowEffect.h @@ -25,8 +25,9 @@ class QOpenGLFramebufferObject; class ProgramObject; /// A generic full screen glow effect. -class GlowEffect : public QObject, public DependencyManager::Dependency { +class GlowEffect : public QObject { Q_OBJECT + SINGLETON_DEPENDENCY(GlowEffect) public: @@ -60,7 +61,6 @@ public slots: private: GlowEffect(); virtual ~GlowEffect(); - friend class DependencyManager; int getDeviceWidth() const; int getDeviceHeight() const; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 16e6b1bf02..6d313bc7aa 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -27,7 +27,9 @@ #include #include #include +#include +#include "AbstractViewStateInterface.h" #include "AnimationHandle.h" #include "DeferredLightingEffect.h" #include "GlowEffect.h" @@ -111,7 +113,7 @@ Model::SkinLocations Model::_skinNormalSpecularMapLocations; Model::SkinLocations Model::_skinShadowLocations; Model::SkinLocations Model::_skinTranslucentLocations; -ViewStateInterface* Model::_viewState = NULL; +AbstractViewStateInterface* Model::_viewState = NULL; void Model::setScale(const glm::vec3& scale) { setScaleInternal(scale); @@ -1161,7 +1163,7 @@ void Blender::run() { } } // post the result to the geometry cache, which will dispatch to the model if still alive - QMetaObject::invokeMethod(DependencyManager::get(), "setBlendedVertices", + QMetaObject::invokeMethod(DependencyManager::get().data(), "setBlendedVertices", Q_ARG(const QPointer&, _model), Q_ARG(int, _blendNumber), Q_ARG(const QWeakPointer&, _geometry), Q_ARG(const QVector&, vertices), Q_ARG(const QVector&, normals)); @@ -2334,8 +2336,8 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod Locations* locations, SkinLocations* skinLocations) { PROFILE_RANGE(__FUNCTION__); - TextureCache* textureCache = DependencyManager::get(); - GlowEffect* glowEffect = DependencyManager::get(); + TextureCache::SharedPointer textureCache = DependencyManager::get(); + GlowEffect::SharedPointer glowEffect = DependencyManager::get(); QString lastMaterialID; int meshPartsRendered = 0; updateVisibleJointStates(); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index d24f349f81..52b0a42211 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -32,8 +32,8 @@ #include "JointState.h" #include "ProgramObject.h" #include "TextureCache.h" -#include "ViewStateInterface.h" +class AbstractViewStateInterface; class QScriptEngine; class Shape; @@ -47,7 +47,7 @@ class Model : public QObject, public PhysicsEntity { public: - static void setViewStateInterface(ViewStateInterface* viewState) { _viewState = viewState; } + static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; } Model(QObject* parent = NULL); virtual ~Model(); @@ -459,7 +459,7 @@ private: bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args); - static ViewStateInterface* _viewState; + static AbstractViewStateInterface* _viewState; }; @@ -468,8 +468,9 @@ Q_DECLARE_METATYPE(QWeakPointer) Q_DECLARE_METATYPE(QVector) /// Handle management of pending models that need blending -class ModelBlender : public QObject, public DependencyManager::Dependency { +class ModelBlender : public QObject { Q_OBJECT + SINGLETON_DEPENDENCY(ModelBlender) public: @@ -483,7 +484,6 @@ public slots: private: ModelBlender(); virtual ~ModelBlender(); - friend class DependencyManager; QList > _modelsRequiringBlends; int _pendingBlenders; diff --git a/interface/src/ui/TextRenderer.cpp b/libraries/render-utils/src/TextRenderer.cpp similarity index 99% rename from interface/src/ui/TextRenderer.cpp rename to libraries/render-utils/src/TextRenderer.cpp index fce4c76c0d..34098c6862 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/libraries/render-utils/src/TextRenderer.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include #include @@ -18,7 +20,6 @@ #include #include -#include "InterfaceConfig.h" #include "TextRenderer.h" #include "glm/glm.hpp" diff --git a/interface/src/ui/TextRenderer.h b/libraries/render-utils/src/TextRenderer.h similarity index 97% rename from interface/src/ui/TextRenderer.h rename to libraries/render-utils/src/TextRenderer.h index 2ffd8b24b7..078efb0463 100644 --- a/interface/src/ui/TextRenderer.h +++ b/libraries/render-utils/src/TextRenderer.h @@ -12,6 +12,8 @@ #ifndef hifi_TextRenderer_h #define hifi_TextRenderer_h +#include + #include #include #include @@ -19,11 +21,10 @@ #include #include -#include "gpu/Resource.h" -#include "gpu/Stream.h" +#include +#include -#include "InterfaceConfig.h" // a special "character" that renders as a solid block const char SOLID_BLOCK_CHAR = 127; diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 56e29bc5fb..f3ad493cb4 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -30,8 +30,9 @@ typedef QSharedPointer NetworkTexturePointer; enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, SPLAT_TEXTURE }; /// Stores cached textures, including render-to-texture targets. -class TextureCache : public ResourceCache, public DependencyManager::Dependency { +class TextureCache : public ResourceCache { Q_OBJECT + SINGLETON_DEPENDENCY(TextureCache) public: @@ -96,7 +97,6 @@ protected: private: TextureCache(); virtual ~TextureCache(); - friend class DependencyManager; friend class DilatableNetworkTexture; QOpenGLFramebufferObject* createFramebufferObject(); diff --git a/libraries/script-engine/src/AbstractScriptingServicesInterface.h b/libraries/script-engine/src/AbstractScriptingServicesInterface.h new file mode 100644 index 0000000000..9d24531b60 --- /dev/null +++ b/libraries/script-engine/src/AbstractScriptingServicesInterface.h @@ -0,0 +1,33 @@ +// +// AbstractScriptingServicesInterface.h +// interface/src/script-engine +// +// Created by Brad Hefta-Gaub on 12/16/14. +// Copyright 2014 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_AbstractScriptingServicesInterface_h +#define hifi_AbstractScriptingServicesInterface_h + +class AbstractControllerScriptingInterface; +class Transform; +class ScriptEngine; +class QThread; + +/// Interface provided by Application to other objects that need access to scripting services of the application +class AbstractScriptingServicesInterface { +public: + + /// Returns the controller interface for the application + virtual AbstractControllerScriptingInterface* getControllerScriptingInterface() = 0; + + /// Registers application specific services with a script engine. + virtual void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) = 0; + +}; + + +#endif // hifi_AbstractScriptingServicesInterface_h diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index d25b3afe4f..7cd6ea07ee 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -255,7 +255,7 @@ void ScriptEngine::init() { registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Uuid", &_uuidLibrary); - registerGlobalObject("AnimationCache", DependencyManager::get()); + registerGlobalObject("AnimationCache", DependencyManager::get().data()); registerGlobalObject("Voxels", &_voxelsScriptingInterface); diff --git a/libraries/shared/src/DependencyManager.cpp b/libraries/shared/src/DependencyManager.cpp index c858cb7059..43bb92258e 100644 --- a/libraries/shared/src/DependencyManager.cpp +++ b/libraries/shared/src/DependencyManager.cpp @@ -17,8 +17,4 @@ DependencyManager& DependencyManager::getInstance() { } DependencyManager::~DependencyManager() { - foreach (Dependency* instance, _instanceHash) { - delete instance; - } - _instanceHash.clear(); } \ No newline at end of file diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index 87c7c7b4a6..fdf8030199 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -12,55 +12,43 @@ #ifndef hifi_DependencyManager_h #define hifi_DependencyManager_h -#include -#include +#include #include -#include + +#define SINGLETON_DEPENDENCY(T)\ +public:\ + typedef QSharedPointer SharedPointer;\ +private:\ + void customDeleter() {\ + QObject* thisObject = dynamic_cast(this);\ + if (thisObject) {\ + thisObject->deleteLater();\ + } else {\ + delete this;\ + }\ + }\ + friend class DependencyManager; + +class QObject; class DependencyManager { public: // Only accessible method. // usage: T* instance = DependencyManager::get(); template - static T* get(); - - // Any class T in the DependencyManager needs to subclass Dependency - // They also need to have protected constructor(s) and virtual destructor - // As well as declare DependencyManager a friend class - class Dependency { - protected: - Dependency() {} - virtual ~Dependency() {} // Ensure the proper destruction of the object - friend DependencyManager; - }; + static QSharedPointer get(); private: static DependencyManager& getInstance(); DependencyManager() {} - ~DependencyManager(); - - typedef QHash InstanceHash; - static InstanceHash& getInstanceHash() { return getInstance()._instanceHash; } - InstanceHash _instanceHash; + ~DependencyManager(); }; template -T* DependencyManager::get() { - const QString& typeId = typeid(T).name(); - - // Search the hash for global instance - Dependency* instance = getInstanceHash().value(typeId, NULL); - if (instance) { - return dynamic_cast(instance); - } - - // Found no instance in hash so we create one. - T* newInstance = new T(); - instance = dynamic_cast(newInstance); - assert(instance != NULL); // If this triggers, check that T is derived from Dependency - getInstanceHash().insert(typeId, instance); - return newInstance; +QSharedPointer DependencyManager::get() { + static QSharedPointer sharedPointer = QSharedPointer(new T(), &T::customDeleter); + return sharedPointer; } #endif // hifi_DependencyManager_h