| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | |
| 41 | #include "qtexturedata.h" |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | namespace Qt3DRender { |
| 46 | |
| 47 | /*! |
| 48 | * \class Qt3DRender::QTextureData |
| 49 | * \inheaderfile Qt3DRender/QTextureData |
| 50 | * \brief The QTextureData class stores texture information such as |
| 51 | * the target, height, width, depth, layers, wrap, and if mipmaps are enabled. |
| 52 | * \since 5.7 |
| 53 | * \inmodule Qt3DRender |
| 54 | */ |
| 55 | |
| 56 | class QTextureDataPrivate |
| 57 | { |
| 58 | public: |
| 59 | QAbstractTexture::Target m_target; |
| 60 | QAbstractTexture::TextureFormat m_format = QAbstractTexture::NoFormat; |
| 61 | int m_width = 0; |
| 62 | int m_height = 0; |
| 63 | int m_depth = 0; |
| 64 | int m_layers = 0; |
| 65 | bool m_autoMipMap = false; |
| 66 | float m_maximumAnisotropy = 0.0f; |
| 67 | QAbstractTexture::Filter m_minFilter; |
| 68 | QAbstractTexture::Filter m_magFilter; |
| 69 | QTextureWrapMode::WrapMode m_wrapModeX; |
| 70 | QTextureWrapMode::WrapMode m_wrapModeY; |
| 71 | QTextureWrapMode::WrapMode m_wrapModeZ; |
| 72 | QAbstractTexture::ComparisonFunction m_comparisonFunction; |
| 73 | QAbstractTexture::ComparisonMode m_comparisonMode; |
| 74 | QVector<QTextureImageDataPtr> m_imagesData; |
| 75 | |
| 76 | }; |
| 77 | |
| 78 | /*! |
| 79 | * Creates a new QTextureData |
| 80 | * instance. |
| 81 | */ |
| 82 | QTextureData::QTextureData() |
| 83 | : d_ptr(new QTextureDataPrivate()) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | /*! |
| 88 | * \internal |
| 89 | */ |
| 90 | QTextureData::~QTextureData() |
| 91 | { |
| 92 | delete d_ptr; |
| 93 | } |
| 94 | |
| 95 | /*! |
| 96 | * Returns the texture data target. |
| 97 | */ |
| 98 | QAbstractTexture::Target QTextureData::target() const |
| 99 | { |
| 100 | Q_D(const QTextureData); |
| 101 | return d->m_target; |
| 102 | } |
| 103 | |
| 104 | /*! |
| 105 | * Sets the target texture to \a target. |
| 106 | */ |
| 107 | void QTextureData::setTarget(QAbstractTexture::Target target) |
| 108 | { |
| 109 | Q_D(QTextureData); |
| 110 | d->m_target = target; |
| 111 | } |
| 112 | |
| 113 | /*! |
| 114 | * Returns the texture format |
| 115 | */ |
| 116 | QAbstractTexture::TextureFormat QTextureData::format() const |
| 117 | { |
| 118 | Q_D(const QTextureData); |
| 119 | return d->m_format; |
| 120 | } |
| 121 | |
| 122 | /*! |
| 123 | * Sets the texture format to \a format. |
| 124 | */ |
| 125 | void QTextureData::setFormat(QAbstractTexture::TextureFormat format) |
| 126 | { |
| 127 | Q_D(QTextureData); |
| 128 | d->m_format = format; |
| 129 | } |
| 130 | |
| 131 | /*! |
| 132 | * Returns the texture width. |
| 133 | */ |
| 134 | int QTextureData::width() const |
| 135 | { |
| 136 | Q_D(const QTextureData); |
| 137 | return d->m_width; |
| 138 | } |
| 139 | |
| 140 | /*! |
| 141 | * Sets the texture width to \a width. |
| 142 | */ |
| 143 | void QTextureData::setWidth(int width) |
| 144 | { |
| 145 | Q_D(QTextureData); |
| 146 | d->m_width = width; |
| 147 | } |
| 148 | |
| 149 | /*! |
| 150 | * Returns the texture height. |
| 151 | */ |
| 152 | int QTextureData::height() const |
| 153 | { |
| 154 | Q_D(const QTextureData); |
| 155 | return d->m_height; |
| 156 | } |
| 157 | |
| 158 | /*! |
| 159 | * Sets the target height to \a height. |
| 160 | */ |
| 161 | void QTextureData::setHeight(int height) |
| 162 | { |
| 163 | Q_D(QTextureData); |
| 164 | d->m_height = height; |
| 165 | } |
| 166 | |
| 167 | /*! |
| 168 | * Returns the texture depth. |
| 169 | */ |
| 170 | int QTextureData::depth() const |
| 171 | { |
| 172 | Q_D(const QTextureData); |
| 173 | return d->m_depth; |
| 174 | } |
| 175 | |
| 176 | /*! |
| 177 | * Sets the texture depth to \a depth |
| 178 | */ |
| 179 | void QTextureData::setDepth(int depth) |
| 180 | { |
| 181 | Q_D(QTextureData); |
| 182 | d->m_depth = depth; |
| 183 | } |
| 184 | |
| 185 | /*! |
| 186 | * Returns the texture layers. |
| 187 | */ |
| 188 | int QTextureData::layers() const |
| 189 | { |
| 190 | Q_D(const QTextureData); |
| 191 | return d->m_layers; |
| 192 | } |
| 193 | |
| 194 | /*! |
| 195 | * Sets the texture layers to \a layers. |
| 196 | */ |
| 197 | void QTextureData::setLayers(int layers) |
| 198 | { |
| 199 | Q_D(QTextureData); |
| 200 | d->m_layers = layers; |
| 201 | } |
| 202 | |
| 203 | /*! |
| 204 | * Returns whether the texture has auto mipmap generation enabled. |
| 205 | */ |
| 206 | bool QTextureData::isAutoMipMapGenerationEnabled() const |
| 207 | { |
| 208 | Q_D(const QTextureData); |
| 209 | return d->m_autoMipMap; |
| 210 | } |
| 211 | |
| 212 | /*! |
| 213 | * Sets whether the texture has automatic mipmap generation enabled, to \a autoMipMap. |
| 214 | */ |
| 215 | void QTextureData::setAutoMipMapGenerationEnabled(bool autoMipMap) |
| 216 | { |
| 217 | Q_D(QTextureData); |
| 218 | d->m_autoMipMap = autoMipMap; |
| 219 | } |
| 220 | |
| 221 | /*! |
| 222 | * Returns the current maximum anisotropy. |
| 223 | */ |
| 224 | float QTextureData::maximumAnisotropy() const |
| 225 | { |
| 226 | Q_D(const QTextureData); |
| 227 | return d->m_maximumAnisotropy; |
| 228 | } |
| 229 | |
| 230 | /*! |
| 231 | * Sets the maximum anisotropy to \a maximumAnisotropy. |
| 232 | */ |
| 233 | void QTextureData::setMaximumAnisotropy(float maximumAnisotropy) |
| 234 | { |
| 235 | Q_D(QTextureData); |
| 236 | d->m_maximumAnisotropy = maximumAnisotropy; |
| 237 | } |
| 238 | |
| 239 | /*! |
| 240 | * Returns the current minification filter. |
| 241 | */ |
| 242 | QAbstractTexture::Filter QTextureData::minificationFilter() const |
| 243 | { |
| 244 | Q_D(const QTextureData); |
| 245 | return d->m_minFilter; |
| 246 | } |
| 247 | |
| 248 | /*! |
| 249 | * Sets the minification filter to \a filter. |
| 250 | */ |
| 251 | void QTextureData::setMinificationFilter(QAbstractTexture::Filter filter) |
| 252 | { |
| 253 | Q_D(QTextureData); |
| 254 | d->m_minFilter = filter; |
| 255 | } |
| 256 | |
| 257 | /*! |
| 258 | * Returns the current magnification filter. |
| 259 | */ |
| 260 | QAbstractTexture::Filter QTextureData::magnificationFilter() const |
| 261 | { |
| 262 | Q_D(const QTextureData); |
| 263 | return d->m_magFilter; |
| 264 | } |
| 265 | |
| 266 | /*! |
| 267 | * Sets the magnification filter to \a filter. |
| 268 | */ |
| 269 | void QTextureData::setMagnificationFilter(QAbstractTexture::Filter filter) |
| 270 | { |
| 271 | Q_D(QTextureData); |
| 272 | d->m_magFilter = filter; |
| 273 | } |
| 274 | |
| 275 | /*! |
| 276 | * Returns the current wrap mode X. |
| 277 | */ |
| 278 | QTextureWrapMode::WrapMode QTextureData::wrapModeX() const |
| 279 | { |
| 280 | Q_D(const QTextureData); |
| 281 | return d->m_wrapModeX; |
| 282 | } |
| 283 | |
| 284 | /*! |
| 285 | * Sets the wrap mode X to \a wrapModeX. |
| 286 | */ |
| 287 | void QTextureData::setWrapModeX(QTextureWrapMode::WrapMode wrapModeX) |
| 288 | { |
| 289 | Q_D(QTextureData); |
| 290 | d->m_wrapModeX = wrapModeX; |
| 291 | } |
| 292 | |
| 293 | /*! |
| 294 | * Returns the current wrap mode Y. |
| 295 | */ |
| 296 | QTextureWrapMode::WrapMode QTextureData::wrapModeY() const |
| 297 | { |
| 298 | Q_D(const QTextureData); |
| 299 | return d->m_wrapModeY; |
| 300 | } |
| 301 | |
| 302 | /*! |
| 303 | * Sets the wrap mode Y to \a wrapModeY. |
| 304 | */ |
| 305 | void QTextureData::setWrapModeY(QTextureWrapMode::WrapMode wrapModeY) |
| 306 | { |
| 307 | Q_D(QTextureData); |
| 308 | d->m_wrapModeY = wrapModeY; |
| 309 | } |
| 310 | |
| 311 | /*! |
| 312 | * Returns the current wrap mode Z. |
| 313 | */ |
| 314 | QTextureWrapMode::WrapMode QTextureData::wrapModeZ() const |
| 315 | { |
| 316 | Q_D(const QTextureData); |
| 317 | return d->m_wrapModeZ; |
| 318 | } |
| 319 | |
| 320 | /*! |
| 321 | * Sets the wrap mode Z to \a wrapModeZ. |
| 322 | */ |
| 323 | void QTextureData::setWrapModeZ(QTextureWrapMode::WrapMode wrapModeZ) |
| 324 | { |
| 325 | Q_D(QTextureData); |
| 326 | d->m_wrapModeZ = wrapModeZ; |
| 327 | } |
| 328 | |
| 329 | /*! |
| 330 | * Returns the current comparison function. |
| 331 | */ |
| 332 | QAbstractTexture::ComparisonFunction QTextureData::comparisonFunction() const |
| 333 | { |
| 334 | Q_D(const QTextureData); |
| 335 | return d->m_comparisonFunction; |
| 336 | } |
| 337 | |
| 338 | /*! |
| 339 | * Sets the comparison function to \a comparisonFunction. |
| 340 | */ |
| 341 | void QTextureData::setComparisonFunction(QAbstractTexture::ComparisonFunction comparisonFunction) |
| 342 | { |
| 343 | Q_D(QTextureData); |
| 344 | d->m_comparisonFunction = comparisonFunction; |
| 345 | } |
| 346 | |
| 347 | /*! |
| 348 | * Returns the current comparison mode. |
| 349 | */ |
| 350 | QAbstractTexture::ComparisonMode QTextureData::comparisonMode() const |
| 351 | { |
| 352 | Q_D(const QTextureData); |
| 353 | return d->m_comparisonMode; |
| 354 | } |
| 355 | |
| 356 | /*! |
| 357 | * Sets the comparison mode to \a comparisonMode. |
| 358 | */ |
| 359 | void QTextureData::setComparisonMode(QAbstractTexture::ComparisonMode comparisonMode) |
| 360 | { |
| 361 | Q_D(QTextureData); |
| 362 | d->m_comparisonMode = comparisonMode; |
| 363 | } |
| 364 | |
| 365 | /*! |
| 366 | * Returns the data of the images used by this texture. |
| 367 | */ |
| 368 | QVector<QTextureImageDataPtr> QTextureData::imageData() const |
| 369 | { |
| 370 | Q_D(const QTextureData); |
| 371 | return d->m_imagesData; |
| 372 | } |
| 373 | |
| 374 | /*! |
| 375 | * Adds an extra image layer to the texture using \a imageData. |
| 376 | * |
| 377 | * \note The texture image should be loaded with the size specified on the texture. |
| 378 | * However, if no size is specified, the size of the first texture image file is used as default. |
| 379 | */ |
| 380 | void QTextureData::addImageData(const QTextureImageDataPtr &imageData) |
| 381 | { |
| 382 | Q_D(QTextureData); |
| 383 | d->m_imagesData.push_back(t: imageData); |
| 384 | } |
| 385 | |
| 386 | } // Qt3DRender |
| 387 | |
| 388 | QT_END_NAMESPACE |
| 389 | |