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