mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:36:47 +02:00
Release px resources when unused
This commit is contained in:
parent
0e9b783ca3
commit
eb2e254aa6
1 changed files with 19 additions and 11 deletions
|
@ -96,6 +96,7 @@ bool Procedural::parseVersion(const QJsonValue& version) {
|
||||||
bool Procedural::parseUrl(const QUrl& shaderUrl) {
|
bool Procedural::parseUrl(const QUrl& shaderUrl) {
|
||||||
if (!shaderUrl.isValid()) {
|
if (!shaderUrl.isValid()) {
|
||||||
qWarning() << "Invalid shader URL: " << shaderUrl;
|
qWarning() << "Invalid shader URL: " << shaderUrl;
|
||||||
|
_networkShader.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ bool Procedural::parseUrl(const QUrl& shaderUrl) {
|
||||||
_shaderPath = _shaderUrl.toLocalFile();
|
_shaderPath = _shaderUrl.toLocalFile();
|
||||||
qDebug() << "Shader path: " << _shaderPath;
|
qDebug() << "Shader path: " << _shaderPath;
|
||||||
if (!QFile(_shaderPath).exists()) {
|
if (!QFile(_shaderPath).exists()) {
|
||||||
|
_networkShader.reset();
|
||||||
return false;;
|
return false;;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -135,9 +137,14 @@ bool Procedural::parseTextures(const QJsonArray& channels) {
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size());
|
size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size());
|
||||||
for (size_t i = 0; i < channelCount; ++i) {
|
size_t channel = 0;
|
||||||
QString url = _parsedChannels.at((int)i).toString();
|
for (; channel < channelCount; ++channel) {
|
||||||
_channels[i] = textureCache->getTexture(QUrl(url));
|
QString url = _parsedChannels.at((int)channel).toString();
|
||||||
|
_channels[channel] = textureCache->getTexture(QUrl(url));
|
||||||
|
}
|
||||||
|
for (; channel < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++channel) {
|
||||||
|
// Release those textures no longer in use
|
||||||
|
_channels[channel] = textureCache->getTexture(QUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
_channelsDirty = true;
|
_channelsDirty = true;
|
||||||
|
@ -149,20 +156,21 @@ bool Procedural::parseTextures(const QJsonArray& channels) {
|
||||||
void Procedural::parse(const QJsonObject& proceduralData) {
|
void Procedural::parse(const QJsonObject& proceduralData) {
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
|
|
||||||
if (proceduralData.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto version = proceduralData[VERSION_KEY];
|
auto version = proceduralData[VERSION_KEY];
|
||||||
auto shaderUrl = proceduralData[URL_KEY].toString();
|
auto shaderUrl = proceduralData[URL_KEY].toString();
|
||||||
shaderUrl = ResourceManager::normalizeURL(shaderUrl);
|
shaderUrl = ResourceManager::normalizeURL(shaderUrl);
|
||||||
auto uniforms = proceduralData[UNIFORMS_KEY].toObject();
|
auto uniforms = proceduralData[UNIFORMS_KEY].toObject();
|
||||||
auto channels = proceduralData[CHANNELS_KEY].toArray();
|
auto channels = proceduralData[CHANNELS_KEY].toArray();
|
||||||
|
|
||||||
if (parseVersion(version) &&
|
bool isValid = true;
|
||||||
parseUrl(shaderUrl) &&
|
|
||||||
parseUniforms(uniforms) &&
|
// Run through parsing regardless of validity to clear old cached resources
|
||||||
parseTextures(channels)) {
|
isValid = parseVersion(version) && isValid;
|
||||||
|
isValid = parseUrl(shaderUrl) && isValid;
|
||||||
|
isValid = parseUniforms(uniforms) && isValid;
|
||||||
|
isValid = parseTextures(channels) && isValid;
|
||||||
|
|
||||||
|
if (!proceduralData.isEmpty() && isValid) {
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue