#include <QFile>
#include <QDebug>
#include <qopenglfunctions.h>
+#include <qqmlfile.h>
//#define ETC_DEBUG
size->setHeight(0);
size->setWidth(0);
- // resolve paths relative to qrc file
- QFile file(QLatin1String(":/textureprovider/") + id);
+ QUrl url = QUrl(id);
+ if (url.isRelative() && !m_baseUrl.isEmpty())
+ url = m_baseUrl.resolved(url);
+ QString path = QQmlFile::urlToLocalFileOrQrc(url);
+
+ QFile file(path);
#ifdef ETC_DEBUG
- qDebug() << "requestTexture opening file: " << id;
+ qDebug() << "requestTexture opening file: " << path;
#endif
if (file.open(QIODevice::ReadOnly)) {
ret = new QEtcTextureFactory;
return ret;
}
+
+void EtcProvider::setBaseUrl(const QUrl &base)
+{
+ m_baseUrl = base;
+}
#include <qopengl.h>
#include <QQuickImageProvider>
#include <QtQuick/QSGTexture>
+#include <QUrl>
class EtcProvider : public QQuickImageProvider
{
{}
QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize);
+
+ void setBaseUrl(const QUrl &base);
+
+private:
+ QUrl m_baseUrl;
};
class EtcTexture : public QSGTexture
QGuiApplication app(argc,argv);
QQuickView view;
- view.engine()->addImageProvider("etc", new EtcProvider());
+ EtcProvider *provider = new EtcProvider();
+ provider->setBaseUrl(QUrl("qrc:///textureprovider/"));
+ view.engine()->addImageProvider("etc", provider);
view.setSource(QUrl("qrc:///textureprovider/textureprovider.qml"));
view.show();