diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f677c46269..e7455ef71e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2051,7 +2051,7 @@ void Application::init() { DependencyManager::get()->associateWithWidget(glCanvas.data()); // initialize the GlowEffect with our widget - DependencyManager::get()->init(glCanvas, + DependencyManager::get()->init(glCanvas.data(), Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); } @@ -4032,7 +4032,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); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0521615257..f0c2a687a4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -427,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())); 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/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 1ee7269480..421461860d 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -20,7 +20,9 @@ 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); @@ -29,7 +31,6 @@ public: private: AmbientOcclusionEffect() {} virtual ~AmbientOcclusionEffect() {} - friend class DependencyManager; ProgramObject* _occlusionProgram; int _nearLocation; diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 5dcd7d35f4..904f9827ea 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -23,7 +23,9 @@ 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); @@ -73,7 +75,6 @@ public: private: DeferredLightingEffect() { } virtual ~DeferredLightingEffect() { } - friend class DependencyManager; class LightLocations { public: diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp index 62e3a9d691..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 @@ -157,7 +156,6 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* destFBO = toTexture ? textureCache->getSecondaryFramebufferObject() : NULL; - GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (!_enabled || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { @@ -165,7 +163,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } else { maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); } glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); @@ -212,8 +210,9 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); - _addSeparateProgram->bind(); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); + } + _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/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index ec5f2bc0e7..6117da9d18 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.h b/libraries/shared/src/DependencyManager.h index 455ec38bca..d1a1896947 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -46,7 +46,7 @@ QSharedPointer DependencyManager::get() { static T* instance = new T(); if (instance) { - if (dynamic_cast(instance)) { // If this is a QOject, call deleteLater for destruction + if (dynamic_cast(instance) != NULL) { // If this is a QOject, call deleteLater for destruction sharedPointer = QSharedPointer(instance, &T::deleteLater); } else { // Otherwise use custom deleter to avoid issues between private destructor and QSharedPointer sharedPointer = QSharedPointer(instance, &T::customDeleter);