mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 11:42:55 +02:00
track texture loading
This commit is contained in:
parent
8d2e81a13b
commit
717da1b6fa
3 changed files with 79 additions and 27 deletions
|
@ -459,6 +459,9 @@ public:
|
||||||
bool needsUpdate() const { return _needsUpdate; }
|
bool needsUpdate() const { return _needsUpdate; }
|
||||||
void setNeedsUpdate(bool needsUpdate) { _needsUpdate = needsUpdate; }
|
void setNeedsUpdate(bool needsUpdate) { _needsUpdate = needsUpdate; }
|
||||||
|
|
||||||
|
void setTexturesLoading(bool value) { _texturesLoading = value; }
|
||||||
|
bool areTexturesLoading() const { return _texturesLoading; }
|
||||||
|
|
||||||
int getTextureCount() const { calculateMaterialInfo(); return _textureCount; }
|
int getTextureCount() const { calculateMaterialInfo(); return _textureCount; }
|
||||||
size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; }
|
size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; }
|
||||||
bool hasTextureInfo() const { return _hasCalculatedTextureInfo; }
|
bool hasTextureInfo() const { return _hasCalculatedTextureInfo; }
|
||||||
|
@ -467,6 +470,7 @@ private:
|
||||||
gpu::BufferView _schemaBuffer;
|
gpu::BufferView _schemaBuffer;
|
||||||
gpu::TextureTablePointer _textureTable { std::make_shared<gpu::TextureTable>() };
|
gpu::TextureTablePointer _textureTable { std::make_shared<gpu::TextureTable>() };
|
||||||
bool _needsUpdate { false };
|
bool _needsUpdate { false };
|
||||||
|
bool _texturesLoading { false };
|
||||||
|
|
||||||
mutable size_t _textureSize { 0 };
|
mutable size_t _textureSize { 0 };
|
||||||
mutable int _textureCount { 0 };
|
mutable int _textureCount { 0 };
|
||||||
|
|
|
@ -347,6 +347,10 @@ void ModelMeshPartPayload::setShapeKey(bool invalidateShapeKey, bool isWireframe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_drawMaterials.needsUpdate()) {
|
||||||
|
RenderPipelines::updateMultiMaterial(_drawMaterials);
|
||||||
|
}
|
||||||
|
|
||||||
graphics::MaterialKey drawMaterialKey = _drawMaterials.getMaterialKey();
|
graphics::MaterialKey drawMaterialKey = _drawMaterials.getMaterialKey();
|
||||||
|
|
||||||
bool isTranslucent = drawMaterialKey.isTranslucent();
|
bool isTranslucent = drawMaterialKey.isTranslucent();
|
||||||
|
|
|
@ -376,7 +376,6 @@ void initZPassPipelines(ShapePlumber& shapePlumber, gpu::StatePointer state, con
|
||||||
void RenderPipelines::bindMaterial(graphics::MaterialPointer& material, gpu::Batch& batch, bool enableTextures) {
|
void RenderPipelines::bindMaterial(graphics::MaterialPointer& material, gpu::Batch& batch, bool enableTextures) {
|
||||||
graphics::MultiMaterial multiMaterial;
|
graphics::MultiMaterial multiMaterial;
|
||||||
multiMaterial.push(graphics::MaterialLayer(material, 0));
|
multiMaterial.push(graphics::MaterialLayer(material, 0));
|
||||||
updateMultiMaterial(multiMaterial);
|
|
||||||
bindMaterials(multiMaterial, batch, enableTextures);
|
bindMaterials(multiMaterial, batch, enableTextures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,13 +387,13 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
|
||||||
auto& drawMaterialTextures = multiMaterial.getTextureTable();
|
auto& drawMaterialTextures = multiMaterial.getTextureTable();
|
||||||
|
multiMaterial.setTexturesLoading(false);
|
||||||
|
|
||||||
// The total list of things we need to look for
|
// The total list of things we need to look for
|
||||||
static std::set<uint> allFlags;
|
static std::set<uint> allFlags;
|
||||||
static std::once_flag once;
|
static std::once_flag once;
|
||||||
std::call_once(once, [textureCache] {
|
std::call_once(once, [] {
|
||||||
for (int i = 0; i < graphics::Material::NUM_TOTAL_FLAGS; i++) {
|
for (int i = 0; i < graphics::Material::NUM_TOTAL_FLAGS; i++) {
|
||||||
// The opacity mask/map are derived from the albedo map
|
// The opacity mask/map are derived from the albedo map
|
||||||
if (i != graphics::MaterialKey::OPACITY_MASK_MAP_BIT &&
|
if (i != graphics::MaterialKey::OPACITY_MASK_MAP_BIT &&
|
||||||
|
@ -481,9 +480,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::ALBEDO_MAP_BIT:
|
case graphics::MaterialKey::ALBEDO_MAP_BIT:
|
||||||
if (materialKey.isAlbedoMap()) {
|
if (materialKey.isAlbedoMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::ALBEDO_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::ALBEDO_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialAlbedo, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialAlbedo, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -495,9 +499,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::METALLIC_MAP_BIT:
|
case graphics::MaterialKey::METALLIC_MAP_BIT:
|
||||||
if (materialKey.isMetallicMap()) {
|
if (materialKey.isMetallicMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::METALLIC_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::METALLIC_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialMetallic, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialMetallic, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -507,9 +516,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::ROUGHNESS_MAP_BIT:
|
case graphics::MaterialKey::ROUGHNESS_MAP_BIT:
|
||||||
if (materialKey.isRoughnessMap()) {
|
if (materialKey.isRoughnessMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::ROUGHNESS_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::ROUGHNESS_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialRoughness, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialRoughness, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -519,9 +533,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::NORMAL_MAP_BIT:
|
case graphics::MaterialKey::NORMAL_MAP_BIT:
|
||||||
if (materialKey.isNormalMap()) {
|
if (materialKey.isNormalMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::NORMAL_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::NORMAL_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialNormal, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialNormal, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -531,9 +550,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::OCCLUSION_MAP_BIT:
|
case graphics::MaterialKey::OCCLUSION_MAP_BIT:
|
||||||
if (materialKey.isOcclusionMap()) {
|
if (materialKey.isOcclusionMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::OCCLUSION_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::OCCLUSION_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialOcclusion, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialOcclusion, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -543,9 +567,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::SCATTERING_MAP_BIT:
|
case graphics::MaterialKey::SCATTERING_MAP_BIT:
|
||||||
if (materialKey.isScatteringMap()) {
|
if (materialKey.isScatteringMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::SCATTERING_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::SCATTERING_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialScattering, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialScattering, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -556,9 +585,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
// Lightmap takes precendence over emissive map for legacy reasons
|
// Lightmap takes precendence over emissive map for legacy reasons
|
||||||
if (materialKey.isEmissiveMap() && !materialKey.isLightmapMap()) {
|
if (materialKey.isEmissiveMap() && !materialKey.isLightmapMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::EMISSIVE_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::EMISSIVE_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialEmissiveLightmap, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialEmissiveLightmap, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -571,9 +605,14 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
case graphics::MaterialKey::LIGHTMAP_MAP_BIT:
|
case graphics::MaterialKey::LIGHTMAP_MAP_BIT:
|
||||||
if (materialKey.isLightmapMap()) {
|
if (materialKey.isLightmapMap()) {
|
||||||
auto itr = textureMaps.find(graphics::MaterialKey::LIGHTMAP_MAP);
|
auto itr = textureMaps.find(graphics::MaterialKey::LIGHTMAP_MAP);
|
||||||
if (itr != textureMaps.end() && itr->second->isDefined()) {
|
if (itr != textureMaps.end()) {
|
||||||
drawMaterialTextures->setTexture(gr::Texture::MaterialEmissiveLightmap, itr->second->getTextureView());
|
if (itr->second->isDefined()) {
|
||||||
wasSet = true;
|
drawMaterialTextures->setTexture(gr::Texture::MaterialEmissiveLightmap, itr->second->getTextureView());
|
||||||
|
wasSet = true;
|
||||||
|
} else {
|
||||||
|
multiMaterial.setTexturesLoading(true);
|
||||||
|
forceDefault = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
forceDefault = true;
|
forceDefault = true;
|
||||||
}
|
}
|
||||||
|
@ -627,6 +666,7 @@ void RenderPipelines::updateMultiMaterial(graphics::MultiMaterial& multiMaterial
|
||||||
flagsToSetDefault.insert(flagBit);
|
flagsToSetDefault.insert(flagBit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
// Handle defaults
|
// Handle defaults
|
||||||
for (auto flag : flagsToSetDefault) {
|
for (auto flag : flagsToSetDefault) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
|
@ -698,6 +738,10 @@ void RenderPipelines::bindMaterials(graphics::MultiMaterial& multiMaterial, gpu:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (multiMaterial.needsUpdate() || multiMaterial.areTexturesLoading()) {
|
||||||
|
updateMultiMaterial(multiMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
|
|
||||||
static gpu::TextureTablePointer defaultMaterialTextures = std::make_shared<gpu::TextureTable>();
|
static gpu::TextureTablePointer defaultMaterialTextures = std::make_shared<gpu::TextureTable>();
|
||||||
|
|
Loading…
Reference in a new issue