qglbuffer.cpp

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

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