1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_QTEXTURE_P_H
5#define QT3DRENDER_QTEXTURE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DCore/QNodeId>
19#include <Qt3DCore/private/qdownloadhelperservice_p.h>
20#include <Qt3DRender/private/qabstracttexture_p.h>
21#include <Qt3DRender/private/qtexturegenerator_p.h>
22#include <Qt3DRender/qtexture.h>
23#include <Qt3DRender/private/qt3drender_global_p.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace Qt3DRender {
28
29class Q_3DRENDERSHARED_PRIVATE_EXPORT QTextureLoaderPrivate : public QAbstractTexturePrivate
30{
31public:
32 QTextureLoaderPrivate();
33
34 Q_DECLARE_PUBLIC(QTextureLoader)
35
36 void setScene(Qt3DCore::QScene *scene) override;
37 void updateGenerator();
38
39 QUrl m_source;
40 bool m_mirrored;
41};
42
43class QTextureFromSourceGenerator;
44typedef QSharedPointer<QTextureFromSourceGenerator> QTextureFromSourceGeneratorPtr;
45
46class Q_AUTOTEST_EXPORT TextureDownloadRequest : public Qt3DCore::QDownloadRequest
47{
48public:
49 TextureDownloadRequest(const QTextureFromSourceGeneratorPtr &functor,
50 const QUrl &url,
51 Qt3DCore::QAspectEngine *engine,
52 Qt3DCore::QNodeId texNodeId);
53
54 void onCompleted() override;
55
56private:
57 QTextureFromSourceGeneratorPtr m_functor;
58 Qt3DCore::QAspectEngine *m_engine;
59 Qt3DCore::QNodeId m_texNodeId;
60};
61
62class Q_AUTOTEST_EXPORT QTextureFromSourceGenerator : public QTextureGenerator,
63 public QEnableSharedFromThis<QTextureFromSourceGenerator>
64{
65public:
66 explicit QTextureFromSourceGenerator(QTextureLoader *textureLoader,
67 Qt3DCore::QAspectEngine *engine,
68 Qt3DCore::QNodeId textureId);
69
70 QTextureFromSourceGenerator(const QTextureFromSourceGenerator &other);
71
72 QTextureDataPtr operator ()() override;
73 bool operator ==(const QTextureGenerator &other) const override;
74 inline QAbstractTexture::Status status() const { return m_status; }
75
76 QT3D_FUNCTOR(QTextureFromSourceGenerator)
77
78 QUrl url() const;
79 bool isMirrored() const;
80
81private:
82 friend class TextureDownloadRequest;
83
84 QUrl m_url;
85 QAbstractTexture::Status m_status;
86 bool m_mirrored;
87
88 QByteArray m_sourceData;
89 Qt3DCore::QNodeId m_texture;
90 Qt3DCore::QAspectEngine *m_engine;
91
92 // Options that can be overridden on TextureLoader when loading
93 QAbstractTexture::TextureFormat m_format;
94};
95
96class Q_AUTOTEST_EXPORT TextureLoadingHelper
97{
98public:
99 static QTextureImageDataPtr loadTextureData(const QUrl &source, bool allow3D, bool mirrored);
100 static QTextureImageDataPtr loadTextureData(QIODevice *data, const QString& suffix,
101 bool allow3D, bool mirrored);
102};
103
104} // namespace Qt3DRender
105
106QT_END_NAMESPACE
107
108#endif // QT3DRENDER_QTEXTURE_P_H
109

source code of qt3d/src/render/texture/qtexture_p.h