remove Application dependency from Model

This commit is contained in:
ZappoMan 2014-12-16 12:53:22 -08:00
parent 58183515e6
commit 16c1e597f1
5 changed files with 29 additions and 10 deletions

View file

@ -429,6 +429,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
#endif #endif
this->installEventFilter(this); this->installEventFilter(this);
Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us
} }
void Application::aboutToQuit() { void Application::aboutToQuit() {

View file

@ -232,7 +232,7 @@ public:
const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; }
void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; }
const Transform& getViewTransform() const { return _viewTransform; } virtual const Transform& getViewTransform() const { return _viewTransform; }
void setViewTransform(const Transform& view); void setViewTransform(const Transform& view);
/// if you need to access the application settings, use lockSettings()/unlockSettings() /// if you need to access the application settings, use lockSettings()/unlockSettings()
@ -255,7 +255,7 @@ public:
void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes); void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes);
void setupWorldLight(); virtual void setupWorldLight();
QImage renderAvatarBillboard(); QImage renderAvatarBillboard();
@ -283,6 +283,7 @@ public:
virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); } virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); }
virtual bool getShadowsEnabled(); virtual bool getShadowsEnabled();
virtual bool getCascadeShadowsEnabled(); virtual bool getCascadeShadowsEnabled();
virtual QThread* getMainThread() { return thread(); }
NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; }

View file

@ -22,6 +22,8 @@
#include <DeferredLightingEffect.h> #include <DeferredLightingEffect.h>
#include <GeometryUtil.h> #include <GeometryUtil.h>
#include <GlowEffect.h> #include <GlowEffect.h>
#include <gpu/Batch.h>
#include <gpu/GLBackend.h>
#include <PathUtils.h> #include <PathUtils.h>
#include <PerfStat.h> #include <PerfStat.h>
#include <PhysicsEntity.h> #include <PhysicsEntity.h>
@ -29,11 +31,10 @@
#include <SphereShape.h> #include <SphereShape.h>
#include "AnimationHandle.h" #include "AnimationHandle.h"
#include "Application.h" #include "Menu.h"
#include "Model.h" #include "Model.h"
#include "gpu/Batch.h"
#include "gpu/GLBackend.h"
#define GLBATCH( call ) batch._##call #define GLBATCH( call ) batch._##call
//#define GLBATCH( call ) call //#define GLBATCH( call ) call
@ -63,7 +64,7 @@ Model::Model(QObject* parent) :
_meshGroupsKnown(false) { _meshGroupsKnown(false) {
// we may have been created in the network thread, but we live in the main thread // we may have been created in the network thread, but we live in the main thread
moveToThread(Application::getInstance()->thread()); moveToThread(_viewState->getMainThread());
} }
Model::~Model() { Model::~Model() {
@ -109,6 +110,8 @@ Model::SkinLocations Model::_skinNormalSpecularMapLocations;
Model::SkinLocations Model::_skinShadowLocations; Model::SkinLocations Model::_skinShadowLocations;
Model::SkinLocations Model::_skinTranslucentLocations; Model::SkinLocations Model::_skinTranslucentLocations;
ViewStateInterface* Model::_viewState = NULL;
void Model::setScale(const glm::vec3& scale) { void Model::setScale(const glm::vec3& scale) {
setScaleInternal(scale); setScaleInternal(scale);
// if anyone sets scale manually, then we are no longer scaled to fit // if anyone sets scale manually, then we are no longer scaled to fit
@ -727,7 +730,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
if (_transforms.empty()) { if (_transforms.empty()) {
_transforms.push_back(Transform()); _transforms.push_back(Transform());
} }
_transforms[0] = Application::getInstance()->getViewTransform(); _transforms[0] = _viewState->getViewTransform();
// apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space) // apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space)
_transforms[0].preTranslate(-_translation); _transforms[0].preTranslate(-_translation);
@ -870,7 +873,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
} }
// restore all the default material settings // restore all the default material settings
Application::getInstance()->setupWorldLight(); _viewState->setupWorldLight();
if (args) { if (args) {
args->_translucentMeshPartsRendered = translucentMeshPartsRendered; args->_translucentMeshPartsRendered = translucentMeshPartsRendered;
@ -1670,7 +1673,7 @@ void Model::setupBatchTransform(gpu::Batch& batch) {
if (_transforms.empty()) { if (_transforms.empty()) {
_transforms.push_back(Transform()); _transforms.push_back(Transform());
} }
_transforms[0] = Application::getInstance()->getViewTransform(); _transforms[0] = _viewState->getViewTransform();
_transforms[0].preTranslate(-_translation); _transforms[0].preTranslate(-_translation);
batch.setViewTransform(_transforms[0]); batch.setViewTransform(_transforms[0]);
} }
@ -1830,7 +1833,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
} }
// restore all the default material settings // restore all the default material settings
Application::getInstance()->setupWorldLight(); _viewState->setupWorldLight();
} }

View file

@ -28,6 +28,7 @@
#include <ProgramObject.h> #include <ProgramObject.h>
#include <TextureCache.h> #include <TextureCache.h>
#include <Transform.h> #include <Transform.h>
#include <ViewStateInterface.h>
#include "AnimationHandle.h" #include "AnimationHandle.h"
@ -46,6 +47,8 @@ class Model : public QObject, public PhysicsEntity {
public: public:
static void setViewStateInterface(ViewStateInterface* viewState) { _viewState = viewState; }
Model(QObject* parent = NULL); Model(QObject* parent = NULL);
virtual ~Model(); virtual ~Model();
@ -455,6 +458,9 @@ private:
static int renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, static int renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args); bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args);
static ViewStateInterface* _viewState;
}; };
Q_DECLARE_METATYPE(QPointer<Model>) Q_DECLARE_METATYPE(QPointer<Model>)

View file

@ -14,6 +14,9 @@
#include <ViewFrustum.h> #include <ViewFrustum.h>
class Transform;
class QThread;
/// Interface provided by Application to other objects that need access to the current view state details /// Interface provided by Application to other objects that need access to the current view state details
class ViewStateInterface { class ViewStateInterface {
public: public:
@ -30,6 +33,10 @@ public:
virtual bool getShadowsEnabled() = 0; virtual bool getShadowsEnabled() = 0;
virtual bool getCascadeShadowsEnabled() = 0; virtual bool getCascadeShadowsEnabled() = 0;
virtual QThread* getMainThread() = 0;
virtual const Transform& getViewTransform() const = 0;
virtual void setupWorldLight() = 0;
}; };