| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qopenglcontext.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include <qpa/qplatformopenglcontext.h> | - | ||||||||||||||||||
| 35 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||
| 36 | #include "qopenglcontext.h" | - | ||||||||||||||||||
| 37 | #include "qopenglcontext_p.h" | - | ||||||||||||||||||
| 38 | #include "qwindow.h" | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include <QtCore/QThreadStorage> | - | ||||||||||||||||||
| 41 | #include <QtCore/QThread> | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||
| 44 | #include <QtGui/private/qopengl_p.h> | - | ||||||||||||||||||
| 45 | #include <QtGui/private/qwindow_p.h> | - | ||||||||||||||||||
| 46 | #include <QtGui/QScreen> | - | ||||||||||||||||||
| 47 | #include <qpa/qplatformnativeinterface.h> | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | #include <private/qopenglextensions_p.h> | - | ||||||||||||||||||
| 50 | #include <private/qopenglversionfunctionsfactory_p.h> | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include <private/qopengltexturehelper_p.h> | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #include <QDebug> | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 57 | #include <QOpenGLFunctions_1_0> | - | ||||||||||||||||||
| 58 | #include <QOpenGLFunctions_3_2_Core> | - | ||||||||||||||||||
| 59 | #endif | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | class QOpenGLVersionProfilePrivate | - | ||||||||||||||||||
| 64 | { | - | ||||||||||||||||||
| 65 | public: | - | ||||||||||||||||||
| 66 | QOpenGLVersionProfilePrivate() | - | ||||||||||||||||||
| 67 | : majorVersion(0), | - | ||||||||||||||||||
| 68 | minorVersion(0), | - | ||||||||||||||||||
| 69 | profile(QSurfaceFormat::NoProfile) | - | ||||||||||||||||||
| 70 | {} never executed: end of block | 0 | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | int majorVersion; | - | ||||||||||||||||||
| 73 | int minorVersion; | - | ||||||||||||||||||
| 74 | QSurfaceFormat::OpenGLContextProfile profile; | - | ||||||||||||||||||
| 75 | }; | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | /*! | - | ||||||||||||||||||
| 79 | \class QOpenGLVersionProfile | - | ||||||||||||||||||
| 80 | \inmodule QtGui | - | ||||||||||||||||||
| 81 | \since 5.1 | - | ||||||||||||||||||
| 82 | \brief The QOpenGLVersionProfile class represents the version and if applicable | - | ||||||||||||||||||
| 83 | the profile of an OpenGL context. | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | An object of this class can be passed to QOpenGLContext::versionFunctions() to | - | ||||||||||||||||||
| 86 | request a functions object for a specific version and profile of OpenGL. | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | It also contains some helper functions to check if a version supports profiles | - | ||||||||||||||||||
| 89 | or is a legacy version. | - | ||||||||||||||||||
| 90 | */ | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | /*! | - | ||||||||||||||||||
| 93 | Creates a default invalid QOpenGLVersionProfile object. | - | ||||||||||||||||||
| 94 | */ | - | ||||||||||||||||||
| 95 | QOpenGLVersionProfile::QOpenGLVersionProfile() | - | ||||||||||||||||||
| 96 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||||||||
| 97 | { | - | ||||||||||||||||||
| 98 | } never executed: end of block | 0 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | /*! | - | ||||||||||||||||||
| 101 | Creates a QOpenGLVersionProfile object initialised with the version and profile | - | ||||||||||||||||||
| 102 | from \a format. | - | ||||||||||||||||||
| 103 | */ | - | ||||||||||||||||||
| 104 | QOpenGLVersionProfile::QOpenGLVersionProfile(const QSurfaceFormat &format) | - | ||||||||||||||||||
| 105 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||||||||
| 106 | { | - | ||||||||||||||||||
| 107 | d->majorVersion = format.majorVersion(); | - | ||||||||||||||||||
| 108 | d->minorVersion = format.minorVersion(); | - | ||||||||||||||||||
| 109 | d->profile = format.profile(); | - | ||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | /*! | - | ||||||||||||||||||
| 113 | Constructs a copy of \a other. | - | ||||||||||||||||||
| 114 | */ | - | ||||||||||||||||||
| 115 | QOpenGLVersionProfile::QOpenGLVersionProfile(const QOpenGLVersionProfile &other) | - | ||||||||||||||||||
| 116 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||||||||
| 117 | { | - | ||||||||||||||||||
| 118 | *d = *(other.d); | - | ||||||||||||||||||
| 119 | } never executed: end of block | 0 | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | /*! | - | ||||||||||||||||||
| 122 | Destroys the QOpenGLVersionProfile object. | - | ||||||||||||||||||
| 123 | */ | - | ||||||||||||||||||
| 124 | QOpenGLVersionProfile::~QOpenGLVersionProfile() | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | delete d; | - | ||||||||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | /*! | - | ||||||||||||||||||
| 130 | Assigns the version and profile of \a rhs to this QOpenGLVersionProfile object. | - | ||||||||||||||||||
| 131 | */ | - | ||||||||||||||||||
| 132 | QOpenGLVersionProfile &QOpenGLVersionProfile::operator=(const QOpenGLVersionProfile &rhs) | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | if (this == &rhs)
| 0 | ||||||||||||||||||
| 135 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 136 | *d = *(rhs.d); | - | ||||||||||||||||||
| 137 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 138 | } | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | /*! | - | ||||||||||||||||||
| 141 | Returns a QPair<int,int> where the components represent the major and minor OpenGL | - | ||||||||||||||||||
| 142 | version numbers respectively. | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | \sa setVersion() | - | ||||||||||||||||||
| 145 | */ | - | ||||||||||||||||||
| 146 | QPair<int, int> QOpenGLVersionProfile::version() const | - | ||||||||||||||||||
| 147 | { | - | ||||||||||||||||||
| 148 | return qMakePair( d->majorVersion, d->minorVersion); never executed: return qMakePair( d->majorVersion, d->minorVersion); | 0 | ||||||||||||||||||
| 149 | } | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | /*! | - | ||||||||||||||||||
| 152 | Sets the major and minor version numbers to \a majorVersion and \a minorVersion respectively. | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | \sa version() | - | ||||||||||||||||||
| 155 | */ | - | ||||||||||||||||||
| 156 | void QOpenGLVersionProfile::setVersion(int majorVersion, int minorVersion) | - | ||||||||||||||||||
| 157 | { | - | ||||||||||||||||||
| 158 | d->majorVersion = majorVersion; | - | ||||||||||||||||||
| 159 | d->minorVersion = minorVersion; | - | ||||||||||||||||||
| 160 | } never executed: end of block | 0 | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | /*! | - | ||||||||||||||||||
| 163 | Returns the OpenGL profile. Only makes sense if profiles are supported by this version. | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | \sa setProfile() | - | ||||||||||||||||||
| 166 | */ | - | ||||||||||||||||||
| 167 | QSurfaceFormat::OpenGLContextProfile QOpenGLVersionProfile::profile() const | - | ||||||||||||||||||
| 168 | { | - | ||||||||||||||||||
| 169 | return d->profile; never executed: return d->profile; | 0 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | /*! | - | ||||||||||||||||||
| 173 | Sets the OpenGL profile \a profile. Only makes sense if profiles are supported by | - | ||||||||||||||||||
| 174 | this version. | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | \sa profile() | - | ||||||||||||||||||
| 177 | */ | - | ||||||||||||||||||
| 178 | void QOpenGLVersionProfile::setProfile(QSurfaceFormat::OpenGLContextProfile profile) | - | ||||||||||||||||||
| 179 | { | - | ||||||||||||||||||
| 180 | d->profile = profile; | - | ||||||||||||||||||
| 181 | } never executed: end of block | 0 | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | /*! | - | ||||||||||||||||||
| 184 | Returns \c true if profiles are supported by the OpenGL version returned by version(). Only | - | ||||||||||||||||||
| 185 | OpenGL versions >= 3.2 support profiles. | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | \sa profile(), version() | - | ||||||||||||||||||
| 188 | */ | - | ||||||||||||||||||
| 189 | bool QOpenGLVersionProfile::hasProfiles() const | - | ||||||||||||||||||
| 190 | { | - | ||||||||||||||||||
| 191 | return ( d->majorVersion > 3 never executed: return ( d->majorVersion > 3 || (d->majorVersion == 3 && d->minorVersion > 1));
| 0 | ||||||||||||||||||
| 192 | || (d->majorVersion == 3 && d->minorVersion > 1)); never executed: return ( d->majorVersion > 3 || (d->majorVersion == 3 && d->minorVersion > 1));
| 0 | ||||||||||||||||||
| 193 | } | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | /*! | - | ||||||||||||||||||
| 196 | Returns \c true is the OpenGL version returned by version() contains deprecated functions | - | ||||||||||||||||||
| 197 | and does not support profiles i.e. if the OpenGL version is <= 3.1. | - | ||||||||||||||||||
| 198 | */ | - | ||||||||||||||||||
| 199 | bool QOpenGLVersionProfile::isLegacyVersion() const | - | ||||||||||||||||||
| 200 | { | - | ||||||||||||||||||
| 201 | return (d->majorVersion < 3 || (d->majorVersion == 3 && d->minorVersion == 0)); never executed: return (d->majorVersion < 3 || (d->majorVersion == 3 && d->minorVersion == 0));
| 0 | ||||||||||||||||||
| 202 | } | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | /*! | - | ||||||||||||||||||
| 205 | Returns \c true if the version number is valid. Note that for a default constructed | - | ||||||||||||||||||
| 206 | QOpenGLVersionProfile object this function will return \c false. | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | \sa setVersion(), version() | - | ||||||||||||||||||
| 209 | */ | - | ||||||||||||||||||
| 210 | bool QOpenGLVersionProfile::isValid() const | - | ||||||||||||||||||
| 211 | { | - | ||||||||||||||||||
| 212 | return d->majorVersion > 0 && d->minorVersion >= 0; never executed: return d->majorVersion > 0 && d->minorVersion >= 0;
| 0 | ||||||||||||||||||
| 213 | } | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | class QGuiGLThreadContext | - | ||||||||||||||||||
| 216 | { | - | ||||||||||||||||||
| 217 | public: | - | ||||||||||||||||||
| 218 | QGuiGLThreadContext() | - | ||||||||||||||||||
| 219 | : context(0) | - | ||||||||||||||||||
| 220 | { | - | ||||||||||||||||||
| 221 | } never executed: end of block | 0 | ||||||||||||||||||
| 222 | ~QGuiGLThreadContext() { | - | ||||||||||||||||||
| 223 | if (context)
| 0 | ||||||||||||||||||
| 224 | context->doneCurrent(); never executed: context->doneCurrent(); | 0 | ||||||||||||||||||
| 225 | } never executed: end of block | 0 | ||||||||||||||||||
| 226 | QOpenGLContext *context; | - | ||||||||||||||||||
| 227 | }; | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | Q_GLOBAL_STATIC(QThreadStorage<QGuiGLThreadContext *>, qwindow_context_storage); never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 230 | static QOpenGLContext *global_share_context = 0; | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 233 | QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker; | - | ||||||||||||||||||
| 234 | QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex; | - | ||||||||||||||||||
| 235 | #endif | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | /*! | - | ||||||||||||||||||
| 238 | \internal | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | This function is used by Qt::AA_ShareOpenGLContexts and the Qt | - | ||||||||||||||||||
| 241 | WebEngine to set up context sharing across multiple windows. Do | - | ||||||||||||||||||
| 242 | not use it for any other purpose. | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | Please maintain the binary compatibility of these functions. | - | ||||||||||||||||||
| 245 | */ | - | ||||||||||||||||||
| 246 | void qt_gl_set_global_share_context(QOpenGLContext *context) | - | ||||||||||||||||||
| 247 | { | - | ||||||||||||||||||
| 248 | global_share_context = context; | - | ||||||||||||||||||
| 249 | } never executed: end of block | 0 | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | /*! | - | ||||||||||||||||||
| 252 | \internal | - | ||||||||||||||||||
| 253 | */ | - | ||||||||||||||||||
| 254 | QOpenGLContext *qt_gl_global_share_context() | - | ||||||||||||||||||
| 255 | { | - | ||||||||||||||||||
| 256 | return global_share_context; never executed: return global_share_context; | 0 | ||||||||||||||||||
| 257 | } | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | /*! | - | ||||||||||||||||||
| 260 | \class QOpenGLContext | - | ||||||||||||||||||
| 261 | \inmodule QtGui | - | ||||||||||||||||||
| 262 | \since 5.0 | - | ||||||||||||||||||
| 263 | \brief The QOpenGLContext class represents a native OpenGL context, enabling | - | ||||||||||||||||||
| 264 | OpenGL rendering on a QSurface. | - | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | QOpenGLContext represents the OpenGL state of an underlying OpenGL context. | - | ||||||||||||||||||
| 267 | To set up a context, set its screen and format such that they match those | - | ||||||||||||||||||
| 268 | of the surface or surfaces with which the context is meant to be used, if | - | ||||||||||||||||||
| 269 | necessary make it share resources with other contexts with | - | ||||||||||||||||||
| 270 | setShareContext(), and finally call create(). Use the return value or isValid() | - | ||||||||||||||||||
| 271 | to check if the context was successfully initialized. | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | A context can be made current against a given surface by calling | - | ||||||||||||||||||
| 274 | makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap | - | ||||||||||||||||||
| 275 | the front and back buffers of the surface, so that the newly rendered | - | ||||||||||||||||||
| 276 | content becomes visible. To be able to support certain platforms, | - | ||||||||||||||||||
| 277 | QOpenGLContext requires that you call makeCurrent() again before starting | - | ||||||||||||||||||
| 278 | rendering a new frame, after calling swapBuffers(). | - | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | If the context is temporarily not needed, such as when the application is | - | ||||||||||||||||||
| 281 | not rendering, it can be useful to delete it in order to free resources. | - | ||||||||||||||||||
| 282 | You can connect to the aboutToBeDestroyed() signal to clean up any | - | ||||||||||||||||||
| 283 | resources that have been allocated with different ownership from the | - | ||||||||||||||||||
| 284 | QOpenGLContext itself. | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | Once a QOpenGLContext has been made current, you can render to it in a | - | ||||||||||||||||||
| 287 | platform independent way by using Qt's OpenGL enablers such as | - | ||||||||||||||||||
| 288 | QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and | - | ||||||||||||||||||
| 289 | QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL | - | ||||||||||||||||||
| 290 | API directly, without using the Qt enablers, although potentially at the | - | ||||||||||||||||||
| 291 | cost of portability. The latter is necessary when wanting to use OpenGL 1.x | - | ||||||||||||||||||
| 292 | or OpenGL ES 1.x. | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | For more information about the OpenGL API, refer to the official | - | ||||||||||||||||||
| 295 | \l{http://www.opengl.org}{OpenGL documentation}. | - | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | For an example of how to use QOpenGLContext see the | - | ||||||||||||||||||
| 298 | \l{OpenGL Window Example}{OpenGL Window} example. | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | \section1 Thread Affinity | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | QOpenGLContext can be moved to a different thread with moveToThread(). Do | - | ||||||||||||||||||
| 303 | not call makeCurrent() from a different thread than the one to which the | - | ||||||||||||||||||
| 304 | QOpenGLContext object belongs. A context can only be current in one thread | - | ||||||||||||||||||
| 305 | and against one surface at a time, and a thread only has one context | - | ||||||||||||||||||
| 306 | current at a time. | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | \section1 Context Resource Sharing | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | Resources, such as framebuffer objects, textures, and vertex buffer objects | - | ||||||||||||||||||
| 311 | can be shared between contexts. Use setShareContext() before calling | - | ||||||||||||||||||
| 312 | create() to specify that the contexts should share these resources. | - | ||||||||||||||||||
| 313 | QOpenGLContext internally keeps track of a QOpenGLContextGroup object which | - | ||||||||||||||||||
| 314 | can be accessed with shareGroup(), and which can be used to find all the | - | ||||||||||||||||||
| 315 | contexts in a given share group. A share group consists of all contexts that | - | ||||||||||||||||||
| 316 | have been successfully initialized and are sharing with an existing context in | - | ||||||||||||||||||
| 317 | the share group. A non-sharing context has a share group consisting of a | - | ||||||||||||||||||
| 318 | single context. | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | \section1 Default Framebuffer | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | On certain platforms, a framebuffer other than 0 might be the default frame | - | ||||||||||||||||||
| 323 | buffer depending on the current surface. Instead of calling | - | ||||||||||||||||||
| 324 | glBindFramebuffer(0), it is recommended that you use | - | ||||||||||||||||||
| 325 | glBindFramebuffer(ctx->defaultFramebufferObject()), to ensure that your | - | ||||||||||||||||||
| 326 | application is portable between different platforms. However, if you use | - | ||||||||||||||||||
| 327 | QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you. | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | \sa QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLFramebufferObject | - | ||||||||||||||||||
| 330 | */ | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | /*! | - | ||||||||||||||||||
| 333 | \internal | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | Set the current context. Returns the previously current context. | - | ||||||||||||||||||
| 336 | */ | - | ||||||||||||||||||
| 337 | QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context) | - | ||||||||||||||||||
| 338 | { | - | ||||||||||||||||||
| 339 | QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); | - | ||||||||||||||||||
| 340 | if (!threadContext) {
| 0 | ||||||||||||||||||
| 341 | if (!QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 342 | qWarning("No QTLS available. currentContext won't work"); | - | ||||||||||||||||||
| 343 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 344 | } | - | ||||||||||||||||||
| 345 | threadContext = new QGuiGLThreadContext; | - | ||||||||||||||||||
| 346 | qwindow_context_storage()->setLocalData(threadContext); | - | ||||||||||||||||||
| 347 | } never executed: end of block | 0 | ||||||||||||||||||
| 348 | QOpenGLContext *previous = threadContext->context; | - | ||||||||||||||||||
| 349 | threadContext->context = context; | - | ||||||||||||||||||
| 350 | return previous; never executed: return previous; | 0 | ||||||||||||||||||
| 351 | } | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | int QOpenGLContextPrivate::maxTextureSize() | - | ||||||||||||||||||
| 354 | { | - | ||||||||||||||||||
| 355 | if (max_texture_size != -1)
| 0 | ||||||||||||||||||
| 356 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | Q_Q(QOpenGLContext); | - | ||||||||||||||||||
| 359 | QOpenGLFunctions *funcs = q->functions(); | - | ||||||||||||||||||
| 360 | funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | - | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 363 | if (!q->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 364 | GLenum proxy = GL_PROXY_TEXTURE_2D; | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | GLint size; | - | ||||||||||||||||||
| 367 | GLint next = 64; | - | ||||||||||||||||||
| 368 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | QOpenGLFunctions_1_0 *gl1funcs = 0; | - | ||||||||||||||||||
| 371 | QOpenGLFunctions_3_2_Core *gl3funcs = 0; | - | ||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | if (q->format().profile() == QSurfaceFormat::CoreProfile)
| 0 | ||||||||||||||||||
| 374 | gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>(); never executed: gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>(); | 0 | ||||||||||||||||||
| 375 | else | - | ||||||||||||||||||
| 376 | gl1funcs = q->versionFunctions<QOpenGLFunctions_1_0>(); never executed: gl1funcs = q->versionFunctions<QOpenGLFunctions_1_0>(); | 0 | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | Q_ASSERT(gl1funcs || gl3funcs); | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | if (gl1funcs)
| 0 | ||||||||||||||||||
| 381 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); never executed: gl1funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &size); | 0 | ||||||||||||||||||
| 382 | else | - | ||||||||||||||||||
| 383 | gl3funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); never executed: gl3funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &size); | 0 | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | if (size == 0) {
| 0 | ||||||||||||||||||
| 386 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 387 | } | - | ||||||||||||||||||
| 388 | do { | - | ||||||||||||||||||
| 389 | size = next; | - | ||||||||||||||||||
| 390 | next = size * 2; | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | if (next > max_texture_size)
| 0 | ||||||||||||||||||
| 393 | break; never executed: break; | 0 | ||||||||||||||||||
| 394 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
| 395 | if (gl1funcs)
| 0 | ||||||||||||||||||
| 396 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); never executed: gl1funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &next); | 0 | ||||||||||||||||||
| 397 | else | - | ||||||||||||||||||
| 398 | gl3funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); never executed: gl3funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &next); | 0 | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | } while (next > size);
| 0 | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | max_texture_size = size; | - | ||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||
| 404 | #endif // QT_OPENGL_ES | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | /*! | - | ||||||||||||||||||
| 410 | Returns the last context which called makeCurrent in the current thread, | - | ||||||||||||||||||
| 411 | or 0, if no context is current. | - | ||||||||||||||||||
| 412 | */ | - | ||||||||||||||||||
| 413 | QOpenGLContext* QOpenGLContext::currentContext() | - | ||||||||||||||||||
| 414 | { | - | ||||||||||||||||||
| 415 | QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); | - | ||||||||||||||||||
| 416 | if (threadContext) {
| 0 | ||||||||||||||||||
| 417 | return threadContext->context; never executed: return threadContext->context; | 0 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 420 | } | - | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | /*! | - | ||||||||||||||||||
| 423 | Returns \c true if the \a first and \a second contexts are sharing OpenGL resources. | - | ||||||||||||||||||
| 424 | */ | - | ||||||||||||||||||
| 425 | bool QOpenGLContext::areSharing(QOpenGLContext *first, QOpenGLContext *second) | - | ||||||||||||||||||
| 426 | { | - | ||||||||||||||||||
| 427 | return first->shareGroup() == second->shareGroup(); never executed: return first->shareGroup() == second->shareGroup(); | 0 | ||||||||||||||||||
| 428 | } | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | /*! | - | ||||||||||||||||||
| 431 | Returns the underlying platform context. | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | \internal | - | ||||||||||||||||||
| 434 | */ | - | ||||||||||||||||||
| 435 | QPlatformOpenGLContext *QOpenGLContext::handle() const | - | ||||||||||||||||||
| 436 | { | - | ||||||||||||||||||
| 437 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 438 | return d->platformGLContext; never executed: return d->platformGLContext; | 0 | ||||||||||||||||||
| 439 | } | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | /*! | - | ||||||||||||||||||
| 442 | Returns the underlying platform context with which this context is sharing. | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | \internal | - | ||||||||||||||||||
| 445 | */ | - | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | QPlatformOpenGLContext *QOpenGLContext::shareHandle() const | - | ||||||||||||||||||
| 448 | { | - | ||||||||||||||||||
| 449 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 450 | if (d->shareContext)
| 0 | ||||||||||||||||||
| 451 | return d->shareContext->handle(); never executed: return d->shareContext->handle(); | 0 | ||||||||||||||||||
| 452 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 453 | } | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | /*! | - | ||||||||||||||||||
| 456 | Creates a new OpenGL context instance with parent object \a parent. | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | Before it can be used you need to set the proper format and call create(). | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | \sa create(), makeCurrent() | - | ||||||||||||||||||
| 461 | */ | - | ||||||||||||||||||
| 462 | QOpenGLContext::QOpenGLContext(QObject *parent) | - | ||||||||||||||||||
| 463 | : QObject(*new QOpenGLContextPrivate(), parent) | - | ||||||||||||||||||
| 464 | { | - | ||||||||||||||||||
| 465 | setScreen(QGuiApplication::primaryScreen()); | - | ||||||||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||||||||
| 467 | - | |||||||||||||||||||
| 468 | /*! | - | ||||||||||||||||||
| 469 | Sets the \a format the OpenGL context should be compatible with. You need | - | ||||||||||||||||||
| 470 | to call create() before it takes effect. | - | ||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | When the format is not explicitly set via this function, the format returned | - | ||||||||||||||||||
| 473 | by QSurfaceFormat::defaultFormat() will be used. This means that when having | - | ||||||||||||||||||
| 474 | multiple contexts, individual calls to this function can be replaced by one | - | ||||||||||||||||||
| 475 | single call to QSurfaceFormat::setDefaultFormat() before creating the first | - | ||||||||||||||||||
| 476 | context. | - | ||||||||||||||||||
| 477 | */ | - | ||||||||||||||||||
| 478 | void QOpenGLContext::setFormat(const QSurfaceFormat &format) | - | ||||||||||||||||||
| 479 | { | - | ||||||||||||||||||
| 480 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 481 | d->requestedFormat = format; | - | ||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||
| 483 | - | |||||||||||||||||||
| 484 | /*! | - | ||||||||||||||||||
| 485 | Makes this context share textures, shaders, and other OpenGL resources | - | ||||||||||||||||||
| 486 | with \a shareContext. You need to call create() before it takes effect. | - | ||||||||||||||||||
| 487 | */ | - | ||||||||||||||||||
| 488 | void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) | - | ||||||||||||||||||
| 489 | { | - | ||||||||||||||||||
| 490 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 491 | d->shareContext = shareContext; | - | ||||||||||||||||||
| 492 | } never executed: end of block | 0 | ||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | /*! | - | ||||||||||||||||||
| 495 | Sets the \a screen the OpenGL context should be valid for. You need to call | - | ||||||||||||||||||
| 496 | create() before it takes effect. | - | ||||||||||||||||||
| 497 | */ | - | ||||||||||||||||||
| 498 | void QOpenGLContext::setScreen(QScreen *screen) | - | ||||||||||||||||||
| 499 | { | - | ||||||||||||||||||
| 500 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 501 | if (d->screen)
| 0 | ||||||||||||||||||
| 502 | disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(_q_screenDestroyed(QObject*))); never executed: disconnect(d->screen, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "502"), this, qFlagLocation("1""_q_screenDestroyed(QObject*)" "\0" __FILE__ ":" "502")); | 0 | ||||||||||||||||||
| 503 | d->screen = screen; | - | ||||||||||||||||||
| 504 | if (!d->screen)
| 0 | ||||||||||||||||||
| 505 | d->screen = QGuiApplication::primaryScreen(); never executed: d->screen = QGuiApplication::primaryScreen(); | 0 | ||||||||||||||||||
| 506 | if (d->screen)
| 0 | ||||||||||||||||||
| 507 | connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(_q_screenDestroyed(QObject*))); never executed: connect(d->screen, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "507"), this, qFlagLocation("1""_q_screenDestroyed(QObject*)" "\0" __FILE__ ":" "507")); | 0 | ||||||||||||||||||
| 508 | } never executed: end of block | 0 | ||||||||||||||||||
| 509 | - | |||||||||||||||||||
| 510 | void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object) | - | ||||||||||||||||||
| 511 | { | - | ||||||||||||||||||
| 512 | Q_Q(QOpenGLContext); | - | ||||||||||||||||||
| 513 | if (object == static_cast<QObject *>(screen)) {
| 0 | ||||||||||||||||||
| 514 | screen = 0; | - | ||||||||||||||||||
| 515 | q->setScreen(0); | - | ||||||||||||||||||
| 516 | } never executed: end of block | 0 | ||||||||||||||||||
| 517 | } never executed: end of block | 0 | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | /*! | - | ||||||||||||||||||
| 520 | Set the native handles for this context. When create() is called and a | - | ||||||||||||||||||
| 521 | native handle is set, configuration settings, like format(), are ignored | - | ||||||||||||||||||
| 522 | since this QOpenGLContext will wrap an already created native context | - | ||||||||||||||||||
| 523 | instead of creating a new one from scratch. | - | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | On some platforms the native context handle is not sufficient and other | - | ||||||||||||||||||
| 526 | related handles (for example, for a window or display) have to be provided | - | ||||||||||||||||||
| 527 | in addition. Therefore \a handle is variant containing a platform-specific | - | ||||||||||||||||||
| 528 | value type. These classes can be found in the QtPlatformHeaders module. | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | When create() is called with native handles set, QOpenGLContext does not | - | ||||||||||||||||||
| 531 | take ownership of the handles, so destroying the QOpenGLContext does not | - | ||||||||||||||||||
| 532 | destroy the native context. | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | \note Some frameworks track the current context and surfaces internally. | - | ||||||||||||||||||
| 535 | Making the adopted QOpenGLContext current via Qt will have no effect on such | - | ||||||||||||||||||
| 536 | other frameworks' internal state. Therefore a subsequent makeCurrent done | - | ||||||||||||||||||
| 537 | via the other framework may have no effect. It is therefore advisable to | - | ||||||||||||||||||
| 538 | make explicit calls to make no context and surface current to reset the | - | ||||||||||||||||||
| 539 | other frameworks' internal state after performing OpenGL operations via Qt. | - | ||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | \note Using foreign contexts with Qt windows and Qt contexts with windows | - | ||||||||||||||||||
| 542 | and surfaces created by other frameworks may give unexpected results, | - | ||||||||||||||||||
| 543 | depending on the platform, due to potential mismatches in context and window | - | ||||||||||||||||||
| 544 | pixel formats. To make sure this does not happen, avoid making contexts and | - | ||||||||||||||||||
| 545 | surfaces from different frameworks current together. Instead, prefer | - | ||||||||||||||||||
| 546 | approaches based on context sharing where OpenGL resources like textures are | - | ||||||||||||||||||
| 547 | accessible both from Qt's and the foreign framework's contexts. | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | \since 5.4 | - | ||||||||||||||||||
| 550 | \sa nativeHandle() | - | ||||||||||||||||||
| 551 | */ | - | ||||||||||||||||||
| 552 | void QOpenGLContext::setNativeHandle(const QVariant &handle) | - | ||||||||||||||||||
| 553 | { | - | ||||||||||||||||||
| 554 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 555 | d->nativeHandle = handle; | - | ||||||||||||||||||
| 556 | } never executed: end of block | 0 | ||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | /*! | - | ||||||||||||||||||
| 559 | Returns the native handle for the context. | - | ||||||||||||||||||
| 560 | - | |||||||||||||||||||
| 561 | This function provides access to the QOpenGLContext's underlying native | - | ||||||||||||||||||
| 562 | context. The returned variant contains a platform-specific value type. These | - | ||||||||||||||||||
| 563 | classes can be found in the module QtPlatformHeaders. | - | ||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | On platforms where retrieving the native handle is not supported, or if | - | ||||||||||||||||||
| 566 | neither create() nor setNativeHandle() was called, a null variant is | - | ||||||||||||||||||
| 567 | returned. | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | \since 5.4 | - | ||||||||||||||||||
| 570 | \sa setNativeHandle() | - | ||||||||||||||||||
| 571 | */ | - | ||||||||||||||||||
| 572 | QVariant QOpenGLContext::nativeHandle() const | - | ||||||||||||||||||
| 573 | { | - | ||||||||||||||||||
| 574 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 575 | return d->nativeHandle; never executed: return d->nativeHandle; | 0 | ||||||||||||||||||
| 576 | } | - | ||||||||||||||||||
| 577 | - | |||||||||||||||||||
| 578 | /*! | - | ||||||||||||||||||
| 579 | Attempts to create the OpenGL context with the current configuration. | - | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | The current configuration includes the format, the share context, and the | - | ||||||||||||||||||
| 582 | screen. | - | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | If the OpenGL implementation on your system does not support the requested | - | ||||||||||||||||||
| 585 | version of OpenGL context, then QOpenGLContext will try to create the closest | - | ||||||||||||||||||
| 586 | matching version. The actual created context properties can be queried | - | ||||||||||||||||||
| 587 | using the QSurfaceFormat returned by the format() function. For example, if | - | ||||||||||||||||||
| 588 | you request a context that supports OpenGL 4.3 Core profile but the driver | - | ||||||||||||||||||
| 589 | and/or hardware only supports version 3.2 Core profile contexts then you will | - | ||||||||||||||||||
| 590 | get a 3.2 Core profile context. | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | Returns \c true if the native context was successfully created and is ready to | - | ||||||||||||||||||
| 593 | be used with makeCurrent(), swapBuffers(), etc. | - | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | \note If the context already exists, this function destroys the existing | - | ||||||||||||||||||
| 596 | context first, and then creates a new one. | - | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | \sa makeCurrent(), format() | - | ||||||||||||||||||
| 599 | */ | - | ||||||||||||||||||
| 600 | bool QOpenGLContext::create() | - | ||||||||||||||||||
| 601 | { | - | ||||||||||||||||||
| 602 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 603 | if (d->platformGLContext)
| 0 | ||||||||||||||||||
| 604 | destroy(); never executed: destroy(); | 0 | ||||||||||||||||||
| 605 | - | |||||||||||||||||||
| 606 | d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this); | - | ||||||||||||||||||
| 607 | if (!d->platformGLContext)
| 0 | ||||||||||||||||||
| 608 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 609 | d->platformGLContext->initialize(); | - | ||||||||||||||||||
| 610 | d->platformGLContext->setContext(this); | - | ||||||||||||||||||
| 611 | if (!d->platformGLContext->isSharing())
| 0 | ||||||||||||||||||
| 612 | d->shareContext = 0; never executed: d->shareContext = 0; | 0 | ||||||||||||||||||
| 613 | d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup;
| 0 | ||||||||||||||||||
| 614 | d->shareGroup->d_func()->addContext(this); | - | ||||||||||||||||||
| 615 | return isValid(); never executed: return isValid(); | 0 | ||||||||||||||||||
| 616 | } | - | ||||||||||||||||||
| 617 | - | |||||||||||||||||||
| 618 | /*! | - | ||||||||||||||||||
| 619 | \internal | - | ||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | Destroy the underlying platform context associated with this context. | - | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | If any other context is directly or indirectly sharing resources with this | - | ||||||||||||||||||
| 624 | context, the shared resources, which includes vertex buffer objects, shader | - | ||||||||||||||||||
| 625 | objects, textures, and framebuffer objects, are not freed. However, | - | ||||||||||||||||||
| 626 | destroying the underlying platform context frees any state associated with | - | ||||||||||||||||||
| 627 | the context. | - | ||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | After \c destroy() has been called, you must call create() if you wish to | - | ||||||||||||||||||
| 630 | use the context again. | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | \note This implicitly calls doneCurrent() if the context is current. | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | \sa create() | - | ||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||
| 636 | void QOpenGLContext::destroy() | - | ||||||||||||||||||
| 637 | { | - | ||||||||||||||||||
| 638 | deleteQGLContext(); | - | ||||||||||||||||||
| 639 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 640 | if (d->platformGLContext)
| 0 | ||||||||||||||||||
| 641 | emit aboutToBeDestroyed(); never executed: aboutToBeDestroyed(); | 0 | ||||||||||||||||||
| 642 | if (QOpenGLContext::currentContext() == this)
| 0 | ||||||||||||||||||
| 643 | doneCurrent(); never executed: doneCurrent(); | 0 | ||||||||||||||||||
| 644 | if (d->shareGroup)
| 0 | ||||||||||||||||||
| 645 | d->shareGroup->d_func()->removeContext(this); never executed: d->shareGroup->d_func()->removeContext(this); | 0 | ||||||||||||||||||
| 646 | d->shareGroup = 0; | - | ||||||||||||||||||
| 647 | delete d->platformGLContext; | - | ||||||||||||||||||
| 648 | d->platformGLContext = 0; | - | ||||||||||||||||||
| 649 | delete d->functions; | - | ||||||||||||||||||
| 650 | d->functions = 0; | - | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | foreach (QAbstractOpenGLFunctions *func, d->externalVersionFunctions) { | - | ||||||||||||||||||
| 653 | QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func); | - | ||||||||||||||||||
| 654 | func_d->owningContext = 0; | - | ||||||||||||||||||
| 655 | func_d->initialized = false; | - | ||||||||||||||||||
| 656 | } never executed: end of block | 0 | ||||||||||||||||||
| 657 | d->externalVersionFunctions.clear(); | - | ||||||||||||||||||
| 658 | qDeleteAll(d->versionFunctions); | - | ||||||||||||||||||
| 659 | d->versionFunctions.clear(); | - | ||||||||||||||||||
| 660 | qDeleteAll(d->versionFunctionsBackend); | - | ||||||||||||||||||
| 661 | d->versionFunctionsBackend.clear(); | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | delete d->textureFunctions; | - | ||||||||||||||||||
| 664 | d->textureFunctions = 0; | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | d->nativeHandle = QVariant(); | - | ||||||||||||||||||
| 667 | } never executed: end of block | 0 | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | /*! | - | ||||||||||||||||||
| 670 | \fn void QOpenGLContext::aboutToBeDestroyed() | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | This signal is emitted before the underlying native OpenGL context is | - | ||||||||||||||||||
| 673 | destroyed, such that users may clean up OpenGL resources that might | - | ||||||||||||||||||
| 674 | otherwise be left dangling in the case of shared OpenGL contexts. | - | ||||||||||||||||||
| 675 | - | |||||||||||||||||||
| 676 | If you wish to make the context current in order to do clean-up, make sure | - | ||||||||||||||||||
| 677 | to only connect to the signal using a direct connection. | - | ||||||||||||||||||
| 678 | */ | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | /*! | - | ||||||||||||||||||
| 681 | Destroys the QOpenGLContext object. | - | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | If this is the current context for the thread, doneCurrent() is also called. | - | ||||||||||||||||||
| 684 | */ | - | ||||||||||||||||||
| 685 | QOpenGLContext::~QOpenGLContext() | - | ||||||||||||||||||
| 686 | { | - | ||||||||||||||||||
| 687 | destroy(); | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 690 | QOpenGLContextPrivate::cleanMakeCurrentTracker(this); | - | ||||||||||||||||||
| 691 | #endif | - | ||||||||||||||||||
| 692 | } never executed: end of block | 0 | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | /*! | - | ||||||||||||||||||
| 695 | Returns if this context is valid, i.e. has been successfully created. | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | On some platforms the return value of \c false for a context that was | - | ||||||||||||||||||
| 698 | successfully created previously indicates that the OpenGL context was lost. | - | ||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | The typical way to handle context loss scenarios in applications is to | - | ||||||||||||||||||
| 701 | check via this function whenever makeCurrent() fails and returns \c false. | - | ||||||||||||||||||
| 702 | If this function then returns \c false, recreate the underlying native | - | ||||||||||||||||||
| 703 | OpenGL context by calling create(), call makeCurrent() again and then | - | ||||||||||||||||||
| 704 | reinitialize all OpenGL resources. | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | \sa create() | - | ||||||||||||||||||
| 707 | */ | - | ||||||||||||||||||
| 708 | bool QOpenGLContext::isValid() const | - | ||||||||||||||||||
| 709 | { | - | ||||||||||||||||||
| 710 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 711 | return d->platformGLContext && d->platformGLContext->isValid(); never executed: return d->platformGLContext && d->platformGLContext->isValid();
| 0 | ||||||||||||||||||
| 712 | } | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | /*! | - | ||||||||||||||||||
| 715 | Get the QOpenGLFunctions instance for this context. | - | ||||||||||||||||||
| 716 | - | |||||||||||||||||||
| 717 | QOpenGLContext offers this as a convenient way to access QOpenGLFunctions | - | ||||||||||||||||||
| 718 | without having to manage it manually. | - | ||||||||||||||||||
| 719 | - | |||||||||||||||||||
| 720 | The context or a sharing context must be current. | - | ||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | The returned QOpenGLFunctions instance is ready to be used and it | - | ||||||||||||||||||
| 723 | does not need initializeOpenGLFunctions() to be called. | - | ||||||||||||||||||
| 724 | */ | - | ||||||||||||||||||
| 725 | QOpenGLFunctions *QOpenGLContext::functions() const | - | ||||||||||||||||||
| 726 | { | - | ||||||||||||||||||
| 727 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 728 | if (!d->functions)
| 0 | ||||||||||||||||||
| 729 | const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext()); never executed: const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext()); | 0 | ||||||||||||||||||
| 730 | return d->functions; never executed: return d->functions; | 0 | ||||||||||||||||||
| 731 | } | - | ||||||||||||||||||
| 732 | - | |||||||||||||||||||
| 733 | /*! | - | ||||||||||||||||||
| 734 | Get the QOpenGLExtraFunctions instance for this context. | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | QOpenGLContext offers this as a convenient way to access QOpenGLExtraFunctions | - | ||||||||||||||||||
| 737 | without having to manage it manually. | - | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | The context or a sharing context must be current. | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | The returned QOpenGLExtraFunctions instance is ready to be used and it | - | ||||||||||||||||||
| 742 | does not need initializeOpenGLFunctions() to be called. | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | \note QOpenGLExtraFunctions contains functionality that is not guaranteed to | - | ||||||||||||||||||
| 745 | be available at runtime. Runtime availability depends on the platform, | - | ||||||||||||||||||
| 746 | graphics driver, and the OpenGL version requested by the application. | - | ||||||||||||||||||
| 747 | - | |||||||||||||||||||
| 748 | \sa QOpenGLFunctions, QOpenGLExtraFunctions | - | ||||||||||||||||||
| 749 | */ | - | ||||||||||||||||||
| 750 | QOpenGLExtraFunctions *QOpenGLContext::extraFunctions() const | - | ||||||||||||||||||
| 751 | { | - | ||||||||||||||||||
| 752 | return static_cast<QOpenGLExtraFunctions *>(functions()); never executed: return static_cast<QOpenGLExtraFunctions *>(functions()); | 0 | ||||||||||||||||||
| 753 | } | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | /*! | - | ||||||||||||||||||
| 756 | \fn T *QOpenGLContext::versionFunctions() const | - | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | \overload versionFunctions() | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | Returns a pointer to an object that provides access to all functions for | - | ||||||||||||||||||
| 761 | the version and profile of this context. There is no need to call | - | ||||||||||||||||||
| 762 | QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context | - | ||||||||||||||||||
| 763 | is current. It is also possible to call this function when the context is not | - | ||||||||||||||||||
| 764 | current, but in that case it is the caller's responsibility to ensure proper | - | ||||||||||||||||||
| 765 | initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() | - | ||||||||||||||||||
| 766 | afterwards. | - | ||||||||||||||||||
| 767 | - | |||||||||||||||||||
| 768 | Usually one would use the template version of this function to automatically | - | ||||||||||||||||||
| 769 | have the result cast to the correct type. | - | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | \code | - | ||||||||||||||||||
| 772 | QOpenGLFunctions_3_3_Core* funcs = 0; | - | ||||||||||||||||||
| 773 | funcs = context->versionFunctions<QOpenGLFunctions_3_3_Core>(); | - | ||||||||||||||||||
| 774 | if (!funcs) { | - | ||||||||||||||||||
| 775 | qWarning() << "Could not obtain required OpenGL context version"; | - | ||||||||||||||||||
| 776 | exit(1); | - | ||||||||||||||||||
| 777 | } | - | ||||||||||||||||||
| 778 | \endcode | - | ||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | It is possible to request a functions object for a different version and profile | - | ||||||||||||||||||
| 781 | than that for which the context was created. To do this either use the template | - | ||||||||||||||||||
| 782 | version of this function specifying the desired functions object type as the | - | ||||||||||||||||||
| 783 | template parameter or by passing in a QOpenGLVersionProfile object as an argument | - | ||||||||||||||||||
| 784 | to the non-template function. | - | ||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | Note that requests for function objects of other versions or profiles can fail and | - | ||||||||||||||||||
| 787 | in doing so will return a null pointer. Situations in which creation of the functions | - | ||||||||||||||||||
| 788 | object can fail are if the request cannot be satisfied due to asking for functions | - | ||||||||||||||||||
| 789 | that are not in the version or profile of this context. For example: | - | ||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | \list | - | ||||||||||||||||||
| 792 | \li Requesting a 3.3 core profile functions object would succeed. | - | ||||||||||||||||||
| 793 | \li Requesting a 3.3 compatibility profile functions object would fail. We would fail | - | ||||||||||||||||||
| 794 | to resolve the deprecated functions. | - | ||||||||||||||||||
| 795 | \li Requesting a 4.3 core profile functions object would fail. We would fail to resolve | - | ||||||||||||||||||
| 796 | the new core functions introduced in versions 4.0-4.3. | - | ||||||||||||||||||
| 797 | \li Requesting a 3.1 functions object would succeed. There is nothing in 3.1 that is not | - | ||||||||||||||||||
| 798 | also in 3.3 core. | - | ||||||||||||||||||
| 799 | \endlist | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | Note that if creating a functions object via this method that the QOpenGLContext | - | ||||||||||||||||||
| 802 | retains ownership of the object. This is to allow the object to be cached and shared. | - | ||||||||||||||||||
| 803 | */ | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | /*! | - | ||||||||||||||||||
| 806 | Returns a pointer to an object that provides access to all functions for the | - | ||||||||||||||||||
| 807 | \a versionProfile of this context. There is no need to call | - | ||||||||||||||||||
| 808 | QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context | - | ||||||||||||||||||
| 809 | is current. It is also possible to call this function when the context is not | - | ||||||||||||||||||
| 810 | current, but in that case it is the caller's responsibility to ensure proper | - | ||||||||||||||||||
| 811 | initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() | - | ||||||||||||||||||
| 812 | afterwards. | - | ||||||||||||||||||
| 813 | - | |||||||||||||||||||
| 814 | Usually one would use the template version of this function to automatically | - | ||||||||||||||||||
| 815 | have the result cast to the correct type. | - | ||||||||||||||||||
| 816 | */ | - | ||||||||||||||||||
| 817 | QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionProfile &versionProfile) const | - | ||||||||||||||||||
| 818 | { | - | ||||||||||||||||||
| 819 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 820 | if (isOpenGLES()) {
| 0 | ||||||||||||||||||
| 821 | qWarning("versionFunctions: Not supported on OpenGL ES"); | - | ||||||||||||||||||
| 822 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 823 | } | - | ||||||||||||||||||
| 824 | #endif // QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 827 | const QSurfaceFormat f = format(); | - | ||||||||||||||||||
| 828 | - | |||||||||||||||||||
| 829 | // Ensure we have a valid version and profile. Default to context's if none specified | - | ||||||||||||||||||
| 830 | QOpenGLVersionProfile vp = versionProfile; | - | ||||||||||||||||||
| 831 | if (!vp.isValid())
| 0 | ||||||||||||||||||
| 832 | vp = QOpenGLVersionProfile(f); never executed: vp = QOpenGLVersionProfile(f); | 0 | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | // Check that context is compatible with requested version | - | ||||||||||||||||||
| 835 | const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion()); | - | ||||||||||||||||||
| 836 | if (v < vp.version())
| 0 | ||||||||||||||||||
| 837 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 838 | - | |||||||||||||||||||
| 839 | // If this context only offers core profile functions then we can't create | - | ||||||||||||||||||
| 840 | // function objects for legacy or compatibility profile requests | - | ||||||||||||||||||
| 841 | if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
| 0 | ||||||||||||||||||
| 842 | && f.profile() == QSurfaceFormat::CoreProfile)
| 0 | ||||||||||||||||||
| 843 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 844 | - | |||||||||||||||||||
| 845 | // Create object if suitable one not cached | - | ||||||||||||||||||
| 846 | QAbstractOpenGLFunctions* funcs = 0; | - | ||||||||||||||||||
| 847 | if (!d->versionFunctions.contains(vp)) {
| 0 | ||||||||||||||||||
| 848 | funcs = QOpenGLVersionFunctionsFactory::create(vp); | - | ||||||||||||||||||
| 849 | if (funcs) {
| 0 | ||||||||||||||||||
| 850 | funcs->setOwningContext(this); | - | ||||||||||||||||||
| 851 | d->versionFunctions.insert(vp, funcs); | - | ||||||||||||||||||
| 852 | } never executed: end of block | 0 | ||||||||||||||||||
| 853 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 854 | funcs = d->versionFunctions.value(vp); | - | ||||||||||||||||||
| 855 | } never executed: end of block | 0 | ||||||||||||||||||
| 856 | - | |||||||||||||||||||
| 857 | if (funcs && QOpenGLContext::currentContext() == this)
| 0 | ||||||||||||||||||
| 858 | funcs->initializeOpenGLFunctions(); never executed: funcs->initializeOpenGLFunctions(); | 0 | ||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | return funcs; never executed: return funcs; | 0 | ||||||||||||||||||
| 861 | } | - | ||||||||||||||||||
| 862 | - | |||||||||||||||||||
| 863 | /*! | - | ||||||||||||||||||
| 864 | Returns the set of OpenGL extensions supported by this context. | - | ||||||||||||||||||
| 865 | - | |||||||||||||||||||
| 866 | The context or a sharing context must be current. | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | \sa hasExtension() | - | ||||||||||||||||||
| 869 | */ | - | ||||||||||||||||||
| 870 | QSet<QByteArray> QOpenGLContext::extensions() const | - | ||||||||||||||||||
| 871 | { | - | ||||||||||||||||||
| 872 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 873 | if (d->extensionNames.isEmpty()) {
| 0 | ||||||||||||||||||
| 874 | QOpenGLExtensionMatcher matcher; | - | ||||||||||||||||||
| 875 | d->extensionNames = matcher.extensions(); | - | ||||||||||||||||||
| 876 | } never executed: end of block | 0 | ||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | return d->extensionNames; never executed: return d->extensionNames; | 0 | ||||||||||||||||||
| 879 | } | - | ||||||||||||||||||
| 880 | - | |||||||||||||||||||
| 881 | /*! | - | ||||||||||||||||||
| 882 | Returns \c true if this OpenGL context supports the specified OpenGL | - | ||||||||||||||||||
| 883 | \a extension, \c false otherwise. | - | ||||||||||||||||||
| 884 | - | |||||||||||||||||||
| 885 | The context or a sharing context must be current. | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | \sa extensions() | - | ||||||||||||||||||
| 888 | */ | - | ||||||||||||||||||
| 889 | bool QOpenGLContext::hasExtension(const QByteArray &extension) const | - | ||||||||||||||||||
| 890 | { | - | ||||||||||||||||||
| 891 | return extensions().contains(extension); never executed: return extensions().contains(extension); | 0 | ||||||||||||||||||
| 892 | } | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | /*! | - | ||||||||||||||||||
| 895 | Call this to get the default framebuffer object for the current surface. | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | On some platforms (for instance, iOS) the default framebuffer object depends | - | ||||||||||||||||||
| 898 | on the surface being rendered to, and might be different from 0. Thus, | - | ||||||||||||||||||
| 899 | instead of calling glBindFramebuffer(0), you should call | - | ||||||||||||||||||
| 900 | glBindFramebuffer(ctx->defaultFramebufferObject()) if you want your | - | ||||||||||||||||||
| 901 | application to work across different Qt platforms. | - | ||||||||||||||||||
| 902 | - | |||||||||||||||||||
| 903 | If you use the glBindFramebuffer() in QOpenGLFunctions you do not have to | - | ||||||||||||||||||
| 904 | worry about this, as it automatically binds the current context's | - | ||||||||||||||||||
| 905 | defaultFramebufferObject() when 0 is passed. | - | ||||||||||||||||||
| 906 | - | |||||||||||||||||||
| 907 | \note Widgets that render via framebuffer objects, like QOpenGLWidget and | - | ||||||||||||||||||
| 908 | QQuickWidget, will override the value returned from this function when | - | ||||||||||||||||||
| 909 | painting is active, because at that time the correct "default" framebuffer | - | ||||||||||||||||||
| 910 | is the widget's associated backing framebuffer, not the platform-specific | - | ||||||||||||||||||
| 911 | one belonging to the top-level window's surface. This ensures the expected | - | ||||||||||||||||||
| 912 | behavior for this function and other classes relying on it (for example, | - | ||||||||||||||||||
| 913 | QOpenGLFramebufferObject::bindDefault() or | - | ||||||||||||||||||
| 914 | QOpenGLFramebufferObject::release()). | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | \sa QOpenGLFramebufferObject | - | ||||||||||||||||||
| 917 | */ | - | ||||||||||||||||||
| 918 | GLuint QOpenGLContext::defaultFramebufferObject() const | - | ||||||||||||||||||
| 919 | { | - | ||||||||||||||||||
| 920 | if (!isValid())
| 0 | ||||||||||||||||||
| 921 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 924 | if (!d->surface || !d->surface->surfaceHandle())
| 0 | ||||||||||||||||||
| 925 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 926 | - | |||||||||||||||||||
| 927 | if (d->defaultFboRedirect)
| 0 | ||||||||||||||||||
| 928 | return d->defaultFboRedirect; never executed: return d->defaultFboRedirect; | 0 | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | return d->platformGLContext->defaultFramebufferObject(d->surface->surfaceHandle()); never executed: return d->platformGLContext->defaultFramebufferObject(d->surface->surfaceHandle()); | 0 | ||||||||||||||||||
| 931 | } | - | ||||||||||||||||||
| 932 | - | |||||||||||||||||||
| 933 | /*! | - | ||||||||||||||||||
| 934 | Makes the context current in the current thread, against the given | - | ||||||||||||||||||
| 935 | \a surface. Returns \c true if successful. | - | ||||||||||||||||||
| 936 | - | |||||||||||||||||||
| 937 | If \a surface is 0 this is equivalent to calling doneCurrent(). | - | ||||||||||||||||||
| 938 | - | |||||||||||||||||||
| 939 | Do not call this function from a different thread than the one the | - | ||||||||||||||||||
| 940 | QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a | - | ||||||||||||||||||
| 941 | different thread you should first call make sure it's not current in the | - | ||||||||||||||||||
| 942 | current thread, by calling doneCurrent() if necessary. Then call | - | ||||||||||||||||||
| 943 | moveToThread(otherThread) before using it in the other thread. | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | \sa functions(), doneCurrent() | - | ||||||||||||||||||
| 946 | */ | - | ||||||||||||||||||
| 947 | bool QOpenGLContext::makeCurrent(QSurface *surface) | - | ||||||||||||||||||
| 948 | { | - | ||||||||||||||||||
| 949 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 950 | if (!isValid())
| 0 | ||||||||||||||||||
| 951 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 952 | - | |||||||||||||||||||
| 953 | if (thread() != QThread::currentThread())
| 0 | ||||||||||||||||||
| 954 | qFatal("Cannot make QOpenGLContext current in a different thread"); never executed: QMessageLogger(__FILE__, 954, __PRETTY_FUNCTION__).fatal("Cannot make QOpenGLContext current in a different thread"); | 0 | ||||||||||||||||||
| 955 | - | |||||||||||||||||||
| 956 | if (!surface) {
| 0 | ||||||||||||||||||
| 957 | doneCurrent(); | - | ||||||||||||||||||
| 958 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 959 | } | - | ||||||||||||||||||
| 960 | - | |||||||||||||||||||
| 961 | if (!surface->surfaceHandle())
| 0 | ||||||||||||||||||
| 962 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 963 | if (!surface->supportsOpenGL()) {
| 0 | ||||||||||||||||||
| 964 | qWarning() << "QOpenGLContext::makeCurrent() called with non-opengl surface" << surface; | - | ||||||||||||||||||
| 965 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 966 | } | - | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | QOpenGLContext *previous = QOpenGLContextPrivate::setCurrentContext(this); | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
| 0 | ||||||||||||||||||
| 971 | d->surface = surface; | - | ||||||||||||||||||
| 972 | - | |||||||||||||||||||
| 973 | d->shareGroup->d_func()->deletePendingResources(this); | - | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 976 | QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true); | - | ||||||||||||||||||
| 977 | #endif | - | ||||||||||||||||||
| 978 | - | |||||||||||||||||||
| 979 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 980 | } | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | QOpenGLContextPrivate::setCurrentContext(previous); | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 985 | } | - | ||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | /*! | - | ||||||||||||||||||
| 988 | Convenience function for calling makeCurrent with a 0 surface. | - | ||||||||||||||||||
| 989 | - | |||||||||||||||||||
| 990 | This results in no context being current in the current thread. | - | ||||||||||||||||||
| 991 | - | |||||||||||||||||||
| 992 | \sa makeCurrent(), currentContext() | - | ||||||||||||||||||
| 993 | */ | - | ||||||||||||||||||
| 994 | void QOpenGLContext::doneCurrent() | - | ||||||||||||||||||
| 995 | { | - | ||||||||||||||||||
| 996 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 997 | if (!isValid())
| 0 | ||||||||||||||||||
| 998 | return; never executed: return; | 0 | ||||||||||||||||||
| 999 | - | |||||||||||||||||||
| 1000 | if (QOpenGLContext::currentContext() == this)
| 0 | ||||||||||||||||||
| 1001 | d->shareGroup->d_func()->deletePendingResources(this); never executed: d->shareGroup->d_func()->deletePendingResources(this); | 0 | ||||||||||||||||||
| 1002 | - | |||||||||||||||||||
| 1003 | d->platformGLContext->doneCurrent(); | - | ||||||||||||||||||
| 1004 | QOpenGLContextPrivate::setCurrentContext(0); | - | ||||||||||||||||||
| 1005 | - | |||||||||||||||||||
| 1006 | d->surface = 0; | - | ||||||||||||||||||
| 1007 | } never executed: end of block | 0 | ||||||||||||||||||
| 1008 | - | |||||||||||||||||||
| 1009 | /*! | - | ||||||||||||||||||
| 1010 | Returns the surface the context has been made current with. | - | ||||||||||||||||||
| 1011 | - | |||||||||||||||||||
| 1012 | This is the surface passed as an argument to makeCurrent(). | - | ||||||||||||||||||
| 1013 | */ | - | ||||||||||||||||||
| 1014 | QSurface *QOpenGLContext::surface() const | - | ||||||||||||||||||
| 1015 | { | - | ||||||||||||||||||
| 1016 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1017 | return d->surface; never executed: return d->surface; | 0 | ||||||||||||||||||
| 1018 | } | - | ||||||||||||||||||
| 1019 | - | |||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | /*! | - | ||||||||||||||||||
| 1022 | Swap the back and front buffers of \a surface. | - | ||||||||||||||||||
| 1023 | - | |||||||||||||||||||
| 1024 | Call this to finish a frame of OpenGL rendering, and make sure to | - | ||||||||||||||||||
| 1025 | call makeCurrent() again before you begin a new frame. | - | ||||||||||||||||||
| 1026 | */ | - | ||||||||||||||||||
| 1027 | void QOpenGLContext::swapBuffers(QSurface *surface) | - | ||||||||||||||||||
| 1028 | { | - | ||||||||||||||||||
| 1029 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1030 | if (!isValid())
| 0 | ||||||||||||||||||
| 1031 | return; never executed: return; | 0 | ||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | if (!surface) {
| 0 | ||||||||||||||||||
| 1034 | qWarning() << "QOpenGLContext::swapBuffers() called with null argument"; | - | ||||||||||||||||||
| 1035 | return; never executed: return; | 0 | ||||||||||||||||||
| 1036 | } | - | ||||||||||||||||||
| 1037 | - | |||||||||||||||||||
| 1038 | if (!surface->supportsOpenGL()) {
| 0 | ||||||||||||||||||
| 1039 | qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface"; | - | ||||||||||||||||||
| 1040 | return; never executed: return; | 0 | ||||||||||||||||||
| 1041 | } | - | ||||||||||||||||||
| 1042 | - | |||||||||||||||||||
| 1043 | if (surface->surfaceClass() == QSurface::Window
| 0 | ||||||||||||||||||
| 1044 | && !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose)
| 0 | ||||||||||||||||||
| 1045 | { | - | ||||||||||||||||||
| 1046 | qWarning() << "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined"; | - | ||||||||||||||||||
| 1047 | } never executed: end of block | 0 | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | QPlatformSurface *surfaceHandle = surface->surfaceHandle(); | - | ||||||||||||||||||
| 1050 | if (!surfaceHandle)
| 0 | ||||||||||||||||||
| 1051 | return; never executed: return; | 0 | ||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | #if !defined(QT_NO_DEBUG) | - | ||||||||||||||||||
| 1054 | if (!QOpenGLContextPrivate::toggleMakeCurrentTracker(this, false))
| 0 | ||||||||||||||||||
| 1055 | qWarning() << "QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"; never executed: QMessageLogger(__FILE__, 1055, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"; | 0 | ||||||||||||||||||
| 1056 | #endif | - | ||||||||||||||||||
| 1057 | if (surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer)
| 0 | ||||||||||||||||||
| 1058 | functions()->glFlush(); never executed: functions()->glFlush(); | 0 | ||||||||||||||||||
| 1059 | d->platformGLContext->swapBuffers(surfaceHandle); | - | ||||||||||||||||||
| 1060 | } never executed: end of block | 0 | ||||||||||||||||||
| 1061 | - | |||||||||||||||||||
| 1062 | /*! | - | ||||||||||||||||||
| 1063 | Resolves the function pointer to an OpenGL extension function, identified by \a procName | - | ||||||||||||||||||
| 1064 | - | |||||||||||||||||||
| 1065 | Returns 0 if no such function can be found. | - | ||||||||||||||||||
| 1066 | */ | - | ||||||||||||||||||
| 1067 | QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) const | - | ||||||||||||||||||
| 1068 | { | - | ||||||||||||||||||
| 1069 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1070 | if (!d->platformGLContext)
| 0 | ||||||||||||||||||
| 1071 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1072 | return d->platformGLContext->getProcAddress(procName); never executed: return d->platformGLContext->getProcAddress(procName); | 0 | ||||||||||||||||||
| 1073 | } | - | ||||||||||||||||||
| 1074 | - | |||||||||||||||||||
| 1075 | /*! | - | ||||||||||||||||||
| 1076 | Returns the format of the underlying platform context, if create() has been called. | - | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | Otherwise, returns the requested format. | - | ||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| 1080 | The requested and the actual format may differ. Requesting a given OpenGL version does | - | ||||||||||||||||||
| 1081 | not mean the resulting context will target exactly the requested version. It is only | - | ||||||||||||||||||
| 1082 | guaranteed that the version/profile/options combination for the created context is | - | ||||||||||||||||||
| 1083 | compatible with the request, as long as the driver is able to provide such a context. | - | ||||||||||||||||||
| 1084 | - | |||||||||||||||||||
| 1085 | For example, requesting an OpenGL version 3.x core profile context may result in an | - | ||||||||||||||||||
| 1086 | OpenGL 4.x core profile context. Similarly, a request for OpenGL 2.1 may result in an | - | ||||||||||||||||||
| 1087 | OpenGL 3.0 context with deprecated functions enabled. Finally, depending on the | - | ||||||||||||||||||
| 1088 | driver, unsupported versions may result in either a context creation failure or in a | - | ||||||||||||||||||
| 1089 | context for the highest supported version. | - | ||||||||||||||||||
| 1090 | - | |||||||||||||||||||
| 1091 | Similar differences are possible in the buffer sizes, for example, the resulting | - | ||||||||||||||||||
| 1092 | context may have a larger depth buffer than requested. This is perfectly normal. | - | ||||||||||||||||||
| 1093 | */ | - | ||||||||||||||||||
| 1094 | QSurfaceFormat QOpenGLContext::format() const | - | ||||||||||||||||||
| 1095 | { | - | ||||||||||||||||||
| 1096 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1097 | if (!d->platformGLContext)
| 0 | ||||||||||||||||||
| 1098 | return d->requestedFormat; never executed: return d->requestedFormat; | 0 | ||||||||||||||||||
| 1099 | return d->platformGLContext->format(); never executed: return d->platformGLContext->format(); | 0 | ||||||||||||||||||
| 1100 | } | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | /*! | - | ||||||||||||||||||
| 1103 | Returns the share group this context belongs to. | - | ||||||||||||||||||
| 1104 | */ | - | ||||||||||||||||||
| 1105 | QOpenGLContextGroup *QOpenGLContext::shareGroup() const | - | ||||||||||||||||||
| 1106 | { | - | ||||||||||||||||||
| 1107 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1108 | return d->shareGroup; never executed: return d->shareGroup; | 0 | ||||||||||||||||||
| 1109 | } | - | ||||||||||||||||||
| 1110 | - | |||||||||||||||||||
| 1111 | /*! | - | ||||||||||||||||||
| 1112 | Returns the share context this context was created with. | - | ||||||||||||||||||
| 1113 | - | |||||||||||||||||||
| 1114 | If the underlying platform was not able to support the requested | - | ||||||||||||||||||
| 1115 | sharing, this will return 0. | - | ||||||||||||||||||
| 1116 | */ | - | ||||||||||||||||||
| 1117 | QOpenGLContext *QOpenGLContext::shareContext() const | - | ||||||||||||||||||
| 1118 | { | - | ||||||||||||||||||
| 1119 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1120 | return d->shareContext; never executed: return d->shareContext; | 0 | ||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||
| 1122 | - | |||||||||||||||||||
| 1123 | /*! | - | ||||||||||||||||||
| 1124 | Returns the screen the context was created for. | - | ||||||||||||||||||
| 1125 | */ | - | ||||||||||||||||||
| 1126 | QScreen *QOpenGLContext::screen() const | - | ||||||||||||||||||
| 1127 | { | - | ||||||||||||||||||
| 1128 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1129 | return d->screen; never executed: return d->screen; | 0 | ||||||||||||||||||
| 1130 | } | - | ||||||||||||||||||
| 1131 | - | |||||||||||||||||||
| 1132 | /*! | - | ||||||||||||||||||
| 1133 | internal: Needs to have a pointer to qGLContext. But since this is in Qt GUI we can't | - | ||||||||||||||||||
| 1134 | have any type information. | - | ||||||||||||||||||
| 1135 | - | |||||||||||||||||||
| 1136 | \internal | - | ||||||||||||||||||
| 1137 | */ | - | ||||||||||||||||||
| 1138 | void *QOpenGLContext::qGLContextHandle() const | - | ||||||||||||||||||
| 1139 | { | - | ||||||||||||||||||
| 1140 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1141 | return d->qGLContextHandle; never executed: return d->qGLContextHandle; | 0 | ||||||||||||||||||
| 1142 | } | - | ||||||||||||||||||
| 1143 | - | |||||||||||||||||||
| 1144 | /*! | - | ||||||||||||||||||
| 1145 | internal: If the delete function is specified QOpenGLContext "owns" | - | ||||||||||||||||||
| 1146 | the passed context handle and will use the delete function to destroy it. | - | ||||||||||||||||||
| 1147 | - | |||||||||||||||||||
| 1148 | \internal | - | ||||||||||||||||||
| 1149 | */ | - | ||||||||||||||||||
| 1150 | void QOpenGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)) | - | ||||||||||||||||||
| 1151 | { | - | ||||||||||||||||||
| 1152 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1153 | d->qGLContextHandle = handle; | - | ||||||||||||||||||
| 1154 | d->qGLContextDeleteFunction = qGLContextDeleteFunction; | - | ||||||||||||||||||
| 1155 | } never executed: end of block | 0 | ||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | /*! | - | ||||||||||||||||||
| 1158 | \internal | - | ||||||||||||||||||
| 1159 | */ | - | ||||||||||||||||||
| 1160 | void QOpenGLContext::deleteQGLContext() | - | ||||||||||||||||||
| 1161 | { | - | ||||||||||||||||||
| 1162 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1163 | if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
| 0 | ||||||||||||||||||
| 1164 | d->qGLContextDeleteFunction(d->qGLContextHandle); | - | ||||||||||||||||||
| 1165 | d->qGLContextDeleteFunction = 0; | - | ||||||||||||||||||
| 1166 | d->qGLContextHandle = 0; | - | ||||||||||||||||||
| 1167 | } never executed: end of block | 0 | ||||||||||||||||||
| 1168 | } never executed: end of block | 0 | ||||||||||||||||||
| 1169 | - | |||||||||||||||||||
| 1170 | /*! | - | ||||||||||||||||||
| 1171 | Returns the platform-specific handle for the OpenGL implementation that | - | ||||||||||||||||||
| 1172 | is currently in use. (for example, a HMODULE on Windows) | - | ||||||||||||||||||
| 1173 | - | |||||||||||||||||||
| 1174 | On platforms that do not use dynamic GL switch the return value is null. | - | ||||||||||||||||||
| 1175 | - | |||||||||||||||||||
| 1176 | The library might be GL-only, meaning that windowing system interface | - | ||||||||||||||||||
| 1177 | functions (for example EGL) may live in another, separate library. | - | ||||||||||||||||||
| 1178 | - | |||||||||||||||||||
| 1179 | \note This function requires that the QGuiApplication instance is already created. | - | ||||||||||||||||||
| 1180 | - | |||||||||||||||||||
| 1181 | \sa openGLModuleType() | - | ||||||||||||||||||
| 1182 | - | |||||||||||||||||||
| 1183 | \since 5.3 | - | ||||||||||||||||||
| 1184 | */ | - | ||||||||||||||||||
| 1185 | void *QOpenGLContext::openGLModuleHandle() | - | ||||||||||||||||||
| 1186 | { | - | ||||||||||||||||||
| 1187 | #ifdef QT_OPENGL_DYNAMIC | - | ||||||||||||||||||
| 1188 | QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface(); | - | ||||||||||||||||||
| 1189 | Q_ASSERT(ni); | - | ||||||||||||||||||
| 1190 | return ni->nativeResourceForIntegration(QByteArrayLiteral("glhandle")); | - | ||||||||||||||||||
| 1191 | #else | - | ||||||||||||||||||
| 1192 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1193 | #endif | - | ||||||||||||||||||
| 1194 | } | - | ||||||||||||||||||
| 1195 | - | |||||||||||||||||||
| 1196 | /*! | - | ||||||||||||||||||
| 1197 | \enum QOpenGLContext::OpenGLModuleType | - | ||||||||||||||||||
| 1198 | This enum defines the type of the underlying OpenGL implementation. | - | ||||||||||||||||||
| 1199 | - | |||||||||||||||||||
| 1200 | \value LibGL OpenGL | - | ||||||||||||||||||
| 1201 | \value LibGLES OpenGL ES 2.0 or higher | - | ||||||||||||||||||
| 1202 | - | |||||||||||||||||||
| 1203 | \since 5.3 | - | ||||||||||||||||||
| 1204 | */ | - | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | /*! | - | ||||||||||||||||||
| 1207 | Returns the underlying OpenGL implementation type. | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | On platforms where the OpenGL implementation is not dynamically | - | ||||||||||||||||||
| 1210 | loaded, the return value is determined during compile time and never | - | ||||||||||||||||||
| 1211 | changes. | - | ||||||||||||||||||
| 1212 | - | |||||||||||||||||||
| 1213 | \note A desktop OpenGL implementation may be capable of creating | - | ||||||||||||||||||
| 1214 | ES-compatible contexts too. Therefore in most cases it is more | - | ||||||||||||||||||
| 1215 | appropriate to check QSurfaceFormat::renderableType() or using the | - | ||||||||||||||||||
| 1216 | the convenience function isOpenGLES(). | - | ||||||||||||||||||
| 1217 | - | |||||||||||||||||||
| 1218 | \note This function requires that the QGuiApplication instance is already created. | - | ||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | \since 5.3 | - | ||||||||||||||||||
| 1221 | */ | - | ||||||||||||||||||
| 1222 | QOpenGLContext::OpenGLModuleType QOpenGLContext::openGLModuleType() | - | ||||||||||||||||||
| 1223 | { | - | ||||||||||||||||||
| 1224 | #if defined(QT_OPENGL_DYNAMIC) | - | ||||||||||||||||||
| 1225 | Q_ASSERT(qGuiApp); | - | ||||||||||||||||||
| 1226 | return QGuiApplicationPrivate::instance()->platformIntegration()->openGLModuleType(); | - | ||||||||||||||||||
| 1227 | #elif defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 1228 | return LibGLES; | - | ||||||||||||||||||
| 1229 | #else | - | ||||||||||||||||||
| 1230 | return LibGL; never executed: return LibGL; | 0 | ||||||||||||||||||
| 1231 | #endif | - | ||||||||||||||||||
| 1232 | } | - | ||||||||||||||||||
| 1233 | - | |||||||||||||||||||
| 1234 | /*! | - | ||||||||||||||||||
| 1235 | Returns true if the context is an OpenGL ES context. | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | If the context has not yet been created, the result is based on the | - | ||||||||||||||||||
| 1238 | requested format set via setFormat(). | - | ||||||||||||||||||
| 1239 | - | |||||||||||||||||||
| 1240 | \sa create(), format(), setFormat() | - | ||||||||||||||||||
| 1241 | - | |||||||||||||||||||
| 1242 | \since 5.3 | - | ||||||||||||||||||
| 1243 | */ | - | ||||||||||||||||||
| 1244 | bool QOpenGLContext::isOpenGLES() const | - | ||||||||||||||||||
| 1245 | { | - | ||||||||||||||||||
| 1246 | return format().renderableType() == QSurfaceFormat::OpenGLES; never executed: return format().renderableType() == QSurfaceFormat::OpenGLES; | 0 | ||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | /*! | - | ||||||||||||||||||
| 1250 | Returns \c true if the platform supports OpenGL rendering outside the main (gui) | - | ||||||||||||||||||
| 1251 | thread. | - | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | The value is controlled by the platform plugin in use and may also depend on the | - | ||||||||||||||||||
| 1254 | graphics drivers. | - | ||||||||||||||||||
| 1255 | - | |||||||||||||||||||
| 1256 | \since 5.5 | - | ||||||||||||||||||
| 1257 | */ | - | ||||||||||||||||||
| 1258 | bool QOpenGLContext::supportsThreadedOpenGL() | - | ||||||||||||||||||
| 1259 | { | - | ||||||||||||||||||
| 1260 | Q_ASSERT(qGuiApp); | - | ||||||||||||||||||
| 1261 | return QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL); never executed: return QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL); | 0 | ||||||||||||||||||
| 1262 | } | - | ||||||||||||||||||
| 1263 | - | |||||||||||||||||||
| 1264 | /*! | - | ||||||||||||||||||
| 1265 | \since 5.5 | - | ||||||||||||||||||
| 1266 | - | |||||||||||||||||||
| 1267 | Returns the application-wide shared OpenGL context, if present. | - | ||||||||||||||||||
| 1268 | Otherwise, returns a null pointer. | - | ||||||||||||||||||
| 1269 | - | |||||||||||||||||||
| 1270 | This is useful if you need to upload OpenGL objects (buffers, textures, | - | ||||||||||||||||||
| 1271 | etc.) before creating or showing a QOpenGLWidget or QQuickWidget. | - | ||||||||||||||||||
| 1272 | - | |||||||||||||||||||
| 1273 | \note You must set the Qt::AA_ShareOpenGLContexts flag on QGuiApplication | - | ||||||||||||||||||
| 1274 | before creating the QGuiApplication object, otherwise Qt may not create a | - | ||||||||||||||||||
| 1275 | global shared context. | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | \warning Do not attempt to make the context returned by this function | - | ||||||||||||||||||
| 1278 | current on any surface. Instead, you can create a new context which shares | - | ||||||||||||||||||
| 1279 | with the global one, and then make the new context current. | - | ||||||||||||||||||
| 1280 | - | |||||||||||||||||||
| 1281 | \sa Qt::AA_ShareOpenGLContexts, setShareContext(), makeCurrent() | - | ||||||||||||||||||
| 1282 | */ | - | ||||||||||||||||||
| 1283 | QOpenGLContext *QOpenGLContext::globalShareContext() | - | ||||||||||||||||||
| 1284 | { | - | ||||||||||||||||||
| 1285 | Q_ASSERT(qGuiApp); | - | ||||||||||||||||||
| 1286 | return qt_gl_global_share_context(); never executed: return qt_gl_global_share_context(); | 0 | ||||||||||||||||||
| 1287 | } | - | ||||||||||||||||||
| 1288 | - | |||||||||||||||||||
| 1289 | /*! | - | ||||||||||||||||||
| 1290 | \internal | - | ||||||||||||||||||
| 1291 | */ | - | ||||||||||||||||||
| 1292 | QOpenGLVersionFunctionsBackend *QOpenGLContext::functionsBackend(const QOpenGLVersionStatus &v) const | - | ||||||||||||||||||
| 1293 | { | - | ||||||||||||||||||
| 1294 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1295 | return d->versionFunctionsBackend.value(v, 0); never executed: return d->versionFunctionsBackend.value(v, 0); | 0 | ||||||||||||||||||
| 1296 | } | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | /*! | - | ||||||||||||||||||
| 1299 | \internal | - | ||||||||||||||||||
| 1300 | */ | - | ||||||||||||||||||
| 1301 | void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionStatus &v, | - | ||||||||||||||||||
| 1302 | QOpenGLVersionFunctionsBackend *backend) | - | ||||||||||||||||||
| 1303 | { | - | ||||||||||||||||||
| 1304 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1305 | d->versionFunctionsBackend.insert(v, backend); | - | ||||||||||||||||||
| 1306 | } never executed: end of block | 0 | ||||||||||||||||||
| 1307 | - | |||||||||||||||||||
| 1308 | /*! | - | ||||||||||||||||||
| 1309 | \internal | - | ||||||||||||||||||
| 1310 | */ | - | ||||||||||||||||||
| 1311 | void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionStatus &v) | - | ||||||||||||||||||
| 1312 | { | - | ||||||||||||||||||
| 1313 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1314 | d->versionFunctionsBackend.remove(v); | - | ||||||||||||||||||
| 1315 | } never executed: end of block | 0 | ||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | /*! | - | ||||||||||||||||||
| 1318 | \internal | - | ||||||||||||||||||
| 1319 | */ | - | ||||||||||||||||||
| 1320 | void QOpenGLContext::insertExternalFunctions(QAbstractOpenGLFunctions *f) | - | ||||||||||||||||||
| 1321 | { | - | ||||||||||||||||||
| 1322 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1323 | d->externalVersionFunctions.insert(f); | - | ||||||||||||||||||
| 1324 | } never executed: end of block | 0 | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | /*! | - | ||||||||||||||||||
| 1327 | \internal | - | ||||||||||||||||||
| 1328 | */ | - | ||||||||||||||||||
| 1329 | void QOpenGLContext::removeExternalFunctions(QAbstractOpenGLFunctions *f) | - | ||||||||||||||||||
| 1330 | { | - | ||||||||||||||||||
| 1331 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1332 | d->externalVersionFunctions.remove(f); | - | ||||||||||||||||||
| 1333 | } never executed: end of block | 0 | ||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | /*! | - | ||||||||||||||||||
| 1336 | \internal | - | ||||||||||||||||||
| 1337 | */ | - | ||||||||||||||||||
| 1338 | QOpenGLTextureHelper* QOpenGLContext::textureFunctions() const | - | ||||||||||||||||||
| 1339 | { | - | ||||||||||||||||||
| 1340 | Q_D(const QOpenGLContext); | - | ||||||||||||||||||
| 1341 | return d->textureFunctions; never executed: return d->textureFunctions; | 0 | ||||||||||||||||||
| 1342 | } | - | ||||||||||||||||||
| 1343 | - | |||||||||||||||||||
| 1344 | /*! | - | ||||||||||||||||||
| 1345 | \internal | - | ||||||||||||||||||
| 1346 | */ | - | ||||||||||||||||||
| 1347 | void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs) | - | ||||||||||||||||||
| 1348 | { | - | ||||||||||||||||||
| 1349 | Q_D(QOpenGLContext); | - | ||||||||||||||||||
| 1350 | d->textureFunctions = textureFuncs; | - | ||||||||||||||||||
| 1351 | } never executed: end of block | 0 | ||||||||||||||||||
| 1352 | - | |||||||||||||||||||
| 1353 | /*! | - | ||||||||||||||||||
| 1354 | \class QOpenGLContextGroup | - | ||||||||||||||||||
| 1355 | \since 5.0 | - | ||||||||||||||||||
| 1356 | \brief The QOpenGLContextGroup class represents a group of contexts sharing | - | ||||||||||||||||||
| 1357 | OpenGL resources. | - | ||||||||||||||||||
| 1358 | \inmodule QtGui | - | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | QOpenGLContextGroup is automatically created and managed by QOpenGLContext | - | ||||||||||||||||||
| 1361 | instances. Its purpose is to identify all the contexts that are sharing | - | ||||||||||||||||||
| 1362 | resources. | - | ||||||||||||||||||
| 1363 | - | |||||||||||||||||||
| 1364 | \sa QOpenGLContext::shareGroup() | - | ||||||||||||||||||
| 1365 | */ | - | ||||||||||||||||||
| 1366 | QOpenGLContextGroup::QOpenGLContextGroup() | - | ||||||||||||||||||
| 1367 | : QObject(*new QOpenGLContextGroupPrivate()) | - | ||||||||||||||||||
| 1368 | { | - | ||||||||||||||||||
| 1369 | } never executed: end of block | 0 | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | /*! | - | ||||||||||||||||||
| 1372 | \internal | - | ||||||||||||||||||
| 1373 | */ | - | ||||||||||||||||||
| 1374 | QOpenGLContextGroup::~QOpenGLContextGroup() | - | ||||||||||||||||||
| 1375 | { | - | ||||||||||||||||||
| 1376 | Q_D(QOpenGLContextGroup); | - | ||||||||||||||||||
| 1377 | d->cleanup(); | - | ||||||||||||||||||
| 1378 | } never executed: end of block | 0 | ||||||||||||||||||
| 1379 | - | |||||||||||||||||||
| 1380 | /*! | - | ||||||||||||||||||
| 1381 | Returns all the QOpenGLContext objects in this share group. | - | ||||||||||||||||||
| 1382 | */ | - | ||||||||||||||||||
| 1383 | QList<QOpenGLContext *> QOpenGLContextGroup::shares() const | - | ||||||||||||||||||
| 1384 | { | - | ||||||||||||||||||
| 1385 | Q_D(const QOpenGLContextGroup); | - | ||||||||||||||||||
| 1386 | return d->m_shares; never executed: return d->m_shares; | 0 | ||||||||||||||||||
| 1387 | } | - | ||||||||||||||||||
| 1388 | - | |||||||||||||||||||
| 1389 | /*! | - | ||||||||||||||||||
| 1390 | Returns the QOpenGLContextGroup corresponding to the current context. | - | ||||||||||||||||||
| 1391 | - | |||||||||||||||||||
| 1392 | \sa QOpenGLContext::currentContext() | - | ||||||||||||||||||
| 1393 | */ | - | ||||||||||||||||||
| 1394 | QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() | - | ||||||||||||||||||
| 1395 | { | - | ||||||||||||||||||
| 1396 | QOpenGLContext *current = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 1397 | return current ? current->shareGroup() : 0; never executed: return current ? current->shareGroup() : 0;
| 0 | ||||||||||||||||||
| 1398 | } | - | ||||||||||||||||||
| 1399 | - | |||||||||||||||||||
| 1400 | void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx) | - | ||||||||||||||||||
| 1401 | { | - | ||||||||||||||||||
| 1402 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
| 1403 | m_refs.ref(); | - | ||||||||||||||||||
| 1404 | m_shares << ctx; | - | ||||||||||||||||||
| 1405 | } never executed: end of block | 0 | ||||||||||||||||||
| 1406 | - | |||||||||||||||||||
| 1407 | void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx) | - | ||||||||||||||||||
| 1408 | { | - | ||||||||||||||||||
| 1409 | Q_Q(QOpenGLContextGroup); | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | bool deleteObject = false; | - | ||||||||||||||||||
| 1412 | - | |||||||||||||||||||
| 1413 | { | - | ||||||||||||||||||
| 1414 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
| 1415 | m_shares.removeOne(ctx); | - | ||||||||||||||||||
| 1416 | - | |||||||||||||||||||
| 1417 | if (ctx == m_context && !m_shares.isEmpty())
| 0 | ||||||||||||||||||
| 1418 | m_context = m_shares.first(); never executed: m_context = m_shares.first(); | 0 | ||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | if (!m_refs.deref()) {
| 0 | ||||||||||||||||||
| 1421 | cleanup(); | - | ||||||||||||||||||
| 1422 | deleteObject = true; | - | ||||||||||||||||||
| 1423 | } never executed: end of block | 0 | ||||||||||||||||||
| 1424 | } | - | ||||||||||||||||||
| 1425 | - | |||||||||||||||||||
| 1426 | if (deleteObject) {
| 0 | ||||||||||||||||||
| 1427 | if (q->thread() == QThread::currentThread())
| 0 | ||||||||||||||||||
| 1428 | delete q; // Delete directly to prevent leak, refer to QTBUG-29056 never executed: delete q; | 0 | ||||||||||||||||||
| 1429 | else | - | ||||||||||||||||||
| 1430 | q->deleteLater(); never executed: q->deleteLater(); | 0 | ||||||||||||||||||
| 1431 | } | - | ||||||||||||||||||
| 1432 | } never executed: end of block | 0 | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | void QOpenGLContextGroupPrivate::cleanup() | - | ||||||||||||||||||
| 1435 | { | - | ||||||||||||||||||
| 1436 | Q_Q(QOpenGLContextGroup); | - | ||||||||||||||||||
| 1437 | { | - | ||||||||||||||||||
| 1438 | QHash<QOpenGLMultiGroupSharedResource *, QOpenGLSharedResource *>::const_iterator it, end; | - | ||||||||||||||||||
| 1439 | end = m_resources.constEnd(); | - | ||||||||||||||||||
| 1440 | for (it = m_resources.constBegin(); it != end; ++it)
| 0 | ||||||||||||||||||
| 1441 | it.key()->cleanup(q, it.value()); never executed: it.key()->cleanup(q, it.value()); | 0 | ||||||||||||||||||
| 1442 | m_resources.clear(); | - | ||||||||||||||||||
| 1443 | } | - | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin(); | - | ||||||||||||||||||
| 1446 | QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end(); | - | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | while (it != end) {
| 0 | ||||||||||||||||||
| 1449 | (*it)->invalidateResource(); | - | ||||||||||||||||||
| 1450 | (*it)->m_group = 0; | - | ||||||||||||||||||
| 1451 | ++it; | - | ||||||||||||||||||
| 1452 | } never executed: end of block | 0 | ||||||||||||||||||
| 1453 | - | |||||||||||||||||||
| 1454 | m_sharedResources.clear(); | - | ||||||||||||||||||
| 1455 | - | |||||||||||||||||||
| 1456 | qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end()); | - | ||||||||||||||||||
| 1457 | m_pendingDeletion.clear(); | - | ||||||||||||||||||
| 1458 | } never executed: end of block | 0 | ||||||||||||||||||
| 1459 | - | |||||||||||||||||||
| 1460 | void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) | - | ||||||||||||||||||
| 1461 | { | - | ||||||||||||||||||
| 1462 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
| 1463 | - | |||||||||||||||||||
| 1464 | const QList<QOpenGLSharedResource *> pending = m_pendingDeletion; | - | ||||||||||||||||||
| 1465 | m_pendingDeletion.clear(); | - | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | QList<QOpenGLSharedResource *>::const_iterator it = pending.begin(); | - | ||||||||||||||||||
| 1468 | QList<QOpenGLSharedResource *>::const_iterator end = pending.end(); | - | ||||||||||||||||||
| 1469 | while (it != end) {
| 0 | ||||||||||||||||||
| 1470 | (*it)->freeResource(ctx); | - | ||||||||||||||||||
| 1471 | delete *it; | - | ||||||||||||||||||
| 1472 | ++it; | - | ||||||||||||||||||
| 1473 | } never executed: end of block | 0 | ||||||||||||||||||
| 1474 | } never executed: end of block | 0 | ||||||||||||||||||
| 1475 | - | |||||||||||||||||||
| 1476 | /*! | - | ||||||||||||||||||
| 1477 | \class QOpenGLSharedResource | - | ||||||||||||||||||
| 1478 | \internal | - | ||||||||||||||||||
| 1479 | \since 5.0 | - | ||||||||||||||||||
| 1480 | \brief The QOpenGLSharedResource class is used to keep track of resources | - | ||||||||||||||||||
| 1481 | that are shared between OpenGL contexts (like textures, framebuffer | - | ||||||||||||||||||
| 1482 | objects, shader programs, etc), and clean them up in a safe way when | - | ||||||||||||||||||
| 1483 | they're no longer needed. | - | ||||||||||||||||||
| 1484 | \inmodule QtGui | - | ||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | The QOpenGLSharedResource instance should never be deleted, instead free() | - | ||||||||||||||||||
| 1487 | should be called when it's no longer needed. Thus it will be put on a queue | - | ||||||||||||||||||
| 1488 | and freed at an appropriate time (when a context in the share group becomes | - | ||||||||||||||||||
| 1489 | current). | - | ||||||||||||||||||
| 1490 | - | |||||||||||||||||||
| 1491 | The sub-class needs to implement two pure virtual functions. The first, | - | ||||||||||||||||||
| 1492 | freeResource() must be implemented to actually do the freeing, for example | - | ||||||||||||||||||
| 1493 | call glDeleteTextures() on a texture id. Qt makes sure a valid context in | - | ||||||||||||||||||
| 1494 | the resource's share group is current at the time. The other, | - | ||||||||||||||||||
| 1495 | invalidateResource(), is called by Qt in the circumstance when the last | - | ||||||||||||||||||
| 1496 | context in the share group is destroyed before free() has been called. The | - | ||||||||||||||||||
| 1497 | implementation of invalidateResource() should set any identifiers to 0 or | - | ||||||||||||||||||
| 1498 | set a flag to prevent them from being used later on. | - | ||||||||||||||||||
| 1499 | */ | - | ||||||||||||||||||
| 1500 | QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group) | - | ||||||||||||||||||
| 1501 | : m_group(group) | - | ||||||||||||||||||
| 1502 | { | - | ||||||||||||||||||
| 1503 | QMutexLocker locker(&m_group->d_func()->m_mutex); | - | ||||||||||||||||||
| 1504 | m_group->d_func()->m_sharedResources << this; | - | ||||||||||||||||||
| 1505 | } never executed: end of block | 0 | ||||||||||||||||||
| 1506 | - | |||||||||||||||||||
| 1507 | QOpenGLSharedResource::~QOpenGLSharedResource() | - | ||||||||||||||||||
| 1508 | { | - | ||||||||||||||||||
| 1509 | } | - | ||||||||||||||||||
| 1510 | - | |||||||||||||||||||
| 1511 | // schedule the resource for deletion at an appropriate time | - | ||||||||||||||||||
| 1512 | void QOpenGLSharedResource::free() | - | ||||||||||||||||||
| 1513 | { | - | ||||||||||||||||||
| 1514 | if (!m_group) {
| 0 | ||||||||||||||||||
| 1515 | delete this; | - | ||||||||||||||||||
| 1516 | return; never executed: return; | 0 | ||||||||||||||||||
| 1517 | } | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | QMutexLocker locker(&m_group->d_func()->m_mutex); | - | ||||||||||||||||||
| 1520 | m_group->d_func()->m_sharedResources.removeOne(this); | - | ||||||||||||||||||
| 1521 | m_group->d_func()->m_pendingDeletion << this; | - | ||||||||||||||||||
| 1522 | - | |||||||||||||||||||
| 1523 | // can we delete right away? | - | ||||||||||||||||||
| 1524 | QOpenGLContext *current = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 1525 | if (current && current->shareGroup() == m_group) {
| 0 | ||||||||||||||||||
| 1526 | m_group->d_func()->deletePendingResources(current); | - | ||||||||||||||||||
| 1527 | } never executed: end of block | 0 | ||||||||||||||||||
| 1528 | } never executed: end of block | 0 | ||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | /*! | - | ||||||||||||||||||
| 1531 | \class QOpenGLSharedResourceGuard | - | ||||||||||||||||||
| 1532 | \internal | - | ||||||||||||||||||
| 1533 | \since 5.0 | - | ||||||||||||||||||
| 1534 | \brief The QOpenGLSharedResourceGuard class is a convenience sub-class of | - | ||||||||||||||||||
| 1535 | QOpenGLSharedResource to be used to track a single OpenGL object with a | - | ||||||||||||||||||
| 1536 | GLuint identifier. The constructor takes a function pointer to a function | - | ||||||||||||||||||
| 1537 | that will be used to free the resource if and when necessary. | - | ||||||||||||||||||
| 1538 | \inmodule QtGui | - | ||||||||||||||||||
| 1539 | - | |||||||||||||||||||
| 1540 | */ | - | ||||||||||||||||||
| 1541 | void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context) | - | ||||||||||||||||||
| 1542 | { | - | ||||||||||||||||||
| 1543 | if (m_id) {
| 0 | ||||||||||||||||||
| 1544 | QOpenGLFunctions functions(context); | - | ||||||||||||||||||
| 1545 | m_func(&functions, m_id); | - | ||||||||||||||||||
| 1546 | m_id = 0; | - | ||||||||||||||||||
| 1547 | } never executed: end of block | 0 | ||||||||||||||||||
| 1548 | } never executed: end of block | 0 | ||||||||||||||||||
| 1549 | - | |||||||||||||||||||
| 1550 | /*! | - | ||||||||||||||||||
| 1551 | \class QOpenGLMultiGroupSharedResource | - | ||||||||||||||||||
| 1552 | \internal | - | ||||||||||||||||||
| 1553 | \since 5.0 | - | ||||||||||||||||||
| 1554 | \brief The QOpenGLMultiGroupSharedResource keeps track of a shared resource | - | ||||||||||||||||||
| 1555 | that might be needed from multiple contexts, like a glyph cache or gradient | - | ||||||||||||||||||
| 1556 | cache. One instance of the object is created for each group when necessary. | - | ||||||||||||||||||
| 1557 | The shared resource instance should have a constructor that takes a | - | ||||||||||||||||||
| 1558 | QOpenGLContext *. To get an instance for a given context one calls | - | ||||||||||||||||||
| 1559 | T *QOpenGLMultiGroupSharedResource::value<T>(context), where T is a sub-class | - | ||||||||||||||||||
| 1560 | of QOpenGLSharedResource. | - | ||||||||||||||||||
| 1561 | \inmodule QtGui | - | ||||||||||||||||||
| 1562 | - | |||||||||||||||||||
| 1563 | You should not call free() on QOpenGLSharedResources owned by a | - | ||||||||||||||||||
| 1564 | QOpenGLMultiGroupSharedResource instance. | - | ||||||||||||||||||
| 1565 | */ | - | ||||||||||||||||||
| 1566 | QOpenGLMultiGroupSharedResource::QOpenGLMultiGroupSharedResource() | - | ||||||||||||||||||
| 1567 | : active(0), | - | ||||||||||||||||||
| 1568 | m_mutex(QMutex::Recursive) | - | ||||||||||||||||||
| 1569 | { | - | ||||||||||||||||||
| 1570 | #ifdef QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
| 1571 | qDebug("Creating context group resource object %p.", this); | - | ||||||||||||||||||
| 1572 | #endif | - | ||||||||||||||||||
| 1573 | } never executed: end of block | 0 | ||||||||||||||||||
| 1574 | - | |||||||||||||||||||
| 1575 | QOpenGLMultiGroupSharedResource::~QOpenGLMultiGroupSharedResource() | - | ||||||||||||||||||
| 1576 | { | - | ||||||||||||||||||
| 1577 | #ifdef QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
| 1578 | qDebug("Deleting context group resource %p. Group size: %d.", this, m_groups.size()); | - | ||||||||||||||||||
| 1579 | #endif | - | ||||||||||||||||||
| 1580 | for (int i = 0; i < m_groups.size(); ++i) {
| 0 | ||||||||||||||||||
| 1581 | if (!m_groups.at(i)->shares().isEmpty()) {
| 0 | ||||||||||||||||||
| 1582 | QOpenGLContext *context = m_groups.at(i)->shares().first(); | - | ||||||||||||||||||
| 1583 | QOpenGLSharedResource *resource = value(context); | - | ||||||||||||||||||
| 1584 | if (resource)
| 0 | ||||||||||||||||||
| 1585 | resource->free(); never executed: resource->free(); | 0 | ||||||||||||||||||
| 1586 | } never executed: end of block | 0 | ||||||||||||||||||
| 1587 | m_groups.at(i)->d_func()->m_resources.remove(this); | - | ||||||||||||||||||
| 1588 | active.deref(); | - | ||||||||||||||||||
| 1589 | } never executed: end of block | 0 | ||||||||||||||||||
| 1590 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 1591 | if (active.load() != 0) {
| 0 | ||||||||||||||||||
| 1592 | qWarning("QtGui: Resources are still available at program shutdown.\n" | - | ||||||||||||||||||
| 1593 | " This is possibly caused by a leaked QOpenGLWidget, \n" | - | ||||||||||||||||||
| 1594 | " QOpenGLFramebufferObject or QOpenGLPixelBuffer."); | - | ||||||||||||||||||
| 1595 | } never executed: end of block | 0 | ||||||||||||||||||
| 1596 | #endif | - | ||||||||||||||||||
| 1597 | } never executed: end of block | 0 | ||||||||||||||||||
| 1598 | - | |||||||||||||||||||
| 1599 | void QOpenGLMultiGroupSharedResource::insert(QOpenGLContext *context, QOpenGLSharedResource *value) | - | ||||||||||||||||||
| 1600 | { | - | ||||||||||||||||||
| 1601 | #ifdef QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
| 1602 | qDebug("Inserting context group resource %p for context %p, managed by %p.", value, context, this); | - | ||||||||||||||||||
| 1603 | #endif | - | ||||||||||||||||||
| 1604 | QOpenGLContextGroup *group = context->shareGroup(); | - | ||||||||||||||||||
| 1605 | Q_ASSERT(!group->d_func()->m_resources.contains(this)); | - | ||||||||||||||||||
| 1606 | group->d_func()->m_resources.insert(this, value); | - | ||||||||||||||||||
| 1607 | m_groups.append(group); | - | ||||||||||||||||||
| 1608 | active.ref(); | - | ||||||||||||||||||
| 1609 | } never executed: end of block | 0 | ||||||||||||||||||
| 1610 | - | |||||||||||||||||||
| 1611 | QOpenGLSharedResource *QOpenGLMultiGroupSharedResource::value(QOpenGLContext *context) | - | ||||||||||||||||||
| 1612 | { | - | ||||||||||||||||||
| 1613 | QOpenGLContextGroup *group = context->shareGroup(); | - | ||||||||||||||||||
| 1614 | return group->d_func()->m_resources.value(this, 0); never executed: return group->d_func()->m_resources.value(this, 0); | 0 | ||||||||||||||||||
| 1615 | } | - | ||||||||||||||||||
| 1616 | - | |||||||||||||||||||
| 1617 | QList<QOpenGLSharedResource *> QOpenGLMultiGroupSharedResource::resources() const | - | ||||||||||||||||||
| 1618 | { | - | ||||||||||||||||||
| 1619 | QList<QOpenGLSharedResource *> result; | - | ||||||||||||||||||
| 1620 | for (QList<QOpenGLContextGroup *>::const_iterator it = m_groups.constBegin(); it != m_groups.constEnd(); ++it) {
| 0 | ||||||||||||||||||
| 1621 | QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), 0); | - | ||||||||||||||||||
| 1622 | if (resource)
| 0 | ||||||||||||||||||
| 1623 | result << resource; never executed: result << resource; | 0 | ||||||||||||||||||
| 1624 | } never executed: end of block | 0 | ||||||||||||||||||
| 1625 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 1626 | } | - | ||||||||||||||||||
| 1627 | - | |||||||||||||||||||
| 1628 | void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenGLSharedResource *value) | - | ||||||||||||||||||
| 1629 | { | - | ||||||||||||||||||
| 1630 | #ifdef QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
| 1631 | qDebug("Cleaning up context group resource %p, for group %p in thread %p.", this, group, QThread::currentThread()); | - | ||||||||||||||||||
| 1632 | #endif | - | ||||||||||||||||||
| 1633 | value->invalidateResource(); | - | ||||||||||||||||||
| 1634 | value->free(); | - | ||||||||||||||||||
| 1635 | active.deref(); | - | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | Q_ASSERT(m_groups.contains(group)); | - | ||||||||||||||||||
| 1638 | m_groups.removeOne(group); | - | ||||||||||||||||||
| 1639 | } never executed: end of block | 0 | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | #include "moc_qopenglcontext.cpp" | - | ||||||||||||||||||
| 1642 | - | |||||||||||||||||||
| 1643 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |