mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +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;
|
||||
}
|
||||
|
||||
_isCacheable = true;
|
||||
finishedLoading(true);
|
||||
|
||||
emit networkTextureCreated(qWeakPointerCast<NetworkTexture, Resource> (_self));
|
||||
|
|
|
@ -132,6 +132,8 @@ signals:
|
|||
|
||||
protected:
|
||||
|
||||
virtual bool isCacheable() const override { return _isCacheable; }
|
||||
|
||||
virtual void downloadFinished(const QByteArray& data) override;
|
||||
|
||||
Q_INVOKABLE void loadContent(const QByteArray& content);
|
||||
|
@ -146,6 +148,7 @@ private:
|
|||
int _originalHeight { 0 };
|
||||
int _width { 0 };
|
||||
int _height { 0 };
|
||||
bool _isCacheable { false };
|
||||
};
|
||||
|
||||
#endif // hifi_TextureCache_h
|
||||
|
|
|
@ -278,20 +278,20 @@ void Resource::refresh() {
|
|||
}
|
||||
|
||||
void Resource::allReferencesCleared() {
|
||||
if (_cache) {
|
||||
if (_cache && isCacheable()) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "allReferencesCleared");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// create and reinsert new shared pointer
|
||||
QSharedPointer<Resource> self(this, &Resource::allReferencesCleared);
|
||||
setSelf(self);
|
||||
reinsert();
|
||||
|
||||
|
||||
// add to the unused list
|
||||
_cache->addUnusedResource(self);
|
||||
|
||||
|
||||
} else {
|
||||
delete this;
|
||||
}
|
||||
|
|
|
@ -192,6 +192,9 @@ protected slots:
|
|||
protected:
|
||||
virtual void init();
|
||||
|
||||
/// Checks whether the resource is cacheable.
|
||||
virtual bool isCacheable() const { return true; }
|
||||
|
||||
/// Called when the download has finished
|
||||
virtual void downloadFinished(const QByteArray& data);
|
||||
|
||||
|
|
Loading…
Reference in a new issue