summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-01-27 15:47:49 +0100
committerPaul Lemire <paul.lemire@kdab.com>2015-02-08 08:39:55 +0000
commit90a09ae2e58dd1bbe1653b405295038f21083931 (patch)
treefee3bee00ae0d0724c8e407970f3378270f0b412
parent32deb9f50a761a4c421f3076eac430e5462286b1 (diff)
Quick3DTextureCubeMapExtension added
Will allow to set each CubeMapFace on a Quick3DTextureCubeMap Change-Id: Id4f4038a161e89f7f9a9083bf03066c52b504fbd Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dtexture.cpp153
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dtexture.h54
2 files changed, 205 insertions, 2 deletions
diff --git a/src/quick3d/quick3drenderer/items/quick3dtexture.cpp b/src/quick3d/quick3drenderer/items/quick3dtexture.cpp
index c609fb884..45484e25b 100644
--- a/src/quick3d/quick3drenderer/items/quick3dtexture.cpp
+++ b/src/quick3d/quick3drenderer/items/quick3dtexture.cpp
@@ -126,8 +126,8 @@ void Quick3DTexture2DExtension::setSource(QUrl arg)
QImage img;
if (img.load(source)) {
parentTexture()->setFormat(img.hasAlphaChannel() ?
- QTexture::RGBA8_UNorm :
- QTexture::RGB8_UNorm);
+ QTexture::RGBA8_UNorm :
+ QTexture::RGB8_UNorm);
parentTexture()->setFromQImage(img);
}
else {
@@ -141,6 +141,155 @@ void Quick3DTexture2DExtension::setSource(QUrl arg)
}
}
+Quick3DTextureCubeMapExtension::Quick3DTextureCubeMapExtension(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void Quick3DTextureCubeMapExtension::setSource(const QUrl &source)
+{
+ if (source != m_source) {
+ m_source = source;
+ emit sourceChanged();
+ QUrl tmp(m_source);
+ // Default to png extension for now
+ tmp.setPath(m_source.path() + QStringLiteral("_posx.png"));
+ setPositiveX(tmp);
+ tmp.setPath(m_source.path() + QStringLiteral("_posy.png"));
+ setPositiveY(tmp);
+ tmp.setPath(m_source.path() + QStringLiteral("_posz.png"));
+ setPositiveZ(tmp);
+ tmp.setPath(m_source.path() + QStringLiteral("_negx.png"));
+ setNegativeX(tmp);
+ tmp.setPath(m_source.path() + QStringLiteral("_negy.png"));
+ setNegativeY(tmp);
+ tmp.setPath(m_source.path() + QStringLiteral("_negz.png"));
+ setNegativeZ(tmp);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setPositiveX(const QUrl &positiveX)
+{
+ if (positiveX != m_positiveX) {
+ m_positiveX = positiveX;
+ emit positiveXChanged();
+ loadFace(positiveX, QTexture::CubeMapPositiveX);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setPositiveY(const QUrl &positiveY)
+{
+ if (positiveY != m_positiveY) {
+ m_positiveY = positiveY;
+ emit positiveYChanged();
+ loadFace(positiveY, QTexture::CubeMapPositiveY);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setPositiveZ(const QUrl &positiveZ)
+{
+ if (positiveZ != m_positiveZ) {
+ m_positiveZ = positiveZ;
+ emit positiveZChanged();
+ loadFace(positiveZ, QTexture::CubeMapPositiveZ);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setNegativeX(const QUrl &negativeX)
+{
+ if (negativeX != m_negativeX) {
+ m_negativeX = negativeX;
+ emit negativeXChanged();
+ loadFace(negativeX, QTexture::CubeMapNegativeX);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setNegativeY(const QUrl &negativeY)
+{
+ if (negativeY != m_negativeY) {
+ m_negativeY = negativeY;
+ emit negativeYChanged();
+ loadFace(negativeY, QTexture::CubeMapNegativeY);
+ }
+}
+
+void Quick3DTextureCubeMapExtension::setNegativeZ(const QUrl &negativeZ)
+{
+ if (negativeZ != m_negativeZ) {
+ m_negativeZ = negativeZ;
+ emit negativeZChanged();
+ loadFace(negativeZ, QTexture::CubeMapNegativeZ);
+ }
+}
+
+QUrl Quick3DTextureCubeMapExtension::source() const
+{
+ return m_source;
+}
+
+QUrl Quick3DTextureCubeMapExtension::positiveX() const
+{
+ return m_positiveX;
+}
+
+QUrl Quick3DTextureCubeMapExtension::positiveY() const
+{
+ return m_positiveY;
+}
+
+QUrl Quick3DTextureCubeMapExtension::positiveZ() const
+{
+ return m_positiveZ;
+}
+
+QUrl Quick3DTextureCubeMapExtension::negativeX() const
+{
+ return m_negativeX;
+}
+
+QUrl Quick3DTextureCubeMapExtension::negativeY() const
+{
+ return m_negativeY;
+}
+
+QUrl Quick3DTextureCubeMapExtension::negativeZ() const
+{
+ return m_negativeZ;
+}
+
+void Quick3DTextureCubeMapExtension::loadFace(const QUrl &faceUrl, QTexture::CubeMapFace face)
+{
+ if (faceUrl.isLocalFile() || faceUrl.scheme() == QStringLiteral("qrc")) {
+ QString source = faceUrl.toString().replace(QStringLiteral("qrc"), QStringLiteral(""));
+ QImage img;
+ parentTexture()->setStatus(QTexture::Loading);
+ if (img.load(source)) {
+ TexImageDataPtr dataPtr(new TexImageData(0, 0));
+
+ dataPtr->setCubeFace(static_cast<QOpenGLTexture::CubeMapFace>(face));
+ if (parentTexture()->height() != img.height())
+ parentTexture()->setHeight(img.height());
+ if (parentTexture()->width() != img.width())
+ parentTexture()->setWidth(img.width());
+ QTexture::TextureFormat format = img.hasAlphaChannel() ?
+ QTexture::RGBA8_UNorm :
+ QTexture::RGB8_UNorm;
+ if (format != parentTexture()->format())
+ parentTexture()->setFormat(format);
+ dataPtr->setImage(img);
+ parentTexture()->addImageData(dataPtr);
+ parentTexture()->setStatus(QTexture::Loaded);
+ }
+ else {
+ qWarning() << "Failed to load image : " << source;
+ parentTexture()->setStatus(QTexture::Error);
+ }
+ } else {
+ parentTexture()->setStatus(QTexture::Error);
+ qWarning() << "implement loading from remote URLs";
+ }
+}
+
} // Quick
} // Render
diff --git a/src/quick3d/quick3drenderer/items/quick3dtexture.h b/src/quick3d/quick3drenderer/items/quick3dtexture.h
index 554cb44f5..fc4d8cb18 100644
--- a/src/quick3d/quick3drenderer/items/quick3dtexture.h
+++ b/src/quick3d/quick3drenderer/items/quick3dtexture.h
@@ -96,6 +96,8 @@ class QT3DQUICKRENDERERSHARED_EXPORT Quick3DTextureCubeMap : public QTexture
Q_OBJECT
public:
explicit Quick3DTextureCubeMap(QNode *parent = 0);
+
+ friend class Quick3DTextureCubeMapExtension;
};
class QT3DQUICKRENDERERSHARED_EXPORT Quick3DTextureCubeMapArray : public QTexture
@@ -151,6 +153,58 @@ private:
inline Qt3D::QTexture *parentTexture() const { return qobject_cast<Qt3D::QTexture *>(parent()); }
};
+class QT3DQUICKRENDERERSHARED_EXPORT Quick3DTextureCubeMapExtension : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged())
+ Q_PROPERTY(QUrl positiveX READ positiveX WRITE setPositiveX NOTIFY positiveXChanged())
+ Q_PROPERTY(QUrl positiveY READ positiveY WRITE setPositiveY NOTIFY positiveYChanged())
+ Q_PROPERTY(QUrl positiveZ READ positiveZ WRITE setPositiveZ NOTIFY positiveZChanged())
+ Q_PROPERTY(QUrl negativeX READ negativeX WRITE setNegativeX NOTIFY negativeXChanged())
+ Q_PROPERTY(QUrl negativeY READ negativeY WRITE setNegativeY NOTIFY negativeYChanged())
+ Q_PROPERTY(QUrl negativeZ READ negativeZ WRITE setNegativeZ NOTIFY negativeZChanged())
+
+public:
+ explicit Quick3DTextureCubeMapExtension(QObject *parent = 0);
+
+ void setSource(const QUrl &source);
+ void setPositiveX(const QUrl &positiveX);
+ void setPositiveY(const QUrl &positiveY);
+ void setPositiveZ(const QUrl &positiveZ);
+ void setNegativeX(const QUrl &negativeX);
+ void setNegativeY(const QUrl &negativeY);
+ void setNegativeZ(const QUrl &negativeZ);
+
+ QUrl source() const;
+ QUrl positiveX() const;
+ QUrl positiveY() const;
+ QUrl positiveZ() const;
+ QUrl negativeX() const;
+ QUrl negativeY() const;
+ QUrl negativeZ() const;
+
+Q_SIGNALS:
+ void positiveXChanged();
+ void positiveYChanged();
+ void positiveZChanged();
+ void negativeXChanged();
+ void negativeYChanged();
+ void negativeZChanged();
+ void sourceChanged();
+
+private:
+ QUrl m_positiveX;
+ QUrl m_positiveY;
+ QUrl m_positiveZ;
+ QUrl m_negativeX;
+ QUrl m_negativeY;
+ QUrl m_negativeZ;
+ QUrl m_source;
+
+ inline Quick3DTextureCubeMap *parentTexture() { return qobject_cast<Quick3DTextureCubeMap *>(parent()); }
+ void loadFace(const QUrl &faceUrl, QTexture::CubeMapFace face);
+};
+
} // Quick
} // Render