From e253b8afa4cd83ef5dd89ad38d6634ce742aa9ea Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 12 Dec 2014 14:18:23 -0800 Subject: [PATCH] move TextureCache out of interface and Application --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 15 ++++++++----- interface/src/Application.h | 11 ++++++---- interface/src/MetavoxelSystem.h | 2 +- interface/src/avatar/Avatar.cpp | 2 +- interface/src/renderer/GeometryCache.h | 2 +- interface/src/renderer/Model.h | 2 +- interface/src/ui/overlays/BillboardOverlay.h | 3 ++- .../render-utils/src}/TextureCache.cpp | 22 +++++++++++++++---- .../render-utils/src}/TextureCache.h | 8 ++++++- 10 files changed, 49 insertions(+), 20 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/TextureCache.cpp (98%) rename {interface/src/renderer => libraries/render-utils/src}/TextureCache.h (97%) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 38dd02c655..ffc401ba63 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -107,7 +107,7 @@ 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) +link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics render-utils) # find any optional and required libraries find_package(ZLIB REQUIRED) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fbe55071e4..0c1d2c3b9f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -177,6 +177,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _touchAvgY(0.0f), _isTouchPressed(false), _mousePressed(false), + _textureCache(NULL), _audio(), _enableProcessVoxelsThread(true), _octreeProcessor(), @@ -194,6 +195,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { + _textureCache = TextureCache::getInstance(); // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -621,10 +623,10 @@ void Application::paintGL() { // Set the desired FBO texture size. If it hasn't changed, this does nothing. // Otherwise, it must rebuild the FBOs if (OculusManager::isConnected()) { - _textureCache.setFrameBufferSize(OculusManager::getRenderTargetSize()); + _textureCache->setFrameBufferSize(OculusManager::getRenderTargetSize()); } else { QSize fbSize = _glWidget->getDeviceSize() * getRenderResolutionScale(); - _textureCache.setFrameBufferSize(fbSize); + _textureCache->setFrameBufferSize(fbSize); } glEnable(GL_LINE_SMOOTH); @@ -2042,6 +2044,9 @@ 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 + _textureCache->associateWithWidget(getGLWidget()); } void Application::closeMirrorView() { @@ -2772,7 +2777,7 @@ glm::vec3 Application::getSunDirection() { void Application::updateShadowMap() { PerformanceTimer perfTimer("shadowMap"); - QOpenGLFramebufferObject* fbo = _textureCache.getShadowFramebufferObject(); + QOpenGLFramebufferObject* fbo = _textureCache->getShadowFramebufferObject(); fbo->bind(); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -2937,7 +2942,7 @@ void Application::setupWorldLight() { } QImage Application::renderAvatarBillboard() { - _textureCache.getPrimaryFramebufferObject()->bind(); + _textureCache->getPrimaryFramebufferObject()->bind(); // the "glow" here causes an alpha of one Glower glower; @@ -2948,7 +2953,7 @@ QImage Application::renderAvatarBillboard() { QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); - _textureCache.getPrimaryFramebufferObject()->release(); + _textureCache->getPrimaryFramebufferObject()->release(); return image; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 833f1374ce..99184e990d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -12,6 +12,9 @@ #ifndef hifi_Application_h #define hifi_Application_h +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" + #include #include @@ -34,9 +37,10 @@ #include #include #include +#include #include #include -#include +#include #include #include @@ -61,7 +65,6 @@ #include "renderer/DeferredLightingEffect.h" #include "renderer/GeometryCache.h" #include "renderer/GlowEffect.h" -#include "renderer/TextureCache.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" @@ -251,7 +254,7 @@ public: GeometryCache* getGeometryCache() { return &_geometryCache; } AnimationCache* getAnimationCache() { return &_animationCache; } - TextureCache* getTextureCache() { return &_textureCache; } + TextureCache* getTextureCache() { return _textureCache; } DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; } GlowEffect* getGlowEffect() { return &_glowEffect; } ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } @@ -571,7 +574,7 @@ private: GeometryCache _geometryCache; AnimationCache _animationCache; - TextureCache _textureCache; + TextureCache* _textureCache; DeferredLightingEffect _deferredLightingEffect; GlowEffect _glowEffect; diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 2ebf7e1146..0c0f9b49b7 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -20,9 +20,9 @@ #include #include +#include #include "renderer/ProgramObject.h" -#include "renderer/TextureCache.h" class HeightfieldBaseLayerBatch; class HeightfieldSplatBatch; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index c680c75056..e4ea33a180 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "Application.h" #include "Avatar.h" @@ -36,7 +37,6 @@ #include "Recorder.h" #include "world.h" #include "devices/OculusManager.h" -#include "renderer/TextureCache.h" #include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index 6faad93fe4..2d06953eb5 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -13,7 +13,7 @@ #define hifi_GeometryCache_h // include this before QOpenGLBuffer, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index e875c8f06c..74b227083f 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -21,13 +21,13 @@ #include #include #include +#include #include "AnimationHandle.h" #include "GeometryCache.h" #include "InterfaceConfig.h" #include "JointState.h" #include "ProgramObject.h" -#include "TextureCache.h" class QScriptEngine; diff --git a/interface/src/ui/overlays/BillboardOverlay.h b/interface/src/ui/overlays/BillboardOverlay.h index 03daef934d..dcb8ab8b0c 100644 --- a/interface/src/ui/overlays/BillboardOverlay.h +++ b/interface/src/ui/overlays/BillboardOverlay.h @@ -15,8 +15,9 @@ #include #include +#include + #include "Base3DOverlay.h" -#include "../../renderer/TextureCache.h" class BillboardOverlay : public Base3DOverlay { Q_OBJECT diff --git a/interface/src/renderer/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp similarity index 98% rename from interface/src/renderer/TextureCache.cpp rename to libraries/render-utils/src/TextureCache.cpp index f40f0e3faf..11ccd4b797 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -10,20 +10,26 @@ // // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include #include +#include #include #include #include #include -#include "Application.h" #include "TextureCache.h" +TextureCache* TextureCache::getInstance() { + static TextureCache instance; + return &instance; +} + + TextureCache::TextureCache() : _permutationNormalTextureID(0), _whiteTextureID(0), @@ -35,7 +41,8 @@ TextureCache::TextureCache() : _secondaryFramebufferObject(NULL), _tertiaryFramebufferObject(NULL), _shadowFramebufferObject(NULL), - _frameBufferSize(100, 100) + _frameBufferSize(100, 100), + _associatedWidget(NULL) { } @@ -350,9 +357,16 @@ QSharedPointer TextureCache::createResource(const QUrl& url, &Resource::allReferencesCleared); } +void TextureCache::associateWithWidget(QGLWidget* widget) { + if (_associatedWidget) { + _associatedWidget->removeEventFilter(this); + } + _associatedWidget = widget; + _associatedWidget->installEventFilter(this); +} + QOpenGLFramebufferObject* TextureCache::createFramebufferObject() { QOpenGLFramebufferObject* fbo = new QOpenGLFramebufferObject(_frameBufferSize); - Application::getInstance()->getGLWidget()->installEventFilter(this); glBindTexture(GL_TEXTURE_2D, fbo->texture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/interface/src/renderer/TextureCache.h b/libraries/render-utils/src/TextureCache.h similarity index 97% rename from interface/src/renderer/TextureCache.h rename to libraries/render-utils/src/TextureCache.h index 66734da9cd..3808485135 100644 --- a/interface/src/renderer/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -14,10 +14,11 @@ #include #include +#include #include -#include "InterfaceConfig.h" +#include class QOpenGLFramebufferObject; @@ -32,10 +33,14 @@ class TextureCache : public ResourceCache { Q_OBJECT public: + + static TextureCache* getInstance(); TextureCache(); virtual ~TextureCache(); + void associateWithWidget(QGLWidget* widget); + /// Sets the desired texture resolution for the framebuffer objects. void setFrameBufferSize(QSize frameBufferSize); const QSize& getFrameBufferSize() const { return _frameBufferSize; } @@ -115,6 +120,7 @@ private: GLuint _shadowDepthTextureID; QSize _frameBufferSize; + QGLWidget* _associatedWidget; }; /// A simple object wrapper for an OpenGL texture.