| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "qopenglvertexarrayobject.h" | - |
| 41 | | - |
| 42 | #include <QtCore/private/qobject_p.h> | - |
| 43 | #include <QtGui/qopenglcontext.h> | - |
| 44 | #include <QtGui/qoffscreensurface.h> | - |
| 45 | | - |
| 46 | #include <QtGui/qopenglfunctions_3_0.h> | - |
| 47 | #include <QtGui/qopenglfunctions_3_2_core.h> | - |
| 48 | | - |
| 49 | #include <private/qopenglextensions_p.h> | - |
| 50 | #include <private/qopenglvertexarrayobject_p.h> | - |
| 51 | | - |
| 52 | QT_BEGIN_NAMESPACE | - |
| 53 | | - |
| 54 | class QOpenGLFunctions_3_0; | - |
| 55 | class QOpenGLFunctions_3_2_Core; | - |
| 56 | | - |
| 57 | void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context) | - |
| 58 | { | - |
| 59 | Q_ASSERT(helper); | - |
| 60 | Q_ASSERT(context); | - |
| 61 | | - |
| 62 | bool tryARB = true; | - |
| 63 | | - |
| 64 | if (context->isOpenGLES()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 65 | if (context->format().majorVersion() >= 3) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 66 | QOpenGLES3HelperQOpenGLExtraFunctionsPrivate *es3extra = static_cast<QOpenGLExtensions *>(context->functionsextraFunctions())->gles3Helperd(); | - |
| 67 | helper->GenVertexArrays = es3extra->f.GenVertexArrays; | - |
| 68 | helper->DeleteVertexArrays = es3extra->f.DeleteVertexArrays; | - |
| 69 | helper->BindVertexArray = es3extra->f.BindVertexArray; | - |
| 70 | helper->IsVertexArray = es3extra->f.IsVertexArray; | - |
| 71 | tryARB = false; | - |
| 72 | } else if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 73 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES")));)); | - |
| 74 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES")));)); | - |
| 75 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES")));)); | - |
| 76 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glIsVertexArrayOES")));)); | - |
| 77 | tryARB = false; | - |
| 78 | } never executed: end of block | 0 |
| 79 | } else if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object")) && never executed: end of block never executed: return ba; | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 80 | !context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { never executed: return ba; | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 81 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE")));)); | - |
| 82 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE")));)); | - |
| 83 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE")));)); | - |
| 84 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glIsVertexArrayAPPLE")));)); | - |
| 85 | tryARB = false; | - |
| 86 | } never executed: end of block | 0 |
| 87 | | - |
| 88 | if (tryARB && context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { never executed: return ba; | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 89 | helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays")));)); | - |
| 90 | helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays")));)); | - |
| 91 | helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray")));)); | - |
| 92 | helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glIsVertexArray")));)); | - |
| 93 | } never executed: end of block | 0 |
| 94 | } never executed: end of block | 0 |
| 95 | | - |
| 96 | class QOpenGLVertexArrayObjectPrivate : public QObjectPrivate | - |
| 97 | { | - |
| 98 | public: | - |
| 99 | QOpenGLVertexArrayObjectPrivate() | - |
| 100 | : vao(0) | - |
| 101 | , vaoFuncsType(NotSupported) | - |
| 102 | , context(0) | - |
| 103 | { | - |
| 104 | } | - |
| 105 | | - |
| 106 | ~QOpenGLVertexArrayObjectPrivate() | - |
| 107 | { | - |
| 108 | if (vaoFuncsType == ARB || vaoFuncsType == APPLE || vaoFuncsType == OES) | - |
| 109 | delete vaoFuncs.helper; | - |
| 110 | } | - |
| 111 | | - |
| 112 | bool create(); | - |
| 113 | void destroy(); | - |
| 114 | void bind(); | - |
| 115 | void release(); | - |
| 116 | void _q_contextAboutToBeDestroyed(); | - |
| 117 | | - |
| 118 | Q_DECLARE_PUBLIC(QOpenGLVertexArrayObject) | - |
| 119 | | - |
| 120 | GLuint vao; | - |
| 121 | | - |
| 122 | union { | - |
| 123 | QOpenGLFunctions_3_0 *core_3_0; | - |
| 124 | QOpenGLFunctions_3_2_Core *core_3_2; | - |
| 125 | QOpenGLVertexArrayObjectHelper *helper; | - |
| 126 | } vaoFuncs; | - |
| 127 | enum { | - |
| 128 | NotSupported, | - |
| 129 | Core_3_0, | - |
| 130 | Core_3_2, | - |
| 131 | ARB, | - |
| 132 | APPLE, | - |
| 133 | OES | - |
| 134 | } vaoFuncsType; | - |
| 135 | | - |
| 136 | QOpenGLContext *context; | - |
| 137 | }; | - |
| 138 | | - |
| 139 | bool QOpenGLVertexArrayObjectPrivate::create() | - |
| 140 | { | - |
| 141 | if (vao) { | - |
| 142 | qWarning("QOpenGLVertexArrayObject::create() VAO is already created"); | - |
| 143 | return false; | - |
| 144 | } | - |
| 145 | | - |
| 146 | Q_Q(QOpenGLVertexArrayObject); | - |
| 147 | | - |
| 148 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - |
| 149 | if (!ctx) { | - |
| 150 | qWarning("QOpenGLVertexArrayObject::create() requires a valid current OpenGL context"); | - |
| 151 | return false; | - |
| 152 | } | - |
| 153 | | - |
| 154 | | - |
| 155 | if (ctx == context) | - |
| 156 | return false; | - |
| 157 | | - |
| 158 | context = ctx; | - |
| 159 | QObject::connect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); | - |
| 160 | | - |
| 161 | if (ctx->isOpenGLES()) { | - |
| 162 | if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) { | - |
| 163 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
| 164 | vaoFuncsType = OES; | - |
| 165 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
| 166 | } | - |
| 167 | } else { | - |
| 168 | vaoFuncs.core_3_0 = 0; | - |
| 169 | vaoFuncsType = NotSupported; | - |
| 170 | QSurfaceFormat format = ctx->format(); | - |
| 171 | #ifndef QT_OPENGL_ES_2 | - |
| 172 | if (format.version() >= qMakePair<int, int>(3,2)) { | - |
| 173 | vaoFuncs.core_3_2 = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>(); | - |
| 174 | vaoFuncsType = Core_3_2; | - |
| 175 | vaoFuncs.core_3_2->glGenVertexArrays(1, &vao); | - |
| 176 | } else if (format.majorVersion() >= 3) { | - |
| 177 | vaoFuncs.core_3_0 = ctx->versionFunctions<QOpenGLFunctions_3_0>(); | - |
| 178 | vaoFuncsType = Core_3_0; | - |
| 179 | vaoFuncs.core_3_0->glGenVertexArrays(1, &vao); | - |
| 180 | } else | - |
| 181 | #endif | - |
| 182 | if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { | - |
| 183 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
| 184 | vaoFuncsType = ARB; | - |
| 185 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
| 186 | } else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) { | - |
| 187 | vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); | - |
| 188 | vaoFuncsType = APPLE; | - |
| 189 | vaoFuncs.helper->glGenVertexArrays(1, &vao); | - |
| 190 | } | - |
| 191 | } | - |
| 192 | | - |
| 193 | return (vao != 0); | - |
| 194 | } | - |
| 195 | | - |
| 196 | void QOpenGLVertexArrayObjectPrivate::destroy() | - |
| 197 | { | - |
| 198 | Q_Q(QOpenGLVertexArrayObject); | - |
| 199 | | - |
| 200 | if (context) { | - |
| 201 | QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); | - |
| 202 | context = 0; | - |
| 203 | } | - |
| 204 | | - |
| 205 | if (!vao) | - |
| 206 | return; | - |
| 207 | | - |
| 208 | switch (vaoFuncsType) { | - |
| 209 | #ifndef QT_OPENGL_ES_2 | - |
| 210 | case Core_3_2: | - |
| 211 | vaoFuncs.core_3_2->glDeleteVertexArrays(1, &vao); | - |
| 212 | break; | - |
| 213 | case Core_3_0: | - |
| 214 | vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao); | - |
| 215 | break; | - |
| 216 | #endif | - |
| 217 | case ARB: | - |
| 218 | case APPLE: | - |
| 219 | case OES: | - |
| 220 | vaoFuncs.helper->glDeleteVertexArrays(1, &vao); | - |
| 221 | break; | - |
| 222 | default: | - |
| 223 | break; | - |
| 224 | } | - |
| 225 | | - |
| 226 | vao = 0; | - |
| 227 | } | - |
| 228 | | - |
| 229 | | - |
| 230 | | - |
| 231 | | - |
| 232 | void QOpenGLVertexArrayObjectPrivate::_q_contextAboutToBeDestroyed() | - |
| 233 | { | - |
| 234 | destroy(); | - |
| 235 | } | - |
| 236 | | - |
| 237 | void QOpenGLVertexArrayObjectPrivate::bind() | - |
| 238 | { | - |
| 239 | switch (vaoFuncsType) { | - |
| 240 | #ifndef QT_OPENGL_ES_2 | - |
| 241 | case Core_3_2: | - |
| 242 | vaoFuncs.core_3_2->glBindVertexArray(vao); | - |
| 243 | break; | - |
| 244 | case Core_3_0: | - |
| 245 | vaoFuncs.core_3_0->glBindVertexArray(vao); | - |
| 246 | break; | - |
| 247 | #endif | - |
| 248 | case ARB: | - |
| 249 | case APPLE: | - |
| 250 | case OES: | - |
| 251 | vaoFuncs.helper->glBindVertexArray(vao); | - |
| 252 | break; | - |
| 253 | default: | - |
| 254 | break; | - |
| 255 | } | - |
| 256 | } | - |
| 257 | | - |
| 258 | void QOpenGLVertexArrayObjectPrivate::release() | - |
| 259 | { | - |
| 260 | switch (vaoFuncsType) { | - |
| 261 | #ifndef QT_OPENGL_ES_2 | - |
| 262 | case Core_3_2: | - |
| 263 | vaoFuncs.core_3_2->glBindVertexArray(0); | - |
| 264 | break; | - |
| 265 | case Core_3_0: | - |
| 266 | vaoFuncs.core_3_0->glBindVertexArray(0); | - |
| 267 | break; | - |
| 268 | #endif | - |
| 269 | case ARB: | - |
| 270 | case APPLE: | - |
| 271 | case OES: | - |
| 272 | vaoFuncs.helper->glBindVertexArray(0); | - |
| 273 | break; | - |
| 274 | default: | - |
| 275 | break; | - |
| 276 | } | - |
| 277 | } | - |
| 278 | | - |
| 279 | | - |
| 280 | | - |
| 281 | | - |
| 282 | | - |
| 283 | | - |
| 284 | | - |
| 285 | | - |
| 286 | | - |
| 287 | | - |
| 288 | | - |
| 289 | | - |
| 290 | | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | | - |
| 295 | | - |
| 296 | | - |
| 297 | | - |
| 298 | | - |
| 299 | | - |
| 300 | | - |
| 301 | | - |
| 302 | | - |
| 303 | | - |
| 304 | | - |
| 305 | | - |
| 306 | | - |
| 307 | | - |
| 308 | | - |
| 309 | | - |
| 310 | | - |
| 311 | | - |
| 312 | | - |
| 313 | | - |
| 314 | | - |
| 315 | | - |
| 316 | | - |
| 317 | | - |
| 318 | | - |
| 319 | | - |
| 320 | | - |
| 321 | | - |
| 322 | | - |
| 323 | | - |
| 324 | | - |
| 325 | | - |
| 326 | | - |
| 327 | | - |
| 328 | | - |
| 329 | | - |
| 330 | | - |
| 331 | | - |
| 332 | | - |
| 333 | | - |
| 334 | | - |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | | - |
| 339 | QOpenGLVertexArrayObject::QOpenGLVertexArrayObject(QObject* parent) | - |
| 340 | : QObject(*new QOpenGLVertexArrayObjectPrivate, parent) | - |
| 341 | { | - |
| 342 | } | - |
| 343 | | - |
| 344 | | - |
| 345 | | - |
| 346 | | - |
| 347 | QOpenGLVertexArrayObject::QOpenGLVertexArrayObject(QOpenGLVertexArrayObjectPrivate &dd) | - |
| 348 | : QObject(dd) | - |
| 349 | { | - |
| 350 | } | - |
| 351 | | - |
| 352 | | - |
| 353 | | - |
| 354 | | - |
| 355 | QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() | - |
| 356 | { | - |
| 357 | QOpenGLContext* ctx = QOpenGLContext::currentContext(); | - |
| 358 | | - |
| 359 | Q_D(QOpenGLVertexArrayObject); | - |
| 360 | QOpenGLContext *oldContext = 0; | - |
| 361 | QSurface *oldContextSurface = 0; | - |
| 362 | QScopedPointer<QOffscreenSurface> offscreenSurface; | - |
| 363 | if (d->context && ctx && d->context != ctx) { | - |
| 364 | oldContext = ctx; | - |
| 365 | oldContextSurface = ctx->surface(); | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | offscreenSurface.reset(new QOffscreenSurface); | - |
| 371 | offscreenSurface->setFormat(d->context->format()); | - |
| 372 | offscreenSurface->create(); | - |
| 373 | if (d->context->makeCurrent(offscreenSurface.data())) { | - |
| 374 | ctx = d->context; | - |
| 375 | } else { | - |
| 376 | qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to make VAO's context current"); | - |
| 377 | ctx = 0; | - |
| 378 | } | - |
| 379 | } | - |
| 380 | | - |
| 381 | if (ctx) | - |
| 382 | destroy(); | - |
| 383 | | - |
| 384 | if (oldContext) { | - |
| 385 | if (!oldContext->makeCurrent(oldContextSurface)) | - |
| 386 | qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context"); | - |
| 387 | } | - |
| 388 | } | - |
| 389 | | - |
| 390 | | - |
| 391 | | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | | - |
| 396 | | - |
| 397 | | - |
| 398 | | - |
| 399 | | - |
| 400 | | - |
| 401 | | - |
| 402 | | - |
| 403 | | - |
| 404 | | - |
| 405 | | - |
| 406 | bool QOpenGLVertexArrayObject::create() | - |
| 407 | { | - |
| 408 | Q_D(QOpenGLVertexArrayObject); | - |
| 409 | return d->create(); | - |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | | - |
| 416 | void QOpenGLVertexArrayObject::destroy() | - |
| 417 | { | - |
| 418 | Q_D(QOpenGLVertexArrayObject); | - |
| 419 | d->destroy(); | - |
| 420 | } | - |
| 421 | | - |
| 422 | | - |
| 423 | | - |
| 424 | | - |
| 425 | | - |
| 426 | | - |
| 427 | bool QOpenGLVertexArrayObject::isCreated() const | - |
| 428 | { | - |
| 429 | Q_D(const QOpenGLVertexArrayObject); | - |
| 430 | return (d->vao != 0); | - |
| 431 | } | - |
| 432 | | - |
| 433 | | - |
| 434 | | - |
| 435 | | - |
| 436 | GLuint QOpenGLVertexArrayObject::objectId() const | - |
| 437 | { | - |
| 438 | Q_D(const QOpenGLVertexArrayObject); | - |
| 439 | return d->vao; | - |
| 440 | } | - |
| 441 | | - |
| 442 | | - |
| 443 | | - |
| 444 | | - |
| 445 | | - |
| 446 | | - |
| 447 | | - |
| 448 | | - |
| 449 | | - |
| 450 | | - |
| 451 | void QOpenGLVertexArrayObject::bind() | - |
| 452 | { | - |
| 453 | Q_D(QOpenGLVertexArrayObject); | - |
| 454 | d->bind(); | - |
| 455 | } | - |
| 456 | | - |
| 457 | | - |
| 458 | | - |
| 459 | | - |
| 460 | void QOpenGLVertexArrayObject::release() | - |
| 461 | { | - |
| 462 | Q_D(QOpenGLVertexArrayObject); | - |
| 463 | d->release(); | - |
| 464 | } | - |
| 465 | | - |
| 466 | | - |
| 467 | | - |
| 468 | | - |
| 469 | | - |
| 470 | | - |
| 471 | | - |
| 472 | | - |
| 473 | | - |
| 474 | | - |
| 475 | | - |
| 476 | | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | | - |
| 481 | | - |
| 482 | | - |
| 483 | | - |
| 484 | | - |
| 485 | | - |
| 486 | | - |
| 487 | | - |
| 488 | | - |
| 489 | | - |
| 490 | | - |
| 491 | | - |
| 492 | | - |
| 493 | | - |
| 494 | | - |
| 495 | | - |
| 496 | | - |
| 497 | | - |
| 498 | | - |
| 499 | | - |
| 500 | | - |
| 501 | | - |
| 502 | | - |
| 503 | | - |
| 504 | | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | | - |
| 509 | | - |
| 510 | | - |
| 511 | | - |
| 512 | | - |
| 513 | | - |
| 514 | | - |
| 515 | | - |
| 516 | | - |
| 517 | | - |
| 518 | | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | | - |
| 523 | | - |
| 524 | QT_END_NAMESPACE | - |
| 525 | | - |
| 526 | #include "moc_qopenglvertexarrayobject.cpp" | - |
| | |