move TextureCache out of interface and Application

This commit is contained in:
ZappoMan 2014-12-12 14:18:23 -08:00
parent 0b85a4cc49
commit e253b8afa4
10 changed files with 49 additions and 20 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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 <map>
#include <time.h>
@ -34,9 +37,10 @@
#include <EntityEditPacketSender.h>
#include <NetworkPacket.h>
#include <NodeList.h>
#include <OctreeQuery.h>
#include <PacketHeaders.h>
#include <ScriptEngine.h>
#include <OctreeQuery.h>
#include <TextureCache.h>
#include <ViewFrustum.h>
#include <VoxelEditPacketSender.h>
@ -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;

View file

@ -20,9 +20,9 @@
#include <glm/glm.hpp>
#include <MetavoxelClientManager.h>
#include <TextureCache.h>
#include "renderer/ProgramObject.h"
#include "renderer/TextureCache.h"
class HeightfieldBaseLayerBatch;
class HeightfieldSplatBatch;

View file

@ -25,6 +25,7 @@
#include <PacketHeaders.h>
#include <PerfStat.h>
#include <SharedUtil.h>
#include <TextureCache.h>
#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;

View file

@ -13,7 +13,7 @@
#define hifi_GeometryCache_h
// include this before QOpenGLBuffer, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <gpu/GPUConfig.h>
#include <QMap>
#include <QOpenGLBuffer>

View file

@ -21,13 +21,13 @@
#include <AnimationCache.h>
#include <GeometryUtil.h>
#include <PhysicsEntity.h>
#include <TextureCache.h>
#include "AnimationHandle.h"
#include "GeometryCache.h"
#include "InterfaceConfig.h"
#include "JointState.h"
#include "ProgramObject.h"
#include "TextureCache.h"
class QScriptEngine;

View file

@ -15,8 +15,9 @@
#include <QScopedPointer>
#include <QUrl>
#include <TextureCache.h>
#include "Base3DOverlay.h"
#include "../../renderer/TextureCache.h"
class BillboardOverlay : public Base3DOverlay {
Q_OBJECT

View file

@ -10,20 +10,26 @@
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QEvent>
#include <QGLWidget>
#include <QNetworkReply>
#include <QOpenGLFramebufferObject>
#include <QResizeEvent>
#include <QRunnable>
#include <QThreadPool>
#include <glm/glm.hpp>
#include <glm/gtc/random.hpp>
#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<Resource> 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);

View file

@ -14,10 +14,11 @@
#include <QImage>
#include <QMap>
#include <QGLWidget>
#include <ResourceCache.h>
#include "InterfaceConfig.h"
#include <gpu/GPUConfig.h>
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.