| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/qglbuffer.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | #include <QtOpenGL/qgl.h> | - | ||||||||||||
| 35 | #include <QtOpenGL/private/qgl_p.h> | - | ||||||||||||
| 36 | #include <private/qopenglextensions_p.h> | - | ||||||||||||
| 37 | #include <QtCore/qatomic.h> | - | ||||||||||||
| 38 | #include "qglbuffer.h" | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | /*! | - | ||||||||||||
| 43 | \class QGLBuffer | - | ||||||||||||
| 44 | \inmodule QtOpenGL | - | ||||||||||||
| 45 | \brief The QGLBuffer class provides functions for creating and managing GL buffer objects. | - | ||||||||||||
| 46 | \since 4.7 | - | ||||||||||||
| 47 | \obsolete | - | ||||||||||||
| 48 | \ingroup painting-3D | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | Buffer objects are created in the GL server so that the | - | ||||||||||||
| 51 | client application can avoid uploading vertices, indices, | - | ||||||||||||
| 52 | texture image data, etc every time they are needed. | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | QGLBuffer objects can be copied around as a reference to the | - | ||||||||||||
| 55 | underlying GL buffer object: | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | \code | - | ||||||||||||
| 58 | QGLBuffer buffer1(QGLBuffer::IndexBuffer); | - | ||||||||||||
| 59 | buffer1.create(); | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | QGLBuffer buffer2 = buffer1; | - | ||||||||||||
| 62 | \endcode | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | QGLBuffer performs a shallow copy when objects are copied in this | - | ||||||||||||
| 65 | manner, but does not implement copy-on-write semantics. The original | - | ||||||||||||
| 66 | object will be affected whenever the copy is modified. | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | \note This class has been deprecated in favor of QOpenGLBuffer. | - | ||||||||||||
| 69 | */ | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | /*! | - | ||||||||||||
| 72 | \enum QGLBuffer::Type | - | ||||||||||||
| 73 | This enum defines the type of GL buffer object to create with QGLBuffer. | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | \value VertexBuffer Vertex buffer object for use when specifying | - | ||||||||||||
| 76 | vertex arrays. | - | ||||||||||||
| 77 | \value IndexBuffer Index buffer object for use with \c{glDrawElements()}. | - | ||||||||||||
| 78 | \value PixelPackBuffer Pixel pack buffer object for reading pixel | - | ||||||||||||
| 79 | data from the GL server (for example, with \c{glReadPixels()}). | - | ||||||||||||
| 80 | Not supported under OpenGL/ES. | - | ||||||||||||
| 81 | \value PixelUnpackBuffer Pixel unpack buffer object for writing pixel | - | ||||||||||||
| 82 | data to the GL server (for example, with \c{glTexImage2D()}). | - | ||||||||||||
| 83 | Not supported under OpenGL/ES. | - | ||||||||||||
| 84 | */ | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | /*! | - | ||||||||||||
| 87 | \enum QGLBuffer::UsagePattern | - | ||||||||||||
| 88 | This enum defines the usage pattern of a QGLBuffer object. | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | \value StreamDraw The data will be set once and used a few times | - | ||||||||||||
| 91 | for drawing operations. Under OpenGL/ES 1.1 this is identical | - | ||||||||||||
| 92 | to StaticDraw. | - | ||||||||||||
| 93 | \value StreamRead The data will be set once and used a few times | - | ||||||||||||
| 94 | for reading data back from the GL server. Not supported | - | ||||||||||||
| 95 | under OpenGL/ES. | - | ||||||||||||
| 96 | \value StreamCopy The data will be set once and used a few times | - | ||||||||||||
| 97 | for reading data back from the GL server for use in further | - | ||||||||||||
| 98 | drawing operations. Not supported under OpenGL/ES. | - | ||||||||||||
| 99 | \value StaticDraw The data will be set once and used many times | - | ||||||||||||
| 100 | for drawing operations. | - | ||||||||||||
| 101 | \value StaticRead The data will be set once and used many times | - | ||||||||||||
| 102 | for reading data back from the GL server. Not supported | - | ||||||||||||
| 103 | under OpenGL/ES. | - | ||||||||||||
| 104 | \value StaticCopy The data will be set once and used many times | - | ||||||||||||
| 105 | for reading data back from the GL server for use in further | - | ||||||||||||
| 106 | drawing operations. Not supported under OpenGL/ES. | - | ||||||||||||
| 107 | \value DynamicDraw The data will be modified repeatedly and used | - | ||||||||||||
| 108 | many times for drawing operations. | - | ||||||||||||
| 109 | \value DynamicRead The data will be modified repeatedly and used | - | ||||||||||||
| 110 | many times for reading data back from the GL server. | - | ||||||||||||
| 111 | Not supported under OpenGL/ES. | - | ||||||||||||
| 112 | \value DynamicCopy The data will be modified repeatedly and used | - | ||||||||||||
| 113 | many times for reading data back from the GL server for | - | ||||||||||||
| 114 | use in further drawing operations. Not supported under OpenGL/ES. | - | ||||||||||||
| 115 | */ | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | /*! | - | ||||||||||||
| 118 | \enum QGLBuffer::Access | - | ||||||||||||
| 119 | This enum defines the access mode for QGLBuffer::map(). | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | \value ReadOnly The buffer will be mapped for reading only. | - | ||||||||||||
| 122 | \value WriteOnly The buffer will be mapped for writing only. | - | ||||||||||||
| 123 | \value ReadWrite The buffer will be mapped for reading and writing. | - | ||||||||||||
| 124 | */ | - | ||||||||||||
| 125 | - | |||||||||||||
| 126 | class QGLBufferPrivate | - | ||||||||||||
| 127 | { | - | ||||||||||||
| 128 | public: | - | ||||||||||||
| 129 | QGLBufferPrivate(QGLBuffer::Type t) | - | ||||||||||||
| 130 | : ref(1), | - | ||||||||||||
| 131 | type(t), | - | ||||||||||||
| 132 | guard(0), | - | ||||||||||||
| 133 | usagePattern(QGLBuffer::StaticDraw), | - | ||||||||||||
| 134 | actualUsagePattern(QGLBuffer::StaticDraw), | - | ||||||||||||
| 135 | funcs(0) | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 138 | - | |||||||||||||
| 139 | QAtomicInt ref; | - | ||||||||||||
| 140 | QGLBuffer::Type type; | - | ||||||||||||
| 141 | QGLSharedResourceGuardBase *guard; | - | ||||||||||||
| 142 | QGLBuffer::UsagePattern usagePattern; | - | ||||||||||||
| 143 | QGLBuffer::UsagePattern actualUsagePattern; | - | ||||||||||||
| 144 | QOpenGLExtensions *funcs; | - | ||||||||||||
| 145 | }; | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | /*! | - | ||||||||||||
| 148 | Constructs a new buffer object of type QGLBuffer::VertexBuffer. | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | Note: this constructor just creates the QGLBuffer instance. The actual | - | ||||||||||||
| 151 | buffer object in the GL server is not created until create() is called. | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | \sa create() | - | ||||||||||||
| 154 | */ | - | ||||||||||||
| 155 | QGLBuffer::QGLBuffer() | - | ||||||||||||
| 156 | : d_ptr(new QGLBufferPrivate(QGLBuffer::VertexBuffer)) | - | ||||||||||||
| 157 | { | - | ||||||||||||
| 158 | } never executed: end of block | 0 | ||||||||||||
| 159 | - | |||||||||||||
| 160 | /*! | - | ||||||||||||
| 161 | Constructs a new buffer object of \a type. | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | Note: this constructor just creates the QGLBuffer instance. The actual | - | ||||||||||||
| 164 | buffer object in the GL server is not created until create() is called. | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | \sa create() | - | ||||||||||||
| 167 | */ | - | ||||||||||||
| 168 | QGLBuffer::QGLBuffer(QGLBuffer::Type type) | - | ||||||||||||
| 169 | : d_ptr(new QGLBufferPrivate(type)) | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 172 | - | |||||||||||||
| 173 | /*! | - | ||||||||||||
| 174 | Constructs a shallow copy of \a other. | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | Note: QGLBuffer does not implement copy-on-write semantics, | - | ||||||||||||
| 177 | so \a other will be affected whenever the copy is modified. | - | ||||||||||||
| 178 | */ | - | ||||||||||||
| 179 | QGLBuffer::QGLBuffer(const QGLBuffer &other) | - | ||||||||||||
| 180 | : d_ptr(other.d_ptr) | - | ||||||||||||
| 181 | { | - | ||||||||||||
| 182 | d_ptr->ref.ref(); | - | ||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||
| 184 | - | |||||||||||||
| 185 | #define ctx QGLContext::currentContext(); | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | /*! | - | ||||||||||||
| 188 | Destroys this buffer object, including the storage being | - | ||||||||||||
| 189 | used in the GL server. | - | ||||||||||||
| 190 | */ | - | ||||||||||||
| 191 | QGLBuffer::~QGLBuffer() | - | ||||||||||||
| 192 | { | - | ||||||||||||
| 193 | if (!d_ptr->ref.deref()) {
| 0-7 | ||||||||||||
| 194 | destroy(); | - | ||||||||||||
| 195 | delete d_ptr; | - | ||||||||||||
| 196 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 197 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | /*! | - | ||||||||||||
| 200 | Assigns a shallow copy of \a other to this object. | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | Note: QGLBuffer does not implement copy-on-write semantics, | - | ||||||||||||
| 203 | so \a other will be affected whenever the copy is modified. | - | ||||||||||||
| 204 | */ | - | ||||||||||||
| 205 | QGLBuffer &QGLBuffer::operator=(const QGLBuffer &other) | - | ||||||||||||
| 206 | { | - | ||||||||||||
| 207 | if (d_ptr != other.d_ptr) {
| 0 | ||||||||||||
| 208 | other.d_ptr->ref.ref(); | - | ||||||||||||
| 209 | if (!d_ptr->ref.deref()) {
| 0 | ||||||||||||
| 210 | destroy(); | - | ||||||||||||
| 211 | delete d_ptr; | - | ||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||
| 213 | d_ptr = other.d_ptr; | - | ||||||||||||
| 214 | } never executed: end of block | 0 | ||||||||||||
| 215 | return *this; never executed: return *this; | 0 | ||||||||||||
| 216 | } | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | /*! | - | ||||||||||||
| 219 | Returns the type of buffer represented by this object. | - | ||||||||||||
| 220 | */ | - | ||||||||||||
| 221 | QGLBuffer::Type QGLBuffer::type() const | - | ||||||||||||
| 222 | { | - | ||||||||||||
| 223 | Q_D(const QGLBuffer); | - | ||||||||||||
| 224 | return d->type; executed 6 times by 1 test: return d->type;Executed by:
| 6 | ||||||||||||
| 225 | } | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | /*! | - | ||||||||||||
| 228 | Returns the usage pattern for this buffer object. | - | ||||||||||||
| 229 | The default value is StaticDraw. | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | \sa setUsagePattern() | - | ||||||||||||
| 232 | */ | - | ||||||||||||
| 233 | QGLBuffer::UsagePattern QGLBuffer::usagePattern() const | - | ||||||||||||
| 234 | { | - | ||||||||||||
| 235 | Q_D(const QGLBuffer); | - | ||||||||||||
| 236 | return d->usagePattern; executed 12 times by 1 test: return d->usagePattern;Executed by:
| 12 | ||||||||||||
| 237 | } | - | ||||||||||||
| 238 | - | |||||||||||||
| 239 | /*! | - | ||||||||||||
| 240 | Sets the usage pattern for this buffer object to \a value. | - | ||||||||||||
| 241 | This function must be called before allocate() or write(). | - | ||||||||||||
| 242 | - | |||||||||||||
| 243 | \sa usagePattern(), allocate(), write() | - | ||||||||||||
| 244 | */ | - | ||||||||||||
| 245 | void QGLBuffer::setUsagePattern(QGLBuffer::UsagePattern value) | - | ||||||||||||
| 246 | { | - | ||||||||||||
| 247 | Q_D(QGLBuffer); | - | ||||||||||||
| 248 | d->usagePattern = d->actualUsagePattern = value; | - | ||||||||||||
| 249 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 250 | - | |||||||||||||
| 251 | #undef ctx | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | namespace { | - | ||||||||||||
| 254 | void freeBufferFunc(QGLContext *ctx, GLuint id) | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | Q_ASSERT(ctx); | - | ||||||||||||
| 257 | ctx->contextHandle()->functions()->glDeleteBuffers(1, &id); | - | ||||||||||||
| 258 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 259 | } | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | /*! | - | ||||||||||||
| 262 | Creates the buffer object in the GL server. Returns \c true if | - | ||||||||||||
| 263 | the object was created; false otherwise. | - | ||||||||||||
| 264 | - | |||||||||||||
| 265 | This function must be called with a current QGLContext. | - | ||||||||||||
| 266 | The buffer will be bound to and can only be used in | - | ||||||||||||
| 267 | that context (or any other context that is shared with it). | - | ||||||||||||
| 268 | - | |||||||||||||
| 269 | This function will return false if the GL implementation | - | ||||||||||||
| 270 | does not support buffers, or there is no current QGLContext. | - | ||||||||||||
| 271 | - | |||||||||||||
| 272 | \sa isCreated(), allocate(), write(), destroy() | - | ||||||||||||
| 273 | */ | - | ||||||||||||
| 274 | bool QGLBuffer::create() | - | ||||||||||||
| 275 | { | - | ||||||||||||
| 276 | Q_D(QGLBuffer); | - | ||||||||||||
| 277 | if (d->guard && d->guard->id())
| 0-7 | ||||||||||||
| 278 | return true; never executed: return true; | 0 | ||||||||||||
| 279 | QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||
| 280 | if (ctx) {
| 0-7 | ||||||||||||
| 281 | delete d->funcs; | - | ||||||||||||
| 282 | d->funcs = new QOpenGLExtensions(ctx->contextHandle()); | - | ||||||||||||
| 283 | if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers))
| 0-7 | ||||||||||||
| 284 | return false; never executed: return false; | 0 | ||||||||||||
| 285 | - | |||||||||||||
| 286 | GLuint bufferId = 0; | - | ||||||||||||
| 287 | d->funcs->glGenBuffers(1, &bufferId); | - | ||||||||||||
| 288 | if (bufferId) {
| 0-7 | ||||||||||||
| 289 | if (d->guard)
| 0-7 | ||||||||||||
| 290 | d->guard->free(); never executed: d->guard->free(); | 0 | ||||||||||||
| 291 | - | |||||||||||||
| 292 | d->guard = createSharedResourceGuard(ctx, bufferId, freeBufferFunc); | - | ||||||||||||
| 293 | return true; executed 7 times by 1 test: return true;Executed by:
| 7 | ||||||||||||
| 294 | } | - | ||||||||||||
| 295 | } never executed: end of block | 0 | ||||||||||||
| 296 | return false; never executed: return false; | 0 | ||||||||||||
| 297 | } | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | #define ctx QGLContext::currentContext() | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | /*! | - | ||||||||||||
| 302 | Returns \c true if this buffer has been created; false otherwise. | - | ||||||||||||
| 303 | - | |||||||||||||
| 304 | \sa create(), destroy() | - | ||||||||||||
| 305 | */ | - | ||||||||||||
| 306 | bool QGLBuffer::isCreated() const | - | ||||||||||||
| 307 | { | - | ||||||||||||
| 308 | Q_D(const QGLBuffer); | - | ||||||||||||
| 309 | return d->guard && d->guard->id(); executed 106 times by 1 test: return d->guard && d->guard->id();Executed by:
| 1-106 | ||||||||||||
| 310 | } | - | ||||||||||||
| 311 | - | |||||||||||||
| 312 | /*! | - | ||||||||||||
| 313 | Destroys this buffer object, including the storage being | - | ||||||||||||
| 314 | used in the GL server. All references to the buffer will | - | ||||||||||||
| 315 | become invalid. | - | ||||||||||||
| 316 | */ | - | ||||||||||||
| 317 | void QGLBuffer::destroy() | - | ||||||||||||
| 318 | { | - | ||||||||||||
| 319 | Q_D(QGLBuffer); | - | ||||||||||||
| 320 | if (d->guard) {
| 0-7 | ||||||||||||
| 321 | d->guard->free(); | - | ||||||||||||
| 322 | d->guard = 0; | - | ||||||||||||
| 323 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 324 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 325 | - | |||||||||||||
| 326 | /*! | - | ||||||||||||
| 327 | Reads the \a count bytes in this buffer starting at \a offset | - | ||||||||||||
| 328 | into \a data. Returns \c true on success; false if reading from | - | ||||||||||||
| 329 | the buffer is not supported. Buffer reading is not supported | - | ||||||||||||
| 330 | under OpenGL/ES. | - | ||||||||||||
| 331 | - | |||||||||||||
| 332 | It is assumed that this buffer has been bound to the current context. | - | ||||||||||||
| 333 | - | |||||||||||||
| 334 | \sa write(), bind() | - | ||||||||||||
| 335 | */ | - | ||||||||||||
| 336 | bool QGLBuffer::read(int offset, void *data, int count) | - | ||||||||||||
| 337 | { | - | ||||||||||||
| 338 | #if !defined(QT_OPENGL_ES) | - | ||||||||||||
| 339 | Q_D(QGLBuffer); | - | ||||||||||||
| 340 | if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers) || !d->guard->id())
| 0-13 | ||||||||||||
| 341 | return false; never executed: return false; | 0 | ||||||||||||
| 342 | while (d->funcs->glGetError() != GL_NO_ERROR) ; // Clear error state. never executed: ;
| 0-13 | ||||||||||||
| 343 | d->funcs->glGetBufferSubData(d->type, offset, count, data); | - | ||||||||||||
| 344 | return d->funcs->glGetError() == GL_NO_ERROR; executed 13 times by 1 test: return d->funcs->glGetError() == 0;Executed by:
| 13 | ||||||||||||
| 345 | #else | - | ||||||||||||
| 346 | Q_UNUSED(offset); | - | ||||||||||||
| 347 | Q_UNUSED(data); | - | ||||||||||||
| 348 | Q_UNUSED(count); | - | ||||||||||||
| 349 | return false; | - | ||||||||||||
| 350 | #endif | - | ||||||||||||
| 351 | } | - | ||||||||||||
| 352 | - | |||||||||||||
| 353 | /*! | - | ||||||||||||
| 354 | Replaces the \a count bytes of this buffer starting at \a offset | - | ||||||||||||
| 355 | with the contents of \a data. Any other bytes in the buffer | - | ||||||||||||
| 356 | will be left unmodified. | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | It is assumed that create() has been called on this buffer and that | - | ||||||||||||
| 359 | it has been bound to the current context. | - | ||||||||||||
| 360 | - | |||||||||||||
| 361 | \sa create(), read(), allocate() | - | ||||||||||||
| 362 | */ | - | ||||||||||||
| 363 | void QGLBuffer::write(int offset, const void *data, int count) | - | ||||||||||||
| 364 | { | - | ||||||||||||
| 365 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 366 | if (!isCreated())
| 0-6 | ||||||||||||
| 367 | qWarning("QGLBuffer::allocate(): buffer not created"); never executed: QMessageLogger(__FILE__, 367, __PRETTY_FUNCTION__).warning("QGLBuffer::allocate(): buffer not created"); | 0 | ||||||||||||
| 368 | #endif | - | ||||||||||||
| 369 | Q_D(QGLBuffer); | - | ||||||||||||
| 370 | if (d->guard && d->guard->id())
| 0-6 | ||||||||||||
| 371 | d->funcs->glBufferSubData(d->type, offset, count, data); executed 6 times by 1 test: d->funcs->glBufferSubData(d->type, offset, count, data);Executed by:
| 6 | ||||||||||||
| 372 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 373 | - | |||||||||||||
| 374 | /*! | - | ||||||||||||
| 375 | Allocates \a count bytes of space to the buffer, initialized to | - | ||||||||||||
| 376 | the contents of \a data. Any previous contents will be removed. | - | ||||||||||||
| 377 | - | |||||||||||||
| 378 | It is assumed that create() has been called on this buffer and that | - | ||||||||||||
| 379 | it has been bound to the current context. | - | ||||||||||||
| 380 | - | |||||||||||||
| 381 | \sa create(), read(), write() | - | ||||||||||||
| 382 | */ | - | ||||||||||||
| 383 | void QGLBuffer::allocate(const void *data, int count) | - | ||||||||||||
| 384 | { | - | ||||||||||||
| 385 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 386 | if (!isCreated())
| 0-19 | ||||||||||||
| 387 | qWarning("QGLBuffer::allocate(): buffer not created"); never executed: QMessageLogger(__FILE__, 387, __PRETTY_FUNCTION__).warning("QGLBuffer::allocate(): buffer not created"); | 0 | ||||||||||||
| 388 | #endif | - | ||||||||||||
| 389 | Q_D(QGLBuffer); | - | ||||||||||||
| 390 | if (d->guard && d->guard->id())
| 0-19 | ||||||||||||
| 391 | d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern); executed 19 times by 1 test: d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);Executed by:
| 19 | ||||||||||||
| 392 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||
| 393 | - | |||||||||||||
| 394 | /*! | - | ||||||||||||
| 395 | \fn void QGLBuffer::allocate(int count) | - | ||||||||||||
| 396 | \overload | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | Allocates \a count bytes of space to the buffer. Any previous | - | ||||||||||||
| 399 | contents will be removed. | - | ||||||||||||
| 400 | - | |||||||||||||
| 401 | It is assumed that create() has been called on this buffer and that | - | ||||||||||||
| 402 | it has been bound to the current context. | - | ||||||||||||
| 403 | - | |||||||||||||
| 404 | \sa create(), write() | - | ||||||||||||
| 405 | */ | - | ||||||||||||
| 406 | - | |||||||||||||
| 407 | /*! | - | ||||||||||||
| 408 | Binds the buffer associated with this object to the current | - | ||||||||||||
| 409 | GL context. Returns \c false if binding was not possible, usually because | - | ||||||||||||
| 410 | type() is not supported on this GL implementation. | - | ||||||||||||
| 411 | - | |||||||||||||
| 412 | The buffer must be bound to the same QGLContext current when create() | - | ||||||||||||
| 413 | was called, or to another QGLContext that is sharing with it. | - | ||||||||||||
| 414 | Otherwise, false will be returned from this function. | - | ||||||||||||
| 415 | - | |||||||||||||
| 416 | \sa release(), create() | - | ||||||||||||
| 417 | */ | - | ||||||||||||
| 418 | bool QGLBuffer::bind() | - | ||||||||||||
| 419 | { | - | ||||||||||||
| 420 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 421 | if (!isCreated())
| 6-9 | ||||||||||||
| 422 | qWarning("QGLBuffer::bind(): buffer not created"); executed 6 times by 1 test: QMessageLogger(__FILE__, 422, __PRETTY_FUNCTION__).warning("QGLBuffer::bind(): buffer not created");Executed by:
| 6 | ||||||||||||
| 423 | #endif | - | ||||||||||||
| 424 | Q_D(const QGLBuffer); | - | ||||||||||||
| 425 | GLuint bufferId = d->guard ? d->guard->id() : 0;
| 6-9 | ||||||||||||
| 426 | if (bufferId) {
| 6-9 | ||||||||||||
| 427 | if (d->guard->group() != QOpenGLContextGroup::currentContextGroup()) {
| 0-9 | ||||||||||||
| 428 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 429 | qWarning("QGLBuffer::bind: buffer is not valid in the current context"); | - | ||||||||||||
| 430 | #endif | - | ||||||||||||
| 431 | return false; never executed: return false; | 0 | ||||||||||||
| 432 | } | - | ||||||||||||
| 433 | d->funcs->glBindBuffer(d->type, bufferId); | - | ||||||||||||
| 434 | return true; executed 9 times by 1 test: return true;Executed by:
| 9 | ||||||||||||
| 435 | } else { | - | ||||||||||||
| 436 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||
| 437 | } | - | ||||||||||||
| 438 | } | - | ||||||||||||
| 439 | - | |||||||||||||
| 440 | /*! | - | ||||||||||||
| 441 | Releases the buffer associated with this object from the | - | ||||||||||||
| 442 | current GL context. | - | ||||||||||||
| 443 | - | |||||||||||||
| 444 | This function must be called with the same QGLContext current | - | ||||||||||||
| 445 | as when bind() was called on the buffer. | - | ||||||||||||
| 446 | - | |||||||||||||
| 447 | \sa bind() | - | ||||||||||||
| 448 | */ | - | ||||||||||||
| 449 | void QGLBuffer::release() | - | ||||||||||||
| 450 | { | - | ||||||||||||
| 451 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 452 | if (!isCreated())
| 0-9 | ||||||||||||
| 453 | qWarning("QGLBuffer::release(): buffer not created"); never executed: QMessageLogger(__FILE__, 453, __PRETTY_FUNCTION__).warning("QGLBuffer::release(): buffer not created"); | 0 | ||||||||||||
| 454 | #endif | - | ||||||||||||
| 455 | Q_D(const QGLBuffer); | - | ||||||||||||
| 456 | if (d->guard && d->guard->id())
| 0-9 | ||||||||||||
| 457 | d->funcs->glBindBuffer(d->type, 0); executed 9 times by 1 test: d->funcs->glBindBuffer(d->type, 0);Executed by:
| 9 | ||||||||||||
| 458 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 459 | - | |||||||||||||
| 460 | #undef ctx | - | ||||||||||||
| 461 | - | |||||||||||||
| 462 | /*! | - | ||||||||||||
| 463 | Releases the buffer associated with \a type in the current | - | ||||||||||||
| 464 | QGLContext. | - | ||||||||||||
| 465 | - | |||||||||||||
| 466 | This function is a direct call to \c{glBindBuffer(type, 0)} | - | ||||||||||||
| 467 | for use when the caller does not know which QGLBuffer has | - | ||||||||||||
| 468 | been bound to the context but wants to make sure that it | - | ||||||||||||
| 469 | is released. | - | ||||||||||||
| 470 | - | |||||||||||||
| 471 | \code | - | ||||||||||||
| 472 | QGLBuffer::release(QGLBuffer::VertexBuffer); | - | ||||||||||||
| 473 | \endcode | - | ||||||||||||
| 474 | */ | - | ||||||||||||
| 475 | void QGLBuffer::release(QGLBuffer::Type type) | - | ||||||||||||
| 476 | { | - | ||||||||||||
| 477 | if (QOpenGLContext *ctx = QOpenGLContext::currentContext())
| 0 | ||||||||||||
| 478 | ctx->functions()->glBindBuffer(GLenum(type), 0); never executed: ctx->functions()->glBindBuffer(GLenum(type), 0); | 0 | ||||||||||||
| 479 | } never executed: end of block | 0 | ||||||||||||
| 480 | - | |||||||||||||
| 481 | #define ctx QGLContext::currentContext() | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | /*! | - | ||||||||||||
| 484 | Returns the GL identifier associated with this buffer; zero if | - | ||||||||||||
| 485 | the buffer has not been created. | - | ||||||||||||
| 486 | - | |||||||||||||
| 487 | \sa isCreated() | - | ||||||||||||
| 488 | */ | - | ||||||||||||
| 489 | GLuint QGLBuffer::bufferId() const | - | ||||||||||||
| 490 | { | - | ||||||||||||
| 491 | Q_D(const QGLBuffer); | - | ||||||||||||
| 492 | return d->guard ? d->guard->id() : 0; executed 14 times by 1 test: return d->guard ? d->guard->id() : 0;Executed by:
| 6-14 | ||||||||||||
| 493 | } | - | ||||||||||||
| 494 | - | |||||||||||||
| 495 | #ifndef GL_BUFFER_SIZE | - | ||||||||||||
| 496 | #define GL_BUFFER_SIZE 0x8764 | - | ||||||||||||
| 497 | #endif | - | ||||||||||||
| 498 | - | |||||||||||||
| 499 | /*! | - | ||||||||||||
| 500 | Returns the size of the data in this buffer, for reading operations. | - | ||||||||||||
| 501 | Returns -1 if fetching the buffer size is not supported, or the | - | ||||||||||||
| 502 | buffer has not been created. | - | ||||||||||||
| 503 | - | |||||||||||||
| 504 | It is assumed that this buffer has been bound to the current context. | - | ||||||||||||
| 505 | - | |||||||||||||
| 506 | \sa isCreated(), bind() | - | ||||||||||||
| 507 | */ | - | ||||||||||||
| 508 | int QGLBuffer::size() const | - | ||||||||||||
| 509 | { | - | ||||||||||||
| 510 | Q_D(const QGLBuffer); | - | ||||||||||||
| 511 | if (!d->guard || !d->guard->id())
| 0-21 | ||||||||||||
| 512 | return -1; executed 6 times by 1 test: return -1;Executed by:
| 6 | ||||||||||||
| 513 | GLint value = -1; | - | ||||||||||||
| 514 | d->funcs->glGetBufferParameteriv(d->type, GL_BUFFER_SIZE, &value); | - | ||||||||||||
| 515 | return value; executed 21 times by 1 test: return value;Executed by:
| 21 | ||||||||||||
| 516 | } | - | ||||||||||||
| 517 | - | |||||||||||||
| 518 | /*! | - | ||||||||||||
| 519 | Maps the contents of this buffer into the application's memory | - | ||||||||||||
| 520 | space and returns a pointer to it. Returns null if memory | - | ||||||||||||
| 521 | mapping is not possible. The \a access parameter indicates the | - | ||||||||||||
| 522 | type of access to be performed. | - | ||||||||||||
| 523 | - | |||||||||||||
| 524 | It is assumed that create() has been called on this buffer and that | - | ||||||||||||
| 525 | it has been bound to the current context. | - | ||||||||||||
| 526 | - | |||||||||||||
| 527 | This function is only supported under OpenGL/ES if the | - | ||||||||||||
| 528 | \c{GL_OES_mapbuffer} extension is present. | - | ||||||||||||
| 529 | - | |||||||||||||
| 530 | \sa unmap(), create(), bind() | - | ||||||||||||
| 531 | */ | - | ||||||||||||
| 532 | void *QGLBuffer::map(QGLBuffer::Access access) | - | ||||||||||||
| 533 | { | - | ||||||||||||
| 534 | Q_D(QGLBuffer); | - | ||||||||||||
| 535 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 536 | if (!isCreated())
| 0-24 | ||||||||||||
| 537 | qWarning("QGLBuffer::map(): buffer not created"); never executed: QMessageLogger(__FILE__, 537, __PRETTY_FUNCTION__).warning("QGLBuffer::map(): buffer not created"); | 0 | ||||||||||||
| 538 | #endif | - | ||||||||||||
| 539 | if (!d->guard || !d->guard->id())
| 0-24 | ||||||||||||
| 540 | return 0; never executed: return 0; | 0 | ||||||||||||
| 541 | return d->funcs->glMapBuffer(d->type, access); executed 24 times by 1 test: return d->funcs->glMapBuffer(d->type, access);Executed by:
| 24 | ||||||||||||
| 542 | } | - | ||||||||||||
| 543 | - | |||||||||||||
| 544 | /*! | - | ||||||||||||
| 545 | Unmaps the buffer after it was mapped into the application's | - | ||||||||||||
| 546 | memory space with a previous call to map(). Returns \c true if | - | ||||||||||||
| 547 | the unmap succeeded; false otherwise. | - | ||||||||||||
| 548 | - | |||||||||||||
| 549 | It is assumed that this buffer has been bound to the current context, | - | ||||||||||||
| 550 | and that it was previously mapped with map(). | - | ||||||||||||
| 551 | - | |||||||||||||
| 552 | This function is only supported under OpenGL/ES if the | - | ||||||||||||
| 553 | \c{GL_OES_mapbuffer} extension is present. | - | ||||||||||||
| 554 | - | |||||||||||||
| 555 | \sa map() | - | ||||||||||||
| 556 | */ | - | ||||||||||||
| 557 | bool QGLBuffer::unmap() | - | ||||||||||||
| 558 | { | - | ||||||||||||
| 559 | Q_D(QGLBuffer); | - | ||||||||||||
| 560 | #ifndef QT_NO_DEBUG | - | ||||||||||||
| 561 | if (!isCreated())
| 0-24 | ||||||||||||
| 562 | qWarning("QGLBuffer::unmap(): buffer not created"); never executed: QMessageLogger(__FILE__, 562, __PRETTY_FUNCTION__).warning("QGLBuffer::unmap(): buffer not created"); | 0 | ||||||||||||
| 563 | #endif | - | ||||||||||||
| 564 | if (!d->guard || !d->guard->id())
| 0-24 | ||||||||||||
| 565 | return false; never executed: return false; | 0 | ||||||||||||
| 566 | return d->funcs->glUnmapBuffer(d->type) == GL_TRUE; executed 24 times by 1 test: return d->funcs->glUnmapBuffer(d->type) == 1;Executed by:
| 24 | ||||||||||||
| 567 | } | - | ||||||||||||
| 568 | - | |||||||||||||
| 569 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |