mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
Merge pull request #7282 from zzmp/fix/tex-cache
Avoid caching textures before they load
This commit is contained in:
commit
a2eb819bc2
4 changed files with 11 additions and 4 deletions
|
@ -344,6 +344,7 @@ void NetworkTexture::setImage(const QImage& image, void* voidTexture, int origin
|
||||||
_width = _height = 0;
|
_width = _height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isCacheable = true;
|
||||||
finishedLoading(true);
|
finishedLoading(true);
|
||||||
|
|
||||||
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));
|
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));
|
||||||
|
|
|
@ -132,6 +132,8 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
virtual bool isCacheable() const override { return _isCacheable; }
|
||||||
|
|
||||||
virtual void downloadFinished(const QByteArray& data) override;
|
virtual void downloadFinished(const QByteArray& data) override;
|
||||||
|
|
||||||
Q_INVOKABLE void loadContent(const QByteArray& content);
|
Q_INVOKABLE void loadContent(const QByteArray& content);
|
||||||
|
@ -146,6 +148,7 @@ private:
|
||||||
int _originalHeight { 0 };
|
int _originalHeight { 0 };
|
||||||
int _width { 0 };
|
int _width { 0 };
|
||||||
int _height { 0 };
|
int _height { 0 };
|
||||||
|
bool _isCacheable { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_TextureCache_h
|
#endif // hifi_TextureCache_h
|
||||||
|
|
|
@ -278,20 +278,20 @@ void Resource::refresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::allReferencesCleared() {
|
void Resource::allReferencesCleared() {
|
||||||
if (_cache) {
|
if (_cache && isCacheable()) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "allReferencesCleared");
|
QMetaObject::invokeMethod(this, "allReferencesCleared");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create and reinsert new shared pointer
|
// create and reinsert new shared pointer
|
||||||
QSharedPointer<Resource> self(this, &Resource::allReferencesCleared);
|
QSharedPointer<Resource> self(this, &Resource::allReferencesCleared);
|
||||||
setSelf(self);
|
setSelf(self);
|
||||||
reinsert();
|
reinsert();
|
||||||
|
|
||||||
// add to the unused list
|
// add to the unused list
|
||||||
_cache->addUnusedResource(self);
|
_cache->addUnusedResource(self);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,9 @@ protected slots:
|
||||||
protected:
|
protected:
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
|
/// Checks whether the resource is cacheable.
|
||||||
|
virtual bool isCacheable() const { return true; }
|
||||||
|
|
||||||
/// Called when the download has finished
|
/// Called when the download has finished
|
||||||
virtual void downloadFinished(const QByteArray& data);
|
virtual void downloadFinished(const QByteArray& data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue