mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:37:49 +02:00
Merge pull request #10364 from huffman/fix/ktx-skybox-loading
Fix progressive loading of KTX skybox textures
This commit is contained in:
commit
479e810173
5 changed files with 47 additions and 9 deletions
|
@ -174,7 +174,7 @@ namespace ktx {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<KTX> KTX::create(const StoragePointer& src) {
|
std::unique_ptr<KTX> KTX::create(const StoragePointer& src) {
|
||||||
if (!src) {
|
if (!src || !(*src)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -421,7 +421,7 @@ void NetworkTexture::startRequestForNextMipLevel() {
|
||||||
|
|
||||||
_ktxResourceState = PENDING_MIP_REQUEST;
|
_ktxResourceState = PENDING_MIP_REQUEST;
|
||||||
|
|
||||||
init();
|
init(false);
|
||||||
float priority = -(float)_originalKtxDescriptor->header.numberOfMipmapLevels + (float)_lowestKnownPopulatedMip;
|
float priority = -(float)_originalKtxDescriptor->header.numberOfMipmapLevels + (float)_lowestKnownPopulatedMip;
|
||||||
setLoadPriority(this, priority);
|
setLoadPriority(this, priority);
|
||||||
_url.setFragment(QString::number(_lowestKnownPopulatedMip - 1));
|
_url.setFragment(QString::number(_lowestKnownPopulatedMip - 1));
|
||||||
|
@ -472,6 +472,10 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
|
||||||
void NetworkTexture::ktxHeaderRequestFinished() {
|
void NetworkTexture::ktxHeaderRequestFinished() {
|
||||||
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA);
|
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA);
|
||||||
|
|
||||||
|
if (!_ktxHeaderRequest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_ktxHeaderRequestFinished = true;
|
_ktxHeaderRequestFinished = true;
|
||||||
maybeHandleFinishedInitialLoad();
|
maybeHandleFinishedInitialLoad();
|
||||||
}
|
}
|
||||||
|
@ -479,6 +483,10 @@ void NetworkTexture::ktxHeaderRequestFinished() {
|
||||||
void NetworkTexture::ktxMipRequestFinished() {
|
void NetworkTexture::ktxMipRequestFinished() {
|
||||||
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA || _ktxResourceState == REQUESTING_MIP);
|
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA || _ktxResourceState == REQUESTING_MIP);
|
||||||
|
|
||||||
|
if (!_ktxMipRequest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_ktxResourceState == LOADING_INITIAL_DATA) {
|
if (_ktxResourceState == LOADING_INITIAL_DATA) {
|
||||||
_ktxHighMipRequestFinished = true;
|
_ktxHighMipRequestFinished = true;
|
||||||
maybeHandleFinishedInitialLoad();
|
maybeHandleFinishedInitialLoad();
|
||||||
|
@ -682,6 +690,27 @@ void NetworkTexture::loadContent(const QByteArray& content) {
|
||||||
QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _maxNumPixels));
|
QThreadPool::globalInstance()->start(new ImageReader(_self, _url, content, _maxNumPixels));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkTexture::refresh() {
|
||||||
|
if ((_ktxHeaderRequest || _ktxMipRequest) && !_loaded && !_failedToLoad) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_ktxHeaderRequest || _ktxMipRequest) {
|
||||||
|
if (_ktxHeaderRequest) {
|
||||||
|
_ktxHeaderRequest->disconnect(this);
|
||||||
|
_ktxHeaderRequest->deleteLater();
|
||||||
|
_ktxHeaderRequest = nullptr;
|
||||||
|
}
|
||||||
|
if (_ktxMipRequest) {
|
||||||
|
_ktxMipRequest->disconnect(this);
|
||||||
|
_ktxMipRequest->deleteLater();
|
||||||
|
_ktxMipRequest = nullptr;
|
||||||
|
}
|
||||||
|
TextureCache::requestCompleted(_self);
|
||||||
|
}
|
||||||
|
|
||||||
|
Resource::refresh();
|
||||||
|
}
|
||||||
|
|
||||||
ImageReader::ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url, const QByteArray& data, int maxNumPixels) :
|
ImageReader::ImageReader(const QWeakPointer<Resource>& resource, const QUrl& url, const QByteArray& data, int maxNumPixels) :
|
||||||
_resource(resource),
|
_resource(resource),
|
||||||
_url(url),
|
_url(url),
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
|
|
||||||
gpu::TexturePointer getFallbackTexture() const;
|
gpu::TexturePointer getFallbackTexture() const;
|
||||||
|
|
||||||
|
void refresh() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void networkTextureCreated(const QWeakPointer<NetworkTexture>& self);
|
void networkTextureCreated(const QWeakPointer<NetworkTexture>& self);
|
||||||
|
|
||||||
|
|
|
@ -533,13 +533,13 @@ void Resource::ensureLoading() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::setLoadPriority(const QPointer<QObject>& owner, float priority) {
|
void Resource::setLoadPriority(const QPointer<QObject>& owner, float priority) {
|
||||||
if (!(_failedToLoad || _loaded)) {
|
if (!(_failedToLoad)) {
|
||||||
_loadPriorities.insert(owner, priority);
|
_loadPriorities.insert(owner, priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::setLoadPriorities(const QHash<QPointer<QObject>, float>& priorities) {
|
void Resource::setLoadPriorities(const QHash<QPointer<QObject>, float>& priorities) {
|
||||||
if (_failedToLoad || _loaded) {
|
if (_failedToLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (QHash<QPointer<QObject>, float>::const_iterator it = priorities.constBegin();
|
for (QHash<QPointer<QObject>, float>::const_iterator it = priorities.constBegin();
|
||||||
|
@ -549,7 +549,7 @@ void Resource::setLoadPriorities(const QHash<QPointer<QObject>, float>& prioriti
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::clearLoadPriority(const QPointer<QObject>& owner) {
|
void Resource::clearLoadPriority(const QPointer<QObject>& owner) {
|
||||||
if (!(_failedToLoad || _loaded)) {
|
if (!(_failedToLoad)) {
|
||||||
_loadPriorities.remove(owner);
|
_loadPriorities.remove(owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,10 +612,12 @@ void Resource::allReferencesCleared() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::init() {
|
void Resource::init(bool resetLoaded) {
|
||||||
_startedLoading = false;
|
_startedLoading = false;
|
||||||
_failedToLoad = false;
|
_failedToLoad = false;
|
||||||
_loaded = false;
|
if (resetLoaded) {
|
||||||
|
_loaded = false;
|
||||||
|
}
|
||||||
_attempts = 0;
|
_attempts = 0;
|
||||||
_activeUrl = _url;
|
_activeUrl = _url;
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ public:
|
||||||
float getProgress() const { return (_bytesTotal <= 0) ? 0.0f : (float)_bytesReceived / _bytesTotal; }
|
float getProgress() const { return (_bytesTotal <= 0) ? 0.0f : (float)_bytesReceived / _bytesTotal; }
|
||||||
|
|
||||||
/// Refreshes the resource.
|
/// Refreshes the resource.
|
||||||
void refresh();
|
virtual void refresh();
|
||||||
|
|
||||||
void setSelf(const QWeakPointer<Resource>& self) { _self = self; }
|
void setSelf(const QWeakPointer<Resource>& self) { _self = self; }
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ protected slots:
|
||||||
void attemptRequest();
|
void attemptRequest();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void init();
|
virtual void init(bool resetLoaded = true);
|
||||||
|
|
||||||
/// Called by ResourceCache to begin loading this Resource.
|
/// Called by ResourceCache to begin loading this Resource.
|
||||||
/// This method can be overriden to provide custom request functionality. If this is done,
|
/// This method can be overriden to provide custom request functionality. If this is done,
|
||||||
|
@ -454,9 +454,14 @@ protected:
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
QUrl _activeUrl;
|
QUrl _activeUrl;
|
||||||
ByteRange _requestByteRange;
|
ByteRange _requestByteRange;
|
||||||
|
|
||||||
|
// _loaded == true means we are in a loaded and usable state. It is possible that there may still be
|
||||||
|
// active requests/loading while in this state. Example: Progressive KTX downloads, where higher resolution
|
||||||
|
// mips are being download.
|
||||||
bool _startedLoading = false;
|
bool _startedLoading = false;
|
||||||
bool _failedToLoad = false;
|
bool _failedToLoad = false;
|
||||||
bool _loaded = false;
|
bool _loaded = false;
|
||||||
|
|
||||||
QHash<QPointer<QObject>, float> _loadPriorities;
|
QHash<QPointer<QObject>, float> _loadPriorities;
|
||||||
QWeakPointer<Resource> _self;
|
QWeakPointer<Resource> _self;
|
||||||
QPointer<ResourceCache> _cache;
|
QPointer<ResourceCache> _cache;
|
||||||
|
|
Loading…
Reference in a new issue