| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtGui 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 | #include "qopenglpixeltransferoptions.h" |
| 41 | #include <QSharedData> |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | /*! |
| 46 | * \class QOpenGLPixelTransferOptions |
| 47 | * |
| 48 | * \brief The QOpenGLPixelTransferOptions class describes the pixel storage |
| 49 | * modes that affect the unpacking of pixels during texture upload. |
| 50 | */ |
| 51 | |
| 52 | /*! |
| 53 | * \fn QOpenGLPixelTransferOptions & QOpenGLPixelTransferOptions::operator=(QOpenGLPixelTransferOptions &&other) |
| 54 | * \internal |
| 55 | */ |
| 56 | |
| 57 | /*! |
| 58 | * \fn void QOpenGLPixelTransferOptions::swap(QOpenGLPixelTransferOptions &other) |
| 59 | * \internal |
| 60 | */ |
| 61 | |
| 62 | class QOpenGLPixelTransferOptionsData : public QSharedData |
| 63 | { |
| 64 | public: |
| 65 | QOpenGLPixelTransferOptionsData() |
| 66 | : alignment(4) |
| 67 | , skipImages(0) |
| 68 | , skipRows(0) |
| 69 | , skipPixels(0) |
| 70 | , imageHeight(0) |
| 71 | , rowLength(0) |
| 72 | , lsbFirst(false) |
| 73 | , swapBytes(false) |
| 74 | {} |
| 75 | |
| 76 | int alignment; |
| 77 | int skipImages; |
| 78 | int skipRows; |
| 79 | int skipPixels; |
| 80 | int imageHeight; |
| 81 | int rowLength; |
| 82 | bool lsbFirst; |
| 83 | bool swapBytes; |
| 84 | }; |
| 85 | |
| 86 | /*! |
| 87 | * Constructs a new QOpenGLPixelTransferOptions instance with the default settings. |
| 88 | */ |
| 89 | QOpenGLPixelTransferOptions::QOpenGLPixelTransferOptions() |
| 90 | : data(new QOpenGLPixelTransferOptionsData) |
| 91 | { |
| 92 | } |
| 93 | |
| 94 | /*! |
| 95 | * \internal |
| 96 | */ |
| 97 | QOpenGLPixelTransferOptions::QOpenGLPixelTransferOptions(const QOpenGLPixelTransferOptions &rhs) |
| 98 | : data(rhs.data) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | /*! |
| 103 | * \internal |
| 104 | */ |
| 105 | QOpenGLPixelTransferOptions &QOpenGLPixelTransferOptions::operator=(const QOpenGLPixelTransferOptions &rhs) |
| 106 | { |
| 107 | if (this != &rhs) |
| 108 | data.operator=(o: rhs.data); |
| 109 | return *this; |
| 110 | } |
| 111 | |
| 112 | /*! |
| 113 | * Destructor. |
| 114 | */ |
| 115 | QOpenGLPixelTransferOptions::~QOpenGLPixelTransferOptions() |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | /*! |
| 120 | * Sets the \a alignment requirements for each pixel row. Corresponds to \c GL_UNPACK_ALIGNMENT. |
| 121 | * The default value is 4, as specified by OpenGL. |
| 122 | */ |
| 123 | void QOpenGLPixelTransferOptions::setAlignment(int alignment) |
| 124 | { |
| 125 | data->alignment = alignment; |
| 126 | } |
| 127 | |
| 128 | /*! |
| 129 | * \return the current alignment requirement for each pixel row. |
| 130 | */ |
| 131 | int QOpenGLPixelTransferOptions::alignment() const |
| 132 | { |
| 133 | return data->alignment; |
| 134 | } |
| 135 | |
| 136 | /*! |
| 137 | * Sets the number of images that are skipped to \a skipImages. |
| 138 | * Corresponds to \c GL_UNPACK_SKIP_IMAGES. Equivalent to incrementing the pointer |
| 139 | * passed to QOpenGLTexture::setData(). The default value is 0. |
| 140 | */ |
| 141 | void QOpenGLPixelTransferOptions::setSkipImages(int skipImages) |
| 142 | { |
| 143 | data->skipImages = skipImages; |
| 144 | } |
| 145 | |
| 146 | /*! |
| 147 | * \return the number of images that are skipped. |
| 148 | */ |
| 149 | int QOpenGLPixelTransferOptions::skipImages() const |
| 150 | { |
| 151 | return data->skipImages; |
| 152 | } |
| 153 | |
| 154 | /*! |
| 155 | * Sets the number of rows that are skipped to \a skipRows. |
| 156 | * Corresponds to \c GL_UNPACK_SKIP_ROWS. Equivalent to incrementing the pointer |
| 157 | * passed to QOpenGLTexture::setData(). The default value is 0. |
| 158 | */ |
| 159 | void QOpenGLPixelTransferOptions::setSkipRows(int skipRows) |
| 160 | { |
| 161 | data->skipRows = skipRows; |
| 162 | } |
| 163 | |
| 164 | /*! |
| 165 | * \return the number of rows that are skipped. |
| 166 | */ |
| 167 | int QOpenGLPixelTransferOptions::skipRows() const |
| 168 | { |
| 169 | return data->skipRows; |
| 170 | } |
| 171 | |
| 172 | /*! |
| 173 | * Sets the number of pixels that are skipped to \a skipPixels. |
| 174 | * Corresponds to \c GL_UNPACK_SKIP_PIXELS. Equivalent to incrementing the pointer |
| 175 | * passed to QOpenGLTexture::setData(). The default value is 0. |
| 176 | */ |
| 177 | void QOpenGLPixelTransferOptions::setSkipPixels(int skipPixels) |
| 178 | { |
| 179 | data->skipPixels = skipPixels; |
| 180 | } |
| 181 | |
| 182 | /*! |
| 183 | * \return the number of pixels that are skipped. |
| 184 | */ |
| 185 | int QOpenGLPixelTransferOptions::skipPixels() const |
| 186 | { |
| 187 | return data->skipPixels; |
| 188 | } |
| 189 | |
| 190 | /*! |
| 191 | * Sets the image height for 3D textures to \a imageHeight. |
| 192 | * Corresponds to \c GL_UNPACK_IMAGE_HEIGHT. |
| 193 | * The default value is 0. |
| 194 | */ |
| 195 | void QOpenGLPixelTransferOptions::setImageHeight(int imageHeight) |
| 196 | { |
| 197 | data->imageHeight = imageHeight; |
| 198 | } |
| 199 | |
| 200 | /*! |
| 201 | * \return the currently set image height. |
| 202 | */ |
| 203 | int QOpenGLPixelTransferOptions::imageHeight() const |
| 204 | { |
| 205 | return data->imageHeight; |
| 206 | } |
| 207 | |
| 208 | /*! |
| 209 | * Sets the number of pixels in a row to \a rowLength. |
| 210 | * Corresponds to \c GL_UNPACK_ROW_LENGTH. |
| 211 | * The default value is 0. |
| 212 | */ |
| 213 | void QOpenGLPixelTransferOptions::setRowLength(int rowLength) |
| 214 | { |
| 215 | data->rowLength = rowLength; |
| 216 | } |
| 217 | |
| 218 | /*! |
| 219 | * \return the currently set row length. |
| 220 | */ |
| 221 | int QOpenGLPixelTransferOptions::rowLength() const |
| 222 | { |
| 223 | return data->rowLength; |
| 224 | } |
| 225 | |
| 226 | /*! |
| 227 | * \a lsbFirst specifies if bits within a byte are ordered from least to most significat. |
| 228 | * The default value is \c false, meaning that the first bit in each byte is the |
| 229 | * most significant one. This is significant for bitmap data only. |
| 230 | * Corresponds to \c GL_UNPACK_LSB_FIRST. |
| 231 | */ |
| 232 | void QOpenGLPixelTransferOptions::setLeastSignificantByteFirst(bool lsbFirst) |
| 233 | { |
| 234 | data->lsbFirst = lsbFirst; |
| 235 | } |
| 236 | |
| 237 | /*! |
| 238 | * \return \c true if bits within a byte are ordered from least to most significant. |
| 239 | */ |
| 240 | bool QOpenGLPixelTransferOptions::isLeastSignificantBitFirst() const |
| 241 | { |
| 242 | return data->lsbFirst; |
| 243 | } |
| 244 | |
| 245 | /*! |
| 246 | * \a swapBytes specifies if the byte ordering for multibyte components is reversed. |
| 247 | * The default value is \c false. |
| 248 | * Corresponds to \c GL_UNPACK_SWAP_BYTES. |
| 249 | */ |
| 250 | void QOpenGLPixelTransferOptions::setSwapBytesEnabled(bool swapBytes) |
| 251 | { |
| 252 | data->swapBytes = swapBytes; |
| 253 | } |
| 254 | |
| 255 | /*! |
| 256 | * \return \c true if the byte ordering for multibyte components is reversed. |
| 257 | */ |
| 258 | bool QOpenGLPixelTransferOptions::isSwapBytesEnabled() const |
| 259 | { |
| 260 | return data->swapBytes; |
| 261 | } |
| 262 | |
| 263 | QT_END_NAMESPACE |
| 264 | |