Fix count of textures

This commit is contained in:
David Rowe 2016-09-10 10:15:13 +12:00
parent 487cb7d893
commit 68499f49ad
5 changed files with 22 additions and 6 deletions

View file

@ -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) {

View file

@ -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;
}

View file

@ -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 {

View file

@ -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) {

View file

@ -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)