qopenglbuffer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopenglbuffer.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3class QOpenGLBufferPrivate-
4{-
5public:-
6 QOpenGLBufferPrivate(QOpenGLBuffer::Type t)-
7 : ref(1),-
8 type(t),-
9 guard(0),-
10 usagePattern(QOpenGLBuffer::StaticDraw),-
11 actualUsagePattern(QOpenGLBuffer::StaticDraw),-
12 funcs(0)-
13 {-
14 }
never executed: end of block
0
15-
16 QAtomicInt ref;-
17 QOpenGLBuffer::Type type;-
18 QOpenGLSharedResourceGuard *guard;-
19 QOpenGLBuffer::UsagePattern usagePattern;-
20 QOpenGLBuffer::UsagePattern actualUsagePattern;-
21 QOpenGLExtensions *funcs;-
22};-
23QOpenGLBuffer::QOpenGLBuffer()-
24 : d_ptr(new QOpenGLBufferPrivate(QOpenGLBuffer::VertexBuffer))-
25{-
26}
never executed: end of block
0
27QOpenGLBuffer::QOpenGLBuffer(QOpenGLBuffer::Type type)-
28 : d_ptr(new QOpenGLBufferPrivate(type))-
29{-
30}
never executed: end of block
0
31-
32-
33-
34-
35-
36-
37-
38QOpenGLBuffer::QOpenGLBuffer(const QOpenGLBuffer &other)-
39 : d_ptr(other.d_ptr)-
40{-
41 d_ptr->ref.ref();-
42}
never executed: end of block
0
43-
44-
45-
46-
47-
48QOpenGLBuffer::~QOpenGLBuffer()-
49{-
50 if (!d_ptr->ref.deref()
!d_ptr->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
51 destroy();-
52 delete d_ptr;-
53 }
never executed: end of block
0
54}
never executed: end of block
0
55-
56-
57-
58-
59-
60-
61-
62QOpenGLBuffer &QOpenGLBuffer::operator=(const QOpenGLBuffer &other)-
63{-
64 if (d_ptr != other.d_ptr
d_ptr != other.d_ptrDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
65 other.d_ptr->ref.ref();-
66 if (!d_ptr->ref.deref()
!d_ptr->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
67 destroy();-
68 delete d_ptr;-
69 }
never executed: end of block
0
70 d_ptr = other.d_ptr;-
71 }
never executed: end of block
0
72 return
never executed: return *this;
*this;
never executed: return *this;
0
73}-
74-
75-
76-
77-
78QOpenGLBuffer::Type QOpenGLBuffer::type() const-
79{-
80 const QOpenGLBufferPrivate * const d = d_func();-
81 return
never executed: return d->type;
d->type;
never executed: return d->type;
0
82}-
83-
84-
85-
86-
87-
88-
89-
90QOpenGLBuffer::UsagePattern QOpenGLBuffer::usagePattern() const-
91{-
92 const QOpenGLBufferPrivate * const d = d_func();-
93 return
never executed: return d->usagePattern;
d->usagePattern;
never executed: return d->usagePattern;
0
94}-
95-
96-
97-
98-
99-
100-
101-
102void QOpenGLBuffer::setUsagePattern(QOpenGLBuffer::UsagePattern value)-
103{-
104 QOpenGLBufferPrivate * const d = d_func();-
105 d->usagePattern = d->actualUsagePattern = value;-
106}
never executed: end of block
0
107-
108namespace {-
109 void freeBufferFunc(QOpenGLFunctions *funcs, GLuint id)-
110 {-
111 funcs->glDeleteBuffers(1, &id);-
112 }
never executed: end of block
0
113}-
114bool QOpenGLBuffer::create()-
115{-
116 QOpenGLBufferPrivate * const d = d_func();-
117 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->guard->id()
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
118 return
never executed: return true;
true;
never executed: return true;
0
119 QOpenGLContext *ctx = QOpenGLContext::currentContext();-
120 if (ctx
ctxDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
121 delete d->funcs;-
122 d->funcs = new QOpenGLExtensions(ctx);-
123 GLuint bufferId = 0;-
124 d->funcs->glGenBuffers(1, &bufferId);-
125 if (bufferId
bufferIdDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
126 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
127 d->guard->free();
never executed: d->guard->free();
0
128-
129 d->guard = new QOpenGLSharedResourceGuard(ctx, bufferId, freeBufferFunc);-
130 return
never executed: return true;
true;
never executed: return true;
0
131 }-
132 }
never executed: end of block
0
133 return
never executed: return false;
false;
never executed: return false;
0
134}-
135-
136-
137-
138-
139-
140-
141bool QOpenGLBuffer::isCreated() const-
142{-
143 const QOpenGLBufferPrivate * const d = d_func();-
144 return
never executed: return d->guard && d->guard->id();
d->guard && d->guard->id();
never executed: return d->guard && d->guard->id();
0
145}-
146-
147-
148-
149-
150-
151-
152void QOpenGLBuffer::destroy()-
153{-
154 QOpenGLBufferPrivate * const d = d_func();-
155 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
156 d->guard->free();-
157 d->guard = 0;-
158 }
never executed: end of block
0
159 delete d->funcs;-
160 d->funcs = 0;-
161}
never executed: end of block
0
162bool QOpenGLBuffer::read(int offset, void *data, int count)-
163{-
164-
165 QOpenGLBufferPrivate * const d = d_func();-
166 if (!d->funcs->hasOpenGLFeature(QOpenGLFunctions::Buffers)
!d->funcs->has...ions::Buffers)Description
TRUEnever evaluated
FALSEnever evaluated
|| !d->guard->id()
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
167 return
never executed: return false;
false;
never executed: return false;
0
168 while (d->funcs->glGetError() != 0
d->funcs->glGetError() != 0Description
TRUEnever evaluated
FALSEnever evaluated
) ;
never executed: ;
0
169 d->funcs->glGetBufferSubData(d->type, offset, count, data);-
170 return
never executed: return d->funcs->glGetError() == 0;
d->funcs->glGetError() == 0;
never executed: return d->funcs->glGetError() == 0;
0
171-
172-
173-
174-
175-
176-
177}-
178void QOpenGLBuffer::write(int offset, const void *data, int count)-
179{-
180-
181 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
182 QMessageLogger(__FILE__, 374, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
never executed: QMessageLogger(__FILE__, 374, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
0
183-
184 QOpenGLBufferPrivate * const d = d_func();-
185 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->guard->id()
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
186 d->funcs->glBufferSubData(d->type, offset, count, data);
never executed: d->funcs->glBufferSubData(d->type, offset, count, data);
0
187}
never executed: end of block
0
188void QOpenGLBuffer::allocate(const void *data, int count)-
189{-
190-
191 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
192 QMessageLogger(__FILE__, 394, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
never executed: QMessageLogger(__FILE__, 394, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::allocate(): buffer not created");
0
193-
194 QOpenGLBufferPrivate * const d = d_func();-
195 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->guard->id()
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
196 d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);
never executed: d->funcs->glBufferData(d->type, count, data, d->actualUsagePattern);
0
197}
never executed: end of block
0
198bool QOpenGLBuffer::bind()-
199{-
200-
201 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
202 QMessageLogger(__FILE__, 429, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::bind(): buffer not created");
never executed: QMessageLogger(__FILE__, 429, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::bind(): buffer not created");
0
203-
204 const QOpenGLBufferPrivate * const d = d_func();-
205 GLuint bufferId = d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
? d->guard->id() : 0;
0
206 if (bufferId
bufferIdDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 if (d->guard->group() != QOpenGLContextGroup::currentContextGroup()
d->guard->grou...ContextGroup()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
208-
209 QMessageLogger(__FILE__, 436, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::bind: buffer is not valid in the current context");-
210-
211 return
never executed: return false;
false;
never executed: return false;
0
212 }-
213 d->funcs->glBindBuffer(d->type, bufferId);-
214 return
never executed: return true;
true;
never executed: return true;
0
215 } else {-
216 return
never executed: return false;
false;
never executed: return false;
0
217 }-
218}-
219void QOpenGLBuffer::release()-
220{-
221-
222 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
223 QMessageLogger(__FILE__, 460, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::release(): buffer not created");
never executed: QMessageLogger(__FILE__, 460, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::release(): buffer not created");
0
224-
225 const QOpenGLBufferPrivate * const d = d_func();-
226 if (d->guard
d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->guard->id()
d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
227 d->funcs->glBindBuffer(d->type, 0);
never executed: d->funcs->glBindBuffer(d->type, 0);
0
228}
never executed: end of block
0
229void QOpenGLBuffer::release(QOpenGLBuffer::Type type)-
230{-
231 QOpenGLContext *ctx = QOpenGLContext::currentContext();-
232 if (ctx
ctxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
233 ctx->functions()->glBindBuffer(GLenum(type), 0);
never executed: ctx->functions()->glBindBuffer(GLenum(type), 0);
0
234}
never executed: end of block
0
235-
236-
237-
238-
239-
240-
241-
242GLuint QOpenGLBuffer::bufferId() const-
243{-
244 const QOpenGLBufferPrivate * const d = d_func();-
245 return
never executed: return d->guard ? d->guard->id() : 0;
d->guard ? d->guard->id() : 0;
never executed: return d->guard ? d->guard->id() : 0;
0
246}-
247int QOpenGLBuffer::size() const-
248{-
249 const QOpenGLBufferPrivate * const d = d_func();-
250 if (!d->guard
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->guard->id()
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
251 return
never executed: return -1;
-1;
never executed: return -1;
0
252 GLint value = -1;-
253 d->funcs->glGetBufferParameteriv(d->type, 0x8764, &value);-
254 return
never executed: return value;
value;
never executed: return value;
0
255}-
256void *QOpenGLBuffer::map(QOpenGLBuffer::Access access)-
257{-
258 QOpenGLBufferPrivate * const d = d_func();-
259-
260 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
261 QMessageLogger(__FILE__, 541, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::map(): buffer not created");
never executed: QMessageLogger(__FILE__, 541, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::map(): buffer not created");
0
262-
263 if (!d->guard
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->guard->id()
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
264 return
never executed: return 0;
0;
never executed: return 0;
0
265 if (d->funcs->hasOpenGLExtension(QOpenGLExtensions::MapBufferRange)
d->funcs->hasO...apBufferRange)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
266 QOpenGLBuffer::RangeAccessFlags rangeAccess = 0;-
267 switch (access) {-
268 case
never executed: case QOpenGLBuffer::ReadOnly:
QOpenGLBuffer::ReadOnly:
never executed: case QOpenGLBuffer::ReadOnly:
0
269 rangeAccess = QOpenGLBuffer::RangeRead;-
270 break;
never executed: break;
0
271 case
never executed: case QOpenGLBuffer::WriteOnly:
QOpenGLBuffer::WriteOnly:
never executed: case QOpenGLBuffer::WriteOnly:
0
272 rangeAccess = QOpenGLBuffer::RangeWrite;-
273 break;
never executed: break;
0
274 case
never executed: case QOpenGLBuffer::ReadWrite:
QOpenGLBuffer::ReadWrite:
never executed: case QOpenGLBuffer::ReadWrite:
0
275 rangeAccess = QOpenGLBuffer::RangeRead | QOpenGLBuffer::RangeWrite;-
276 break;
never executed: break;
0
277 }-
278 return
never executed: return d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess);
d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess);
never executed: return d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess);
0
279 } else {-
280 return
never executed: return d->funcs->glMapBuffer(d->type, access);
d->funcs->glMapBuffer(d->type, access);
never executed: return d->funcs->glMapBuffer(d->type, access);
0
281 }-
282}-
283void *QOpenGLBuffer::mapRange(int offset, int count, QOpenGLBuffer::RangeAccessFlags access)-
284{-
285 QOpenGLBufferPrivate * const d = d_func();-
286-
287 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
288 QMessageLogger(__FILE__, 582, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::mapRange(): buffer not created");
never executed: QMessageLogger(__FILE__, 582, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::mapRange(): buffer not created");
0
289-
290 if (!d->guard
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->guard->id()
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
291 return
never executed: return 0;
0;
never executed: return 0;
0
292 return
never executed: return d->funcs->glMapBufferRange(d->type, offset, count, access);
d->funcs->glMapBufferRange(d->type, offset, count, access);
never executed: return d->funcs->glMapBufferRange(d->type, offset, count, access);
0
293}-
294bool QOpenGLBuffer::unmap()-
295{-
296 QOpenGLBufferPrivate * const d = d_func();-
297-
298 if (!isCreated()
!isCreated()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
299 QMessageLogger(__FILE__, 607, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::unmap(): buffer not created");
never executed: QMessageLogger(__FILE__, 607, __PRETTY_FUNCTION__).warning("QOpenGLBuffer::unmap(): buffer not created");
0
300-
301 if (!d->guard
!d->guardDescription
TRUEnever evaluated
FALSEnever evaluated
|| !d->guard->id()
!d->guard->id()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
302 return
never executed: return false;
false;
never executed: return false;
0
303 return
never executed: return d->funcs->glUnmapBuffer(d->type) == 1;
d->funcs->glUnmapBuffer(d->type) == 1;
never executed: return d->funcs->glUnmapBuffer(d->type) == 1;
0
304}-
305-
306-
Switch to Source codePreprocessed file

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