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

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