From 68499f49ad595f9c1ffc4e18b72a3054bebcf814 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 10 Sep 2016 10:15:13 +1200 Subject: [PATCH] Fix count of textures --- libraries/entities/src/EntityItemProperties.cpp | 2 +- libraries/render-utils/src/MeshPartPayload.cpp | 2 ++ libraries/render-utils/src/MeshPartPayload.h | 2 ++ libraries/render-utils/src/Model.cpp | 17 ++++++++++++++--- libraries/render-utils/src/Model.h | 5 +++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 8169c2a802..588c6e2977 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -769,7 +769,7 @@ void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object QScriptValue EntityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags) { return EntityItemProperties::entityPropertyFlagsToScriptValue(engine, flags); QScriptValue result = engine->newObject(); - return result; + return result; } void EntityPropertyFlagsFromScriptValue(const QScriptValue& object, EntityPropertyFlags& flags) { diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 3e891bffe2..50c0c869ff 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -77,6 +77,7 @@ void MeshPartPayload::updateMaterial(model::MaterialPointer drawMaterial) { bool MeshPartPayload::calculateMaterialSize() { bool allTextures = true; // assume we got this... _materialTextureSize = 0; + _materialTextureCount = 0; auto textureMaps = _drawMaterial->getTextureMaps(); for (auto const &textureMapItem : textureMaps) { auto textureMap = textureMapItem.second; @@ -88,6 +89,7 @@ bool MeshPartPayload::calculateMaterialSize() { //auto storedSize = texture->getStoredSize(); auto size = texture->getSize(); _materialTextureSize += size; + _materialTextureCount++; } else { allTextures = false; } diff --git a/libraries/render-utils/src/MeshPartPayload.h b/libraries/render-utils/src/MeshPartPayload.h index f7ea77beba..3ecd8da03e 100644 --- a/libraries/render-utils/src/MeshPartPayload.h +++ b/libraries/render-utils/src/MeshPartPayload.h @@ -67,10 +67,12 @@ public: size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; } size_t getMaterialTextureSize() { return _materialTextureSize; } + int getMaterialTextureCount() { return _materialTextureCount; } bool calculateMaterialSize(); protected: size_t _materialTextureSize { 0 }; + int _materialTextureCount { 0 }; }; namespace render { diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index ebf5cb4327..8e74c3db0d 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -161,22 +161,33 @@ void Model::setOffset(const glm::vec3& offset) { _snappedToRegistrationPoint = false; } -size_t Model::getRenderInfoTextureSize() { - if (!_hasCalculatedTextureSize && isLoaded() && getGeometry()->areTexturesLoaded()) { +void Model::calculateTextureInfo() { + if (!_hasCalculatedTextureInfo && isLoaded() && getGeometry()->areTexturesLoaded()) { size_t textureSize = 0; + int textureCount = 0; bool allTexturesLoaded = true; foreach(auto renderItem, _modelMeshRenderItemsSet) { auto meshPart = renderItem.get(); bool allTexturesForThisMesh = meshPart->calculateMaterialSize(); allTexturesLoaded = allTexturesLoaded & allTexturesForThisMesh; textureSize += meshPart->getMaterialTextureSize(); + textureCount += meshPart->getMaterialTextureCount(); } _renderInfoTextureSize = textureSize; - _hasCalculatedTextureSize = allTexturesLoaded; // only do this once + _renderInfoTextureCount = textureCount; + _hasCalculatedTextureInfo = allTexturesLoaded; // only do this once } +} + +size_t Model::getRenderInfoTextureSize() { + calculateTextureInfo(); return _renderInfoTextureSize; } +int Model::getRenderInfoTextureCount() { + calculateTextureInfo(); + return _renderInfoTextureCount; +} void Model::updateRenderItems() { if (!_addedToScene) { diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 1b16892296..bd94fb706b 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -233,8 +233,8 @@ public: void setLoadingPriority(float priority) { _loadingPriority = priority; } size_t getRenderInfoVertexCount() const { return _renderInfoVertexCount; } - int getRenderInfoTextureCount() const { return _renderInfoTextureCount; } size_t getRenderInfoTextureSize(); + int getRenderInfoTextureCount(); int getRenderInfoDrawCalls() const { return _renderInfoDrawCalls; } bool getRenderInfoHasTransparent() const { return _renderInfoHasTransparent; } @@ -409,13 +409,14 @@ protected: size_t _renderInfoVertexCount { 0 }; int _renderInfoTextureCount { 0 }; size_t _renderInfoTextureSize { 0 }; - bool _hasCalculatedTextureSize { false }; + bool _hasCalculatedTextureInfo { false }; int _renderInfoDrawCalls { 0 }; int _renderInfoHasTransparent { false }; private: float _loadingPriority { 0.0f }; + void calculateTextureInfo(); }; Q_DECLARE_METATYPE(ModelPointer)