diff options
author | Tomi Korpipää <tomi.korpipaa@theqtcompany.com> | 2015-10-30 11:56:28 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@theqtcompany.com> | 2015-10-30 10:01:22 +0000 |
commit | 0dbded1506abf172b7b3cf7685bdcb30c7b8012d (patch) | |
tree | a0cdb79e6a482697cc96c3300b0502595b42d4b1 /src | |
parent | 9b9f34701f47824e8201453d148152fb0855f98a (diff) |
d-pointer classes, private/public changes
Change-Id: I4ca133aebad0c088296ab293f95f0a6d76d18395
Task-number: QTBUG-39946
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
31 files changed, 406 insertions, 111 deletions
diff --git a/src/core/nodes/nodes.pri b/src/core/nodes/nodes.pri index 1b5383d68..0d3d68052 100644 --- a/src/core/nodes/nodes.pri +++ b/src/core/nodes/nodes.pri @@ -11,6 +11,7 @@ HEADERS += \ $$PWD/qbackendnode.h \ $$PWD/qnodeid.h \ $$PWD/qnodevisitor.h \ + $$PWD/qnodevisitor_p.h \ $$PWD/qabstractnodefactory.h \ $$PWD/propertychangehandler_p.h diff --git a/src/core/nodes/qnodevisitor.cpp b/src/core/nodes/qnodevisitor.cpp index d07809101..21192d926 100644 --- a/src/core/nodes/qnodevisitor.cpp +++ b/src/core/nodes/qnodevisitor.cpp @@ -34,33 +34,54 @@ ** ****************************************************************************/ -#include "qnodevisitor.h" +#include "qnodevisitor_p.h" QT_BEGIN_NAMESPACE namespace Qt3DCore { -QNodeVisitor::QNodeVisitor() +QNodeVisitorPrivate::QNodeVisitorPrivate() +{ +} + +QNodeVisitor::QNodeVisitor() : + d_ptr(new QNodeVisitorPrivate) { } QNodeVisitor::~QNodeVisitor() { + delete d_ptr; } QNode* QNodeVisitor::rootNode() const { - return m_path.front(); + return d_ptr->m_path.front(); } QNode* QNodeVisitor::currentNode() const { - return m_path.back(); + return d_ptr->m_path.back(); +} + +void QNodeVisitor::setPath(QNodeList path) +{ + d_ptr->m_path = path; } QNodeList QNodeVisitor::path() const { - return m_path; + return d_ptr->m_path; +} + +void QNodeVisitor::append(QNode *n) +{ + d_ptr->m_path.append(n); +} + +void QNodeVisitor::pop_back() +{ + d_ptr->m_path.pop_back(); } } // namespace Qt3DCore diff --git a/src/core/nodes/qnodevisitor.h b/src/core/nodes/qnodevisitor.h index 3664e99f9..69a452a83 100644 --- a/src/core/nodes/qnodevisitor.h +++ b/src/core/nodes/qnodevisitor.h @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE namespace Qt3DCore { +class QNodeVisitorPrivate; + class QT3DCORESHARED_EXPORT QNodeVisitor { public: @@ -78,15 +80,18 @@ public: QNode *rootNode() const; QNode *currentNode() const; + void setPath(QNodeList path); QNodeList path() const; + void append(QNode *n); + void pop_back(); private: - QNodeList m_path; + QNodeVisitorPrivate *d_ptr; template<typename NodeVisitorFunctor> void startTraversing(QNode *rootNode_, NodeVisitorFunctor fN) { - m_path = QNodeList() << rootNode_; + setPath(QNodeList() << rootNode_); if (rootNode_) visitNode(rootNode_, fN); } @@ -94,7 +99,7 @@ private: template<typename NodeVisitorFunctor, typename EntityVisitorFunctor> void startTraversing(QNode *rootNode_, NodeVisitorFunctor fN, EntityVisitorFunctor fE) { - m_path = QNodeList() << rootNode_; + setPath(QNodeList() << rootNode_); QEntity* rootEntity = qobject_cast<QEntity *>(rootNode_); if (rootEntity) @@ -147,22 +152,22 @@ private: template<typename NodeVisitorFunctor, typename EntityVisitorFunctor> void outerVisitNode(QNode *n, NodeVisitorFunctor &fN, EntityVisitorFunctor &fE) { - m_path.append(n); + append(n); QEntity* e = qobject_cast<QEntity *>(n); if (e) { visitEntity(e, fN, fE); } else { visitNode(n, fN, fE); } - m_path.pop_back(); + pop_back(); } template<typename NodeVisitorFunctor> void outerVisitNode(QNode *n, NodeVisitorFunctor &fN) { - m_path.append(n); + append(n); visitNode(n, fN); - m_path.pop_back(); + pop_back(); } template <typename NodeType> diff --git a/src/core/nodes/qnodevisitor_p.h b/src/core/nodes/qnodevisitor_p.h new file mode 100644 index 000000000..316a3a713 --- /dev/null +++ b/src/core/nodes/qnodevisitor_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 QT3DCORE_QNODEVISITOR_P_H +#define QT3DCORE_QNODEVISITOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qnodevisitor.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore +{ + +class QNodeVisitorPrivate +{ +public: + QNodeVisitorPrivate(); + + QNodeList m_path; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QNODEVISITOR_H diff --git a/src/core/resources/qhandle.h b/src/core/resources/qhandle_p.h index 4ac751641..6952c54e3 100644 --- a/src/core/resources/qhandle.h +++ b/src/core/resources/qhandle_p.h @@ -34,8 +34,19 @@ ** ****************************************************************************/ -#ifndef QT3DCORE_QHANDLE_H -#define QT3DCORE_QHANDLE_H +#ifndef QT3DCORE_QHANDLE_P_H +#define QT3DCORE_QHANDLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// #include <Qt3DCore/qt3dcore_global.h> #include <QtCore/QDebug> diff --git a/src/core/resources/qhandlemanager.h b/src/core/resources/qhandlemanager_p.h index 0ff41c899..e37dedff0 100644 --- a/src/core/resources/qhandlemanager.h +++ b/src/core/resources/qhandlemanager_p.h @@ -34,12 +34,23 @@ ** ****************************************************************************/ -#ifndef QT3DCORE_QHANDLEMANAGER_H -#define QT3DCORE_QHANDLEMANAGER_H +#ifndef QT3DCORE_QHANDLEMANAGER_P_H +#define QT3DCORE_QHANDLEMANAGER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// #include <QtGlobal> #include <Qt3DCore/qt3dcore_global.h> -#include <Qt3DCore/qhandle.h> +#include "qhandle_p.h" #include <QtCore/QVector> diff --git a/src/core/resources/qresourcemanager_p.h b/src/core/resources/qresourcemanager_p.h index 4af596c33..eeb150e50 100644 --- a/src/core/resources/qresourcemanager_p.h +++ b/src/core/resources/qresourcemanager_p.h @@ -52,8 +52,8 @@ #include <QMutex> #include <QHash> #include <Qt3DCore/qt3dcore_global.h> -#include <Qt3DCore/qhandle.h> -#include <Qt3DCore/qhandlemanager.h> +#include "qhandle_p.h" +#include "qhandlemanager_p.h" QT_BEGIN_NAMESPACE diff --git a/src/core/resources/resources.pri b/src/core/resources/resources.pri index fc9e289e7..e45d8649f 100644 --- a/src/core/resources/resources.pri +++ b/src/core/resources/resources.pri @@ -1,11 +1,11 @@ HEADERS += \ - $$PWD/qhandle.h \ - $$PWD/qhandlemanager.h \ + $$PWD/qhandlemanager_p.h \ $$PWD/qresourcemanager_p.h \ $$PWD/qcircularbuffer_p.h \ $$PWD/qboundedcircularbuffer_p.h \ $$PWD/qframeallocator.h \ - $$PWD/qframeallocator_p.h + $$PWD/qframeallocator_p.h \ + $$PWD/qhandle_p.h SOURCES += \ $$PWD/qresourcemanager.cpp \ diff --git a/src/input/handle_types_p.h b/src/input/handle_types_p.h index e478405d4..dfa26b53b 100644 --- a/src/input/handle_types_p.h +++ b/src/input/handle_types_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include <Qt3DCore/qhandle.h> +#include <Qt3DCore/private/qhandle_p.h> QT_BEGIN_NAMESPACE diff --git a/src/input/input.pri b/src/input/input.pri index 93c031947..0c0a62d8b 100644 --- a/src/input/input.pri +++ b/src/input/input.pri @@ -22,8 +22,8 @@ HEADERS += \ $$PWD/q3dmouseevent.h \ $$PWD/mousecontroller_p.h \ $$PWD/mouseinput_p.h \ - $$PWD/mouseeventfilter.h \ - $$PWD/mouseeventdispatcherjob_p.h + $$PWD/mouseeventdispatcherjob_p.h \ + $$PWD/mouseeventfilter_p.h SOURCES += \ $$PWD/cameracontroller.cpp \ diff --git a/src/input/inputhandler.cpp b/src/input/inputhandler.cpp index 13d32b956..1fd778501 100644 --- a/src/input/inputhandler.cpp +++ b/src/input/inputhandler.cpp @@ -37,7 +37,7 @@ #include "inputhandler_p.h" #include "inputmanagers_p.h" #include "keyboardeventfilter_p.h" -#include "mouseeventfilter.h" +#include "mouseeventfilter_p.h" #include "assignkeyboardfocusjob_p.h" #include "keyeventdispatcherjob_p.h" #include "mouseeventdispatcherjob_p.h" diff --git a/src/input/mouseeventfilter.cpp b/src/input/mouseeventfilter.cpp index 7fa245ec0..fcf8eb922 100644 --- a/src/input/mouseeventfilter.cpp +++ b/src/input/mouseeventfilter.cpp @@ -34,7 +34,7 @@ ** ****************************************************************************/ -#include "mouseeventfilter.h" +#include "mouseeventfilter_p.h" #include "inputhandler_p.h" #include <QEvent> #include <QKeyEvent> diff --git a/src/input/mouseeventfilter.h b/src/input/mouseeventfilter_p.h index 38c82ff96..6fba946b8 100644 --- a/src/input/mouseeventfilter.h +++ b/src/input/mouseeventfilter_p.h @@ -37,6 +37,17 @@ #ifndef QT3DINPUT_INPUT_MOUSEEVENTFILTER_P_H #define QT3DINPUT_INPUT_MOUSEEVENTFILTER_P_H +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + #include <QObject> QT_BEGIN_NAMESPACE diff --git a/src/logic/handle_types_p.h b/src/logic/handle_types_p.h index 94eb05aa2..3b25cdc02 100644 --- a/src/logic/handle_types_p.h +++ b/src/logic/handle_types_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include <Qt3DCore/qhandle.h> +#include <Qt3DCore/private/qhandle_p.h> QT_BEGIN_NAMESPACE diff --git a/src/plugins/sceneparsers/assimp/assimpparser.cpp b/src/plugins/sceneparsers/assimp/assimpparser.cpp index 35437ff07..ad6b5ccd3 100644 --- a/src/plugins/sceneparsers/assimp/assimpparser.cpp +++ b/src/plugins/sceneparsers/assimp/assimpparser.cpp @@ -274,7 +274,7 @@ private: public: explicit AssimpRawTextureImageFunctor(const QByteArray &data); - TexImageDataPtr operator()() Q_DECL_FINAL; + QTexImageDataPtr operator()() Q_DECL_FINAL; bool operator ==(const QTextureDataFunctor &other) const Q_DECL_FINAL; QT3D_FUNCTOR(AssimpRawTextureImageFunctor) @@ -897,9 +897,9 @@ AssimpRawTextureImage::AssimpRawTextureImageFunctor::AssimpRawTextureImageFuncto { } -TexImageDataPtr AssimpRawTextureImage::AssimpRawTextureImageFunctor::operator()() +QTexImageDataPtr AssimpRawTextureImage::AssimpRawTextureImageFunctor::operator()() { - TexImageDataPtr dataPtr; + QTexImageDataPtr dataPtr; dataPtr->setData(m_data, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); return dataPtr; } diff --git a/src/render/backend/entity_p.h b/src/render/backend/entity_p.h index d03e8e1cb..d3528f369 100644 --- a/src/render/backend/entity_p.h +++ b/src/render/backend/entity_p.h @@ -53,7 +53,7 @@ #include <Qt3DRender/private/handle_types_p.h> #include <Qt3DCore/qbackendnode.h> #include <Qt3DCore/qnodeid.h> -#include <Qt3DCore/qhandle.h> +#include <Qt3DCore/private/qhandle_p.h> #include <QVector> QT_BEGIN_NAMESPACE diff --git a/src/render/backend/handle_types_p.h b/src/render/backend/handle_types_p.h index 571613f70..01ee9e09d 100644 --- a/src/render/backend/handle_types_p.h +++ b/src/render/backend/handle_types_p.h @@ -49,7 +49,7 @@ // #include <Qt3DRender/qt3drender_global.h> -#include <Qt3DCore/qhandle.h> +#include <Qt3DCore/private/qhandle_p.h> QT_BEGIN_NAMESPACE @@ -58,7 +58,7 @@ class QOpenGLVertexArrayObject; namespace Qt3DRender { -class TexImageData; +class QTexImageData; namespace Render { @@ -103,7 +103,7 @@ typedef Qt3DCore::QHandle<Texture, 16> HTexture; typedef Qt3DCore::QHandle<Transform, 16> HTransform; typedef Qt3DCore::QHandle<RenderTarget, 8> HTarget; typedef Qt3DCore::QHandle<RenderPass, 16> HRenderPass; -typedef Qt3DCore::QHandle<TexImageData, 16> HTextureData; +typedef Qt3DCore::QHandle<QTexImageData, 16> HTextureData; typedef Qt3DCore::QHandle<Parameter, 16> HParameter; typedef Qt3DCore::QHandle<ShaderData, 16> HShaderData; typedef Qt3DCore::QHandle<TextureImage, 16> HTextureImage; diff --git a/src/render/framegraph/framegraphnode_p.h b/src/render/framegraph/framegraphnode_p.h index e68d0b9bc..3e65ca598 100644 --- a/src/render/framegraph/framegraphnode_p.h +++ b/src/render/framegraph/framegraphnode_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include <Qt3DCore/qhandle.h> +#include <Qt3DCore/private/qhandle_p.h> #include <Qt3DCore/qnode.h> #include <Qt3DCore/qbackendnode.h> #include <Qt3DRender/qframegraphnode.h> diff --git a/src/render/jobs/loadtexturedatajob.cpp b/src/render/jobs/loadtexturedatajob.cpp index b2dd8eb21..4b34690ef 100644 --- a/src/render/jobs/loadtexturedatajob.cpp +++ b/src/render/jobs/loadtexturedatajob.cpp @@ -67,7 +67,7 @@ void LoadTextureDataJob::run() if (texImg != Q_NULLPTR && texImg->isDirty() && !texImg->dataFunctor().isNull()) { QTextureDataFunctorPtr functor = texImg->dataFunctor(); HTextureData textureDataHandle; - TexImageData *data = Q_NULLPTR; + QTexImageData *data = Q_NULLPTR; // scoped for locker { @@ -80,11 +80,11 @@ void LoadTextureDataJob::run() if (!textureDataHandle.isNull()) { data = m_renderer->textureDataManager()->data(textureDataHandle); } else { - TexImageDataPtr dataPtr = functor->operator ()(); + QTexImageDataPtr dataPtr = functor->operator ()(); if (dataPtr.isNull()) { qCDebug(Jobs) << Q_FUNC_INFO << "Texture has no raw data"; } else { - // Save the TexImageDataPtr with it's functor as a key + // Save the QTexImageDataPtr with it's functor as a key textureDataHandle = m_renderer->textureDataManager()->acquire(); data = m_renderer->textureDataManager()->data(textureDataHandle); *data = *(dataPtr.data()); diff --git a/src/render/texture/qabstracttextureimage.h b/src/render/texture/qabstracttextureimage.h index a34306314..bb626fa35 100644 --- a/src/render/texture/qabstracttextureimage.h +++ b/src/render/texture/qabstracttextureimage.h @@ -52,7 +52,7 @@ class QT3DRENDERSHARED_EXPORT QTextureDataFunctor : public Qt3DCore::QAbstractFu { public: virtual ~QTextureDataFunctor() {} - virtual TexImageDataPtr operator()() = 0; + virtual QTexImageDataPtr operator()() = 0; virtual bool operator ==(const QTextureDataFunctor &other) const = 0; }; diff --git a/src/render/texture/qabstracttextureprovider.h b/src/render/texture/qabstracttextureprovider.h index 09644a0e5..1e9aa08c8 100644 --- a/src/render/texture/qabstracttextureprovider.h +++ b/src/render/texture/qabstracttextureprovider.h @@ -37,7 +37,7 @@ #ifndef QT3DRENDER_QABSTRACTTEXTUREPROVIDER_H #define QT3DRENDER_QABSTRACTTEXTUREPROVIDER_H -#include <Qt3DRender/texturedata.h> +#include <Qt3DRender/qtexturedata.h> #include <Qt3DRender/qt3drender_global.h> #include <Qt3DCore/qnode.h> diff --git a/src/render/texture/qabstracttextureprovider_p.h b/src/render/texture/qabstracttextureprovider_p.h index b27ef3660..47577bb87 100644 --- a/src/render/texture/qabstracttextureprovider_p.h +++ b/src/render/texture/qabstracttextureprovider_p.h @@ -69,7 +69,7 @@ public : int m_width, m_height, m_depth; bool m_autoMipMap; - QList<TexImageDataPtr> m_data; + QList<QTexImageDataPtr> m_data; QAbstractTextureProvider::Filter m_minFilter, m_magFilter; // FIXME, store per direction diff --git a/src/render/texture/qtexture.h b/src/render/texture/qtexture.h index 84f84fc3d..d5d2d5199 100644 --- a/src/render/texture/qtexture.h +++ b/src/render/texture/qtexture.h @@ -38,7 +38,7 @@ #define QT3DRENDER_QTEXTURE_H #include <QOpenGLTexture> -#include <Qt3DRender/texturedata.h> +#include <Qt3DRender/qtexturedata.h> #include <Qt3DRender/qwrapmode.h> #include <Qt3DRender/qtextureproviders.h> #include <Qt3DRender/qtextureimage.h> diff --git a/src/render/texture/texturedata.cpp b/src/render/texture/qtexturedata.cpp index b54c526f9..d6663a479 100644 --- a/src/render/texture/texturedata.cpp +++ b/src/render/texture/qtexturedata.cpp @@ -34,10 +34,9 @@ ** ****************************************************************************/ -#include "texturedata.h" +#include "qtexturedata_p.h" #include <QDebug> -#include <QOpenGLTexture> #include <QFileInfo> #include <QFile> #include <qendian.h> @@ -46,7 +45,7 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { -TexImageData::TexImageData() +QTexImageDataPrivate::QTexImageDataPrivate() : m_width(-1) , m_height(-1) , m_depth(-1) @@ -55,42 +54,104 @@ TexImageData::TexImageData() { } -TexImageData::~TexImageData() +QTexImageData::QTexImageData() + : d_ptr(new QTexImageDataPrivate()) { } -void TexImageData::cleanup() +QTexImageData::QTexImageData(QTexImageDataPrivate &dd) + : d_ptr(&dd) { - m_width = -1; - m_height = -1; - m_depth = -1; - m_isCompressed = false; - m_data.clear(); } -void TexImageData::setImage(const QImage &image) +QTexImageData::~QTexImageData() { - m_width = image.width(); - m_height = image.height(); - m_depth = 1; + cleanup(); + delete d_ptr; +} + +QTexImageData &QTexImageData::operator=(const QTexImageData &other) +{ + Q_D(QTexImageData); + d->m_width = other.d_ptr->m_width; + d->m_height = other.d_ptr->m_height; + d->m_depth = other.d_ptr->m_depth; + d->m_isCompressed = other.d_ptr->m_isCompressed; + d->m_pixelFormat = other.d_ptr->m_pixelFormat; + d->m_pixelType = other.d_ptr->m_pixelType; + d->m_data = other.d_ptr->m_data; + + return *this; +} + +void QTexImageData::cleanup() +{ + Q_D(QTexImageData); + d->m_width = -1; + d->m_height = -1; + d->m_depth = -1; + d->m_isCompressed = false; + d->m_data.clear(); +} + +bool QTexImageData::isCompressed() const +{ + Q_D(const QTexImageData); + return d->m_isCompressed; +} + +int QTexImageData::width() const +{ + Q_D(const QTexImageData); + return d->m_width; +} + +int QTexImageData::height() const +{ + Q_D(const QTexImageData); + return d->m_height; +} + +int QTexImageData::depth() const +{ + Q_D(const QTexImageData); + return d->m_depth; +} + +QOpenGLTexture::TextureFormat QTexImageData::format() const +{ + Q_D(const QTexImageData); + return d->m_format; +} + +void QTexImageData::setImage(const QImage &image) +{ + Q_D(QTexImageData); + d->m_width = image.width(); + d->m_height = image.height(); + d->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 + Q_ASSERT_X(glImage.bytesPerLine() == (glImage.width() * glImage.depth() + 7) / 8, + "QTexImageData::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; + d->m_format = QOpenGLTexture::RGBA8_UNorm; } -void TexImageData::setData(const QByteArray &data, QOpenGLTexture::PixelFormat fmt, QOpenGLTexture::PixelType ptype) +void QTexImageData::setData(const QByteArray &data, QOpenGLTexture::PixelFormat fmt, + QOpenGLTexture::PixelType ptype) { - m_isCompressed = false; - m_data = data; - m_pixelFormat = fmt; - m_pixelType = ptype; + Q_D(QTexImageData); + d->m_isCompressed = false; + d->m_data = data; + d->m_pixelFormat = fmt; + d->m_pixelType = ptype; } -bool TexImageData::setCompressedFile(const QString &source) +bool QTexImageData::setCompressedFile(const QString &source) { + Q_D(QTexImageData); const bool isPkm = QFileInfo(source).suffix() == QStringLiteral("pkm"); if (!isPkm) return false; @@ -106,22 +167,40 @@ bool TexImageData::setCompressedFile(const QString &source) 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 + d->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; + d->m_width = qFromBigEndian(*(reinterpret_cast<const quint16 *>(header.constData() + 6 + 2))); + d->m_height = qFromBigEndian(*(reinterpret_cast<const quint16 *>(header.constData() + 6 + 2 + 2))); + d->m_depth = 1; QByteArray data = f.readAll(); - if (data.size() < (m_width / 4) * (m_height / 4) * 8) + if (data.size() < (d->m_width / 4) * (d->m_height / 4) * 8) qWarning() << "Unexpected end of ETC1 data in" << source; setData(data, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); - m_isCompressed = true; + d->m_isCompressed = true; return true; } return false; } +QByteArray QTexImageData::data() const +{ + Q_D(const QTexImageData); + return d->m_data; +} + +QOpenGLTexture::PixelFormat QTexImageData::pixelFormat() const +{ + Q_D(const QTexImageData); + return d->m_pixelFormat; +} + +QOpenGLTexture::PixelType QTexImageData::pixelType() const +{ + Q_D(const QTexImageData); + return d->m_pixelType; +} + } // namespace Qt3DRender QT_END_NAMESPACE diff --git a/src/render/texture/texturedata.h b/src/render/texture/qtexturedata.h index 031bd441b..f87109743 100644 --- a/src/render/texture/texturedata.h +++ b/src/render/texture/qtexturedata.h @@ -37,30 +37,33 @@ #ifndef QT3DRENDER_TEXTUREDATA_H #define QT3DRENDER_TEXTUREDATA_H -#include <QOpenGLTexture> -#include <QImage> -#include <QSharedPointer> +#include <QtGui/QOpenGLTexture> +#include <QtGui/QImage> +#include <QtCore/QSharedPointer> #include <Qt3DRender/qt3drender_global.h> QT_BEGIN_NAMESPACE namespace Qt3DRender { -class QT3DRENDERSHARED_EXPORT TexImageData +class QTexImageDataPrivate; + +class QT3DRENDERSHARED_EXPORT QTexImageData { public: - TexImageData(); - ~TexImageData(); + QTexImageData(); + virtual ~QTexImageData(); + + QTexImageData &operator=(const QTexImageData &other); void cleanup(); - bool isCompressed() const - { return m_isCompressed; } + bool isCompressed() const; - 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; } + int width() const; + int height() const; + int depth() const; + QOpenGLTexture::TextureFormat format() const; void setImage(const QImage &); @@ -70,26 +73,30 @@ public: bool setCompressedFile(const QString &source); - QByteArray data() const - { return m_data; } + QByteArray data() const; + + QOpenGLTexture::PixelFormat pixelFormat() const; - QOpenGLTexture::PixelFormat pixelFormat() const - { return m_pixelFormat; } + QOpenGLTexture::PixelType pixelType() const; - QOpenGLTexture::PixelType pixelType() const - { return m_pixelType; } +protected: + QTexImageData(QTexImageDataPrivate &dd); private: - int m_width, m_height, m_depth; - QOpenGLTexture::PixelFormat m_pixelFormat; - QOpenGLTexture::PixelType m_pixelType; + Q_DECLARE_PRIVATE(QTexImageData) + QTexImageDataPrivate *d_ptr; + +// int m_width, m_height, m_depth; +// QOpenGLTexture::PixelFormat m_pixelFormat; +// QOpenGLTexture::PixelType m_pixelType; + +// bool m_isCompressed; +// QByteArray m_data; +// QOpenGLTexture::TextureFormat m_format; - bool m_isCompressed; - QByteArray m_data; - QOpenGLTexture::TextureFormat m_format; }; -typedef QSharedPointer<TexImageData> TexImageDataPtr; +typedef QSharedPointer<QTexImageData> QTexImageDataPtr; } // namespace Qt3DRender diff --git a/src/render/texture/qtexturedata_p.h b/src/render/texture/qtexturedata_p.h new file mode 100644 index 000000000..6bad6f036 --- /dev/null +++ b/src/render/texture/qtexturedata_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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_TEXTUREDATA_P_H +#define QT3DRENDER_TEXTUREDATA_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qtexturedata.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QTexImageDataPrivate +{ +public: + QTexImageDataPrivate(); + + int m_width; + int m_height; + int m_depth; + QOpenGLTexture::PixelFormat m_pixelFormat; + QOpenGLTexture::PixelType m_pixelType; + + bool m_isCompressed; + QByteArray m_data; + QOpenGLTexture::TextureFormat m_format; +}; + +} // namespace Qt3DRender + + +QT_END_NAMESPACE + +#endif // QT3DRENDER_TEXTUREDATA_P_H diff --git a/src/render/texture/qtextureimage.cpp b/src/render/texture/qtextureimage.cpp index 19f729eeb..154f1e0aa 100644 --- a/src/render/texture/qtextureimage.cpp +++ b/src/render/texture/qtextureimage.cpp @@ -63,12 +63,12 @@ public: {} // Will be executed from within a QAspectJob - TexImageDataPtr operator ()() Q_DECL_FINAL + QTexImageDataPtr operator ()() Q_DECL_FINAL { - TexImageDataPtr dataPtr; + QTexImageDataPtr dataPtr; if (m_url.isLocalFile() || m_url.scheme() == QStringLiteral("qrc")) { QString source = Qt3DCore::QUrlHelper::urlToLocalFileOrQrc(m_url); - dataPtr.reset(new TexImageData()); + dataPtr.reset(new QTexImageData()); if (dataPtr->setCompressedFile(source)) return dataPtr; QImage img; diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp index c665e3cf8..f17425705 100644 --- a/src/render/texture/texture.cpp +++ b/src/render/texture/texture.cpp @@ -42,7 +42,7 @@ #include <QOpenGLTexture> #include <QOpenGLPixelTransferOptions> #include <Qt3DRender/qtexture.h> -#include <Qt3DRender/texturedata.h> +#include <Qt3DRender/qtexturedata.h> #include <Qt3DCore/qscenepropertychange.h> #include <Qt3DCore/private/qaspectmanager_p.h> #include <Qt3DRender/private/managers_p.h> @@ -298,7 +298,7 @@ QOpenGLTexture *Texture::buildGLTexture() } // RenderThread -void Texture::setToGLTexture(TextureImage *rImg, TexImageData *imgData) +void Texture::setToGLTexture(TextureImage *rImg, QTexImageData *imgData) { Q_ASSERT(m_gl && m_gl->isCreated() && m_gl->isStorageAllocated()); // ensure we don't accidently cause a detach / copy of the raw bytes @@ -536,7 +536,7 @@ void Texture::updateAndLoadTextureImage() img->unsetDirty(); continue; } - TexImageData *data = m_textureDataManager->data(img->textureDataHandle()); + QTexImageData *data = m_textureDataManager->data(img->textureDataHandle()); if (data != Q_NULLPTR) { setToGLTexture(img, data); dnas.append(img->dna()); diff --git a/src/render/texture/texture.pri b/src/render/texture/texture.pri index 9df52c131..36a4e1952 100644 --- a/src/render/texture/texture.pri +++ b/src/render/texture/texture.pri @@ -10,9 +10,10 @@ HEADERS += \ $$PWD/qtextureproviders.h \ $$PWD/qwrapmode.h \ $$PWD/texture_p.h \ - $$PWD/texturedata.h \ $$PWD/texturedatamanager_p.h \ - $$PWD/textureimage_p.h + $$PWD/textureimage_p.h \ + $$PWD/qtexturedata_p.h \ + $$PWD/qtexturedata.h SOURCES += \ $$PWD/qabstracttextureimage.cpp \ @@ -21,6 +22,6 @@ SOURCES += \ $$PWD/qtextureproviders.cpp \ $$PWD/qwrapmode.cpp \ $$PWD/texture.cpp \ - $$PWD/texturedata.cpp \ $$PWD/texturedatamanager.cpp \ - $$PWD/textureimage.cpp + $$PWD/textureimage.cpp \ + $$PWD/qtexturedata.cpp diff --git a/src/render/texture/texture_p.h b/src/render/texture/texture_p.h index a784a4e91..71fc3f3ec 100644 --- a/src/render/texture/texture_p.h +++ b/src/render/texture/texture_p.h @@ -51,7 +51,7 @@ #include <QOpenGLContext> #include <QMutex> #include <Qt3DRender/qtexture.h> -#include <Qt3DRender/texturedata.h> +#include <Qt3DRender/qtexturedata.h> #include <Qt3DCore/qbackendnode.h> #include <Qt3DRender/private/handle_types_p.h> @@ -109,7 +109,7 @@ private: QOpenGLTexture *m_gl; QOpenGLTexture *buildGLTexture(); - void setToGLTexture(TextureImage *rImg, TexImageData *imgData); + void setToGLTexture(TextureImage *rImg, QTexImageData *imgData); void updateWrapAndFilters(); int m_width; diff --git a/src/render/texture/texturedatamanager_p.h b/src/render/texture/texturedatamanager_p.h index 9748b3699..9248ce8a2 100644 --- a/src/render/texture/texturedatamanager_p.h +++ b/src/render/texture/texturedatamanager_p.h @@ -50,7 +50,7 @@ #include <Qt3DCore/private/qresourcemanager_p.h> #include <Qt3DRender/qtexture.h> -#include <Qt3DRender/texturedata.h> +#include <Qt3DRender/qtexturedata.h> #include <Qt3DRender/private/handle_types_p.h> #include <QPair> @@ -65,7 +65,7 @@ namespace Render { typedef QPair<QTextureDataFunctorPtr, QVector<HTextureImage> > FunctorImageHandlesPair; typedef QPair<QTextureDataFunctorPtr, HTextureData> FunctorTextureDataPair; -class TextureDataManager : public Qt3DCore::QResourceManager<TexImageData, +class TextureDataManager : public Qt3DCore::QResourceManager<QTexImageData, Qt3DCore::QNodeId, 16, Qt3DCore::ArrayAllocatingPolicy, @@ -97,7 +97,7 @@ private: } // namespace Render } // namespace Qt3DRender -Q_DECLARE_RESOURCE_INFO(Qt3DRender::TexImageData, Q_REQUIRES_CLEANUP) +Q_DECLARE_RESOURCE_INFO(Qt3DRender::QTexImageData, Q_REQUIRES_CLEANUP) QT_END_NAMESPACE |