mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 22:43:50 +02:00
Add prefetch overload for texture specificity
This commit is contained in:
parent
c096b0dfa1
commit
df4857947b
4 changed files with 22 additions and 5 deletions
|
@ -35,6 +35,12 @@ TextureCache::TextureCache() {
|
|||
const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE;
|
||||
setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE);
|
||||
setObjectName("TextureCache");
|
||||
|
||||
// Expose enum Type to JS/QML via properties
|
||||
auto metaEnum = QMetaEnum::fromType<Type>();
|
||||
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
||||
setProperty(metaEnum.key(i), metaEnum.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
TextureCache::~TextureCache() {
|
||||
|
@ -149,6 +155,12 @@ public:
|
|||
const QByteArray& content;
|
||||
};
|
||||
|
||||
ScriptableResource* TextureCache::prefetch(const QUrl& url, int type) {
|
||||
auto byteArray = QByteArray();
|
||||
TextureExtra extra = { (Type)type, byteArray };
|
||||
return ResourceCache::prefetch(url, &extra);
|
||||
}
|
||||
|
||||
NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) {
|
||||
TextureExtra extra = { type, content };
|
||||
return ResourceCache::getResource(url, QUrl(), content.isEmpty(), &extra).staticCast<NetworkTexture>();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QImage>
|
||||
#include <QMap>
|
||||
#include <QColor>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include <ResourceCache.h>
|
||||
|
@ -34,7 +35,6 @@ public:
|
|||
};
|
||||
|
||||
/// A texture loaded from the network.
|
||||
|
||||
class NetworkTexture : public Resource, public Texture {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -98,8 +98,11 @@ class TextureCache : public ResourceCache, public Dependency {
|
|||
SINGLETON_DEPENDENCY
|
||||
|
||||
using Type = NetworkTexture::Type;
|
||||
|
||||
|
||||
public:
|
||||
// Overload ResourceCache::prefetch to allow specifying texture type for loads
|
||||
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type);
|
||||
|
||||
/// Returns the ID of the permutation/normal texture used for Perlin noise shader programs. This texture
|
||||
/// has two lines: the first, a set of random numbers in [0, 255] to be used as permutation offsets, and
|
||||
/// the second, a set of random unit vectors to be used as noise gradients.
|
||||
|
|
|
@ -140,7 +140,7 @@ void ScriptableResource::finished(bool success) {
|
|||
emit loadedChanged(_isLoaded);
|
||||
}
|
||||
|
||||
ScriptableResource* ResourceCache::prefetch(const QUrl& url) {
|
||||
ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) {
|
||||
auto result = new ScriptableResource();
|
||||
|
||||
if (QThread::currentThread() != thread()) {
|
||||
|
@ -151,7 +151,7 @@ ScriptableResource* ResourceCache::prefetch(const QUrl& url) {
|
|||
}
|
||||
|
||||
|
||||
auto resource = getResource(url);
|
||||
auto resource = getResource(url, QUrl(), false, extra);
|
||||
result->_resource = resource;
|
||||
result->setObjectName(url.toString());
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
Q_INVOKABLE QVariantList getResourceList();
|
||||
|
||||
// This must be exposed as a ptr so the ScriptEngine may take ownership
|
||||
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url);
|
||||
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); }
|
||||
|
||||
static void setRequestLimit(int limit);
|
||||
static int getRequestLimit() { return _requestLimit; }
|
||||
|
@ -164,6 +164,8 @@ private slots:
|
|||
void clearATPAssets();
|
||||
|
||||
protected:
|
||||
ScriptableResource* prefetch(const QUrl& url, void* extra);
|
||||
|
||||
/// Loads a resource from the specified URL.
|
||||
/// \param fallback a fallback URL to load if the desired one is unavailable
|
||||
/// \param delayLoad if true, don't load the resource immediately; wait until load is first requested
|
||||
|
|
Loading…
Reference in a new issue