Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | class QOpenGLFunctions_3_0; | - |
8 | class QOpenGLFunctions_3_2_Core; | - |
9 | | - |
10 | void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context) | - |
11 | { | - |
12 | ((!(helper)) ? qt_assert("helper",__FILE__,5359) : qt_noop()); | - |
13 | ((!(context)) ? qt_assert("context",__FILE__,5460) : qt_noop()); | - |
14 | | - |
15 | bool tryARB = true; | - |
16 | | - |
17 | if (context->isOpenGLES()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
18 | if (context->format().majorVersion() >= 3TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
19 | QOpenGLES3HelperQOpenGLExtraFunctionsPrivate *es3extra = static_cast<QOpenGLExtensions *>(context->functionsextraFunctions())->gles3Helperd(); | - |
20 | helper->GenVertexArrays = es3extra->f.GenVertexArrays; | - |
21 | helper->DeleteVertexArrays = es3extra->f.DeleteVertexArrays; | - |
22 | helper->BindVertexArray = es3extra->f.BindVertexArray; | - |
23 | helper->IsVertexArray = es3extra->f.IsVertexArray; | - |
24 | tryARB = false; | - |
25 | } never executed: end of block else if (context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_OES_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_OES_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
26 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glGenVertexArraysOES") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glGenVertexArraysOES"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
27 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glDeleteVertexArraysOES") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glDeleteVertexArraysOES"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
28 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glBindVertexArrayOES") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glBindVertexArrayOES"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
29 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glIsVertexArrayOES") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glIsVertexArrayOES"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
30 | tryARB = false; | - |
31 | } never executed: end of block | 0 |
32 | } never executed: end of block else if (context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_APPLE_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_APPLE_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))TRUE | never evaluated | FALSE | never evaluated |
&& | 0 |
33 | !context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
34 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glGenVertexArraysAPPLE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glGenVertexArraysAPPLE"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
35 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glDeleteVertexArraysAPPLE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glDeleteVertexArraysAPPLE"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
36 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glBindVertexArrayAPPLE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glBindVertexArrayAPPLE"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
37 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glIsVertexArrayAPPLE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glIsVertexArrayAPPLE"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
38 | tryARB = false; | - |
39 | } never executed: end of block | 0 |
40 | | - |
41 | if (tryARBTRUE | never evaluated | FALSE | never evaluated |
&& context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
42 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glGenVertexArrays") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glGenVertexArrays"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
43 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glDeleteVertexArrays") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glDeleteVertexArrays"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
44 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glBindVertexArray") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glBindVertexArray"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
45 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(([]() -> QByteArray { enum { Size = sizeof("glIsVertexArray") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "glIsVertexArray"}; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }())));)); | - |
46 | } never executed: end of block | 0 |
47 | } never executed: end of block | 0 |
48 | | - |
49 | class QOpenGLVertexArrayObjectPrivate : public QObjectPrivate | - |
50 | { | - |
51 | public: | - |
52 | QOpenGLVertexArrayObjectPrivate() | - |
53 | : vao(0) | - |
54 | , vaoFuncsType(NotSupported) | - |
55 | , context(0) | - |
56 | { | - |
57 | } | - |
58 | | - |
59 | ~QOpenGLVertexArrayObjectPrivate() | - |
60 | { | - |
61 | if (vaoFuncsType == ARB || vaoFuncsType == APPLE || vaoFuncsType == OES) | - |
62 | delete vaoFuncs.helper; | - |
63 | } | - |
64 | | - |
65 | bool create(); | - |
66 | void destroy(); | - |
67 | void bind(); | - |
68 | void release(); | - |
69 | void _q_contextAboutToBeDestroyed(); | - |
70 | | - |
71 | inline QOpenGLVertexArrayObject* q_func() { return static_cast<QOpenGLVertexArrayObject *>(q_ptr); } inline const QOpenGLVertexArrayObject* q_func() const { return static_cast<const QOpenGLVertexArrayObject *>(q_ptr); } friend class QOpenGLVertexArrayObject; | - |
72 | | - |
73 | GLuint vao; | - |
74 | | - |
75 | union { | - |
76 | QOpenGLFunctions_3_0 *core_3_0; | - |
77 | QOpenGLFunctions_3_2_Core *core_3_2; | - |
78 | QOpenGLVertexArrayObjectHelper *helper; | - |
79 | } vaoFuncs; | - |
80 | enum { | - |
81 | NotSupported, | - |
82 | Core_3_0, | - |
83 | Core_3_2, | - |
84 | ARB, | - |
85 | APPLE, | - |
86 | OES | - |
87 | } vaoFuncsType; | - |
88 | | - |
89 | QOpenGLContext *context; | - |
90 | }; | - |
91 | | - |
92 | bool QOpenGLVertexArrayObjectPrivate::create() | - |
93 | { | - |
94 | if (vao) { | - |
95 | QMessageLogger(__FILE__, 136142, __PRETTY_FUNCTION__).warning("QOpenGLVertexArrayObject::create() VAO is already created"); | - |
96 | return false; | - |
97 | } | - |
98 | | - |
99 | QOpenGLVertexArrayObject * const q = q_func(); | - |
100 | | - |
101 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - |
102 | if (!ctx) { | - |
103 | QMessageLogger(__FILE__, 144150, __PRETTY_FUNCTION__).warning("QOpenGLVertexArrayObject::create() requires a valid current OpenGL context"); | - |
104 | return false; | - |
105 | } | - |
106 | | - |
107 | | - |
108 | if (ctx == context) | - |
109 | return false; | - |
110 | | - |
111 | context = ctx; | - |
112 | QObject::connect(context, qFlagLocation("2""aboutToBeDestroyed()" "\0" __FILE__ ":" "153""159"), q, qFlagLocation("1""_q_contextAboutToBeDestroyed()" "\0" __FILE__ ":" "153""159")); | - |
113 | | - |
114 | if (ctx->isOpenGLES()) { | - |
115 | if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_OES_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_OES_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))) { | - |
116 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
117 | vaoFuncsType = OES; | - |
118 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
119 | } | - |
120 | } else { | - |
121 | vaoFuncs.core_3_0 = 0; | - |
122 | vaoFuncsType = NotSupported; | - |
123 | QSurfaceFormat format = ctx->format(); | - |
124 | | - |
125 | if (format.version() >= qMakePair<int, int>(3,2)) { | - |
126 | vaoFuncs.core_3_2 = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>(); | - |
127 | vaoFuncsType = Core_3_2; | - |
128 | vaoFuncs.core_3_2->glGenVertexArrays(1, &vao); | - |
129 | } else if (format.majorVersion() >= 3) { | - |
130 | vaoFuncs.core_3_0 = ctx->versionFunctions<QOpenGLFunctions_3_0>(); | - |
131 | vaoFuncsType = Core_3_0; | - |
132 | vaoFuncs.core_3_0->glGenVertexArrays(1, &vao); | - |
133 | } else | - |
134 | | - |
135 | if (ctx->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_ARB_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_ARB_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))) { | - |
136 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
137 | vaoFuncsType = ARB; | - |
138 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
139 | } else if (ctx->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_APPLE_vertex_array_object") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_APPLE_vertex_array_object" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))) { | - |
140 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
141 | vaoFuncsType = APPLE; | - |
142 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
143 | } | - |
144 | } | - |
145 | | - |
146 | return (vao != 0); | - |
147 | } | - |
148 | | - |
149 | void QOpenGLVertexArrayObjectPrivate::destroy() | - |
150 | { | - |
151 | QOpenGLVertexArrayObject * const q = q_func(); | - |
152 | | - |
153 | if (context) { | - |
154 | QObject::disconnect(context, qFlagLocation("2""aboutToBeDestroyed()" "\0" __FILE__ ":" "195""201"), q, qFlagLocation("1""_q_contextAboutToBeDestroyed()" "\0" __FILE__ ":" "195""201")); | - |
155 | context = 0; | - |
156 | } | - |
157 | | - |
158 | if (!vao) | - |
159 | return; | - |
160 | | - |
161 | switch (vaoFuncsType) { | - |
162 | | - |
163 | case Core_3_2: | - |
164 | vaoFuncs.core_3_2->glDeleteVertexArrays(1, &vao); | - |
165 | break; | - |
166 | case Core_3_0: | - |
167 | vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao); | - |
168 | break; | - |
169 | | - |
170 | case ARB: | - |
171 | case APPLE: | - |
172 | case OES: | - |
173 | vaoFuncs.helper->glDeleteVertexArrays(1, &vao); | - |
174 | break; | - |
175 | default: | - |
176 | break; | - |
177 | } | - |
178 | | - |
179 | vao = 0; | - |
180 | } | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | void QOpenGLVertexArrayObjectPrivate::_q_contextAboutToBeDestroyed() | - |
186 | { | - |
187 | destroy(); | - |
188 | } | - |
189 | | - |
190 | void QOpenGLVertexArrayObjectPrivate::bind() | - |
191 | { | - |
192 | switch (vaoFuncsType) { | - |
193 | | - |
194 | case Core_3_2: | - |
195 | vaoFuncs.core_3_2->glBindVertexArray(vao); | - |
196 | break; | - |
197 | case Core_3_0: | - |
198 | vaoFuncs.core_3_0->glBindVertexArray(vao); | - |
199 | break; | - |
200 | | - |
201 | case ARB: | - |
202 | case APPLE: | - |
203 | case OES: | - |
204 | vaoFuncs.helper->glBindVertexArray(vao); | - |
205 | break; | - |
206 | default: | - |
207 | break; | - |
208 | } | - |
209 | } | - |
210 | | - |
211 | void QOpenGLVertexArrayObjectPrivate::release() | - |
212 | { | - |
213 | switch (vaoFuncsType) { | - |
214 | | - |
215 | case Core_3_2: | - |
216 | vaoFuncs.core_3_2->glBindVertexArray(0); | - |
217 | break; | - |
218 | case Core_3_0: | - |
219 | vaoFuncs.core_3_0->glBindVertexArray(0); | - |
220 | break; | - |
221 | | - |
222 | case ARB: | - |
223 | case APPLE: | - |
224 | case OES: | - |
225 | vaoFuncs.helper->glBindVertexArray(0); | - |
226 | break; | - |
227 | default: | - |
228 | break; | - |
229 | } | - |
230 | } | - |
231 | QOpenGLVertexArrayObject::QOpenGLVertexArrayObject(QObject* parent) | - |
232 | : QObject(*new QOpenGLVertexArrayObjectPrivate, parent) | - |
233 | { | - |
234 | } | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | QOpenGLVertexArrayObject::QOpenGLVertexArrayObject(QOpenGLVertexArrayObjectPrivate &dd) | - |
240 | : QObject(dd) | - |
241 | { | - |
242 | } | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() | - |
248 | { | - |
249 | QOpenGLContext* ctx = QOpenGLContext::currentContext(); | - |
250 | | - |
251 | QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
252 | QOpenGLContext *oldContext = 0; | - |
253 | QSurface *oldContextSurface = 0; | - |
254 | QScopedPointer<QOffscreenSurface> offscreenSurface; | - |
255 | if (d->context && ctx && d->context != ctx) { | - |
256 | oldContext = ctx; | - |
257 | oldContextSurface = ctx->surface(); | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | offscreenSurface.reset(new QOffscreenSurface); | - |
263 | offscreenSurface->setFormat(d->context->format()); | - |
264 | offscreenSurface->create(); | - |
265 | if (d->context->makeCurrent(offscreenSurface.data())) { | - |
266 | ctx = d->context; | - |
267 | } else { | - |
268 | QMessageLogger(__FILE__, 370376, __PRETTY_FUNCTION__).warning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to make VAO's context current"); | - |
269 | ctx = 0; | - |
270 | } | - |
271 | } | - |
272 | | - |
273 | if (ctx) | - |
274 | destroy(); | - |
275 | | - |
276 | if (oldContext) { | - |
277 | if (!oldContext->makeCurrent(oldContextSurface)) | - |
278 | QMessageLogger(__FILE__, 380386, __PRETTY_FUNCTION__).warning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context"); | - |
279 | } | - |
280 | } | - |
281 | bool QOpenGLVertexArrayObject::create() | - |
282 | { | - |
283 | QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
284 | return d->create(); | - |
285 | } | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | void QOpenGLVertexArrayObject::destroy() | - |
292 | { | - |
293 | QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
294 | d->destroy(); | - |
295 | } | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | bool QOpenGLVertexArrayObject::isCreated() const | - |
303 | { | - |
304 | const QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
305 | return (d->vao != 0); | - |
306 | } | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | GLuint QOpenGLVertexArrayObject::objectId() const | - |
312 | { | - |
313 | const QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
314 | return d->vao; | - |
315 | } | - |
316 | void QOpenGLVertexArrayObject::bind() | - |
317 | { | - |
318 | QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
319 | d->bind(); | - |
320 | } | - |
321 | | - |
322 | | - |
323 | | - |
324 | | - |
325 | void QOpenGLVertexArrayObject::release() | - |
326 | { | - |
327 | QOpenGLVertexArrayObjectPrivate * const d = d_func(); | - |
328 | d->release(); | - |
329 | } | - |
330 | | - |
331 | | - |
| | |