From efa8a752f20fb9092df8279f4adbeabeb210f846 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 13:14:57 -0800 Subject: [PATCH] remove dependency on Menu from Model --- interface/src/Application.cpp | 8 ++++++-- interface/src/Application.h | 1 + interface/src/renderer/Model.cpp | 16 ++++++++++------ libraries/render-utils/src/ViewStateInterface.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 02dae8e08e..8b3c5a2fa1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -191,6 +191,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { + Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us + // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -429,8 +431,6 @@ 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() { @@ -2939,6 +2939,10 @@ void Application::setupWorldLight() { glMateriali(GL_FRONT, GL_SHININESS, 96); } +bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { + return Menu::getInstance()->shouldRenderMesh(largestDimension, distanceToCamera); +} + QImage Application::renderAvatarBillboard() { DependencyManager::get()->getPrimaryFramebufferObject()->bind(); diff --git a/interface/src/Application.h b/interface/src/Application.h index dea7c80940..9aca90fac8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -256,6 +256,7 @@ public: void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes); virtual void setupWorldLight(); + virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera); QImage renderAvatarBillboard(); diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 7fe024b8fe..2faeeeea55 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -31,7 +31,6 @@ #include #include "AnimationHandle.h" -#include "Menu.h" #include "Model.h" @@ -64,7 +63,9 @@ Model::Model(QObject* parent) : _meshGroupsKnown(false) { // we may have been created in the network thread, but we live in the main thread - moveToThread(_viewState->getMainThread()); + if (_viewState) { + moveToThread(_viewState->getMainThread()); + } } Model::~Model() { @@ -720,6 +721,9 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { PROFILE_RANGE(__FUNCTION__); + if (!_viewState) { + return false; + } // Let's introduce a gpu::Batch to capture all the calls to the graphics api _renderBatch.clear(); @@ -2329,9 +2333,9 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, RenderArgs* args, Locations* locations, SkinLocations* skinLocations) { PROFILE_RANGE(__FUNCTION__); - bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); - bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); - bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); + bool dontCullOutOfViewMeshParts = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); + bool cullTooSmallMeshParts = true; // !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); + bool dontReduceMaterialSwitches = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); TextureCache* textureCache = DependencyManager::get(); GlowEffect* glowEffect = DependencyManager::get(); @@ -2373,7 +2377,7 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod args->_viewFrustum->boxInFrustum(_calculatedMeshBoxes.at(i)) != ViewFrustum::OUTSIDE; if (shouldRender && cullTooSmallMeshParts) { float distance = args->_viewFrustum->distanceToCamera(_calculatedMeshBoxes.at(i).calcCenter()); - shouldRender = Menu::getInstance()->shouldRenderMesh(_calculatedMeshBoxes.at(i).getLargestDimension(), + shouldRender = !_viewState ? false : _viewState->shouldRenderMesh(_calculatedMeshBoxes.at(i).getLargestDimension(), distance); if (!shouldRender) { args->_meshesTooSmall++; diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h index 83501589d0..9110eb8eb6 100644 --- a/libraries/render-utils/src/ViewStateInterface.h +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -37,6 +37,7 @@ public: virtual QThread* getMainThread() = 0; virtual const Transform& getViewTransform() const = 0; virtual void setupWorldLight() = 0; + virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera) = 0; };