qopenglbuffer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopenglbuffer.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
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 <QtGui/qopengl.h>-
41#include <QtGui/private/qopenglcontext_p.h>-
42#include <QtCore/qatomic.h>-
43#include "qopenglbuffer.h"-
44#include <private/qopenglextensions_p.h>-
45-
46QT_BEGIN_NAMESPACE-
47-
48/*!-
49 \class QOpenGLBuffer-
50 \brief The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects.-
51 \since 5.0-
52 \ingroup painting-3D-
53 \inmodule QtGui-
54-
55 Buffer objects are created in the OpenGL server so that the-
56 client application can avoid uploading vertices, indices,-
57 texture image data, etc every time they are needed.-
58-
59 QOpenGLBuffer objects can be copied around as a reference to the-
60 underlying OpenGL buffer object:-
61-
62 \code-
63 QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer);-
64 buffer1.create();-
65-
66 QOpenGLBuffer buffer2 = buffer1;-
67 \endcode-
68-
69 QOpenGLBuffer performs a shallow copy when objects are copied in this-
70 manner, but does not implement copy-on-write semantics. The original-
71 object will be affected whenever the copy is modified.-
72*/-
73-
74/*!-
75 \enum QOpenGLBuffer::Type-
76 This enum defines the type of OpenGL buffer object to create with QOpenGLBuffer.-
77-
78 \value VertexBuffer Vertex buffer object for use when specifying-
79 vertex arrays.-
80 \value IndexBuffer Index buffer object for use with \c{glDrawElements()}.-
81 \value PixelPackBuffer Pixel pack buffer object for reading pixel-
82 data from the OpenGL server (for example, with \c{glReadPixels()}).-
83 Not supported under OpenGL/ES.-
84 \value PixelUnpackBuffer Pixel unpack buffer object for writing pixel-
85 data to the OpenGL server (for example, with \c{glTexImage2D()}).-
86 Not supported under OpenGL/ES.-
87*/-
88-
89/*!-
90 \enum QOpenGLBuffer::UsagePattern-
91 This enum defines the usage pattern of a QOpenGLBuffer object.-
92-
93 \value StreamDraw The data will be set once and used a few times-
94 for drawing operations. Under OpenGL/ES 1.1 this is identical-
95 to StaticDraw.-
96 \value StreamRead The data will be set once and used a few times-
97 for reading data back from the OpenGL server. Not supported-
98 under OpenGL/ES.-
99 \value StreamCopy The data will be set once and used a few times-
100 for reading data back from the OpenGL server for use in further-
101 drawing operations. Not supported under OpenGL/ES.-
102 \value StaticDraw The data will be set once and used many times-
103 for drawing operations.-
104 \value StaticRead The data will be set once and used many times-
105 for reading data back from the OpenGL server. Not supported-
106 under OpenGL/ES.-
107 \value StaticCopy The data will be set once and used many times-
108 for reading data back from the OpenGL server for use in further-
109 drawing operations. Not supported under OpenGL/ES.-
110 \value DynamicDraw The data will be modified repeatedly and used-
111 many times for drawing operations.-
112 \value DynamicRead The data will be modified repeatedly and used-
113 many times for reading data back from the OpenGL server.-
114 Not supported under OpenGL/ES.-
115 \value DynamicCopy The data will be modified repeatedly and used-
116 many times for reading data back from the OpenGL server for-
117 use in further drawing operations. Not supported under OpenGL/ES.-
118*/-
119-
120/*!-
121 \enum QOpenGLBuffer::Access-
122 This enum defines the access mode for QOpenGLBuffer::map().-
123-
124 \value ReadOnly The buffer will be mapped for reading only.-
125 \value WriteOnly The buffer will be mapped for writing only.-
126 \value ReadWrite The buffer will be mapped for reading and writing.-
127*/-
128-
129/*!-
130 \enum QOpenGLBuffer::RangeAccessFlag-
131 This enum defines the access mode bits for QOpenGLBuffer::mapRange().-
132-
133 \value RangeRead The buffer will be mapped for reading.-
134 \value RangeWrite The buffer will be mapped for writing.-
135 \value RangeInvalidate Discard the previous contents of the specified range.-
136 \value RangeInvalidateBuffer Discard the previous contents of the entire buffer.-
137 \value RangeFlushExplicit Indicates that modifications are to be flushed explicitly via \c glFlushMappedBufferRange.-
138 \value RangeUnsynchronized Indicates that pending operations should not be synchronized before returning from mapRange().-
139*/-
140-
141class QOpenGLBufferPrivate-
142{-
143public:-
144 QOpenGLBufferPrivate(QOpenGLBuffer::Type t)-
145 : ref(1),-
146 type(t),-
147 guard(0),-
148 usagePattern(QOpenGLBuffer::StaticDraw),-
149 actualUsagePattern(QOpenGLBuffer::StaticDraw),-
150 funcs(0)-
151 {-
152 }
never executed: end of block
0
153-
154 QAtomicInt ref;-
155 QOpenGLBuffer::Type type;-
156 QOpenGLSharedResourceGuard *guard;-
157 QOpenGLBuffer::UsagePattern usagePattern;-
158 QOpenGLBuffer::UsagePattern actualUsagePattern;-
159 QOpenGLExtensions *funcs;-
160};-
161-
162/*!-
163 Constructs a new buffer object of type QOpenGLBuffer::VertexBuffer.-
164-
165 Note: this constructor just creates the QOpenGLBuffer instance. The actual-
166 buffer object in the OpenGL server is not created until create() is called.-
167-
168 \sa create()-
169*/-
170QOpenGLBuffer::QOpenGLBuffer()-
171 : d_ptr(new QOpenGLBufferPrivate(QOpenGLBuffer::VertexBuffer))-
172{-
173}
never executed: end of block
0
174-
175/*!-
176 Constructs a new buffer object of \a type.-
177-
178 Note: this constructor just creates the QOpenGLBuffer instance. The actual-
179 buffer object in the OpenGL server is not created until create() is called.-
180-
181 \sa create()-
182*/-
183QOpenGLBuffer::QOpenGLBuffer(QOpenGLBuffer::Type type)-
184 : d_ptr(new QOpenGLBufferPrivate(type))-
185{-
186}
never executed: end of block
0
187-
188/*!-
189 Constructs a shallow copy of \a other.-
190-
191 Note: QOpenGLBuffer does not implement copy-on-write semantics,-
192 so \a other will be affected whenever the copy is modified.-
193*/-
194QOpenGLBuffer::QOpenGLBuffer(const QOpenGLBuffer &other)-
195 : d_ptr(other.d_ptr)-
196{-
197 d_ptr->ref.ref();-
198}
never executed: end of block
0
199-
200/*!-
201 Destroys this buffer object, including the storage being-
202 used in the OpenGL server.-
203*/-
204QOpenGLBuffer::~QOpenGLBuffer()-
205{-
206 if (!d_ptr->ref.deref()) {
!d_ptr->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
207 destroy();-
208 delete d_ptr;-
209 }
never executed: end of block
0
210}
never executed: end of block
0
211-
212/*!-
213 Assigns a shallow copy of \a other to this object.-
214-
215 Note: QOpenGLBuffer does not implement copy-on-write semantics,-
216 so \a other will be affected whenever the copy is modified.-
217*/-
218QOpenGLBuffer &QOpenGLBuffer::operator=(const QOpenGLBuffer &other)-
219{-
220 if (d_ptr != other.d_ptr) {
d_ptr != other.d_ptrDescription
TRUEnever evaluated
FALSEnever evaluated
0
221 other.d_ptr->ref.ref();-
222 if (!d_ptr->ref.deref()) {
!d_ptr->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
223 destroy();-
224 delete d_ptr;-
225 }
never executed: end of block
0
226 d_ptr = other.d_ptr;-
227 }
never executed: end of block
0
228 return *this;
never executed: return *this;
0
229}-
230-
231/*!-
232 Returns the type of buffer represented by this object.-
233*/-
234QOpenGLBuffer::Type QOpenGLBuffer::type() const-
235{-
236 Q_D(const QOpenGLBuffer);-
237 return d->type;
never executed: return d->type;
0
238}-
239-
240/*!-
241 Returns the usage pattern for this buffer object.-
242 The default value is StaticDraw.-
243-
244 \sa setUsagePattern()-
245*/-
246QOpenGLBuffer::UsagePattern QOpenGLBuffer::usagePattern() const-
247{-
248 Q_D(const QOpenGLBuffer);-
249 return d->usagePattern;
never executed: return d->usagePattern;
0
250}-
251-
252/*!-
253 Sets the usage pattern for this buffer object to \a value.-
254 This function must be called before allocate() or write().-
255-
256 \sa usagePattern(), allocate(), write()-
257*/-
258void QOpenGLBuffer::setUsagePattern(QOpenGLBuffer::UsagePattern value)-
259{-
260 Q_D(QOpenGLBuffer);-
261 d->usagePattern = d->actualUsagePattern = value;-
262}
never executed: end of block
0
263-
264namespace {-
265 void freeBufferFunc(QOpenGLFunctions *funcs, GLuint id)-
266 {-
267 funcs->glDeleteBuffers(1, &id);-
268 }
never executed: end of block
0
269}-
270-
271/*!-
272 Creates the buffer object in the OpenGL server. Returns \c true if-
273 the object was created; false otherwise.-
274-
275 This function must be called with a current QOpenGLContext.-
276 The buffer will be bound to and can only be used in-
277 that context (or any other context that is shared with it).-
278-
279 This function will return false if the OpenGL implementation-
280 does not support buffers, or there is no current QOpenGLContext.-
281-
282 \sa isCreated(), allocate(), write(), destroy()-
283*/-
284bool QOpenGLBuffer::create()-
285{-
286 Q_D(QOpenGLBuffer);-
287 if (d->guard && d->guard->id())
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
288 return true;
never executed: return true;
0
289 QOpenGLContext *ctx = QOpenGLContext::currentContext();-
290 if (ctx) {
ctxDescription
TRUEnever evaluated
FALSEnever evaluated
0
291 delete d->funcs;-
292 d->funcs = new QOpenGLExtensions(ctx);-
293 GLuint bufferId = 0;-
294 d->funcs->glGenBuffers(1, &bufferId);-
295 if (bufferId) {
bufferIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
296 if (d->guard)
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
297 d->guard->free();
never executed: d->guard->free();
0
298-
299 d->guard = new QOpenGLSharedResourceGuard(ctx, bufferId, freeBufferFunc);-
300 return true;
never executed: return true;
0
301 }-
302 }
never executed: end of block
0
303 return false;
never executed: return false;
0
304}-
305-
306/*!-
307 Returns \c true if this buffer has been created; false otherwise.-
308-
309 \sa create(), destroy()-
310*/-
311bool QOpenGLBuffer::isCreated() const-
312{-
313 Q_D(const QOpenGLBuffer);-
314 return d->guard && d->guard->id();
never executed: return d->guard && d->guard->id();
0
315}-
316-
317/*!-
318 Destroys this buffer object, including the storage being-
319 used in the OpenGL server. All references to the buffer will-
320 become invalid.-
321*/-
322void QOpenGLBuffer::destroy()-
323{-
324 Q_D(QOpenGLBuffer);-
325 if (d->guard) {
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
326 d->guard->free();-
327 d->guard = 0;-
328 }
never executed: end of block
0
329 delete d->funcs;-
330 d->funcs = 0;-
331}
never executed: end of block
0
332-
333/*!-
334 Reads the \a count bytes in this buffer starting at \a offset-
335 into \a data. Returns \c true on success; false if reading from-
336 the buffer is not supported. Buffer reading is not supported-
337 under OpenGL/ES.-
338-
339 It is assumed that this buffer has been bound to the current context.-
340-
341 \sa write(), bind()-
342*/-
343bool QOpenGLBuffer::read(int offset, void *data, int count)-
344{-
345#if !defined(QT_OPENGL_ES)-
346 Q_D(QOpenGLBuffer);-
347 if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers) || !d->guard->id())
!d->funcs->has...ions::Buffers)Description
TRUEnever evaluated
FALSEnever evaluated
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
348 return false;
never executed: return false;
0
349 while (d->funcs->glGetError() != GL_NO_ERROR) ; // Clear error state.
never executed: ;
d->funcs->glGetError() != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
350 d->funcs->glGetBufferSubData(d->type, offset, count, data);-
351 return d->funcs->glGetError() == GL_NO_ERROR;
never executed: return d->funcs->glGetError() == 0;
0
352#else-
353 Q_UNUSED(offset);-
354 Q_UNUSED(data);-
355 Q_UNUSED(count);-
356 return false;-
357#endif-
358}-
359-
360/*!-
361 Replaces the \a count bytes of this buffer starting at \a offset-
362 with the contents of \a data. Any other bytes in the buffer-
363 will be left unmodified.-
364-
365 It is assumed that create() has been called on this buffer and that-
366 it has been bound to the current context.-
367-
368 \sa create(), read(), allocate()-
369*/-
370void QOpenGLBuffer::write(int offset, const void *data, int count)-
371{-
372#ifndef QT_NO_DEBUG-
373 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
374 qWarning("QOpenGLBuffer::allocate(): buffer not created");
never executed: QMessageLogger(__FILE__, 374, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
0
375#endif-
376 Q_D(QOpenGLBuffer);-
377 if (d->guard && d->guard->id())
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
378 d->funcs->glBufferSubData(d->type, offset, count, data);
never executed: d->funcs->glBufferSubData(d->type, offset, count, data);
0
379}
never executed: end of block
0
380-
381/*!-
382 Allocates \a count bytes of space to the buffer, initialized to-
383 the contents of \a data. Any previous contents will be removed.-
384-
385 It is assumed that create() has been called on this buffer and that-
386 it has been bound to the current context.-
387-
388 \sa create(), read(), write()-
389*/-
390void QOpenGLBuffer::allocate(const void *data, int count)-
391{-
392#ifndef QT_NO_DEBUG-
393 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
394 qWarning("QOpenGLBuffer::allocate(): buffer not created");
never executed: QMessageLogger(__FILE__, 394, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
0
395#endif-
396 Q_D(QOpenGLBuffer);-
397 if (d->guard && d->guard->id())
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
398 d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);
never executed: d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);
0
399}
never executed: end of block
0
400-
401/*!-
402 \fn void QOpenGLBuffer::allocate(int count)-
403 \overload-
404-
405 Allocates \a count bytes of space to the buffer. Any previous-
406 contents will be removed.-
407-
408 It is assumed that create() has been called on this buffer and that-
409 it has been bound to the current context.-
410-
411 \sa create(), write()-
412*/-
413-
414/*!-
415 Binds the buffer associated with this object to the current-
416 OpenGL context. Returns \c false if binding was not possible, usually because-
417 type() is not supported on this OpenGL implementation.-
418-
419 The buffer must be bound to the same QOpenGLContext current when create()-
420 was called, or to another QOpenGLContext that is sharing with it.-
421 Otherwise, false will be returned from this function.-
422-
423 \sa release(), create()-
424*/-
425bool QOpenGLBuffer::bind()-
426{-
427#ifndef QT_NO_DEBUG-
428 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
429 qWarning("QOpenGLBuffer::bind(): buffer not created");
never executed: QMessageLogger(__FILE__, 429, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::bind(): buffer not created");
0
430#endif-
431 Q_D(const QOpenGLBuffer);-
432 GLuint bufferId = d->guard ? d->guard->id() : 0;
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
433 if (bufferId) {
bufferIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
434 if (d->guard->group() != QOpenGLContextGroup::currentContextGroup()) {
d->guard->grou...ContextGroup()Description
TRUEnever evaluated
FALSEnever evaluated
0
435#ifndef QT_NO_DEBUG-
436 qWarning("QOpenGLBuffer::bind: buffer is not valid in the current context");-
437#endif-
438 return false;
never executed: return false;
0
439 }-
440 d->funcs->glBindBuffer(d->type, bufferId);-
441 return true;
never executed: return true;
0
442 } else {-
443 return false;
never executed: return false;
0
444 }-
445}-
446-
447/*!-
448 Releases the buffer associated with this object from the-
449 current OpenGL context.-
450-
451 This function must be called with the same QOpenGLContext current-
452 as when bind() was called on the buffer.-
453-
454 \sa bind()-
455*/-
456void QOpenGLBuffer::release()-
457{-
458#ifndef QT_NO_DEBUG-
459 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
460 qWarning("QOpenGLBuffer::release(): buffer not created");
never executed: QMessageLogger(__FILE__, 460, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::release(): buffer not created");
0
461#endif-
462 Q_D(const QOpenGLBuffer);-
463 if (d->guard && d->guard->id())
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
464 d->funcs->glBindBuffer(d->type, 0);
never executed: d->funcs->glBindBuffer(d->type, 0);
0
465}
never executed: end of block
0
466-
467/*!-
468 Releases the buffer associated with \a type in the current-
469 QOpenGLContext.-
470-
471 This function is a direct call to \c{glBindBuffer(type, 0)}-
472 for use when the caller does not know which QOpenGLBuffer has-
473 been bound to the context but wants to make sure that it-
474 is released.-
475-
476 \code-
477 QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer);-
478 \endcode-
479*/-
480void QOpenGLBuffer::release(QOpenGLBuffer::Type type)-
481{-
482 QOpenGLContext *ctx = QOpenGLContext::currentContext();-
483 if (ctx)
ctxDescription
TRUEnever evaluated
FALSEnever evaluated
0
484 ctx->functions()->glBindBuffer(GLenum(type), 0);
never executed: ctx->functions()->glBindBuffer(GLenum(type), 0);
0
485}
never executed: end of block
0
486-
487/*!-
488 Returns the OpenGL identifier associated with this buffer; zero if-
489 the buffer has not been created.-
490-
491 \sa isCreated()-
492*/-
493GLuint QOpenGLBuffer::bufferId() const-
494{-
495 Q_D(const QOpenGLBuffer);-
496 return d->guard ? d->guard->id() : 0;
never executed: return d->guard ? d->guard->id() : 0;
0
497}-
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*/-
508int QOpenGLBuffer::size() const-
509{-
510 Q_D(const QOpenGLBuffer);-
511 if (!d->guard || !d->guard->id())
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
512 return -1;
never executed: return -1;
0
513 GLint value = -1;-
514 d->funcs->glGetBufferParameteriv(d->type, GL_BUFFER_SIZE, &value);-
515 return value;
never executed: return value;
0
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 \note This function is only supported under OpenGL ES 2.0 or-
528 earlier if the \c GL_OES_mapbuffer extension is present.-
529-
530 \note On OpenGL ES 3.0 and newer, or, in case if desktop OpenGL,-
531 if \c GL_ARB_map_buffer_range is supported, this function uses-
532 \c glMapBufferRange instead of \c glMapBuffer.-
533-
534 \sa unmap(), create(), bind(), mapRange()-
535*/-
536void *QOpenGLBuffer::map(QOpenGLBuffer::Access access)-
537{-
538 Q_D(QOpenGLBuffer);-
539#ifndef QT_NO_DEBUG-
540 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
541 qWarning("QOpenGLBuffer::map(): buffer not created");
never executed: QMessageLogger(__FILE__, 541, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::map(): buffer not created");
0
542#endif-
543 if (!d->guard || !d->guard->id())
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
544 return 0;
never executed: return 0;
0
545 if (d->funcs->hasOpenGLExtension(QOpenGLExtensions::MapBufferRange)) {
d->funcs->hasO...apBufferRange)Description
TRUEnever evaluated
FALSEnever evaluated
0
546 QOpenGLBuffer::RangeAccessFlags rangeAccess = 0;-
547 switch (access) {-
548 case QOpenGLBuffer::ReadOnly:
never executed: case QOpenGLBuffer::ReadOnly:
0
549 rangeAccess = QOpenGLBuffer::RangeRead;-
550 break;
never executed: break;
0
551 case QOpenGLBuffer::WriteOnly:
never executed: case QOpenGLBuffer::WriteOnly:
0
552 rangeAccess = QOpenGLBuffer::RangeWrite;-
553 break;
never executed: break;
0
554 case QOpenGLBuffer::ReadWrite:
never executed: case QOpenGLBuffer::ReadWrite:
0
555 rangeAccess = QOpenGLBuffer::RangeRead | QOpenGLBuffer::RangeWrite;-
556 break;
never executed: break;
0
557 }-
558 return d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess);
never executed: return d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess);
0
559 } else {-
560 return d->funcs->glMapBuffer(d->type, access);
never executed: return d->funcs->glMapBuffer(d->type, access);
0
561 }-
562}-
563-
564/*!-
565 Maps the range specified by \a offset and \a count of the contents-
566 of this buffer into the application's memory space and returns a-
567 pointer to it. Returns null if memory mapping is not possible.-
568 The \a access parameter specifies a combination of access flags.-
569-
570 It is assumed that create() has been called on this buffer and that-
571 it has been bound to the current context.-
572-
573 \note This function is not available on OpenGL ES 2.0 and earlier.-
574-
575 \sa unmap(), create(), bind()-
576 */-
577void *QOpenGLBuffer::mapRange(int offset, int count, QOpenGLBuffer::RangeAccessFlags access)-
578{-
579 Q_D(QOpenGLBuffer);-
580#ifndef QT_NO_DEBUG-
581 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
582 qWarning("QOpenGLBuffer::mapRange(): buffer not created");
never executed: QMessageLogger(__FILE__, 582, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::mapRange(): buffer not created");
0
583#endif-
584 if (!d->guard || !d->guard->id())
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
585 return 0;
never executed: return 0;
0
586 return d->funcs->glMapBufferRange(d->type, offset, count, access);
never executed: return d->funcs->glMapBufferRange(d->type, offset, count, access);
0
587}-
588-
589/*!-
590 Unmaps the buffer after it was mapped into the application's-
591 memory space with a previous call to map(). Returns \c true if-
592 the unmap succeeded; false otherwise.-
593-
594 It is assumed that this buffer has been bound to the current context,-
595 and that it was previously mapped with map().-
596-
597 \note This function is only supported under OpenGL ES 2.0 and-
598 earlier if the \c{GL_OES_mapbuffer} extension is present.-
599-
600 \sa map()-
601*/-
602bool QOpenGLBuffer::unmap()-
603{-
604 Q_D(QOpenGLBuffer);-
605#ifndef QT_NO_DEBUG-
606 if (!isCreated())
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
0
607 qWarning("QOpenGLBuffer::unmap(): buffer not created");
never executed: QMessageLogger(__FILE__, 607, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::unmap(): buffer not created");
0
608#endif-
609 if (!d->guard || !d->guard->id())
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
0
610 return false;
never executed: return false;
0
611 return d->funcs->glUnmapBuffer(d->type) == GL_TRUE;
never executed: return d->funcs->glUnmapBuffer(d->type) == 1;
0
612}-
613-
614QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9