From f4c3c30f6a70a49323370860754daca2a451f59e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Aug 2015 12:49:48 -0700 Subject: [PATCH] quick optimization to RenderableModelEntityItem::render() --- .../src/RenderableModelEntityItem.cpp | 16 +++++++++++----- libraries/render-utils/src/Model.cpp | 15 +++++++-------- libraries/render-utils/src/Model.h | 2 ++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 1576007263..e6441a5386 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -227,24 +227,30 @@ void RenderableModelEntityItem::render(RenderArgs* args) { if (hasModel()) { if (_model) { - if (QUrl(getModelURL()) != _model->getURL()) { + if (getModelURL() != _model->getURLAsString()) { qDebug() << "Updating model URL: " << getModelURL(); _model->setURL(getModelURL()); } + render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene(); + // check to see if when we added our models to the scene they were ready, if they were not ready, then // fix them up in the scene - render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene(); - render::PendingChanges pendingChanges; if (_model->needsFixupInScene()) { + render::PendingChanges pendingChanges; + _model->removeFromScene(scene, pendingChanges); render::Item::Status::Getters statusGetters; makeEntityItemStatusGetters(this, statusGetters); _model->addToScene(scene, pendingChanges, statusGetters); - } - scene->enqueuePendingChanges(pendingChanges); + scene->enqueuePendingChanges(pendingChanges); + } + + // FIXME: this seems like it could be optimized if we tracked our last known visible state in + // the renderable item. As it stands now the model checks it's visible/invisible state + // so most of the time we don't do anything in this function. _model->setVisibleInScene(getVisible(), scene); } diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 8839a5b463..04f72debd7 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -54,6 +54,7 @@ static int modelPointerTypeId = qRegisterMetaType >(); static int weakNetworkGeometryPointerTypeId = qRegisterMetaType >(); static int vec3VectorTypeId = qRegisterMetaType >(); float Model::FAKE_DIMENSION_PLACEHOLDER = -1.0f; +#define HTTP_INVALID_COM "http://invalid.com" Model::Model(RigPointer rig, QObject* parent) : QObject(parent), @@ -67,7 +68,8 @@ Model::Model(RigPointer rig, QObject* parent) : _cauterizeBones(false), _lodDistance(0.0f), _pupilDilation(0.0f), - _url("http://invalid.com"), + _url(HTTP_INVALID_COM), + _urlAsString(HTTP_INVALID_COM), _isVisible(true), _blendNumber(0), _appliedBlendNumber(0), @@ -181,17 +183,12 @@ void Model::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, Model: locations.texcoordMatrices = program->getUniforms().findLocation("texcoordMatrices"); locations.emissiveParams = program->getUniforms().findLocation("emissiveParams"); locations.glowIntensity = program->getUniforms().findLocation("glowIntensity"); - locations.normalFittingMapUnit = program->getTextures().findLocation("normalFittingMap"); - locations.specularTextureUnit = program->getTextures().findLocation("specularMap"); locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap"); - locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer"); locations.lightBufferUnit = program->getBuffers().findLocation("lightBuffer"); - locations.clusterMatrices = program->getUniforms().findLocation("clusterMatrices"); - locations.clusterIndices = program->getInputs().findLocation("inSkinClusterIndex"); locations.clusterWeights = program->getInputs().findLocation("inSkinClusterWeight"); } @@ -1085,6 +1082,7 @@ void Model::setURL(const QUrl& url, const QUrl& fallback, bool retainCurrent, bo invalidCalculatedMeshBoxes(); _url = url; + _urlAsString = _url.toString(); onInvalidate(); @@ -1868,8 +1866,9 @@ void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, f batch._glUniform1f(locations->glowIntensity, DEFAULT_GLOW_INTENSITY); } - if ((locations->normalFittingMapUnit > -1)) { - batch.setResourceTexture(locations->normalFittingMapUnit, DependencyManager::get()->getNormalFittingTexture()); + if ((locations->normalFittingMapUnit > -1)) { + batch.setResourceTexture(locations->normalFittingMapUnit, + DependencyManager::get()->getNormalFittingTexture()); } } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 9fdb2f3691..c9b63b598e 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -74,6 +74,7 @@ public: Q_INVOKABLE void setURL(const QUrl& url, const QUrl& fallback = QUrl(), bool retainCurrent = false, bool delayLoad = false); const QUrl& getURL() const { return _url; } + const QString& getURLAsString() const { return _urlAsString; } // new Scene/Engine rendering support void setVisibleInScene(bool newValue, std::shared_ptr scene); @@ -328,6 +329,7 @@ private: QVector _blendshapeCoefficients; QUrl _url; + QString _urlAsString; QUrl _collisionUrl; bool _isVisible;