mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:41:02 +02:00
Merge pull request #8704 from ZappoMan/calculateMaterialSizeFixes
make calculateTextureInfo thread safe
This commit is contained in:
commit
964f766427
5 changed files with 62 additions and 42 deletions
|
@ -44,8 +44,11 @@ Material::Material(const Material& material) :
|
||||||
}
|
}
|
||||||
|
|
||||||
Material& Material::operator= (const Material& material) {
|
Material& Material::operator= (const Material& material) {
|
||||||
|
QMutexLocker locker(&_textureMapsMutex);
|
||||||
|
|
||||||
_key = (material._key);
|
_key = (material._key);
|
||||||
_textureMaps = (material._textureMaps);
|
_textureMaps = (material._textureMaps);
|
||||||
|
_hasCalculatedTextureInfo = false;
|
||||||
|
|
||||||
// copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer
|
// copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer
|
||||||
Schema schema;
|
Schema schema;
|
||||||
|
@ -112,6 +115,8 @@ void Material::setScattering(float scattering) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textureMap) {
|
void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textureMap) {
|
||||||
|
QMutexLocker locker(&_textureMapsMutex);
|
||||||
|
|
||||||
if (textureMap) {
|
if (textureMap) {
|
||||||
_key.setMapChannel(channel, (true));
|
_key.setMapChannel(channel, (true));
|
||||||
_textureMaps[channel] = textureMap;
|
_textureMaps[channel] = textureMap;
|
||||||
|
@ -119,6 +124,7 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur
|
||||||
_key.setMapChannel(channel, (false));
|
_key.setMapChannel(channel, (false));
|
||||||
_textureMaps.erase(channel);
|
_textureMaps.erase(channel);
|
||||||
}
|
}
|
||||||
|
_hasCalculatedTextureInfo = false;
|
||||||
|
|
||||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
|
|
||||||
|
@ -173,6 +179,8 @@ void Material::resetOpacityMap() const {
|
||||||
|
|
||||||
|
|
||||||
const TextureMapPointer Material::getTextureMap(MapChannel channel) const {
|
const TextureMapPointer Material::getTextureMap(MapChannel channel) const {
|
||||||
|
QMutexLocker locker(&_textureMapsMutex);
|
||||||
|
|
||||||
auto result = _textureMaps.find(channel);
|
auto result = _textureMaps.find(channel);
|
||||||
if (result != _textureMaps.end()) {
|
if (result != _textureMaps.end()) {
|
||||||
return (result->second);
|
return (result->second);
|
||||||
|
@ -180,3 +188,37 @@ const TextureMapPointer Material::getTextureMap(MapChannel channel) const {
|
||||||
return TextureMapPointer();
|
return TextureMapPointer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Material::calculateMaterialInfo() const {
|
||||||
|
if (!_hasCalculatedTextureInfo) {
|
||||||
|
QMutexLocker locker(&_textureMapsMutex);
|
||||||
|
|
||||||
|
bool allTextures = true; // assume we got this...
|
||||||
|
_textureSize = 0;
|
||||||
|
_textureCount = 0;
|
||||||
|
|
||||||
|
for (auto const &textureMapItem : _textureMaps) {
|
||||||
|
auto textureMap = textureMapItem.second;
|
||||||
|
if (textureMap) {
|
||||||
|
auto textureSoure = textureMap->getTextureSource();
|
||||||
|
if (textureSoure) {
|
||||||
|
auto texture = textureSoure->getGPUTexture();
|
||||||
|
if (texture) {
|
||||||
|
auto size = texture->getSize();
|
||||||
|
_textureSize += size;
|
||||||
|
_textureCount++;
|
||||||
|
} else {
|
||||||
|
allTextures = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
allTextures = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
allTextures = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_hasCalculatedTextureInfo = allTextures;
|
||||||
|
}
|
||||||
|
return _hasCalculatedTextureInfo;
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#ifndef hifi_model_Material_h
|
#ifndef hifi_model_Material_h
|
||||||
#define hifi_model_Material_h
|
#define hifi_model_Material_h
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
@ -324,7 +326,7 @@ public:
|
||||||
|
|
||||||
// The texture map to channel association
|
// The texture map to channel association
|
||||||
void setTextureMap(MapChannel channel, const TextureMapPointer& textureMap);
|
void setTextureMap(MapChannel channel, const TextureMapPointer& textureMap);
|
||||||
const TextureMaps& getTextureMaps() const { return _textureMaps; }
|
const TextureMaps& getTextureMaps() const { return _textureMaps; } // FIXME - not thread safe...
|
||||||
const TextureMapPointer getTextureMap(MapChannel channel) const;
|
const TextureMapPointer getTextureMap(MapChannel channel) const;
|
||||||
|
|
||||||
// Albedo maps cannot have opacity detected until they are loaded
|
// Albedo maps cannot have opacity detected until they are loaded
|
||||||
|
@ -344,12 +346,25 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
const UniformBufferView& getTexMapArrayBuffer() const { return _texMapArrayBuffer; }
|
const UniformBufferView& getTexMapArrayBuffer() const { return _texMapArrayBuffer; }
|
||||||
|
|
||||||
|
int getTextureCount() const { calculateMaterialInfo(); return _textureCount; }
|
||||||
|
size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; }
|
||||||
|
bool hasTextureInfo() const { return _hasCalculatedTextureInfo; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable MaterialKey _key;
|
mutable MaterialKey _key;
|
||||||
mutable UniformBufferView _schemaBuffer;
|
mutable UniformBufferView _schemaBuffer;
|
||||||
mutable UniformBufferView _texMapArrayBuffer;
|
mutable UniformBufferView _texMapArrayBuffer;
|
||||||
|
|
||||||
TextureMaps _textureMaps;
|
TextureMaps _textureMaps;
|
||||||
|
|
||||||
|
mutable QMutex _textureMapsMutex { QMutex::Recursive };
|
||||||
|
mutable size_t _textureSize { 0 };
|
||||||
|
mutable int _textureCount { 0 };
|
||||||
|
mutable bool _hasCalculatedTextureInfo { false };
|
||||||
|
bool calculateMaterialInfo() const;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr< Material > MaterialPointer;
|
typedef std::shared_ptr< Material > MaterialPointer;
|
||||||
|
|
||||||
|
|
|
@ -71,39 +71,8 @@ void MeshPartPayload::updateTransform(const Transform& transform, const Transfor
|
||||||
|
|
||||||
void MeshPartPayload::updateMaterial(model::MaterialPointer drawMaterial) {
|
void MeshPartPayload::updateMaterial(model::MaterialPointer drawMaterial) {
|
||||||
_drawMaterial = drawMaterial;
|
_drawMaterial = drawMaterial;
|
||||||
calculateMaterialSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
if (textureMap) {
|
|
||||||
auto textureSoure = textureMap->getTextureSource();
|
|
||||||
if (textureSoure) {
|
|
||||||
auto texture = textureSoure->getGPUTexture();
|
|
||||||
if (texture) {
|
|
||||||
//auto storedSize = texture->getStoredSize();
|
|
||||||
auto size = texture->getSize();
|
|
||||||
_materialTextureSize += size;
|
|
||||||
_materialTextureCount++;
|
|
||||||
} else {
|
|
||||||
allTextures = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
allTextures = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
allTextures = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return allTextures;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ItemKey MeshPartPayload::getKey() const {
|
ItemKey MeshPartPayload::getKey() const {
|
||||||
ItemKey::Builder builder;
|
ItemKey::Builder builder;
|
||||||
builder.withTypeShape();
|
builder.withTypeShape();
|
||||||
|
@ -378,7 +347,6 @@ void ModelMeshPartPayload::initCache() {
|
||||||
auto networkMaterial = _model->getGeometry()->getShapeMaterial(_shapeID);
|
auto networkMaterial = _model->getGeometry()->getShapeMaterial(_shapeID);
|
||||||
if (networkMaterial) {
|
if (networkMaterial) {
|
||||||
_drawMaterial = networkMaterial;
|
_drawMaterial = networkMaterial;
|
||||||
calculateMaterialSize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,13 +66,9 @@ public:
|
||||||
bool _hasColorAttrib = false;
|
bool _hasColorAttrib = false;
|
||||||
|
|
||||||
size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; }
|
size_t getVerticesCount() const { return _drawMesh ? _drawMesh->getNumVertices() : 0; }
|
||||||
size_t getMaterialTextureSize() { return _materialTextureSize; }
|
size_t getMaterialTextureSize() { return _drawMaterial ? _drawMaterial->getTextureSize() : 0; }
|
||||||
int getMaterialTextureCount() { return _materialTextureCount; }
|
int getMaterialTextureCount() { return _drawMaterial ? _drawMaterial->getTextureCount() : 0; }
|
||||||
bool calculateMaterialSize();
|
bool hasTextureInfo() const { return _drawMaterial ? _drawMaterial->hasTextureInfo() : false; }
|
||||||
|
|
||||||
protected:
|
|
||||||
size_t _materialTextureSize { 0 };
|
|
||||||
int _materialTextureCount { 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
|
@ -168,10 +168,9 @@ void Model::calculateTextureInfo() {
|
||||||
bool allTexturesLoaded = true;
|
bool allTexturesLoaded = true;
|
||||||
foreach(auto renderItem, _modelMeshRenderItemsSet) {
|
foreach(auto renderItem, _modelMeshRenderItemsSet) {
|
||||||
auto meshPart = renderItem.get();
|
auto meshPart = renderItem.get();
|
||||||
bool allTexturesForThisMesh = meshPart->calculateMaterialSize();
|
|
||||||
allTexturesLoaded = allTexturesLoaded & allTexturesForThisMesh;
|
|
||||||
textureSize += meshPart->getMaterialTextureSize();
|
textureSize += meshPart->getMaterialTextureSize();
|
||||||
textureCount += meshPart->getMaterialTextureCount();
|
textureCount += meshPart->getMaterialTextureCount();
|
||||||
|
allTexturesLoaded = allTexturesLoaded & meshPart->hasTextureInfo();
|
||||||
}
|
}
|
||||||
_renderInfoTextureSize = textureSize;
|
_renderInfoTextureSize = textureSize;
|
||||||
_renderInfoTextureCount = textureCount;
|
_renderInfoTextureCount = textureCount;
|
||||||
|
|
Loading…
Reference in a new issue