| 1 | // Copyright (C) 2015 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 | #include "qabstracttextureimage.h" |
| 5 | #include "qabstracttextureimage_p.h" |
| 6 | #include <Qt3DRender/qtextureimagedatagenerator.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | |
| 11 | namespace Qt3DRender { |
| 12 | |
| 13 | using namespace Qt3DCore; |
| 14 | |
| 15 | QTextureImageDataGenerator::~QTextureImageDataGenerator() = default; |
| 16 | |
| 17 | /*! |
| 18 | \class Qt3DRender::QTextureImageDataGenerator |
| 19 | \inmodule Qt3DRender |
| 20 | \since 5.7 |
| 21 | \brief Provides texture image data for QAbstractTextureImage. |
| 22 | |
| 23 | QTextureImageDataGenerator is a data provider for QAbstractTexture. |
| 24 | QTextureImageDataGenerator can be used to expand Qt3D with more ways to load |
| 25 | texture image data as well as support user-defined formats and formats Qt3D |
| 26 | does not natively support. The data is returned by the QTextureImageDataPtr |
| 27 | which contains the data that will be loaded to the texture. |
| 28 | QTextureImageDataGenerator is executed by Aspect jobs in the backend. |
| 29 | */ |
| 30 | /*! |
| 31 | \typedef Qt3DRender::QTextureImageDataPtr |
| 32 | \relates Qt3DRender::QTextureImageDataGenerator |
| 33 | |
| 34 | Shared pointer to \l QTextureImageData. |
| 35 | */ |
| 36 | |
| 37 | /*! |
| 38 | \fn Qt3DRender::QTextureImageDataPtr Qt3DRender::QTextureImageDataGenerator::operator()() |
| 39 | |
| 40 | Implement the method to return the texture image data. |
| 41 | */ |
| 42 | |
| 43 | /*! |
| 44 | \fn bool Qt3DRender::QTextureImageDataGenerator::operator ==(const QTextureImageDataGenerator &other) const |
| 45 | |
| 46 | Implement the method to compare this texture data generator to \a other. |
| 47 | Returns a boolean that indicates whether the \l QAbstractTextureImage needs to reload |
| 48 | the \l QTextureImageData. |
| 49 | */ |
| 50 | |
| 51 | QAbstractTextureImagePrivate::QAbstractTextureImagePrivate() |
| 52 | : QNodePrivate(), |
| 53 | m_mipLevel(0), |
| 54 | m_layer(0), |
| 55 | m_face(QAbstractTexture::CubeMapPositiveX) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | QAbstractTextureImagePrivate::~QAbstractTextureImagePrivate() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | QTextureImageDataGeneratorPtr QAbstractTextureImagePrivate::dataGenerator() const |
| 64 | { |
| 65 | Q_Q(const QAbstractTextureImage); |
| 66 | return q->dataGenerator(); |
| 67 | } |
| 68 | |
| 69 | /*! |
| 70 | \qmltype AbstractTextureImage |
| 71 | \nativetype Qt3DRender::QAbstractTextureImage |
| 72 | \inherits Node |
| 73 | \inqmlmodule Qt3D.Render |
| 74 | \qmlabstract |
| 75 | \since 5.5 |
| 76 | \brief Encapsulates the necessary information to create an OpenGL texture image. |
| 77 | */ |
| 78 | |
| 79 | /*! |
| 80 | \class Qt3DRender::QAbstractTextureImage |
| 81 | \inmodule Qt3DRender |
| 82 | \since 5.5 |
| 83 | \brief Encapsulates the necessary information to create an OpenGL texture image. |
| 84 | |
| 85 | QAbstractTextureImage should be used as the means of providing image data to a |
| 86 | QAbstractTexture. It contains the necessary information: mipmap |
| 87 | level, layer, cube face load at the proper place data into an OpenGL texture. |
| 88 | |
| 89 | The actual data is provided through a QTextureImageDataGenerator that will be |
| 90 | executed by Aspect jobs in the backend. QAbstractTextureImage should be |
| 91 | subclassed to provide a functor and eventual additional properties needed by |
| 92 | the functor to load actual data. |
| 93 | |
| 94 | \note: QAbstractTextureImage should never be shared. Expect crashes, undefined |
| 95 | behavior at best if this rule is not respected. |
| 96 | */ |
| 97 | |
| 98 | /*! |
| 99 | \fn Qt3DRender::QTextureImageDataGeneratorPtr Qt3DRender::QAbstractTextureImage::dataGenerator() const |
| 100 | |
| 101 | Implement this method to return the QTextureImageDataGeneratorPtr instance, |
| 102 | which will provide the data for the texture image. |
| 103 | */ |
| 104 | |
| 105 | /*! |
| 106 | Constructs a new QAbstractTextureImage instance with \a parent as parent. |
| 107 | */ |
| 108 | QAbstractTextureImage::QAbstractTextureImage(QNode *parent) |
| 109 | : QNode(*new QAbstractTextureImagePrivate, parent) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | /*! \internal */ |
| 114 | QAbstractTextureImage::~QAbstractTextureImage() |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /*! |
| 120 | \qmlproperty int Qt3D.Render::AbstractTextureImage::mipLevel |
| 121 | |
| 122 | Holds the mipmap level of the texture image. |
| 123 | */ |
| 124 | |
| 125 | /*! |
| 126 | \property Qt3DRender::QAbstractTextureImage::mipLevel |
| 127 | |
| 128 | Holds the mipmap level of the texture image. |
| 129 | */ |
| 130 | int QAbstractTextureImage::mipLevel() const |
| 131 | { |
| 132 | Q_D(const QAbstractTextureImage); |
| 133 | return d->m_mipLevel; |
| 134 | } |
| 135 | |
| 136 | /*! |
| 137 | \qmlproperty int Qt3D.Render::AbstractTextureImage::layer |
| 138 | |
| 139 | Holds the layer of the texture image. |
| 140 | */ |
| 141 | |
| 142 | /*! |
| 143 | \property Qt3DRender::QAbstractTextureImage::layer |
| 144 | |
| 145 | \return the layer of the texture image. |
| 146 | */ |
| 147 | int QAbstractTextureImage::layer() const |
| 148 | { |
| 149 | Q_D(const QAbstractTextureImage); |
| 150 | return d->m_layer; |
| 151 | } |
| 152 | |
| 153 | /*! |
| 154 | \qmlproperty enumeration Qt3D.Render::AbstractTextureImage::face |
| 155 | |
| 156 | Holds the cube map face of the texture image. |
| 157 | |
| 158 | \value CubeMapPositiveX 0x8515 GL_TEXTURE_CUBE_MAP_POSITIVE_X |
| 159 | \value CubeMapNegativeX 0x8516 GL_TEXTURE_CUBE_MAP_NEGATIVE_X |
| 160 | \value CubeMapPositiveY 0x8517 GL_TEXTURE_CUBE_MAP_POSITIVE_Y |
| 161 | \value CubeMapNegativeY 0x8518 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y |
| 162 | \value CubeMapPositiveZ 0x8519 GL_TEXTURE_CUBE_MAP_POSITIVE_Z |
| 163 | \value CubeMapNegativeZ 0x851A GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
| 164 | |
| 165 | \note The cube map face has a meaning only for |
| 166 | \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMap} and |
| 167 | \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMapArray}. |
| 168 | */ |
| 169 | |
| 170 | /*! |
| 171 | \property Qt3DRender::QAbstractTextureImage::face |
| 172 | |
| 173 | Holds the cube map face of the texture image. |
| 174 | |
| 175 | \note The cube map face has a meaning only for |
| 176 | \l {QAbstractTexture::}{TargetCubeMap} and |
| 177 | \l {QAbstractTexture::}{TargetCubeMapArray}. |
| 178 | */ |
| 179 | QAbstractTexture::CubeMapFace QAbstractTextureImage::face() const |
| 180 | { |
| 181 | Q_D(const QAbstractTextureImage); |
| 182 | return d->m_face; |
| 183 | } |
| 184 | |
| 185 | /*! |
| 186 | * Sets the mip level of a texture to \a level. |
| 187 | * \param level |
| 188 | */ |
| 189 | void QAbstractTextureImage::setMipLevel(int level) |
| 190 | { |
| 191 | Q_D(QAbstractTextureImage); |
| 192 | if (level != d->m_mipLevel) { |
| 193 | d->m_mipLevel = level; |
| 194 | emit mipLevelChanged(mipLevel: level); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /*! |
| 199 | * Sets the layer of a texture to \a layer. |
| 200 | * \param layer |
| 201 | */ |
| 202 | void QAbstractTextureImage::setLayer(int layer) |
| 203 | { |
| 204 | Q_D(QAbstractTextureImage); |
| 205 | if (layer != d->m_layer) { |
| 206 | d->m_layer = layer; |
| 207 | emit layerChanged(layer); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /*! |
| 212 | * Sets the texture image face to \a face. |
| 213 | * \param face |
| 214 | */ |
| 215 | void QAbstractTextureImage::setFace(QAbstractTexture::CubeMapFace face) |
| 216 | { |
| 217 | Q_D(QAbstractTextureImage); |
| 218 | if (face != d->m_face) { |
| 219 | d->m_face = face; |
| 220 | emit faceChanged(face); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /*! |
| 225 | Triggers an update of the data generator that is sent to the backend. |
| 226 | */ |
| 227 | void QAbstractTextureImage::notifyDataGeneratorChanged() |
| 228 | { |
| 229 | Q_D(QAbstractTextureImage); |
| 230 | d->update(); |
| 231 | } |
| 232 | |
| 233 | /*! \internal */ |
| 234 | QAbstractTextureImage::QAbstractTextureImage(QAbstractTextureImagePrivate &dd, QNode *parent) |
| 235 | : QNode(dd, parent) |
| 236 | { |
| 237 | } |
| 238 | |
| 239 | } // namespace Qt3DRender |
| 240 | |
| 241 | QT_END_NAMESPACE |
| 242 | |
| 243 | #include "moc_qabstracttextureimage.cpp" |
| 244 | |