Update Geometry and Texture caches to use updated ResourceCache

This commit is contained in:
Ryan Huffman 2015-08-03 16:26:51 -07:00
parent ccc0000fd0
commit 3a2ef35a3b
4 changed files with 35 additions and 39 deletions

View file

@ -2030,7 +2030,7 @@ class GeometryReader : public QRunnable {
public:
GeometryReader(const QWeakPointer<Resource>& geometry, const QUrl& url,
QNetworkReply* reply, const QVariantHash& mapping);
QByteArray data, const QVariantHash& mapping);
virtual void run();
@ -2038,28 +2038,25 @@ private:
QWeakPointer<Resource> _geometry;
QUrl _url;
QNetworkReply* _reply;
QByteArray _data;
QVariantHash _mapping;
};
GeometryReader::GeometryReader(const QWeakPointer<Resource>& geometry, const QUrl& url,
QNetworkReply* reply, const QVariantHash& mapping) :
QByteArray data, const QVariantHash& mapping) :
_geometry(geometry),
_url(url),
_reply(reply),
_data(data),
_mapping(mapping) {
}
void GeometryReader::run() {
QSharedPointer<Resource> geometry = _geometry.toStrongRef();
if (geometry.isNull()) {
_reply->deleteLater();
// _reply->deleteLater();
return;
}
try {
if (!_reply) {
throw QString("Reply is NULL ?!");
}
QString urlname = _url.path().toLower();
bool urlValid = true;
urlValid &= !urlname.isEmpty();
@ -2082,9 +2079,11 @@ void GeometryReader::run() {
} else if (_url.path().toLower().endsWith("palaceoforinthilian4.fbx")) {
lightmapLevel = 3.5f;
}
fbxgeo = readFBX(_reply, _mapping, grabLightmaps, lightmapLevel);
fbxgeo = readFBX(_data, _mapping, grabLightmaps, lightmapLevel);
} else if (_url.path().toLower().endsWith(".obj")) {
fbxgeo = OBJReader().readOBJ(_reply, _mapping, &_url);
auto d = QByteArray(_data);
QBuffer buffer { &d };
fbxgeo = OBJReader().readOBJ(&buffer, _mapping, &_url);
}
QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));
} else {
@ -2095,7 +2094,6 @@ void GeometryReader::run() {
qCDebug(renderutils) << "Error reading " << _url << ": " << error;
QMetaObject::invokeMethod(geometry.data(), "finishedLoading", Q_ARG(bool, false));
}
_reply->deleteLater();
}
void NetworkGeometry::init() {
@ -2104,16 +2102,15 @@ void NetworkGeometry::init() {
_meshes.clear();
_lods.clear();
_pendingTextureChanges.clear();
_request.setUrl(_url);
//_request.setUrl(_url);
Resource::init();
}
void NetworkGeometry::downloadFinished(QNetworkReply* reply) {
QUrl url = reply->url();
void NetworkGeometry::downloadFinished(const QByteArray& data) {
QUrl url = getURL();
if (url.path().toLower().endsWith(".fst")) {
// it's a mapping file; parse it and get the mesh filename
_mapping = FSTReader::readMapping(reply->readAll());
reply->deleteLater();
_mapping = FSTReader::readMapping(data);
QString filename = _mapping.value("filename").toString();
if (filename.isNull()) {
qCDebug(renderutils) << "Mapping file " << url << " has no filename.";
@ -2135,19 +2132,28 @@ void NetworkGeometry::downloadFinished(QNetworkReply* reply) {
geometry->setLODParent(_lodParent);
_lods.insert(it.value().toFloat(), geometry);
}
_request.setUrl(url.resolved(filename));
// make the request immediately only if we have no LODs to switch between
// TODO reimplement using ResourceRequest
_url = url.resolved(filename);
_startedLoading = false;
if (_lods.isEmpty()) {
attemptRequest();
}
// _request.setUrl(url.resolved(filename));
// make the request immediately only if we have no LODs to switch between
// _startedLoading = false;
// if (_lods.isEmpty()) {
// attemptRequest();
// }
}
return;
}
// send the reader off to the thread pool
QThreadPool::globalInstance()->start(new GeometryReader(_self, url, reply, _mapping));
QThreadPool::globalInstance()->start(new GeometryReader(_self, url, data, _mapping));
}
void NetworkGeometry::reinsert() {

View file

@ -380,7 +380,7 @@ public:
protected:
virtual void init();
virtual void downloadFinished(QNetworkReply* reply);
virtual void downloadFinished(const QByteArray& reply) override;
virtual void reinsert();
Q_INVOKABLE void setGeometry(const FBXGeometry& geometry);

View file

@ -206,8 +206,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr
class ImageReader : public QRunnable {
public:
ImageReader(const QWeakPointer<Resource>& texture, TextureType type, QNetworkReply* reply, const QUrl& url = QUrl(),
const QByteArray& content = QByteArray());
ImageReader(const QWeakPointer<Resource>& texture, TextureType type, const QByteArray& data, const QUrl& url = QUrl());
virtual void run();
@ -215,27 +214,25 @@ private:
QWeakPointer<Resource> _texture;
TextureType _type;
QNetworkReply* _reply;
QUrl _url;
QByteArray _content;
};
void NetworkTexture::downloadFinished(QNetworkReply* reply) {
void NetworkTexture::downloadFinished(const QByteArray& data) {
// send the reader off to the thread pool
QThreadPool::globalInstance()->start(new ImageReader(_self, _type, reply));
QThreadPool::globalInstance()->start(new ImageReader(_self, _type, data, _url));
}
void NetworkTexture::loadContent(const QByteArray& content) {
QThreadPool::globalInstance()->start(new ImageReader(_self, _type, NULL, _url, content));
QThreadPool::globalInstance()->start(new ImageReader(_self, _type, content));
}
ImageReader::ImageReader(const QWeakPointer<Resource>& texture, TextureType type, QNetworkReply* reply,
const QUrl& url, const QByteArray& content) :
ImageReader::ImageReader(const QWeakPointer<Resource>& texture, TextureType type, const QByteArray& data,
const QUrl& url) :
_texture(texture),
_type(type),
_reply(reply),
_url(url),
_content(content) {
_content(data) {
}
std::once_flag onceListSupportedFormatsflag;
@ -288,16 +285,9 @@ public:
void ImageReader::run() {
QSharedPointer<Resource> texture = _texture.toStrongRef();
if (texture.isNull()) {
if (_reply) {
_reply->deleteLater();
}
qDebug() << "TEXTURE IS NULL";
return;
}
if (_reply) {
_url = _reply->url();
_content = _reply->readAll();
_reply->deleteLater();
}
listSupportedImageFormats();

View file

@ -119,7 +119,7 @@ public:
TextureType getType() const { return _type; }
protected:
virtual void downloadFinished(QNetworkReply* reply);
virtual void downloadFinished(const QByteArray& data) override;
Q_INVOKABLE void loadContent(const QByteArray& content);
// FIXME: This void* should be a gpu::Texture* but i cannot get it to work for now, moving on...