diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c9309616ae..02dae8e08e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -429,6 +429,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : #endif this->installEventFilter(this); + + Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us } void Application::aboutToQuit() { diff --git a/interface/src/Application.h b/interface/src/Application.h index 6b5bcc0770..dea7c80940 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -232,7 +232,7 @@ public: const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } 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); /// 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 setupWorldLight(); + virtual void setupWorldLight(); QImage renderAvatarBillboard(); @@ -283,6 +283,7 @@ public: virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); } virtual bool getShadowsEnabled(); virtual bool getCascadeShadowsEnabled(); + virtual QThread* getMainThread() { return thread(); } NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 56d7d30def..7fe024b8fe 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -29,11 +31,10 @@ #include #include "AnimationHandle.h" -#include "Application.h" +#include "Menu.h" #include "Model.h" -#include "gpu/Batch.h" -#include "gpu/GLBackend.h" + #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call @@ -63,7 +64,7 @@ Model::Model(QObject* parent) : _meshGroupsKnown(false) { // 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() { @@ -109,6 +110,8 @@ Model::SkinLocations Model::_skinNormalSpecularMapLocations; Model::SkinLocations Model::_skinShadowLocations; Model::SkinLocations Model::_skinTranslucentLocations; +ViewStateInterface* Model::_viewState = NULL; + void Model::setScale(const glm::vec3& scale) { setScaleInternal(scale); // 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()) { _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) _transforms[0].preTranslate(-_translation); @@ -870,7 +873,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { } // restore all the default material settings - Application::getInstance()->setupWorldLight(); + _viewState->setupWorldLight(); if (args) { args->_translucentMeshPartsRendered = translucentMeshPartsRendered; @@ -1670,7 +1673,7 @@ void Model::setupBatchTransform(gpu::Batch& batch) { if (_transforms.empty()) { _transforms.push_back(Transform()); } - _transforms[0] = Application::getInstance()->getViewTransform(); + _transforms[0] = _viewState->getViewTransform(); _transforms[0].preTranslate(-_translation); batch.setViewTransform(_transforms[0]); } @@ -1830,7 +1833,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { } // restore all the default material settings - Application::getInstance()->setupWorldLight(); + _viewState->setupWorldLight(); } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 8000e7385b..2c6b0bd6ae 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "AnimationHandle.h" @@ -46,6 +47,8 @@ class Model : public QObject, public PhysicsEntity { public: + static void setViewStateInterface(ViewStateInterface* viewState) { _viewState = viewState; } + Model(QObject* parent = NULL); virtual ~Model(); @@ -455,6 +458,9 @@ private: static int renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args); + + static ViewStateInterface* _viewState; + }; Q_DECLARE_METATYPE(QPointer) diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h index decccdc401..83501589d0 100644 --- a/libraries/render-utils/src/ViewStateInterface.h +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -14,6 +14,9 @@ #include +class Transform; +class QThread; + /// Interface provided by Application to other objects that need access to the current view state details class ViewStateInterface { public: @@ -30,6 +33,10 @@ public: virtual bool getShadowsEnabled() = 0; virtual bool getCascadeShadowsEnabled() = 0; + + virtual QThread* getMainThread() = 0; + virtual const Transform& getViewTransform() const = 0; + virtual void setupWorldLight() = 0; };