summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPasi Keranen <pasi.keranen@digia.com>2014-10-23 16:36:08 +0300
committerPasi Keränen <pasi.keranen@digia.com>2014-10-24 08:16:11 +0200
commitc8db22aee453ca3ecea45e91183a02a61f40335f (patch)
tree13619c6c2cf82dc3ed434e8d3c6889f22d81abf0 /src
parentc769a3915f80eff6fafab009a260ddb536a1817c (diff)
Reverses QQmlPropertyMap rebase and removed TextureLoader.
QQmlPropertyMap as baseclass doesn't work without additional work, it has been now removed as baseclass from QtCanvas3D for now. TextureLoader has been removed in favor of TextureImageFactory as that allows easier porting of WebGL based JavaScript code to QtCanvas3D. Change-Id: I6fb374fd012d7569b9f173b08f4a6f21dcd83abe Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com> Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/abstractobject3d.cpp31
-rw-r--r--src/abstractobject3d_p.h14
-rw-r--r--src/activeinfo3d.cpp28
-rw-r--r--src/activeinfo3d_p.h22
-rw-r--r--src/canvas3d.cpp43
-rw-r--r--src/canvas3d_p.h7
-rw-r--r--src/context3d.cpp14
-rw-r--r--src/context3d_p.h8
-rw-r--r--src/qcanvas3d_plugin.cpp7
-rw-r--r--src/qcanvas3d_plugin.h4
-rw-r--r--src/src.pro2
-rw-r--r--src/teximage3d.cpp209
-rw-r--r--src/teximage3d_p.h60
-rw-r--r--src/teximage3dloader.cpp217
-rw-r--r--src/teximage3dloader_p.h93
-rw-r--r--src/typedarrayfactory.cpp13
-rw-r--r--src/typedarrayfactory_p.h2
17 files changed, 303 insertions, 471 deletions
diff --git a/src/abstractobject3d.cpp b/src/abstractobject3d.cpp
index 0f432d2..6f1c87f 100644
--- a/src/abstractobject3d.cpp
+++ b/src/abstractobject3d.cpp
@@ -36,20 +36,39 @@
#include "abstractobject3d_p.h"
+/*!
+ * \internal
+ */
CanvasAbstractObject::CanvasAbstractObject(QObject *parent) :
- QQmlPropertyMap(parent)
+ QObject(parent)
{
- insert("name", QVariant::fromValue(QString("0x%1").arg((long long) this, 0, 16)));
+ m_name = QString("0x%1").arg((long long) this, 0, 16);
}
+/*!
+ * \internal
+ */
CanvasAbstractObject::~CanvasAbstractObject()
{
}
-QString CanvasAbstractObject::name() const
+/*!
+ * \internal
+ */
+void CanvasAbstractObject::setName(const QString &name)
{
- if (!contains("name"))
- return "";
+ if (m_name == name)
+ return;
- return value("name").toString();
+ m_name = name;
+
+ emit nameChanged(m_name);
+}
+
+/*!
+ * \internal
+ */
+const QString &CanvasAbstractObject::name() const
+{
+ return m_name;
}
diff --git a/src/abstractobject3d_p.h b/src/abstractobject3d_p.h
index c223b54..0845adf 100644
--- a/src/abstractobject3d_p.h
+++ b/src/abstractobject3d_p.h
@@ -48,18 +48,26 @@
#define ABSTRACTOBJECT3D_P_H
#include <QObject>
-#include <QQmlPropertyMap>
#include <QThread>
-class CanvasAbstractObject : public QQmlPropertyMap
+class CanvasAbstractObject : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
public:
explicit CanvasAbstractObject(QObject *parent = 0);
virtual ~CanvasAbstractObject();
- QString name() const;
+ void setName(const QString &name);
+ const QString &name() const;
+
+signals:
+ void nameChanged(const QString &name);
+
+private:
+ QString m_name;
};
+
#endif // ABSTRACTOBJECT3D_P_H
diff --git a/src/activeinfo3d.cpp b/src/activeinfo3d.cpp
index 6df460c..188b000 100644
--- a/src/activeinfo3d.cpp
+++ b/src/activeinfo3d.cpp
@@ -48,11 +48,9 @@
* \sa Context3D, Canvas3D, {QML Canvas 3D QML Types}
*/
-
-
CanvasActiveInfo::CanvasActiveInfo(int size, CanvasContext::glEnums type,
QString name, QObject *parent) :
- CanvasAbstractObject(parent),
+ QObject(parent),
m_size(size),
m_type(type),
m_name(name)
@@ -60,37 +58,25 @@ CanvasActiveInfo::CanvasActiveInfo(int size, CanvasContext::glEnums type,
}
/*!
- * \qmlproperty int ActiveInfo3D::size
- * Size of the active attrib or uniform.
- */
-/*!
* \internal
*/
-int CanvasActiveInfo::infoSize() const
+const QString CanvasActiveInfo::name() const
{
- return m_size;
+ return m_name;
}
/*!
- * \qmlproperty Context3D.glEnums ActiveInfo3D::type
- * Type of the active attrib or uniform.
- */
-/*!
* \internal
*/
-CanvasContext::glEnums CanvasActiveInfo::infoType() const
+int CanvasActiveInfo::size() const
{
- return m_type;
+ return m_size;
}
/*!
- * \qmlproperty string ActiveInfo3D::name
- * Name of the active attrib or uniform.
- */
-/*!
* \internal
*/
-QString CanvasActiveInfo::infoName() const
+CanvasContext::glEnums CanvasActiveInfo::type() const
{
- return m_name;
+ return m_type;
}
diff --git a/src/activeinfo3d_p.h b/src/activeinfo3d_p.h
index 13a1ba2..66ddd43 100644
--- a/src/activeinfo3d_p.h
+++ b/src/activeinfo3d_p.h
@@ -47,29 +47,29 @@
#ifndef CANVASACTIVEINFO_P_H
#define CANVASACTIVEINFO_P_H
-#include "abstractobject3d_p.h"
+#include <QObject>
#include "context3d_p.h"
-class CanvasActiveInfo : public CanvasAbstractObject
+class CanvasActiveInfo : public QObject
{
Q_OBJECT
- Q_PROPERTY(int size READ infoSize NOTIFY infoSizeChanged)
- Q_PROPERTY(CanvasContext::glEnums type READ infoType NOTIFY infoTypeChanged)
- Q_PROPERTY(QString name READ infoName NOTIFY infoNameChanged)
+ Q_PROPERTY(int size READ size NOTIFY sizeChanged)
+ Q_PROPERTY(CanvasContext::glEnums type READ type NOTIFY typeChanged)
+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
public:
explicit CanvasActiveInfo(int size, CanvasContext::glEnums type,
QString name, QObject *parent = 0);
- int infoSize() const;
- CanvasContext::glEnums infoType() const;
- QString infoName() const;
+ int size() const;
+ CanvasContext::glEnums type() const;
+ const QString name() const;
signals:
- void infoSizeChanged(int size);
- void infoTypeChanged(CanvasContext::glEnums type);
- void infoNameChanged(QString &name);
+ void sizeChanged(int size);
+ void typeChanged(CanvasContext::glEnums type);
+ void nameChanged(const QString name);
private:
int m_size;
diff --git a/src/canvas3d.cpp b/src/canvas3d.cpp
index 72128ef..5b503c5 100644
--- a/src/canvas3d.cpp
+++ b/src/canvas3d.cpp
@@ -41,11 +41,14 @@
#include "arraybuffer_p.h"
#include "canvas3dcommon_p.h"
#include "canvasrendernode_p.h"
+#include "teximage3d_p.h"
-#include <QGuiApplication>
+#include <QtGui/QGuiApplication>
#include <QtGui/QOffscreenSurface>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFramebufferObject>
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlContext>
static QList<const QQuickWindow *> staticClearList;
static QHash<Canvas *, QQuickWindow *> canvasWindowList;
@@ -94,7 +97,6 @@ Canvas::Canvas(QQuickItem *parent):
#endif
m_samples(0),
m_devicePixelRatio(1.0f),
- m_imageLoader(0),
m_isContextAttribsSet(false),
m_antialiasFbo(0),
m_renderFbo(0),
@@ -108,6 +110,7 @@ Canvas::Canvas(QQuickItem *parent):
// Set contents to false in case we are in qml designer to make component look nice
m_runningInDesigner = QGuiApplication::applicationDisplayName() == "Qml2Puppet";
setFlag(ItemHasContents, !m_runningInDesigner);
+
}
/*!
@@ -375,7 +378,7 @@ CanvasContext *Canvas::getContext(const QString &type, const QVariantMap &option
m_antialiasFbo = new QOpenGLFramebufferObject(m_initialisedSize, antialiasFboFormat);
}
- m_context3D = new CanvasContext(m_glContext, m_initialisedSize.width() * m_devicePixelRatio,
+ m_context3D = new CanvasContext(m_glContext, m_offscreenSurface, m_initialisedSize.width() * m_devicePixelRatio,
m_initialisedSize.height() * m_devicePixelRatio);
m_context3D->setCanvas(this);
m_context3D->setDevicePixelRatio(m_devicePixelRatio);
@@ -447,33 +450,6 @@ CanvasContext *Canvas::context()
}
/*!
- * \qmlproperty TextureImageLoader Canvas3D::imageLoader
- * Specifies the texture image loader that can be used to load images and used with the Context3D
- * texture methods.
- * \sa Context3D, TextureImageLoader
- */
-/*!
- * \internal
- */
-CanvasTextureImageLoader *Canvas::imageLoader()
-{
- if (m_logAllCalls) qDebug() << "Canvas3D::" << __FUNCTION__;
- return m_imageLoader;
-}
-
-void Canvas::setImageLoader(CanvasTextureImageLoader *loader)
-{
- if (m_logAllCalls) qDebug() << "Canvas3D::" << __FUNCTION__ << "(loader: " << loader << ")";
- if (loader == m_imageLoader)
- return;
-
- m_imageLoader = loader;
- loader->setCanvas(this);
-
- emit imageLoaderChanged(loader);
-}
-
-/*!
* \internal
*/
void Canvas::updateWindowParameters()
@@ -637,9 +613,10 @@ void Canvas::renderNext()
if (!isComponentComplete())
return;
- // Check if there is a image loader ask it to notify any image loads
- if (m_imageLoader)
- m_imageLoader->notifyLoadedImages();
+ // Check if any images are loaded and need to be notified while the correct
+ // GL context is current.
+ QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
+ CanvasTextureImageFactory::factory(engine)->notifyLoadedImages();
// Call render in QML JavaScript side
emit renderGL();
diff --git a/src/canvas3d_p.h b/src/canvas3d_p.h
index ef9c4e3..82f00ae 100644
--- a/src/canvas3d_p.h
+++ b/src/canvas3d_p.h
@@ -49,7 +49,6 @@
#include "canvas3dcommon_p.h"
#include "context3d_p.h"
-#include "teximage3dloader_p.h"
#include <QQuickItem>
#include <QQuickWindow>
@@ -65,7 +64,6 @@ class QT_CANVAS3D_EXPORT Canvas : public QQuickItem, QOpenGLFunctions
Q_PROPERTY(bool logAllCalls READ logAllCalls WRITE setLogAllCalls NOTIFY logAllCallsChanged)
Q_PROPERTY(bool logAllErrors READ logAllErrors WRITE setLogAllErrors NOTIFY logAllErrorsChanged)
Q_PROPERTY(float devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged)
- Q_PROPERTY(CanvasTextureImageLoader *imageLoader READ imageLoader WRITE setImageLoader NOTIFY imageLoaderChanged)
public:
Canvas(QQuickItem *parent = 0);
@@ -81,9 +79,6 @@ public:
GLuint drawFBOHandle();
- CanvasTextureImageLoader *imageLoader();
- void setImageLoader(CanvasTextureImageLoader *loader);
-
Q_INVOKABLE CanvasContext *getContext(const QString &name);
Q_INVOKABLE CanvasContext *getContext(const QString &name, const QVariantMap &options);
CanvasContext *context();
@@ -97,7 +92,6 @@ signals:
void needRender();
void devicePixelRatioChanged(float ratio);
void animatedChanged(bool animated);
- void imageLoaderChanged(CanvasTextureImageLoader *loader);
void logAllCallsChanged(bool logCalls);
void logAllErrorsChanged(bool logErrors);
void contextChanged(CanvasContext *context);
@@ -134,7 +128,6 @@ private:
int m_samples;
float m_devicePixelRatio;
- CanvasTextureImageLoader *m_imageLoader;
bool m_runningInDesigner;
CanvasContextAttributes m_contextAttribs;
bool m_isContextAttribsSet;
diff --git a/src/context3d.cpp b/src/context3d.cpp
index 4be262b..6d351cc 100644
--- a/src/context3d.cpp
+++ b/src/context3d.cpp
@@ -76,7 +76,8 @@
*/
// Owned by the SG Render Thread!
-CanvasContext::CanvasContext(QOpenGLContext *context, int width, int height, QObject *parent) :
+CanvasContext::CanvasContext(QOpenGLContext *context, QSurface *surface,
+ int width, int height, QObject *parent) :
CanvasAbstractObject(parent),
QOpenGLFunctions(context),
m_unpackFlipYEnabled(false),
@@ -88,15 +89,14 @@ CanvasContext::CanvasContext(QOpenGLContext *context, int width, int height, QOb
m_currentArrayBuffer(0),
m_currentElementArrayBuffer(0),
m_currentTexture(0),
- m_context(0),
+ m_context(context),
+ m_surface(surface),
m_error(NO_ERROR),
m_currentFramebuffer(0),
m_map(EnumToStringMap::newInstance()),
m_canvas(0),
m_maxVertexAttribs(0)
{
- m_context = context;
-
int value = 0;
glGetIntegerv(MAX_VERTEX_ATTRIBS, &value);
m_maxVertexAttribs = uint(value);
@@ -3159,7 +3159,7 @@ CanvasUniformLocation *CanvasContext::getUniformLocation(CanvasProgram *program,
}
CanvasUniformLocation *location = new CanvasUniformLocation(index, this);
- location->insert("name", name);
+ location->setName(name);
if (m_logAllCalls) qDebug() << "Context3D::" << __FUNCTION__
<< "(program:" << program
<< ", name:" << name
@@ -4932,9 +4932,7 @@ QVariant CanvasContext::getUniform(CanvasProgram *program, CanvasUniformLocation
CanvasActiveInfo *info = getActiveUniform(program, locationId);
int numValues = 4;
- qDebug() << "Context3D::" << __FUNCTION__ << "info->type():" << glEnumToString(info->infoType());
-
- switch (info->infoType()) {
+ switch (info->type()) {
case SAMPLER_2D:
// Intentional flow through
case SAMPLER_CUBE:
diff --git a/src/context3d_p.h b/src/context3d_p.h
index 20477cf..344356e 100644
--- a/src/context3d_p.h
+++ b/src/context3d_p.h
@@ -939,7 +939,8 @@ public:
ENUM_AS_PROPERTY(UNPACK_COLORSPACE_CONVERSION_WEBGL)
ENUM_AS_PROPERTY(BROWSER_DEFAULT_WEBGL)
- CanvasContext(QOpenGLContext *context, int width, int height, QObject *parent = 0);
+ CanvasContext(QOpenGLContext *context, QSurface *surface,
+ int width, int height, QObject *parent = 0);
~CanvasContext();
void setCanvas(Canvas *canvas);
@@ -1168,7 +1169,9 @@ public:
Q_INVOKABLE void vertexAttrib3fva(uint indx, QVariantList values);
Q_INVOKABLE void vertexAttrib4fva(uint indx, QVariantList values);
- Q_INVOKABLE int getFramebufferAttachmentParameter(glEnums target, glEnums attachment, glEnums pname);
+ Q_INVOKABLE int getFramebufferAttachmentParameter(glEnums target,
+ glEnums attachment,
+ glEnums pname);
Q_INVOKABLE int getRenderbufferParameter(glEnums target, glEnums pname);
Q_INVOKABLE QVariant getTexParameter(glEnums target, glEnums pname);
Q_INVOKABLE QVariant getUniform(CanvasProgram *program, CanvasUniformLocation *location);
@@ -1215,6 +1218,7 @@ private:
CanvasBuffer *m_currentElementArrayBuffer;
CanvasTexture *m_currentTexture;
QOpenGLContext *m_context;
+ QSurface *m_surface;
glEnums m_error;
CanvasFrameBuffer *m_currentFramebuffer;
CanvasRenderBuffer *m_currentRenderbuffer;
diff --git a/src/qcanvas3d_plugin.cpp b/src/qcanvas3d_plugin.cpp
index 3c1cf1b..703af02 100644
--- a/src/qcanvas3d_plugin.cpp
+++ b/src/qcanvas3d_plugin.cpp
@@ -45,10 +45,11 @@ void QtCanvas3DPlugin::registerTypes(const char *uri)
1, 0,
"Arrays",
CanvasTypedArrayFactory::type_array_factory_provider);
+ qmlRegisterSingletonType<CanvasTextureImageFactory>(uri,
+ 1, 0,
+ "TextureImageFactory",
+ CanvasTextureImageFactory::texture_image_factory_provider);
- qmlRegisterType<CanvasTextureImageLoader>(uri,
- 1, 0,
- "TextureImageLoader");
qmlRegisterType<CanvasTextureImage>(uri,
1, 0,
"TextureImage");
diff --git a/src/qcanvas3d_plugin.h b/src/qcanvas3d_plugin.h
index 72f9d81..3cd0e9e 100644
--- a/src/qcanvas3d_plugin.h
+++ b/src/qcanvas3d_plugin.h
@@ -62,7 +62,6 @@
#include "framebuffer3d_p.h"
#include "renderbuffer3d_p.h"
#include "shaderprecisionformat_p.h"
-#include "teximage3dloader_p.h"
#include "activeinfo3d_p.h"
#include <QQmlExtensionPlugin>
@@ -90,14 +89,13 @@ QML_DECLARE_TYPE(CanvasArrayBufferView)
QML_DECLARE_TYPE(CanvasArrayBuffer)
QML_DECLARE_TYPE(CanvasTypedArrayFactory)
QML_DECLARE_TYPE(CanvasTextureImage)
+QML_DECLARE_TYPE(CanvasTextureImageFactory)
QML_DECLARE_TYPE(CanvasTypedArray)
QML_DECLARE_TYPE(CanvasContextAttributes)
QML_DECLARE_TYPE(CanvasFrameBuffer)
QML_DECLARE_TYPE(CanvasRenderBuffer)
QML_DECLARE_TYPE(CanvasShaderPrecisionFormat)
-QML_DECLARE_TYPE(CanvasTextureImageLoader)
QML_DECLARE_TYPE(CanvasActiveInfo)
-
class QtCanvas3DPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
diff --git a/src/src.pro b/src/src.pro
index 1ad3389..5231741 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -43,7 +43,6 @@ SOURCES += qcanvas3d_plugin.cpp \
shader3d.cpp \
shaderprecisionformat.cpp \
teximage3d.cpp \
- teximage3dloader.cpp \
texture3d.cpp \
uniformlocation.cpp \
activeinfo3d.cpp
@@ -78,7 +77,6 @@ HEADERS += qcanvas3d_plugin.h \
shader3d_p.h \
shaderprecisionformat_p.h \
teximage3d_p.h \
- teximage3dloader_p.h \
texture3d_p.h \
uniformlocation_p.h \
activeinfo3d_p.h
diff --git a/src/teximage3d.cpp b/src/teximage3d.cpp
index 3e9e1b6..601e318 100644
--- a/src/teximage3d.cpp
+++ b/src/teximage3d.cpp
@@ -39,6 +39,108 @@
#include <QJSValueIterator>
+static QMap<QQmlEngine *,CanvasTextureImageFactory *>m_qmlEngineToImageFactoryMap;
+
+/*!
+ * \internal
+ */
+CanvasTextureImageFactory::CanvasTextureImageFactory(QQmlEngine *engine, QObject *parent) :
+ QObject(parent)
+{
+ m_qmlEngine = engine;
+}
+
+/*!
+ * \internal
+ */
+CanvasTextureImageFactory::~CanvasTextureImageFactory()
+{
+ m_qmlEngineToImageFactoryMap.remove(m_qmlEngine);
+}
+
+/*!
+ * \qmltype TextureImageFactory
+ * \since QtCanvas3D 1.0
+ * \ingroup qtcanvas3d-qml-types
+ * \brief Create TextureImage elements.
+ *
+ * This static QML type is used for creating TextureImage instances by calling the
+ * TextureImageFactory::newTexImage() function.
+ *
+ * \sa TextureImage
+ */
+
+/*!
+ * \internal
+ */
+QObject *CanvasTextureImageFactory::texture_image_factory_provider(QQmlEngine *engine,
+ QJSEngine *scriptEngine)
+{
+ Q_UNUSED(scriptEngine)
+ return factory(engine);
+}
+
+/*!
+ * \internal
+ */
+CanvasTextureImageFactory *CanvasTextureImageFactory::factory(QQmlEngine *engine)
+{
+ if (m_qmlEngineToImageFactoryMap.contains(engine))
+ return m_qmlEngineToImageFactoryMap[engine];
+
+ CanvasTextureImageFactory *factory = new CanvasTextureImageFactory(engine);
+ m_qmlEngineToImageFactoryMap[engine] = factory;
+ return factory;
+}
+
+/*!
+ * \internal
+ */
+void CanvasTextureImageFactory::handleImageLoadingStarted(CanvasTextureImage *image)
+{
+ if (m_loadingImagesList.contains(image))
+ return;
+
+ m_loadingImagesList << image;
+}
+
+/*!
+ * \internal
+ */
+void CanvasTextureImageFactory::notifyLoadedImages()
+{
+ if (!m_loadingImagesList.size())
+ return;
+
+ QMutableListIterator<CanvasTextureImage *> it(m_loadingImagesList);
+ while (it.hasNext()) {
+ CanvasTextureImage *image = it.next();
+ if (image->imageState() == CanvasTextureImage::LOADING_FINISHED) {
+ m_loadingImagesList.removeOne(image);
+ image->emitImageLoaded();
+
+ } else if (image->imageState() == CanvasTextureImage::LOADING_ERROR) {
+ m_loadingImagesList.removeOne(image);
+ image->emitImageLoadingError();
+ }
+ }
+}
+
+/*!
+ * \qmlmethod TextureImage TextureImageFactory::newTexImage()
+ * Returns a new empty TextureImage.
+ */
+/*!
+ * \internal
+ */
+CanvasTextureImage *CanvasTextureImageFactory::newTexImage()
+{
+ CanvasTextureImage *newImg = new CanvasTextureImage(this);
+ connect(newImg, &CanvasTextureImage::imageLoadingStarted,
+ this, &CanvasTextureImageFactory::handleImageLoadingStarted);
+ return newImg;
+}
+
/*!
* \qmltype TextureImage
* \since QtCanvas3D 1.0
@@ -46,17 +148,35 @@
* \brief Contains a texture image.
*
* An uncreatable QML type that contains a texture image created by calling
- * TextureImageLoader::loadImage().
+ * TextureImageFactory::newTexImage() and settings the \c src of the image.
*
- * \sa TextureImageLoader
+ * \sa TextureImageFactory
*/
/*!
* \internal
*/
-CanvasTextureImage::CanvasTextureImage(QObject *parent) :
+CanvasTextureImage::CanvasTextureImage(CanvasTextureImageFactory *parent) :
CanvasAbstractObject(parent),
- m_requestId(0),
+ m_networkAccessManager(0),
+ m_state(INITIALIZED),
+ m_errorString(""),
+ m_pixelCache(0),
+ m_pixelCacheFormat(CanvasContext::NONE),
+ m_pixelCacheFlipY(false),
+ m_parentFactory(parent)
+{
+ m_networkAccessManager = new QNetworkAccessManager(this);
+ QObject::connect(m_networkAccessManager, &QNetworkAccessManager::finished,
+ this, &CanvasTextureImage::handleReply);
+}
+
+/*!
+ * \internal
+ */
+CanvasTextureImage::CanvasTextureImage(const QImage &source, int width, int height, QObject *parent) :
+ CanvasAbstractObject(parent),
+ m_networkAccessManager(0),
m_state(INITIALIZED),
m_errorString(""),
m_pixelCache(0),
@@ -66,6 +186,9 @@ CanvasTextureImage::CanvasTextureImage(QObject *parent) :
m_networkAccessManager = new QNetworkAccessManager(this);
QObject::connect(m_networkAccessManager, &QNetworkAccessManager::finished,
this, &CanvasTextureImage::handleReply);
+
+ m_image = source.scaled(width, height);
+ setImageState(LOADING_FINISHED);
}
/*!
@@ -78,13 +201,21 @@ CanvasTextureImage::~CanvasTextureImage()
}
/*!
- * \qmlproperty url TextureImage::source()
- * Contains the url to the image.
+ * \internal
+ */
+CanvasTextureImage *CanvasTextureImage::create()
+{
+ return new CanvasTextureImage();
+}
+
+/*!
+ * \qmlproperty url TextureImage::src()
+ * Contains the url source where the image data is loaded from.
*/
/*!
* \internal
*/
-const QUrl &CanvasTextureImage::source() const
+const QUrl &CanvasTextureImage::src() const
{
return m_source;
}
@@ -92,13 +223,13 @@ const QUrl &CanvasTextureImage::source() const
/*!
* \internal
*/
-void CanvasTextureImage::setSource(const QUrl &url)
+void CanvasTextureImage::setSrc(const QUrl &url)
{
if (url == m_source)
return;
m_source = url;
- emit sourceChanged(m_source);
+ emit srcChanged(m_source);
load();
}
@@ -118,6 +249,22 @@ ulong CanvasTextureImage::id()
/*!
* \internal
*/
+void CanvasTextureImage::emitImageLoaded()
+{
+ emit imageLoaded(this);
+}
+
+/*!
+ * \internal
+ */
+void CanvasTextureImage::emitImageLoadingError()
+{
+ emit imageLoadingFailed(this);
+}
+
+/*!
+ * \internal
+ */
void CanvasTextureImage::load()
{
if (m_source.isEmpty()) {
@@ -132,6 +279,8 @@ void CanvasTextureImage::load()
return;
setImageState(LOADING);
+ emit imageLoadingStarted(this);
+
QNetworkRequest request(m_source);
m_networkAccessManager->get(request);
}
@@ -154,9 +303,9 @@ QString CanvasTextureImage::errorString() const
void CanvasTextureImage::handleReply(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
- setImageState(LOADING_ERROR);
m_errorString = reply->errorString();
emit errorStringChanged(m_errorString);
+ setImageState(LOADING_ERROR);
return;
}
@@ -168,7 +317,7 @@ void CanvasTextureImage::handleReply(QNetworkReply *reply)
/*!
* \internal
*/
-QImage & CanvasTextureImage::getImage()
+QImage &CanvasTextureImage::getImage()
{
return m_image;
}
@@ -176,7 +325,7 @@ QImage & CanvasTextureImage::getImage()
/*!
* \internal
*/
-QVariant *CanvasTextureImage::anything()
+QVariant *CanvasTextureImage::anything() const
{
return m_anyValue;
}
@@ -201,7 +350,7 @@ void CanvasTextureImage::setAnything(QVariant *value)
/*!
* \internal
*/
-CanvasTextureImage::TextureImageState CanvasTextureImage::imageState()
+CanvasTextureImage::TextureImageState CanvasTextureImage::imageState() const
{
return m_state;
}
@@ -224,7 +373,7 @@ void CanvasTextureImage::setImageState(TextureImageState state)
/*!
* \internal
*/
-int CanvasTextureImage::width()
+int CanvasTextureImage::width() const
{
if (m_state != LOADING_FINISHED)
return 0;
@@ -239,7 +388,7 @@ int CanvasTextureImage::width()
/*!
* \internal
*/
-int CanvasTextureImage::height()
+int CanvasTextureImage::height() const
{
if (m_state != LOADING_FINISHED)
return 0;
@@ -250,21 +399,6 @@ int CanvasTextureImage::height()
/*!
* \internal
*/
-void CanvasTextureImage::emitImageLoadedSGRT()
-{
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImage::emitImageLoadingErrorSGRT()
-{
-}
-
-
-/*!
- * \internal
- */
uchar *CanvasTextureImage::convertToFormat(CanvasContext::glEnums format, bool flipY)
{
if (m_pixelCacheFormat == format && m_pixelCacheFlipY == flipY)
@@ -353,6 +487,21 @@ uchar *CanvasTextureImage::convertToFormat(CanvasContext::glEnums format, bool f
}
/*!
+ * \qmlmethod TextureImage TextureImage::resize(int width, int height)
+ * Returns a copy of the texture image resized to the given \a width and \a height.
+ */
+/*!
+ * \internal
+ */
+CanvasTextureImage *CanvasTextureImage::resize(int width, int height)
+{
+ if (m_state != LOADING_FINISHED)
+ return 0;
+
+ return new CanvasTextureImage(m_image, width, height);
+}
+
+/*!
* \internal
*/
QDebug operator<<(QDebug dbg, const CanvasTextureImage *texImage)
diff --git a/src/teximage3d_p.h b/src/teximage3d_p.h
index c2824c3..de93a7b 100644
--- a/src/teximage3d_p.h
+++ b/src/teximage3d_p.h
@@ -50,16 +50,36 @@
#include "context3d_p.h"
#include "abstractobject3d_p.h"
-#include <QUrl>
-#include <QNetworkAccessManager>
-#include <QImage>
-#include <QNetworkReply>
+#include <QtCore/QUrl>
+#include <QtGui/QImage>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+
+class CanvasTextureImageFactory : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(CanvasTextureImageFactory)
+
+public:
+ static QObject *texture_image_factory_provider(QQmlEngine *engine, QJSEngine *scriptEngine);
+ static CanvasTextureImageFactory *factory(QQmlEngine *engine);
+ explicit CanvasTextureImageFactory(QQmlEngine *engine, QObject *parent = 0);
+ ~CanvasTextureImageFactory();
+
+ void handleImageLoadingStarted(CanvasTextureImage *image);
+ void notifyLoadedImages();
+
+ Q_INVOKABLE CanvasTextureImage* newTexImage();
+private:
+ QQmlEngine *m_qmlEngine;
+ QList<CanvasTextureImage *> m_loadingImagesList;
+};
class CanvasTextureImage : public CanvasAbstractObject
{
Q_OBJECT
Q_DISABLE_COPY(CanvasTextureImage)
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(QUrl src READ src WRITE setSrc NOTIFY srcChanged)
Q_PROPERTY(TextureImageState imageState READ imageState NOTIFY imageStateChanged)
Q_PROPERTY(int width READ width NOTIFY widthChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
@@ -75,45 +95,50 @@ public:
LOADING_ERROR
};
- explicit CanvasTextureImage(QObject *parent = 0);
+ Q_INVOKABLE explicit CanvasTextureImage(CanvasTextureImageFactory *parent = 0);
virtual ~CanvasTextureImage();
+ Q_INVOKABLE CanvasTextureImage *create();
Q_INVOKABLE ulong id();
+ Q_INVOKABLE CanvasTextureImage *resize(int width, int height);
- QVariant *anything();
+ QVariant *anything() const;
void setAnything(QVariant *value);
- const QUrl &source() const;
- void setSource(const QUrl &src);
- TextureImageState imageState();
- int width();
- int height();
+ const QUrl &src() const;
+ void setSrc(const QUrl &src);
+ TextureImageState imageState() const;
+ int width() const;
+ int height() const;
QString errorString() const;
+ void emitImageLoaded();
+ void emitImageLoadingError();
+
void load();
void handleReply(QNetworkReply *reply);
QImage &getImage();
uchar *convertToFormat(CanvasContext::glEnums format, bool flipY = false);
- void emitImageLoadedSGRT();
- void emitImageLoadingErrorSGRT();
-
friend QDebug operator<< (QDebug d, const CanvasTextureImage *buffer);
private:
void setImageState(TextureImageState state);
+ explicit CanvasTextureImage(const QImage &source, int width, int height, QObject *parent = 0);
signals:
- void sourceChanged(QUrl source);
+ void srcChanged(QUrl source);
void imageStateChanged(TextureImageState state);
void widthChanged(int width);
void heightChanged(int height);
void errorStringChanged(const QString errorString);
void anythingChanged(QVariant *value);
+ void imageLoadingStarted(CanvasTextureImage *image);
+ void imageLoaded(CanvasTextureImage *image);
+ void imageLoadingFailed(CanvasTextureImage *image);
private:
QNetworkAccessManager *m_networkAccessManager;
- int m_requestId;
QImage m_image;
QUrl m_source;
TextureImageState m_state;
@@ -123,6 +148,7 @@ private:
bool m_pixelCacheFlipY;
QImage m_glImage;
QVariant *m_anyValue;
+ CanvasTextureImageFactory *m_parentFactory;
};
#endif // TEXIMAGE3D_P_H
diff --git a/src/teximage3dloader.cpp b/src/teximage3dloader.cpp
deleted file mode 100644
index 4a5e2d8..0000000
--- a/src/teximage3dloader.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCanvas3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "teximage3dloader_p.h"
-#include "canvas3d_p.h"
-#include "canvas3dcommon_p.h"
-
-/*!
- * \qmltype TextureImageLoader
- * \since QtCanvas3D 1.0
- * \ingroup qtcanvas3d-qml-types
- * \brief Texture image loader.
- *
- * Texture image loader that allows loading of 2D images to be used as input of Context3D
- * texture upload calls.
- *
- * \sa Context3D, TextureImage, {QML Canvas 3D QML Types}
- */
-
-/*!
- * \qmlproperty TextureImage TextureImageLoader::image
- * A read-only property holding the last loaded or failed texture. Should be called on receiving the
- * imageLoaded or imageLoadingFailed signal.
- */
-
-/*!
- * \qmlsignal void TextureImageLoader::imageLoaded()
- * Emitted when a texture has been successfully loaded.
- */
-
-/*!
- * \qmlsignal void TextureImageLoader::imageLoadingFailed()
- * Emitted when a texture loading has failed.
- */
-
-/*!
- * \internal
- */
-CanvasTextureImageLoader::CanvasTextureImageLoader(QObject *parent) :
- CanvasAbstractObject(parent),
- m_logAllCalls(false),
- m_logAllErrors(true),
- m_image(0),
- m_canvas(0)
-{
-}
-
-/*!
- * \internal
- */
-CanvasTextureImageLoader::~CanvasTextureImageLoader()
-{
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::setLogAllCalls(bool logCalls)
-{
- if (m_logAllCalls != logCalls) {
- m_logAllCalls = logCalls;
- emit logAllCallsChanged(logCalls);
- }
-}
-
-/*!
- * \qmlproperty bool TextureImageLoader::logAllCalls
- * Specifies if all TextureImageLoader method calls (including internal ones) are logged to the
- * console.
- * Defaults to \c{false}.
- */
-/*!
- * \internal
- */
-bool CanvasTextureImageLoader::logAllCalls() const
-{
- return m_logAllCalls;
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::setLogAllErrors(bool logErrors)
-{
- if (m_logAllErrors != logErrors) {
- m_logAllErrors = logErrors;
- emit logAllErrorsChanged(logErrors);
- }
-}
-
-/*!
- * \qmlproperty bool TextureImageLoader::logAllErrors
- * Specifies if all TextureImageLoader errors are logged to the console. Defaults to \c{true}.
- */
-/*!
- * \internal
- */
-bool CanvasTextureImageLoader::logAllErrors() const
-{
- return m_logAllErrors;
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::emitImageLoaded(CanvasTextureImage *textureImage)
-{
- if (m_logAllCalls) qDebug() << "TexImage3DLoader::" << __FUNCTION__;
- m_image = textureImage;
- emit imageLoaded();
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::emitImageLoadingError(CanvasTextureImage *textureImage)
-{
- if (m_logAllCalls) qDebug() << "TexImage3DLoader::" << __FUNCTION__;
- m_image = textureImage;
- emit imageLoadingFailed();
-}
-
-/*!
- * \qmlmethod TextureImage TextureImageLoader::loadImage(url url)
- * Loads an image located in \a url and creates a TextureImage of it.
- */
-/*!
- * \internal
- */
-CanvasTextureImage *CanvasTextureImageLoader::loadImage(const QUrl &url)
-{
- if (m_logAllCalls) qDebug() << "TexImage3DLoader::" << __FUNCTION__ << "(url:" << url << ")";
-
- if (!m_canvas && m_logAllErrors) qDebug() << "TexImage3DLoader::" << __FUNCTION__ << ": ERROR tried to load image before setting as property of a canvas.";
-
- CanvasContext *context = m_canvas->context();
- if (!context) {
- if (m_logAllErrors) qDebug() << "TexImage3DLoader::" << __FUNCTION__ << ": ERROR tried to load image before GL context was created.";
- return 0;
- }
-
- CanvasTextureImage *img;
- if (m_urlToImageMap.contains(url) && m_urlToImageMap.values(url).size() != 0) {
- img = m_urlToImageMap[url];
- } else {
- img = new CanvasTextureImage(context);
- m_urlToImageMap[url] = img;
- m_loadingImagesList << img;
- img->setSource(url);
- }
-
- return img;
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::setCanvas(Canvas *canvas)
-{
- m_canvas = canvas;
-}
-
-/*!
- * \internal
- */
-void CanvasTextureImageLoader::notifyLoadedImages()
-{
- if (!m_loadingImagesList.size())
- return;
-
- if (m_logAllCalls) qDebug() << "TexImage3DLoader::" << __FUNCTION__ << "(m_loadingImagesList.size():"<<m_loadingImagesList.size()<<")";
-
- QMutableListIterator<CanvasTextureImage *> it(m_loadingImagesList);
- while (it.hasNext()) {
- CanvasTextureImage *loader = it.next();
- if (loader->imageState() == CanvasTextureImage::LOADING_FINISHED) {
- m_loadingImagesList.removeOne(loader);
- emitImageLoaded(loader);
- } else if (loader->imageState() == CanvasTextureImage::LOADING_ERROR) {
- m_loadingImagesList.removeOne(loader);
- emitImageLoadingError(loader);
- }
- }
-}
diff --git a/src/teximage3dloader_p.h b/src/teximage3dloader_p.h
deleted file mode 100644
index 6df8870..0000000
--- a/src/teximage3dloader_p.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCanvas3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the QtCanvas3D API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-
-#ifndef TEXIMAGE3DLOADER_P_H
-#define TEXIMAGE3DLOADER_P_H
-
-#include "abstractobject3d_p.h"
-#include "teximage3d_p.h"
-
-class Canvas;
-
-class CanvasTextureImageLoader : public CanvasAbstractObject
-{
- Q_OBJECT
- Q_PROPERTY(CanvasTextureImage* image READ image)
- Q_PROPERTY(bool logAllCalls READ logAllCalls WRITE setLogAllCalls NOTIFY logAllCallsChanged)
- Q_PROPERTY(bool logAllErrors READ logAllErrors WRITE setLogAllErrors NOTIFY logAllErrorsChanged)
-
-public:
- explicit CanvasTextureImageLoader(QObject *parent = 0);
- virtual ~CanvasTextureImageLoader();
-
- Q_INVOKABLE CanvasTextureImage *loadImage(const QUrl &url);
-
- void setLogAllCalls(bool logCalls);
- bool logAllCalls() const;
- void setLogAllErrors(bool logErrors);
- bool logAllErrors() const;
- void setCanvas(Canvas *canvas);
- void notifyLoadedImages();
- void emitImageLoaded(CanvasTextureImage *textureImage);
- void emitImageLoadingError(CanvasTextureImage *textureImage);
- inline CanvasTextureImage *image() { return m_image; }
-
-signals:
- void imageLoaded();
- void imageLoadingFailed();
- void logAllCallsChanged(bool logCalls);
- void logAllErrorsChanged(bool logErrors);
-
-private:
- bool m_logAllCalls;
- bool m_logAllErrors;
- QMap<QUrl, CanvasTextureImage *> m_urlToImageMap;
- QList<CanvasTextureImage *> m_loadingImagesList;
- CanvasTextureImage *m_image;
- Canvas *m_canvas;
-};
-
-#endif // TEXIMAGE3DLOADER_P_H
diff --git a/src/typedarrayfactory.cpp b/src/typedarrayfactory.cpp
index 78e7a4d..8fd8fcc 100644
--- a/src/typedarrayfactory.cpp
+++ b/src/typedarrayfactory.cpp
@@ -574,16 +574,3 @@ CanvasUint8ClampedArray *CanvasTypedArrayFactory::newUint8ClampedArray(CanvasArr
return new CanvasUint8ClampedArray(buffer, byteOffset);
}
-/*!
- * \qmlmethod TextureImage Arrays::newTexImage()
- * Returns a new empty TextureImage.
- */
-/*!
- * \internal
- */
-CanvasTextureImage *CanvasTypedArrayFactory::newTexImage()
-{
- CanvasTextureImage *newImg = new CanvasTextureImage();
- if (VERBOSE_ALL_TYPED_ARRAY_CALLS) qDebug() << "Arrays::" << __FUNCTION__ << "():"<<newImg;
- return newImg;
-}
diff --git a/src/typedarrayfactory_p.h b/src/typedarrayfactory_p.h
index f36bf29..bd9d30d 100644
--- a/src/typedarrayfactory_p.h
+++ b/src/typedarrayfactory_p.h
@@ -130,8 +130,6 @@ public:
Q_INVOKABLE CanvasUint8ClampedArray* newUint8ClampedArray(QVariantList array);
Q_INVOKABLE CanvasUint8ClampedArray* newUint8ClampedArray(CanvasArrayBuffer *buffer,
unsigned long byteOffset);
-
- Q_INVOKABLE CanvasTextureImage* newTexImage();
};
#endif // TYPEDARRAYFACTORY_P_H