summaryrefslogtreecommitdiffstats
path: root/src/render/io
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2015-09-18 18:04:22 +0100
committerPaul Lemire <paul.lemire@kdab.com>2015-10-13 12:13:09 +0000
commitb6756277908e1d8e15dd3e35da72c42569494152 (patch)
tree237ea333015f4479f9fbafd4184b89789983a304 /src/render/io
parent9c1281f56317bfb8c050d0c464a5a1da1ca885bd (diff)
Final batch of file moves for now
Change-Id: I0c9e83e3142e6b083feb2cbcabcc4279de64b95b Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/io.pri20
-rw-r--r--src/render/io/qabstractsceneloader.cpp (renamed from src/render/io/qbuffer.cpp)94
-rw-r--r--src/render/io/qabstractsceneloader.h (renamed from src/render/io/qattribute.h)53
-rw-r--r--src/render/io/qabstractsceneloader_p.h (renamed from src/render/io/qbuffer_p.h)25
-rw-r--r--src/render/io/qattribute.cpp264
-rw-r--r--src/render/io/qbuffer.h116
-rw-r--r--src/render/io/qsceneloader.cpp91
-rw-r--r--src/render/io/qsceneloader.h (renamed from src/render/io/qattribute_p.h)21
-rw-r--r--src/render/io/render-io.pri21
-rw-r--r--src/render/io/scene.cpp129
-rw-r--r--src/render/io/scene_p.h (renamed from src/render/io/qbufferfunctor.h)55
-rw-r--r--src/render/io/scenemanager.cpp (renamed from src/render/io/texturedata.h)81
-rw-r--r--src/render/io/scenemanager_p.h (renamed from src/render/io/qgeometryfunctor.h)48
-rw-r--r--src/render/io/texturedata.cpp127
14 files changed, 430 insertions, 715 deletions
diff --git a/src/render/io/io.pri b/src/render/io/io.pri
new file mode 100644
index 000000000..70f00ab9a
--- /dev/null
+++ b/src/render/io/io.pri
@@ -0,0 +1,20 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/abstractsceneparser_p.h \
+ $$PWD/objloader_p.h \
+ $$PWD/qabstractsceneloader.h \
+ $$PWD/qabstractsceneloader_p.h \
+ $$PWD/qsceneloader.h \
+ $$PWD/scene_p.h \
+ $$PWD/scenemanager_p.h \
+ $$PWD/uniformbuffer_p.h
+
+SOURCES += \
+ $$PWD/abstractsceneparser.cpp \
+ $$PWD/objloader.cpp \
+ $$PWD/qabstractsceneloader.cpp \
+ $$PWD/qsceneloader.cpp \
+ $$PWD/scene.cpp \
+ $$PWD/scenemanager.cpp \
+ $$PWD/uniformbuffer.cpp
diff --git a/src/render/io/qbuffer.cpp b/src/render/io/qabstractsceneloader.cpp
index 6a86f74f7..d0e9a8838 100644
--- a/src/render/io/qbuffer.cpp
+++ b/src/render/io/qabstractsceneloader.cpp
@@ -34,104 +34,76 @@
**
****************************************************************************/
-#include "qbuffer.h"
-#include "qbuffer_p.h"
+#include "qabstractsceneloader.h"
+#include "qabstractsceneloader_p.h"
#include <Qt3DRenderer/private/renderlogging_p.h>
+#include <Qt3DRenderer/private/abstractsceneparser_p.h>
#include <Qt3DCore/qscenepropertychange.h>
QT_BEGIN_NAMESPACE
-using namespace Qt3D;
-
namespace Qt3DRender {
/*!
- \class Qt3D::BufferPrivate
+ \class Qt3DRender::Render::QAbstractSceneLoaderPrivate
\internal
*/
-QBufferPrivate::QBufferPrivate()
- : QAbstractBufferPrivate()
- , m_usage(QBuffer::StaticDraw)
-{
-}
-
-
-QBuffer::QBuffer(QBuffer::BufferType ty, QNode *parent)
- : QAbstractBuffer(*new QBufferPrivate(), parent)
+QAbstractSceneLoaderPrivate::QAbstractSceneLoaderPrivate()
+ : QComponentPrivate()
+ , m_status(QAbstractSceneLoader::Loading)
{
- Q_D(QBuffer);
- d->m_type = ty;
-}
-
-QBuffer::~QBuffer()
-{
- QAbstractBuffer::cleanup();
+ m_shareable = false;
}
/*! \internal */
-QBuffer::QBuffer(QBufferPrivate &dd, QBuffer::BufferType ty, QNode *parent)
- : QAbstractBuffer(dd, parent)
+QAbstractSceneLoader::QAbstractSceneLoader(QAbstractSceneLoaderPrivate &dd, QNode *parent)
+ : QComponent(dd, parent)
{
- Q_D(QBuffer);
- d->m_type = ty;
}
-void QBuffer::copy(const QNode *ref)
+QAbstractSceneLoader::QAbstractSceneLoader(QNode *parent)
+ : QComponent(*new QAbstractSceneLoaderPrivate, parent)
{
- QAbstractBuffer::copy(ref);
- const QBuffer *buffer = static_cast<const QBuffer *>(ref);
- d_func()->m_type = buffer->d_func()->m_type;
- d_func()->m_usage = buffer->d_func()->m_usage;
- d_func()->m_functor = buffer->d_func()->m_functor;
}
-QBuffer::UsageType QBuffer::usage() const
+QAbstractSceneLoader::~QAbstractSceneLoader()
{
- Q_D(const QBuffer);
- return d->m_usage;
+ Q_ASSERT_X(Qt3D::QNodePrivate::get(this)->m_wasCleanedUp, Q_FUNC_INFO, "QNode::cleanup should have been called by now. A Qt3DRender::QAbstractSceneLoader subclass didn't call QNode::cleanup in its destructor");
}
-void QBuffer::setUsage(QBuffer::UsageType usage)
+void QAbstractSceneLoader::copy(const QNode *ref)
{
- Q_D(QBuffer);
- if (usage != d->m_usage) {
- d->m_usage = usage;
- emit usageChanged();
- }
+ const QAbstractSceneLoader *s = static_cast<const QAbstractSceneLoader*>(ref);
+ d_func()->m_source = s->d_func()->m_source;
}
-QBuffer::BufferType QBuffer::type() const
+QUrl QAbstractSceneLoader::source() const
{
- Q_D(const QBuffer);
- return d->m_type;
+ Q_D(const QAbstractSceneLoader);
+ return d->m_source;
}
-void QBuffer::setBufferFunctor(const QBufferFunctorPtr &functor)
+void QAbstractSceneLoader::setSource(const QUrl &arg)
{
- Q_D(QBuffer);
- if (functor && d->m_functor && *functor == *d->m_functor)
- return;
- d->m_functor = functor;
- if (d->m_changeArbiter != Q_NULLPTR) {
- QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, QSceneChange::Node, id()));
- change->setPropertyName("bufferFunctor");
- change->setValue(QVariant::fromValue(d->m_functor));
- d->notifyObservers(change);
+ Q_D(QAbstractSceneLoader);
+ if (d->m_source != arg) {
+ d->m_source = arg;
+ emit sourceChanged();
}
}
-QBufferFunctorPtr QBuffer::bufferFunctor() const
+QAbstractSceneLoader::Status QAbstractSceneLoader::status() const
{
- Q_D(const QBuffer);
- return d->m_functor;
+ Q_D(const QAbstractSceneLoader);
+ return d->m_status;
}
-void QBuffer::setType(QBuffer::BufferType type)
+void QAbstractSceneLoader::setStatus(QAbstractSceneLoader::Status status)
{
- Q_D(QBuffer);
- if (type != d->m_type) {
- d->m_type = type;
- emit typeChanged();
+ Q_D(QAbstractSceneLoader);
+ if (d->m_status != status) {
+ d->m_status = status;
+ emit statusChanged();
}
}
diff --git a/src/render/io/qattribute.h b/src/render/io/qabstractsceneloader.h
index 9106cbda9..88af95577 100644
--- a/src/render/io/qattribute.h
+++ b/src/render/io/qabstractsceneloader.h
@@ -34,54 +34,57 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QATTRIBUTE_H
-#define QT3DRENDER_QATTRIBUTE_H
+#ifndef QT3DRENDER_QABSTRACTSCENELOADER_H
+#define QT3DRENDER_QABSTRACTSCENELOADER_H
-#include <Qt3DCore/qabstractattribute.h>
+#include <Qt3DCore/qcomponent.h>
+#include <Qt3DCore/qscenechange.h>
#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <QtCore/QSharedPointer>
+#include <QUrl>
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
-class QAttributePrivate;
-class QBuffer;
+class QAbstractSceneLoader;
+class QAbstractSceneLoaderPrivate;
-class QT3DRENDERERSHARED_EXPORT QAttribute : public Qt3D::QAbstractAttribute
+class QT3DRENDERERSHARED_EXPORT QAbstractSceneLoader : public Qt3D::QComponent
{
Q_OBJECT
-
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
public:
- explicit QAttribute(Qt3D::QNode *parent = 0);
- QAttribute(QBuffer *buf, DataType type, uint dataSize, int count, int offset=0, int stride = 0);
- QAttribute(QBuffer *buf, const QString &name, DataType type, uint dataSize, int count, int offset=0, int stride = 0);
- ~QAttribute();
+ explicit QAbstractSceneLoader(Qt3D::QNode *parent = 0);
+ ~QAbstractSceneLoader();
- QVector<QVector4D> asVector4D() const Q_DECL_OVERRIDE;
- QVector<QVector3D> asVector3D() const Q_DECL_OVERRIDE;
- QVector<QVector2D> asVector2D() const Q_DECL_OVERRIDE;
+ enum Status {
+ Loading = 0,
+ Loaded,
+ Error
+ };
+ Q_ENUM(Status)
- void dump(int count) Q_DECL_OVERRIDE;
+ QUrl source() const;
+ void setSource(const QUrl &arg);
- QBuffer *buffer() const;
+ Status status() const;
+ void setStatus(Status status);
- static QString defaultPositionAttributeName();
- static QString defaultNormalAttributeName();
- static QString defaultColorAttributeName();
- static QString defaultTextureCoordinateAttributeName();
- static QString defaultTangentAttributeName();
+Q_SIGNALS:
+ void sourceChanged();
+ void statusChanged();
protected:
+ QAbstractSceneLoader(QAbstractSceneLoaderPrivate &dd, Qt3D::QNode *parent = 0);
void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE;
private:
- QT3D_CLONEABLE(QAttribute)
- Q_DECLARE_PRIVATE(QAttribute)
+ Q_DECLARE_PRIVATE(QAbstractSceneLoader)
};
} // namespace Qt3DRender
QT_END_NAMESPACE
-#endif // QT3DRENDER_QATTRIBUTE_H
+#endif // QT3DRENDER_QABSTRACTSCENELOADER_H
diff --git a/src/render/io/qbuffer_p.h b/src/render/io/qabstractsceneloader_p.h
index 53bea6359..3377c730c 100644
--- a/src/render/io/qbuffer_p.h
+++ b/src/render/io/qabstractsceneloader_p.h
@@ -34,31 +34,32 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QBUFFER_P_H
-#define QT3DRENDER_QBUFFER_P_H
+#ifndef QT3DRENDER_QABSTRACTSCENELOADER_P_H
+#define QT3DRENDER_QABSTRACTSCENELOADER_P_H
-#include <private/qabstractbuffer_p.h>
-#include <Qt3DRenderer/qbuffer.h>
-#include <Qt3DRenderer/qbufferfunctor.h>
+#include <private/qcomponent_p.h>
#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <QOpenGLBuffer>
+#include <Qt3DRenderer/qabstractsceneloader.h>
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
-class QT3DRENDERERSHARED_EXPORT QBufferPrivate : public Qt3D::QAbstractBufferPrivate
+class AbstractSceneParser;
+
+class QT3DRENDERERSHARED_EXPORT QAbstractSceneLoaderPrivate : public Qt3D::QComponentPrivate
{
public:
- QBufferPrivate();
+ QAbstractSceneLoaderPrivate();
+
+ Q_DECLARE_PUBLIC(QAbstractSceneLoader)
- QBuffer::BufferType m_type;
- QBuffer::UsageType m_usage;
- QBufferFunctorPtr m_functor;
+ QUrl m_source;
+ QAbstractSceneLoader::Status m_status;
};
} // namespace Qt3DRender
QT_END_NAMESPACE
-#endif // QT3DRENDER_QBUFFER_P_H
+#endif // QT3DRENDER_QABSTRACTSCENE_P_H
diff --git a/src/render/io/qattribute.cpp b/src/render/io/qattribute.cpp
deleted file mode 100644
index 09b858128..000000000
--- a/src/render/io/qattribute.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/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 "qattribute.h"
-#include "qattribute_p.h"
-#include <QVector4D>
-#include <QVector3D>
-#include <QVector2D>
-#include <QVector>
-#include <Qt3DRenderer/qbuffer.h>
-#include <Qt3DRenderer/private/renderlogging_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-
-/*!
- class Qt3D::AttributePrivate
- \internal
-*/
-QAttributePrivate::QAttributePrivate()
- : QAbstractAttributePrivate()
-{
-}
-
-QAttribute::QAttribute(QNode *parent)
- : QAbstractAttribute(*new QAttributePrivate(), parent)
-{
-}
-
-QAttribute::QAttribute(QBuffer *buf, DataType type, uint dataSize, int count, int offset, int stride)
- : QAbstractAttribute(*new QAttributePrivate(), buf, QString(), type, dataSize, count, offset, stride)
-{
-}
-
-QAttribute::QAttribute(QBuffer *buf, const QString &name, DataType type, uint dataSize, int count, int offset, int stride)
- : QAbstractAttribute(*new QAttributePrivate(), buf, name, type, dataSize, count, offset, stride)
-{
-}
-
-QAttribute::~QAttribute()
-{
- QAbstractAttribute::cleanup();
-}
-
-void QAttribute::copy(const QNode *ref)
-{
- QAbstractAttribute::copy(ref);
-}
-
-QVector<QVector4D> QAttribute::asVector4D() const
-{
- Q_D(const QAttribute);
- const QByteArray buffer = d->m_buffer->data();
- const char *rawBuffer = buffer.constData();
- rawBuffer += d->m_byteOffset;
- const float* fptr;
- int stride;
-
- switch (dataType()) {
- case QAttribute::Float:
- stride = sizeof(float) * dataSize();
- break;
-
- default:
- qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << dataType() << "x" << dataSize() << "to QVector3D";
- return QVector<QVector4D>();
- }
-
- if (d->m_byteStride != 0)
- stride = d->m_byteStride;
- QVector<QVector4D> result;
- result.resize(d->m_count);
-
- for (uint c = 0; c < d->m_count; ++c) {
- QVector4D v;
- fptr = reinterpret_cast<const float*>(rawBuffer);
-
- for (uint i = 0, m = dataSize(); i < m; ++i)
- v[i] = fptr[i];
-
- result[c] = v;
- rawBuffer += stride;
- }
-
- return result;
-}
-
-QVector<QVector3D> QAttribute::asVector3D() const
-{
- Q_D(const QAttribute);
- const QByteArray buffer = d->m_buffer->data();
- const char *rawBuffer = buffer.constData();
- rawBuffer += d->m_byteOffset;
- const float* fptr;
- int stride;
-
- switch (dataType()) {
- case QAttribute::Float:
- stride = sizeof(float) * dataSize();
- break;
-
- default:
- qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << dataType() << "x" << dataSize() << "to QVector3D";
- return QVector<QVector3D>();
- }
-
- if (d->m_byteStride != 0)
- stride = d->m_byteStride;
- QVector<QVector3D> result;
- result.resize(d->m_count);
-
- for (uint c = 0; c < d->m_count; ++c) {
- QVector3D v;
- fptr = reinterpret_cast<const float*>(rawBuffer);
-
- for (uint i = 0, m = qMin(dataSize(), 3U); i < m; ++i)
- v[i] = fptr[i];
-
- result[c] = v;
- rawBuffer += stride;
- }
-
- return result;
-}
-
-QVector<QVector2D> QAttribute::asVector2D() const
-{
- Q_D(const QAttribute);
- char* rawBuffer = d->m_buffer->data().data();
- rawBuffer += d->m_byteOffset;
- float* fptr;
- int stride;
-
- switch (dataType()) {
- case QAttribute::Float:
- stride = sizeof(float) * dataSize();
- break;
-
- default:
- qCDebug(Render::Io) << Q_FUNC_INFO << "can't convert" << dataType() << "x" << dataSize() << "to QVector3D";
- return QVector<QVector2D>();
- }
-
- if (d->m_byteStride != 0)
- stride = d->m_byteStride;
-
- QVector<QVector2D> result;
- result.resize(d->m_count);
-
- for (uint c = 0; c < d->m_count; ++c) {
- QVector2D v;
- fptr = reinterpret_cast<float*>(rawBuffer);
- for (uint i = 0, m = qMin(dataSize(), 2U); i < m; ++i)
- v[i] = fptr[i];
- result[c] = v;
- rawBuffer += stride;
- }
-
- return result;
-}
-
-void QAttribute::dump(int count)
-{
- Q_D(const QAttribute);
- const char* rawBuffer = d->m_buffer->data().data();
- rawBuffer += d->m_byteOffset;
-
- const float* fptr;
- const quint16* usptr;
-
- int stride = d->m_byteStride;
-
- for (int c=0; c<count; ++c) {
- switch (dataType()) {
- case QAttribute::UnsignedShort:
- if (stride == 0)
- stride = sizeof(quint16);
- usptr = reinterpret_cast<const quint16*>(rawBuffer + stride * c);
- qCDebug(Render::Io) << c << ":u16:" << usptr[0];
- break;
- case QAttribute::UnsignedInt:
- if (stride == 0)
- stride = sizeof(quint32);
- qCDebug(Render::Io) << c << ":u32:" << reinterpret_cast<const quint32*>(rawBuffer + stride * c)[0];
- break;
- case QAttribute::Float:
- if (stride == 0)
- stride = sizeof(float) * dataSize();
- fptr = reinterpret_cast<const float*>(rawBuffer + stride * c);
- qCDebug(Render::Io) << c << QString::fromLatin1(":vec") + QString::number(dataSize()) << fptr[0] << fptr[1];
- break;
-
- default: qCDebug(Render::Io) << Q_FUNC_INFO << "unspported type:" << dataType();
- }
- }
-}
-
-QBuffer *QAttribute::buffer() const
-{
- return static_cast<QBuffer *>(QAbstractAttribute::buffer());
-}
-
-QString QAttribute::defaultPositionAttributeName()
-{
- return QStringLiteral("vertexPosition");
-}
-
-QString QAttribute::defaultNormalAttributeName()
-{
- return QStringLiteral("vertexNormal");
-}
-
-QString QAttribute::defaultColorAttributeName()
-{
- return QStringLiteral("vertexColor");
-}
-
-QString QAttribute::defaultTextureCoordinateAttributeName()
-{
- return QStringLiteral("vertexTexCoord");
-}
-
-QString QAttribute::defaultTangentAttributeName()
-{
- return QStringLiteral("vertexTangent");
-}
-
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
diff --git a/src/render/io/qbuffer.h b/src/render/io/qbuffer.h
deleted file mode 100644
index d1d9f9929..000000000
--- a/src/render/io/qbuffer.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/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$
-**
-****************************************************************************/
-
-#ifndef QT3DRENDER_QBUFFER_H
-#define QT3DRENDER_QBUFFER_H
-
-#include <Qt3DCore/qabstractbuffer.h>
-#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <QSharedPointer>
-#include <QOpenGLBuffer>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-
-GLint elementType(GLint type);
-GLint tupleSizeFromType(GLint type);
-GLuint byteSizeFromType(GLint type);
-
-class QBufferPrivate;
-class QBufferFunctor;
-typedef QSharedPointer<QBufferFunctor> QBufferFunctorPtr;
-
-class QT3DRENDERERSHARED_EXPORT QBuffer : public Qt3D::QAbstractBuffer
-{
- Q_OBJECT
- Q_PROPERTY(BufferType type READ type WRITE setType NOTIFY typeChanged)
- Q_PROPERTY(UsageType usage READ usage WRITE setUsage NOTIFY usageChanged)
-
-public:
- enum BufferType
- {
- VertexBuffer = 0x8892, // GL_ARRAY_BUFFER
- IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER
- PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER
- PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER
- };
- Q_ENUM(BufferType)
-
- enum UsageType
- {
- StreamDraw = 0x88E0, // GL_STREAM_DRAW
- StreamRead = 0x88E1, // GL_STREAM_READ
- StreamCopy = 0x88E2, // GL_STREAM_COPY
- StaticDraw = 0x88E4, // GL_STATIC_DRAW
- StaticRead = 0x88E5, // GL_STATIC_READ
- StaticCopy = 0x88E6, // GL_STATIC_COPY
- DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW
- DynamicRead = 0x88E9, // GL_DYNAMIC_READ
- DynamicCopy = 0x88EA // GL_DYNAMIC_COPY
- };
- Q_ENUM(UsageType)
-
- QBuffer(BufferType ty = QBuffer::VertexBuffer, Qt3D::QNode *parent = 0);
- ~QBuffer();
-
- void setUsage(UsageType usage);
- UsageType usage() const;
-
- void setType(BufferType type);
- BufferType type() const;
-
- void setBufferFunctor(const QBufferFunctorPtr &functor);
- QBufferFunctorPtr bufferFunctor() const;
-
-protected:
- QBuffer(QBufferPrivate &dd, QBuffer::BufferType ty, Qt3D::QNode *parent = 0);
- void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE;
-
-Q_SIGNALS:
- void typeChanged();
- void usageChanged();
-
-private:
- Q_DECLARE_PRIVATE(QBuffer)
- QT3D_CLONEABLE(QBuffer)
-};
-
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
-
-#endif // QT3DRENDER_QBUFFER_H
diff --git a/src/render/io/qsceneloader.cpp b/src/render/io/qsceneloader.cpp
new file mode 100644
index 000000000..b5b4975e7
--- /dev/null
+++ b/src/render/io/qsceneloader.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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 "qsceneloader.h"
+#include "qabstractsceneloader_p.h"
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/qscenepropertychange.h>
+#include <Qt3DCore/qentity.h>
+#include <Qt3DRenderer/private/renderlogging_p.h>
+#include <QThread>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt3D;
+
+namespace Qt3DRender {
+
+QSceneLoader::QSceneLoader(QNode *parent)
+ : QAbstractSceneLoader(parent)
+{
+}
+
+QSceneLoader::~QSceneLoader()
+{
+ QNode::cleanup();
+}
+
+// Called in main thread
+void QSceneLoader::sceneChangeEvent(const Qt3D::QSceneChangePtr &change)
+{
+ QAbstractSceneLoaderPrivate *d = static_cast<QAbstractSceneLoaderPrivate*>(QNodePrivate::get(this));
+ QScenePropertyChangePtr e = qSharedPointerCast<QScenePropertyChange>(change);
+ if (e->type() == NodeUpdated) {
+ if (e->propertyName() == QByteArrayLiteral("scene")) {
+ QEntity *scene = e->value().value<QEntity *>();
+ // TO DO: We should send a QNodePtr so that it is release automatically
+ if (scene != Q_NULLPTR && d->m_scene != Q_NULLPTR) {
+ QList<QNodeId> entities = d->m_scene->entitiesForComponent(d->m_id);
+ if (entities.size() > 1) // TO DO: QComponent shareable property
+ qCWarning(Render::Frontend) << "It is strongly discouraged to share SceneLoader component between entities";
+ Q_FOREACH (const QNodeId &id, entities) {
+ QEntity *parentEntity = qobject_cast<QEntity *>(d->m_scene->lookupNode(id));
+ if (parentEntity != Q_NULLPTR) {
+ QEntity *cloneScene = qobject_cast<QEntity *>(QNode::clone(scene));
+ QNodePrivate::get(parentEntity)->insertTree(cloneScene);
+ }
+ }
+ }
+ }
+ else if (e->propertyName() == QByteArrayLiteral("status")) {
+ QAbstractSceneLoader::setStatus(static_cast<QAbstractSceneLoader::Status>(e->value().toInt()));
+ }
+ }
+}
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/io/qattribute_p.h b/src/render/io/qsceneloader.h
index 0e7ef390f..adbed1dda 100644
--- a/src/render/io/qattribute_p.h
+++ b/src/render/io/qsceneloader.h
@@ -34,26 +34,29 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QATTRIBUTE_P_H
-#define QT3DRENDER_QATTRIBUTE_P_H
+#ifndef QT3DRENDER_QSCENELOADER_H
+#define QT3DRENDER_QSCENELOADER_H
-#include <private/qabstractattribute_p.h>
-#include <Qt3DRenderer/qt3drenderer_global.h>
+#include <Qt3DRenderer/qabstractsceneloader.h>
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
-class QAttribute;
-
-class QT3DRENDERERSHARED_EXPORT QAttributePrivate : public Qt3D::QAbstractAttributePrivate
+class QT3DRENDERERSHARED_EXPORT QSceneLoader : public QAbstractSceneLoader
{
+ Q_OBJECT
public:
- QAttributePrivate();
+ explicit QSceneLoader(Qt3D::QNode *parent = 0);
+ ~QSceneLoader();
+ void sceneChangeEvent(const Qt3D::QSceneChangePtr &change) Q_DECL_OVERRIDE;
+
+protected:
+ QT3D_CLONEABLE(QSceneLoader)
};
} // namespace Qt3DRender
QT_END_NAMESPACE
-#endif // QT3DRENDER_QATTRIBUTE_P_H
+#endif // QT3DRENDER_QSCENELOADER_H
diff --git a/src/render/io/render-io.pri b/src/render/io/render-io.pri
deleted file mode 100644
index ababc3cd0..000000000
--- a/src/render/io/render-io.pri
+++ /dev/null
@@ -1,21 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/objloader_p.h \
- $$PWD/texturedata.h \
- $$PWD/abstractsceneparser_p.h \
- $$PWD/qattribute.h \
- $$PWD/qattribute_p.h \
- $$PWD/qbuffer.h \
- $$PWD/qbuffer_p.h \
- $$PWD/uniformbuffer_p.h \
- $$PWD/qbufferfunctor.h \
- $$PWD/qgeometryfunctor.h
-
-SOURCES += \
- $$PWD/objloader.cpp \
- $$PWD/texturedata.cpp \
- $$PWD/abstractsceneparser.cpp \
- $$PWD/qattribute.cpp \
- $$PWD/qbuffer.cpp \
- $$PWD/uniformbuffer.cpp
diff --git a/src/render/io/scene.cpp b/src/render/io/scene.cpp
new file mode 100644
index 000000000..a92dc1fd8
--- /dev/null
+++ b/src/render/io/scene.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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 "scene_p.h"
+#include <Qt3DCore/qentity.h>
+#include <Qt3DCore/qscenepropertychange.h>
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/qbackendscenepropertychange.h>
+#include <Qt3DRenderer/qabstractsceneloader.h>
+#include <Qt3DRenderer/private/scenemanager_p.h>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt3D;
+
+namespace Qt3DRender {
+namespace Render {
+
+Scene::Scene()
+ : QBackendNode(QBackendNode::ReadWrite)
+ , m_sceneManager(Q_NULLPTR)
+{
+}
+
+void Scene::updateFromPeer(Qt3D::QNode *peer)
+{
+ QAbstractSceneLoader *loader = static_cast<QAbstractSceneLoader *>(peer);
+
+ m_source = loader->source();
+ m_sceneManager->addSceneData(m_source, peerUuid());
+}
+
+void Scene::sceneChangeEvent(const Qt3D::QSceneChangePtr &e)
+{
+ QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e);
+ if (propertyChange->propertyName() == QByteArrayLiteral("source")) {
+ m_source = propertyChange->value().toUrl();
+ m_sceneManager->addSceneData(m_source, peerUuid());
+ }
+}
+
+QUrl Scene::source() const
+{
+ return m_source;
+}
+
+void Scene::setSceneSubtree(Qt3D::QEntity *subTree)
+{
+ QBackendScenePropertyChangePtr e(new QBackendScenePropertyChange(NodeUpdated, peerUuid()));
+ e->setPropertyName("scene");
+ // The Frontend element has to perform the clone
+ // So that the objects are created in the main thread
+ e->setValue(QVariant::fromValue(subTree));
+ e->setTargetNode(peerUuid());
+ notifyObservers(e);
+ QBackendScenePropertyChangePtr e2(new QBackendScenePropertyChange(NodeUpdated, peerUuid()));
+ e2->setPropertyName("status");
+ e2->setValue(subTree != Q_NULLPTR ? QAbstractSceneLoader::Loaded : QAbstractSceneLoader::Error);
+ e2->setTargetNode(peerUuid());
+ notifyObservers(e2);
+}
+
+void Scene::setSceneManager(SceneManager *manager)
+{
+ if (m_sceneManager != manager)
+ m_sceneManager = manager;
+}
+
+RenderSceneFunctor::RenderSceneFunctor(SceneManager *sceneManager)
+ : m_sceneManager(sceneManager)
+{
+}
+
+Qt3D::QBackendNode *RenderSceneFunctor::create(Qt3D::QNode *frontend, const Qt3D::QBackendNodeFactory *factory) const
+{
+ Scene *scene = m_sceneManager->getOrCreateResource(frontend->id());
+ scene->setFactory(factory);
+ scene->setSceneManager(m_sceneManager);
+ scene->setPeer(frontend);
+ return scene;
+}
+
+Qt3D::QBackendNode *RenderSceneFunctor::get(const Qt3D::QNodeId &id) const
+{
+ return m_sceneManager->lookupResource(id);
+}
+
+void RenderSceneFunctor::destroy(const Qt3D::QNodeId &id) const
+{
+ m_sceneManager->releaseResource(id);
+}
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/io/qbufferfunctor.h b/src/render/io/scene_p.h
index 4a508b975..f69192cfa 100644
--- a/src/render/io/qbufferfunctor.h
+++ b/src/render/io/scene_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
@@ -34,32 +34,57 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QBUFFERFUNCTOR
-#define QT3DRENDER_QBUFFERFUNCTOR
+#ifndef QT3DRENDER_RENDER_SCENE_P_H
+#define QT3DRENDER_RENDER_SCENE_P_H
-#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <Qt3DCore/qabstractfunctor.h>
-#include <QSharedPointer>
+#include <QtGlobal>
+#include <Qt3DCore/qbackendnode.h>
+#include <QUrl>
QT_BEGIN_NAMESPACE
+namespace Qt3D {
+class QEntity;
+}
+
namespace Qt3DRender {
+namespace Render {
+
+class SceneManager;
-class QT3DRENDERERSHARED_EXPORT QBufferFunctor : public Qt3D::QAbstractFunctor
+class Scene : public Qt3D::QBackendNode
{
public:
- virtual ~QBufferFunctor() {}
- virtual QByteArray operator()() = 0;
- virtual bool operator ==(const QBufferFunctor &other) const = 0;
+ Scene();
+
+ void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE;
+
+ // QObserverInterface interface
+ void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE;
+ QUrl source() const;
+ void setSceneSubtree(Qt3D::QEntity *subTree);
+ void setSceneManager(SceneManager *manager);
+
+private:
+ SceneManager *m_sceneManager;
+ QUrl m_source;
};
-typedef QSharedPointer<QBufferFunctor> QBufferFunctorPtr;
+class RenderSceneFunctor : public Qt3D::QBackendNodeFunctor
+{
+public:
+ explicit RenderSceneFunctor(SceneManager *sceneManager);
+ Qt3D::QBackendNode *create(Qt3D::QNode *frontend, const Qt3D::QBackendNodeFactory *factory) const Q_DECL_OVERRIDE;
+ Qt3D::QBackendNode *get(const Qt3D::QNodeId &id) const Q_DECL_OVERRIDE;
+ void destroy(const Qt3D::QNodeId &id) const Q_DECL_OVERRIDE;
+
+private:
+ SceneManager *m_sceneManager;
+};
+} // namespace Render
} // namespace Qt3DRender
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(Qt3DRender::QBufferFunctorPtr)
-
-#endif // QT3DRENDER_QBUFFERFUNCTOR
-
+#endif // QT3DRENDER_RENDER_SCENE_P_H
diff --git a/src/render/io/texturedata.h b/src/render/io/scenemanager.cpp
index 2f3fdb9a9..52fd2a627 100644
--- a/src/render/io/texturedata.h
+++ b/src/render/io/scenemanager.cpp
@@ -34,66 +34,53 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_TEXTUREDATA_H
-#define QT3DRENDER_TEXTUREDATA_H
-
-#include <QOpenGLTexture>
-#include <QImage>
-#include <QSharedPointer>
-#include <Qt3DRenderer/qt3drenderer_global.h>
+#include "scenemanager_p.h"
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
+namespace Render {
-class QT3DRENDERERSHARED_EXPORT TexImageData
+SceneManager::SceneManager() : QResourceManager<Scene,
+ Qt3D::QNodeId,
+ 8,
+ Qt3D::ArrayAllocatingPolicy,
+ Qt3D::ObjectLevelLockingPolicy>()
{
-public:
- TexImageData();
- ~TexImageData();
-
- void cleanup();
-
- bool isCompressed() const
- { return m_isCompressed; }
-
- inline int width() const { return m_width; }
- inline int height() const { return m_height; }
- inline int depth() const { return m_depth; }
- inline QOpenGLTexture::TextureFormat format() const { return m_format; }
-
- void setImage(const QImage &);
-
- void setData(const QByteArray &data,
- QOpenGLTexture::PixelFormat fmt,
- QOpenGLTexture::PixelType ptype);
-
- bool setCompressedFile(const QString &source);
+}
- QByteArray data() const
- { return m_data; }
+void SceneManager::addSceneData(const QUrl &source, const Qt3D::QNodeId &sceneUuid)
+{
+ LoadSceneJobPtr newJob(new LoadSceneJob(source, sceneUuid));
- QOpenGLTexture::PixelFormat pixelFormat() const
- { return m_pixelFormat; }
+ // We cannot run two jobs that use the same scene loader plugin
+ // in two different threads at the same time
+ if (!m_pendingJobs.isEmpty())
+ newJob->addDependency(m_pendingJobs.last());
- QOpenGLTexture::PixelType pixelType() const
- { return m_pixelType; }
+ m_pendingJobs.append(newJob);
+}
-private:
- int m_width, m_height, m_depth;
- QOpenGLTexture::PixelFormat m_pixelFormat;
- QOpenGLTexture::PixelType m_pixelType;
+QVector<LoadSceneJobPtr> SceneManager::pendingSceneLoaderJobs()
+{
+ QVector<LoadSceneJobPtr> copy = m_pendingJobs;
+ m_pendingJobs.clear();
+ return copy;
+}
- bool m_isCompressed;
- QByteArray m_data;
- QOpenGLTexture::TextureFormat m_format;
-};
+void SceneManager::addLoadedSceneTree(const QUrl &source, Qt3D::QEntity *tree)
+{
+ SceneManager::Locker lock(this);
+ m_loadedSceneTrees.insert(source, tree);
+}
-typedef QSharedPointer<TexImageData> TexImageDataPtr;
+Qt3D::QEntity *SceneManager::sceneTreeFromSource(const QUrl &source)
+{
+ SceneManager::Locker lock(this);
+ return m_loadedSceneTrees.value(source);
+}
+} // namespace Render
} // namespace Qt3DRender
-
QT_END_NAMESPACE
-
-#endif // QT3DRENDER_TEXTUREDATA_H
diff --git a/src/render/io/qgeometryfunctor.h b/src/render/io/scenemanager_p.h
index 4290fbe7b..889601db1 100644
--- a/src/render/io/qgeometryfunctor.h
+++ b/src/render/io/scenemanager_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
@@ -34,34 +34,46 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QGEOMETRYFUNCTOR
-#define QT3DRENDER_QGEOMETRYFUNCTOR
+#ifndef QT3DRENDER_RENDER_SCENEMANAGER_P_H
+#define QT3DRENDER_RENDER_SCENEMANAGER_P_H
-#include <Qt3DRenderer/qt3drenderer_global.h>
-#include <Qt3DCore/qabstractfunctor.h>
-#include <QSharedPointer>
+#include <Qt3DCore/private/qresourcemanager_p.h>
+#include <Qt3DRenderer/private/scene_p.h>
+#include <Qt3DCore/qnodeid.h>
+#include <Qt3DRenderer/private/loadscenejob_p.h>
QT_BEGIN_NAMESPACE
-namespace Qt3DRender {
+namespace Qt3D {
+class QEntity;
+}
-class QGeometry;
+namespace Qt3DRender {
+namespace Render {
-class QT3DRENDERERSHARED_EXPORT QGeometryFunctor : public Qt3D::QAbstractFunctor
+class SceneManager : public Qt3D::QResourceManager<Scene,
+ Qt3D::QNodeId,
+ 8,
+ Qt3D::ArrayAllocatingPolicy,
+ Qt3D::ObjectLevelLockingPolicy>
{
public:
- virtual ~QGeometryFunctor() {}
- virtual QGeometry *operator()() = 0;
- virtual bool operator ==(const QGeometryFunctor &other) const = 0;
-};
+ SceneManager();
-typedef QSharedPointer<QGeometryFunctor> QGeometryFunctorPtr;
+ void addSceneData(const QUrl &source, const Qt3D::QNodeId &sceneUuid);
+ QVector<LoadSceneJobPtr> pendingSceneLoaderJobs();
-} // namespace Qt3DRender
+ void addLoadedSceneTree(const QUrl &source, Qt3D::QEntity *tree);
+ Qt3D::QEntity *sceneTreeFromSource(const QUrl &source);
-QT_END_NAMESPACE
+private:
+ QHash<QUrl, Qt3D::QEntity *> m_loadedSceneTrees;
+ QVector<LoadSceneJobPtr> m_pendingJobs;
+};
-Q_DECLARE_METATYPE(Qt3DRender::QGeometryFunctorPtr)
+} // namespace Render
+} // namespace Qt3DRender
-#endif // QT3DRENDER_QGEOMETRYFUNCTOR
+QT_END_NAMESPACE
+#endif // SCENEMANAGER_P_H
diff --git a/src/render/io/texturedata.cpp b/src/render/io/texturedata.cpp
deleted file mode 100644
index b54c526f9..000000000
--- a/src/render/io/texturedata.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/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 "texturedata.h"
-
-#include <QDebug>
-#include <QOpenGLTexture>
-#include <QFileInfo>
-#include <QFile>
-#include <qendian.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-
-TexImageData::TexImageData()
- : m_width(-1)
- , m_height(-1)
- , m_depth(-1)
- , m_isCompressed(false)
- , m_format(QOpenGLTexture::RGBA8_UNorm)
-{
-}
-
-TexImageData::~TexImageData()
-{
-}
-
-void TexImageData::cleanup()
-{
- m_width = -1;
- m_height = -1;
- m_depth = -1;
- m_isCompressed = false;
- m_data.clear();
-}
-
-void TexImageData::setImage(const QImage &image)
-{
- m_width = image.width();
- m_height = image.height();
- m_depth = 1;
-
- QImage glImage = image.convertToFormat(QImage::Format_RGBA8888);
- Q_ASSERT_X(glImage.bytesPerLine() == (glImage.width() * glImage.depth() + 7) / 8, "TexImageData::setImage", "glImage is not packed"); // QTBUG-48330
- QByteArray imageBytes((const char*) glImage.constBits(), glImage.byteCount());
- setData(imageBytes, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8);
- m_format = QOpenGLTexture::RGBA8_UNorm;
-}
-
-void TexImageData::setData(const QByteArray &data, QOpenGLTexture::PixelFormat fmt, QOpenGLTexture::PixelType ptype)
-{
- m_isCompressed = false;
- m_data = data;
- m_pixelFormat = fmt;
- m_pixelType = ptype;
-}
-
-bool TexImageData::setCompressedFile(const QString &source)
-{
- const bool isPkm = QFileInfo(source).suffix() == QStringLiteral("pkm");
- if (!isPkm)
- return false;
-
- QFile f(source);
- if (!f.open(QIODevice::ReadOnly)) {
- qWarning() << "Failed to open" << source;
- return false;
- }
-
- // ETC1 in PKM, as generated by f.ex. Android's etc1tool
- static const char pkmMagic[] = { 'P', 'K', 'M', ' ', '1', '0' };
- const int pkmHeaderSize = 6 + 2 + 4 * 2;
- QByteArray header = f.read(pkmHeaderSize);
- if (header.size() >= pkmHeaderSize && !qstrncmp(header.constData(), pkmMagic, 6)) {
- m_format = QOpenGLTexture::RGB8_ETC1; // may get changed to RGB8_ETC2 later on
- // get the extended (multiple of 4) width and height
- m_width = qFromBigEndian(*(reinterpret_cast<const quint16 *>(header.constData() + 6 + 2)));
- m_height = qFromBigEndian(*(reinterpret_cast<const quint16 *>(header.constData() + 6 + 2 + 2)));
- m_depth = 1;
- QByteArray data = f.readAll();
- if (data.size() < (m_width / 4) * (m_height / 4) * 8)
- qWarning() << "Unexpected end of ETC1 data in" << source;
- setData(data, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8);
- m_isCompressed = true;
- return true;
- }
-
- return false;
-}
-
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE