mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 08:17:11 +02:00
remove Application dependency from Model
This commit is contained in:
parent
58183515e6
commit
16c1e597f1
5 changed files with 29 additions and 10 deletions
|
@ -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() {
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <DeferredLightingEffect.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <GlowEffect.h>
|
||||
#include <gpu/Batch.h>
|
||||
#include <gpu/GLBackend.h>
|
||||
#include <PathUtils.h>
|
||||
#include <PerfStat.h>
|
||||
#include <PhysicsEntity.h>
|
||||
|
@ -29,11 +31,10 @@
|
|||
#include <SphereShape.h>
|
||||
|
||||
#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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <ProgramObject.h>
|
||||
#include <TextureCache.h>
|
||||
#include <Transform.h>
|
||||
#include <ViewStateInterface.h>
|
||||
|
||||
#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<Model>)
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
#include <ViewFrustum.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue