WE DID IT FOLKS

This commit is contained in:
SamGondelman 2019-02-19 15:02:36 -08:00
parent 2986ca20c5
commit 44e70db4cd
7 changed files with 39 additions and 19 deletions

View file

@ -354,7 +354,8 @@ NetworkTexture::NetworkTexture(const NetworkTexture& other) :
_originalHeight(other._originalHeight),
_width(other._width),
_height(other._height),
_maxNumPixels(other._maxNumPixels)
_maxNumPixels(other._maxNumPixels),
_content(other._content)
{
if (_width == 0 || _height == 0 ||
other._currentlyLoadingResourceType == ResourceType::META ||
@ -368,17 +369,30 @@ static bool isLocalUrl(const QUrl& url) {
return (scheme == HIFI_URL_SCHEME_FILE || scheme == URL_SCHEME_QRC || scheme == RESOURCE_SCHEME);
}
void NetworkTexture::setExtra(void* extra, bool isNewExtra) {
void NetworkTexture::setExtra(void* extra) {
const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra);
_type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE;
_maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS;
_sourceChannel = textureExtra ? textureExtra->sourceChannel : image::ColorChannel::NONE;
if (isNewExtra && !_loaded) {
bool needsNewTextureSource = false;
auto type = textureExtra ? textureExtra->type : image::TextureUsage::DEFAULT_TEXTURE;
auto sourceChannel = textureExtra ? textureExtra->sourceChannel : image::ColorChannel::NONE;
if (type != _type || sourceChannel != _sourceChannel) {
needsNewTextureSource = true;
}
_type = type;
_sourceChannel = sourceChannel;
auto content = textureExtra ? textureExtra->content : QByteArray();
if (_content.isEmpty() && !content.isEmpty()) {
_content = content;
needsNewTextureSource = true;
}
if (needsNewTextureSource) {
_startedLoading = false;
}
if (!_textureSource || isNewExtra) {
if (!_textureSource || needsNewTextureSource) {
_textureSource = std::make_shared<gpu::TextureSource>(_url, (int)_type);
}
_lowestRequestedMipLevel = 0;
@ -405,10 +419,9 @@ void NetworkTexture::setExtra(void* extra, bool isNewExtra) {
}
// if we have content, load it after we have our self pointer
auto content = textureExtra ? textureExtra->content : QByteArray();
if (!content.isEmpty()) {
if (!_content.isEmpty()) {
_startedLoading = true;
QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(const QByteArray&, content));
QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(const QByteArray&, _content));
}
}

View file

@ -64,7 +64,7 @@ public:
Q_INVOKABLE void setOriginalDescriptor(ktx::KTXDescriptor* descriptor) { _originalKtxDescriptor.reset(descriptor); }
void setExtra(void* extra, bool isNewExtra) override;
void setExtra(void* extra) override;
signals:
void networkTextureCreated(const QWeakPointer<NetworkTexture>& self);
@ -136,12 +136,12 @@ private:
// mip offsets to change.
ktx::KTXDescriptorPointer _originalKtxDescriptor;
int _originalWidth { 0 };
int _originalHeight { 0 };
int _width { 0 };
int _height { 0 };
int _maxNumPixels { ABSOLUTE_MAX_TEXTURE_NUM_PIXELS };
QByteArray _content;
friend class TextureCache;
};

View file

@ -309,7 +309,7 @@ public:
virtual void downloadFinished(const QByteArray& data) override;
void setExtra(void* extra, bool isNewExtra) override;
void setExtra(void* extra) override;
protected:
Q_INVOKABLE void setGeometryDefinition(HFMModel::Pointer hfmModel, QVariantHash mapping);
@ -320,7 +320,7 @@ private:
bool _combineParts;
};
void GeometryDefinitionResource::setExtra(void* extra, bool isNewExtra) {
void GeometryDefinitionResource::setExtra(void* extra) {
const GeometryExtra* geometryExtra = static_cast<const GeometryExtra*>(extra);
_mapping = geometryExtra ? geometryExtra->mapping : QVariantHash();
_textureBaseUrl = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl();

View file

@ -355,7 +355,7 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
} else if (resourcesWithExtraHash.size() > 0.0f) {
// We haven't seen this extra info before, but we've already downloaded the resource. We need a new copy of this object (with any old hash).
resource = createResourceCopy(resourcesWithExtraHash.begin().value().lock());
resource->setExtra(extra, true);
resource->setExtra(extra);
resource->setExtraHash(extraHash);
resource->setSelf(resource);
resource->setCache(this);
@ -375,7 +375,7 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
if (!resource) {
resource = createResource(url);
resource->setExtra(extra, false);
resource->setExtra(extra);
resource->setExtraHash(extraHash);
resource->setSelf(resource);
resource->setCache(this);

View file

@ -417,7 +417,7 @@ public:
unsigned int getDownloadAttempts() { return _attempts; }
unsigned int getDownloadAttemptsRemaining() { return _attemptsRemaining; }
virtual void setExtra(void* extra, bool isNewExtra) {};
virtual void setExtra(void* extra) {};
void setExtraHash(size_t extraHash) { _extraHash = extraHash; }
size_t getExtraHash() const { return _extraHash; }

View file

@ -1269,7 +1269,14 @@ QVariantMap parseTexturesToMap(QString newTextures, const QVariantMap& defaultTe
QVariantMap newTexturesMap = newTexturesJson.toVariant().toMap();
QVariantMap toReturn = defaultTextures;
for (auto& texture : newTexturesMap.keys()) {
toReturn[texture] = newTexturesMap[texture];
auto newURL = newTexturesMap[texture];
if (newURL.canConvert<QUrl>()) {
toReturn[texture] = newURL.toUrl();
} else if (newURL.canConvert<QString>()) {
toReturn[texture] = QUrl(newURL.toString());
} else {
toReturn[texture] = newURL;
}
}
return toReturn;

View file

@ -26,10 +26,10 @@ QScriptValue variantToScriptValue(QVariant& qValue, QScriptEngine& scriptEngine)
case QVariant::Double:
return qValue.toDouble();
break;
case QVariant::String: {
case QVariant::String:
case QVariant::Url:
return scriptEngine.newVariant(qValue);
break;
}
case QVariant::Map: {
QVariantMap childMap = qValue.toMap();
return variantMapToScriptValue(childMap, scriptEngine);