| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/qgl.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qapplication.h" | - | ||||||||||||||||||
| 41 | #include "qplatformdefs.h" | - | ||||||||||||||||||
| 42 | #include "qgl.h" | - | ||||||||||||||||||
| 43 | #include <qdebug.h> | - | ||||||||||||||||||
| 44 | #include <qglfunctions.h> | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | #include <qdatetime.h> | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | #include <stdlib.h> // malloc | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include "qpixmap.h" | - | ||||||||||||||||||
| 51 | #include "qimage.h" | - | ||||||||||||||||||
| 52 | #include "qgl_p.h" | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #include "gl2paintengineex/qpaintengineex_opengl2_p.h" | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | #include <qpa/qplatformopenglcontext.h> | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | #include <qglpixelbuffer.h> | - | ||||||||||||||||||
| 59 | #include <qglframebufferobject.h> | - | ||||||||||||||||||
| 60 | #include <private/qopenglextensions_p.h> | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | #include <private/qimage_p.h> | - | ||||||||||||||||||
| 63 | #include <qpa/qplatformpixmap.h> | - | ||||||||||||||||||
| 64 | #include <private/qglpixelbuffer_p.h> | - | ||||||||||||||||||
| 65 | #include <private/qimagepixmapcleanuphooks_p.h> | - | ||||||||||||||||||
| 66 | #include "qcolormap.h" | - | ||||||||||||||||||
| 67 | #include "qfile.h" | - | ||||||||||||||||||
| 68 | #include "qlibrary.h" | - | ||||||||||||||||||
| 69 | #include <qmutex.h> | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | #include "qsurfaceformat.h" | - | ||||||||||||||||||
| 72 | #include <private/qapplication_p.h> | - | ||||||||||||||||||
| 73 | #include <qpa/qplatformopenglcontext.h> | - | ||||||||||||||||||
| 74 | #include <qpa/qplatformwindow.h> | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 77 | #include <qopenglfunctions_1_1.h> | - | ||||||||||||||||||
| 78 | #endif | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | // #define QT_GL_CONTEXT_RESOURCE_DEBUG | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | class QGLDefaultExtensions | - | ||||||||||||||||||
| 85 | { | - | ||||||||||||||||||
| 86 | public: | - | ||||||||||||||||||
| 87 | QGLDefaultExtensions() : extensions(0) { | - | ||||||||||||||||||
| 88 | QGLTemporaryContext tempContext; | - | ||||||||||||||||||
| 89 | Q_ASSERT(QOpenGLContext::currentContext()); | - | ||||||||||||||||||
| 90 | QOpenGLExtensions *ext = qgl_extensions(); | - | ||||||||||||||||||
| 91 | Q_ASSERT(ext); | - | ||||||||||||||||||
| 92 | extensions = ext->openGLExtensions(); | - | ||||||||||||||||||
| 93 | features = ext->openGLFeatures(); | - | ||||||||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | QOpenGLFunctions::OpenGLFeatures features; | - | ||||||||||||||||||
| 97 | QOpenGLExtensions::OpenGLExtensions extensions; | - | ||||||||||||||||||
| 98 | }; | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | bool qgl_hasFeature(QOpenGLFunctions::OpenGLFeature feature) | - | ||||||||||||||||||
| 103 | { | - | ||||||||||||||||||
| 104 | if (QOpenGLContext::currentContext())
| 0 | ||||||||||||||||||
| 105 | return QOpenGLContext::currentContext()->functions()->hasOpenGLFeature(feature); never executed: return QOpenGLContext::currentContext()->functions()->hasOpenGLFeature(feature); | 0 | ||||||||||||||||||
| 106 | return qtDefaultExtensions()->features & feature; never executed: return qtDefaultExtensions()->features & feature; | 0 | ||||||||||||||||||
| 107 | } | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | bool qgl_hasExtension(QOpenGLExtensions::OpenGLExtension extension) | - | ||||||||||||||||||
| 110 | { | - | ||||||||||||||||||
| 111 | if (QOpenGLContext::currentContext())
| 0 | ||||||||||||||||||
| 112 | return qgl_extensions()->hasOpenGLExtension(extension); never executed: return qgl_extensions()->hasOpenGLExtension(extension); | 0 | ||||||||||||||||||
| 113 | return qtDefaultExtensions()->extensions & extension; never executed: return qtDefaultExtensions()->extensions & extension; | 0 | ||||||||||||||||||
| 114 | } | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | QOpenGLExtensions::OpenGLExtensions extensions; | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | /* | - | ||||||||||||||||||
| 119 | Returns the GL extensions for the current QOpenGLContext. If there is no | - | ||||||||||||||||||
| 120 | current QOpenGLContext, a default context will be created and the extensions | - | ||||||||||||||||||
| 121 | for that context will be returned instead. | - | ||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||
| 123 | QOpenGLExtensions* qgl_extensions() | - | ||||||||||||||||||
| 124 | { | - | ||||||||||||||||||
| 125 | if (QOpenGLContext *context = QOpenGLContext::currentContext())
| 0-1 | ||||||||||||||||||
| 126 | return static_cast<QOpenGLExtensions *>(context->functions()); executed 1 time by 1 test: return static_cast<QOpenGLExtensions *>(context->functions());Executed by:
| 1 | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | Q_ASSERT(false); | - | ||||||||||||||||||
| 129 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 130 | } | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | QOpenGLFunctions *qgl_functions() | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | return qgl_extensions(); // QOpenGLExtensions is just a subclass of QOpenGLFunctions executed 1 time by 1 test: return qgl_extensions();Executed by:
| 1 | ||||||||||||||||||
| 135 | } | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 138 | QOpenGLFunctions_1_1 *qgl1_functions() | - | ||||||||||||||||||
| 139 | { | - | ||||||||||||||||||
| 140 | QOpenGLFunctions_1_1 *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_1_1>(); | - | ||||||||||||||||||
| 141 | f->initializeOpenGLFunctions(); | - | ||||||||||||||||||
| 142 | return f; never executed: return f; | 0 | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | #endif | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | struct QGLThreadContext { | - | ||||||||||||||||||
| 147 | ~QGLThreadContext() { | - | ||||||||||||||||||
| 148 | if (context)
| 0 | ||||||||||||||||||
| 149 | context->doneCurrent(); never executed: context->doneCurrent(); | 0 | ||||||||||||||||||
| 150 | } never executed: end of block | 0 | ||||||||||||||||||
| 151 | QGLContext *context; | - | ||||||||||||||||||
| 152 | }; | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | Q_GLOBAL_STATIC(QGLFormat, qgl_default_format) executed 3 times by 3 tests: end of blockExecuted by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 12 times by 3 tests: return &holder.value;Executed by:
| 0-12 | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | class QGLDefaultOverlayFormat: public QGLFormat | - | ||||||||||||||||||
| 157 | { | - | ||||||||||||||||||
| 158 | public: | - | ||||||||||||||||||
| 159 | inline QGLDefaultOverlayFormat() | - | ||||||||||||||||||
| 160 | { | - | ||||||||||||||||||
| 161 | setOption(QGL::FormatOption(0xffff << 16)); // turn off all options | - | ||||||||||||||||||
| 162 | setOption(QGL::DirectRendering); | - | ||||||||||||||||||
| 163 | setPlane(1); | - | ||||||||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||||||||
| 165 | }; | - | ||||||||||||||||||
| 166 | Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy) executed 3 times by 3 tests: end of blockExecuted by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 12 times by 3 tests: return &holder.value;Executed by:
| 0-12 | ||||||||||||||||||
| 169 | QGLSignalProxy *QGLSignalProxy::instance() | - | ||||||||||||||||||
| 170 | { | - | ||||||||||||||||||
| 171 | QGLSignalProxy *proxy = theSignalProxy(); | - | ||||||||||||||||||
| 172 | if (proxy && qApp && proxy->thread() != qApp->thread()) {
| 0-12 | ||||||||||||||||||
| 173 | if (proxy->thread() == QThread::currentThread())
| 0 | ||||||||||||||||||
| 174 | proxy->moveToThread(qApp->thread()); never executed: proxy->moveToThread((static_cast<QApplication *>(QCoreApplication::instance()))->thread()); | 0 | ||||||||||||||||||
| 175 | } never executed: end of block | 0 | ||||||||||||||||||
| 176 | return proxy; executed 12 times by 3 tests: return proxy;Executed by:
| 12 | ||||||||||||||||||
| 177 | } | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | /*! | - | ||||||||||||||||||
| 181 | \namespace QGL | - | ||||||||||||||||||
| 182 | \inmodule QtOpenGL | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | \brief The QGL namespace specifies miscellaneous identifiers used | - | ||||||||||||||||||
| 185 | in the Qt OpenGL module. | - | ||||||||||||||||||
| 186 | */ | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | /*! | - | ||||||||||||||||||
| 189 | \enum QGL::FormatOption | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | This enum specifies the format options that can be used to configure an OpenGL | - | ||||||||||||||||||
| 192 | context. These are set using QGLFormat::setOption(). | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | \value DoubleBuffer Specifies the use of double buffering. | - | ||||||||||||||||||
| 195 | \value DepthBuffer Enables the use of a depth buffer. | - | ||||||||||||||||||
| 196 | \value Rgba Specifies that the context should use RGBA as its pixel format. | - | ||||||||||||||||||
| 197 | \value AlphaChannel Enables the use of an alpha channel. | - | ||||||||||||||||||
| 198 | \value AccumBuffer Enables the use of an accumulation buffer. | - | ||||||||||||||||||
| 199 | \value StencilBuffer Enables the use of a stencil buffer. | - | ||||||||||||||||||
| 200 | \value StereoBuffers Enables the use of a stereo buffers for use with visualization hardware. | - | ||||||||||||||||||
| 201 | \value DirectRendering Specifies that the context is used for direct rendering to a display. | - | ||||||||||||||||||
| 202 | \value HasOverlay Enables the use of an overlay. | - | ||||||||||||||||||
| 203 | \value SampleBuffers Enables the use of sample buffers. | - | ||||||||||||||||||
| 204 | \value DeprecatedFunctions Enables the use of deprecated functionality for OpenGL 3.x | - | ||||||||||||||||||
| 205 | contexts. A context with deprecated functionality enabled is | - | ||||||||||||||||||
| 206 | called a full context in the OpenGL specification. | - | ||||||||||||||||||
| 207 | \value SingleBuffer Specifies the use of a single buffer, as opposed to double buffers. | - | ||||||||||||||||||
| 208 | \value NoDepthBuffer Disables the use of a depth buffer. | - | ||||||||||||||||||
| 209 | \value ColorIndex Specifies that the context should use a color index as its pixel format. | - | ||||||||||||||||||
| 210 | \value NoAlphaChannel Disables the use of an alpha channel. | - | ||||||||||||||||||
| 211 | \value NoAccumBuffer Disables the use of an accumulation buffer. | - | ||||||||||||||||||
| 212 | \value NoStencilBuffer Disables the use of a stencil buffer. | - | ||||||||||||||||||
| 213 | \value NoStereoBuffers Disables the use of stereo buffers. | - | ||||||||||||||||||
| 214 | \value IndirectRendering Specifies that the context is used for indirect rendering to a buffer. | - | ||||||||||||||||||
| 215 | \value NoOverlay Disables the use of an overlay. | - | ||||||||||||||||||
| 216 | \value NoSampleBuffers Disables the use of sample buffers. | - | ||||||||||||||||||
| 217 | \value NoDeprecatedFunctions Disables the use of deprecated functionality for OpenGL 3.x | - | ||||||||||||||||||
| 218 | contexts. A context with deprecated functionality disabled is | - | ||||||||||||||||||
| 219 | called a forward compatible context in the OpenGL specification. | - | ||||||||||||||||||
| 220 | */ | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | /***************************************************************************** | - | ||||||||||||||||||
| 223 | QGLFormat implementation | - | ||||||||||||||||||
| 224 | *****************************************************************************/ | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | /*! | - | ||||||||||||||||||
| 228 | \class QGLFormat | - | ||||||||||||||||||
| 229 | \inmodule QtOpenGL | - | ||||||||||||||||||
| 230 | \obsolete | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | \brief The QGLFormat class specifies the display format of an OpenGL | - | ||||||||||||||||||
| 233 | rendering context. | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | A display format has several characteristics: | - | ||||||||||||||||||
| 236 | \list | - | ||||||||||||||||||
| 237 | \li \l{setDoubleBuffer()}{Double or single buffering.} | - | ||||||||||||||||||
| 238 | \li \l{setDepth()}{Depth buffer.} | - | ||||||||||||||||||
| 239 | \li \l{setRgba()}{RGBA or color index mode.} | - | ||||||||||||||||||
| 240 | \li \l{setAlpha()}{Alpha channel.} | - | ||||||||||||||||||
| 241 | \li \l{setAccum()}{Accumulation buffer.} | - | ||||||||||||||||||
| 242 | \li \l{setStencil()}{Stencil buffer.} | - | ||||||||||||||||||
| 243 | \li \l{setStereo()}{Stereo buffers.} | - | ||||||||||||||||||
| 244 | \li \l{setDirectRendering()}{Direct rendering.} | - | ||||||||||||||||||
| 245 | \li \l{setOverlay()}{Presence of an overlay.} | - | ||||||||||||||||||
| 246 | \li \l{setPlane()}{Plane of an overlay.} | - | ||||||||||||||||||
| 247 | \li \l{setSampleBuffers()}{Multisample buffers.} | - | ||||||||||||||||||
| 248 | \endlist | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | You can also specify preferred bit depths for the color buffer, | - | ||||||||||||||||||
| 251 | depth buffer, alpha buffer, accumulation buffer and the stencil | - | ||||||||||||||||||
| 252 | buffer with the functions: setRedBufferSize(), setGreenBufferSize(), | - | ||||||||||||||||||
| 253 | setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), | - | ||||||||||||||||||
| 254 | setAccumBufferSize() and setStencilBufferSize(). | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | Note that even if you specify that you prefer a 32 bit depth | - | ||||||||||||||||||
| 257 | buffer (e.g. with setDepthBufferSize(32)), the format that is | - | ||||||||||||||||||
| 258 | chosen may not have a 32 bit depth buffer, even if there is a | - | ||||||||||||||||||
| 259 | format available with a 32 bit depth buffer. The main reason for | - | ||||||||||||||||||
| 260 | this is how the system dependant picking algorithms work on the | - | ||||||||||||||||||
| 261 | different platforms, and some format options may have higher | - | ||||||||||||||||||
| 262 | precedence than others. | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | You create and tell a QGLFormat object what rendering options you | - | ||||||||||||||||||
| 265 | want from an OpenGL rendering context. | - | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | OpenGL drivers or accelerated hardware may or may not support | - | ||||||||||||||||||
| 268 | advanced features such as alpha channel or stereographic viewing. | - | ||||||||||||||||||
| 269 | If you request some features that the driver/hardware does not | - | ||||||||||||||||||
| 270 | provide when you create a QGLWidget, you will get a rendering | - | ||||||||||||||||||
| 271 | context with the nearest subset of features. | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | There are different ways to define the display characteristics of | - | ||||||||||||||||||
| 274 | a rendering context. One is to create a QGLFormat and make it the | - | ||||||||||||||||||
| 275 | default for the entire application: | - | ||||||||||||||||||
| 276 | \snippet code/src_opengl_qgl.cpp 0 | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | Or you can specify the desired format when creating an object of | - | ||||||||||||||||||
| 279 | your QGLWidget subclass: | - | ||||||||||||||||||
| 280 | \snippet code/src_opengl_qgl.cpp 1 | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | After the widget has been created, you can find out which of the | - | ||||||||||||||||||
| 283 | requested features the system was able to provide: | - | ||||||||||||||||||
| 284 | \snippet code/src_opengl_qgl.cpp 2 | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | \legalese | - | ||||||||||||||||||
| 287 | OpenGL is a trademark of Silicon Graphics, Inc. in the | - | ||||||||||||||||||
| 288 | United States and other countries. | - | ||||||||||||||||||
| 289 | \endlegalese | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | \sa QGLContext, QGLWidget | - | ||||||||||||||||||
| 292 | */ | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) | - | ||||||||||||||||||
| 297 | { | - | ||||||||||||||||||
| 298 | #define M(row,col) m[col*4+row] | - | ||||||||||||||||||
| 299 | out[0] = | - | ||||||||||||||||||
| 300 | M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; | - | ||||||||||||||||||
| 301 | out[1] = | - | ||||||||||||||||||
| 302 | M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3]; | - | ||||||||||||||||||
| 303 | out[2] = | - | ||||||||||||||||||
| 304 | M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3]; | - | ||||||||||||||||||
| 305 | out[3] = | - | ||||||||||||||||||
| 306 | M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3]; | - | ||||||||||||||||||
| 307 | #undef M | - | ||||||||||||||||||
| 308 | } never executed: end of block | 0 | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, | - | ||||||||||||||||||
| 311 | const GLdouble model[16], const GLdouble proj[16], | - | ||||||||||||||||||
| 312 | const GLint viewport[4], | - | ||||||||||||||||||
| 313 | GLdouble * winx, GLdouble * winy, GLdouble * winz) | - | ||||||||||||||||||
| 314 | { | - | ||||||||||||||||||
| 315 | GLdouble in[4], out[4]; | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | in[0] = objx; | - | ||||||||||||||||||
| 318 | in[1] = objy; | - | ||||||||||||||||||
| 319 | in[2] = objz; | - | ||||||||||||||||||
| 320 | in[3] = 1.0; | - | ||||||||||||||||||
| 321 | transform_point(out, model, in); | - | ||||||||||||||||||
| 322 | transform_point(in, proj, out); | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | if (in[3] == 0.0)
| 0 | ||||||||||||||||||
| 325 | return GL_FALSE; never executed: return 0; | 0 | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | in[0] /= in[3]; | - | ||||||||||||||||||
| 328 | in[1] /= in[3]; | - | ||||||||||||||||||
| 329 | in[2] /= in[3]; | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2; | - | ||||||||||||||||||
| 332 | *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2; | - | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | *winz = (1 + in[2]) / 2; | - | ||||||||||||||||||
| 335 | return GL_TRUE; never executed: return 1; | 0 | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | #endif // !QT_OPENGL_ES | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | /*! | - | ||||||||||||||||||
| 341 | Constructs a QGLFormat object with the following default settings: | - | ||||||||||||||||||
| 342 | \list | - | ||||||||||||||||||
| 343 | \li \l{setDoubleBuffer()}{Double buffer:} Enabled. | - | ||||||||||||||||||
| 344 | \li \l{setDepth()}{Depth buffer:} Enabled. | - | ||||||||||||||||||
| 345 | \li \l{setRgba()}{RGBA:} Enabled (i.e., color index disabled). | - | ||||||||||||||||||
| 346 | \li \l{setAlpha()}{Alpha channel:} Disabled. | - | ||||||||||||||||||
| 347 | \li \l{setAccum()}{Accumulator buffer:} Disabled. | - | ||||||||||||||||||
| 348 | \li \l{setStencil()}{Stencil buffer:} Enabled. | - | ||||||||||||||||||
| 349 | \li \l{setStereo()}{Stereo:} Disabled. | - | ||||||||||||||||||
| 350 | \li \l{setDirectRendering()}{Direct rendering:} Enabled. | - | ||||||||||||||||||
| 351 | \li \l{setOverlay()}{Overlay:} Disabled. | - | ||||||||||||||||||
| 352 | \li \l{setPlane()}{Plane:} 0 (i.e., normal plane). | - | ||||||||||||||||||
| 353 | \li \l{setSampleBuffers()}{Multisample buffers:} Disabled. | - | ||||||||||||||||||
| 354 | \endlist | - | ||||||||||||||||||
| 355 | */ | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | QGLFormat::QGLFormat() | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | d = new QGLFormatPrivate; | - | ||||||||||||||||||
| 360 | } executed 39 times by 3 tests: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | /*! | - | ||||||||||||||||||
| 364 | Creates a QGLFormat object that is a copy of the current | - | ||||||||||||||||||
| 365 | defaultFormat(). | - | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | If \a options is not 0, the default format is modified by the | - | ||||||||||||||||||
| 368 | specified format options. The \a options parameter should be | - | ||||||||||||||||||
| 369 | QGL::FormatOption values OR'ed together. | - | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | This constructor makes it easy to specify a certain desired format | - | ||||||||||||||||||
| 372 | in classes derived from QGLWidget, for example: | - | ||||||||||||||||||
| 373 | \snippet code/src_opengl_qgl.cpp 3 | - | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | Note that there are QGL::FormatOption values to turn format settings | - | ||||||||||||||||||
| 376 | both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, | - | ||||||||||||||||||
| 377 | QGL::DirectRendering and QGL::IndirectRendering, etc. | - | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | The \a plane parameter defaults to 0 and is the plane which this | - | ||||||||||||||||||
| 380 | format should be associated with. Not all OpenGL implementations | - | ||||||||||||||||||
| 381 | supports overlay/underlay rendering planes. | - | ||||||||||||||||||
| 382 | - | |||||||||||||||||||
| 383 | \sa defaultFormat(), setOption(), setPlane() | - | ||||||||||||||||||
| 384 | */ | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) | - | ||||||||||||||||||
| 387 | { | - | ||||||||||||||||||
| 388 | d = new QGLFormatPrivate; | - | ||||||||||||||||||
| 389 | QGL::FormatOptions newOpts = options; | - | ||||||||||||||||||
| 390 | d->opts = defaultFormat().d->opts; | - | ||||||||||||||||||
| 391 | d->opts |= (newOpts & 0xffff); | - | ||||||||||||||||||
| 392 | d->opts &= ~(newOpts >> 16); | - | ||||||||||||||||||
| 393 | d->pln = plane; | - | ||||||||||||||||||
| 394 | } never executed: end of block | 0 | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | /*! | - | ||||||||||||||||||
| 397 | \internal | - | ||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||
| 399 | void QGLFormat::detach() | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | if (d->ref.load() != 1) {
| 0-180 | ||||||||||||||||||
| 402 | QGLFormatPrivate *newd = new QGLFormatPrivate(d); | - | ||||||||||||||||||
| 403 | if (!d->ref.deref())
| 0 | ||||||||||||||||||
| 404 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
| 405 | d = newd; | - | ||||||||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||||||||
| 407 | } executed 180 times by 3 tests: end of blockExecuted by:
| 180 | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | /*! | - | ||||||||||||||||||
| 410 | Constructs a copy of \a other. | - | ||||||||||||||||||
| 411 | */ | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | QGLFormat::QGLFormat(const QGLFormat &other) | - | ||||||||||||||||||
| 414 | { | - | ||||||||||||||||||
| 415 | d = other.d; | - | ||||||||||||||||||
| 416 | d->ref.ref(); | - | ||||||||||||||||||
| 417 | } executed 24 times by 3 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | /*! | - | ||||||||||||||||||
| 420 | Assigns \a other to this object. | - | ||||||||||||||||||
| 421 | */ | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | QGLFormat &QGLFormat::operator=(const QGLFormat &other) | - | ||||||||||||||||||
| 424 | { | - | ||||||||||||||||||
| 425 | if (d != other.d) {
| 0-36 | ||||||||||||||||||
| 426 | other.d->ref.ref(); | - | ||||||||||||||||||
| 427 | if (!d->ref.deref())
| 12-24 | ||||||||||||||||||
| 428 | delete d; executed 24 times by 3 tests: delete d;Executed by:
| 24 | ||||||||||||||||||
| 429 | d = other.d; | - | ||||||||||||||||||
| 430 | } executed 36 times by 3 tests: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 431 | return *this; executed 36 times by 3 tests: return *this;Executed by:
| 36 | ||||||||||||||||||
| 432 | } | - | ||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | /*! | - | ||||||||||||||||||
| 435 | Destroys the QGLFormat. | - | ||||||||||||||||||
| 436 | */ | - | ||||||||||||||||||
| 437 | QGLFormat::~QGLFormat() | - | ||||||||||||||||||
| 438 | { | - | ||||||||||||||||||
| 439 | if (!d->ref.deref())
| 15-48 | ||||||||||||||||||
| 440 | delete d; executed 15 times by 3 tests: delete d;Executed by:
| 15 | ||||||||||||||||||
| 441 | } executed 63 times by 3 tests: end of blockExecuted by:
| 63 | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | /*! | - | ||||||||||||||||||
| 444 | Returns an OpenGL format for the window format specified by \a format. | - | ||||||||||||||||||
| 445 | */ | - | ||||||||||||||||||
| 446 | QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format) | - | ||||||||||||||||||
| 447 | { | - | ||||||||||||||||||
| 448 | QGLFormat retFormat; | - | ||||||||||||||||||
| 449 | if (format.alphaBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 450 | retFormat.setAlphaBufferSize(format.alphaBufferSize()); executed 12 times by 3 tests: retFormat.setAlphaBufferSize(format.alphaBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 451 | if (format.blueBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 452 | retFormat.setBlueBufferSize(format.blueBufferSize()); executed 12 times by 3 tests: retFormat.setBlueBufferSize(format.blueBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 453 | if (format.greenBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 454 | retFormat.setGreenBufferSize(format.greenBufferSize()); executed 12 times by 3 tests: retFormat.setGreenBufferSize(format.greenBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 455 | if (format.redBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 456 | retFormat.setRedBufferSize(format.redBufferSize()); executed 12 times by 3 tests: retFormat.setRedBufferSize(format.redBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 457 | if (format.depthBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 458 | retFormat.setDepthBufferSize(format.depthBufferSize()); executed 12 times by 3 tests: retFormat.setDepthBufferSize(format.depthBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 459 | if (format.samples() > 1) {
| 0-12 | ||||||||||||||||||
| 460 | retFormat.setSampleBuffers(true); | - | ||||||||||||||||||
| 461 | retFormat.setSamples(format.samples()); | - | ||||||||||||||||||
| 462 | } never executed: end of block | 0 | ||||||||||||||||||
| 463 | if (format.stencilBufferSize() > 0) {
| 0-12 | ||||||||||||||||||
| 464 | retFormat.setStencil(true); | - | ||||||||||||||||||
| 465 | retFormat.setStencilBufferSize(format.stencilBufferSize()); | - | ||||||||||||||||||
| 466 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 467 | retFormat.setSwapInterval(format.swapInterval()); | - | ||||||||||||||||||
| 468 | retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer); | - | ||||||||||||||||||
| 469 | retFormat.setStereo(format.stereo()); | - | ||||||||||||||||||
| 470 | retFormat.setVersion(format.majorVersion(), format.minorVersion()); | - | ||||||||||||||||||
| 471 | retFormat.setProfile(static_cast<QGLFormat::OpenGLContextProfile>(format.profile())); | - | ||||||||||||||||||
| 472 | return retFormat; executed 12 times by 3 tests: return retFormat;Executed by:
| 12 | ||||||||||||||||||
| 473 | } | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | /*! | - | ||||||||||||||||||
| 476 | Returns a window format for the OpenGL format specified by \a format. | - | ||||||||||||||||||
| 477 | */ | - | ||||||||||||||||||
| 478 | QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format) | - | ||||||||||||||||||
| 479 | { | - | ||||||||||||||||||
| 480 | QSurfaceFormat retFormat; | - | ||||||||||||||||||
| 481 | if (format.alpha())
| 0-12 | ||||||||||||||||||
| 482 | retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); never executed: retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); | 0 | ||||||||||||||||||
| 483 | if (format.blueBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 484 | retFormat.setBlueBufferSize(format.blueBufferSize()); never executed: retFormat.setBlueBufferSize(format.blueBufferSize()); | 0 | ||||||||||||||||||
| 485 | if (format.greenBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 486 | retFormat.setGreenBufferSize(format.greenBufferSize()); never executed: retFormat.setGreenBufferSize(format.greenBufferSize()); | 0 | ||||||||||||||||||
| 487 | if (format.redBufferSize() >= 0)
| 0-12 | ||||||||||||||||||
| 488 | retFormat.setRedBufferSize(format.redBufferSize()); never executed: retFormat.setRedBufferSize(format.redBufferSize()); | 0 | ||||||||||||||||||
| 489 | if (format.depth())
| 0-12 | ||||||||||||||||||
| 490 | retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); executed 12 times by 3 tests: retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 491 | retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::SingleBuffer); | - | ||||||||||||||||||
| 492 | if (format.sampleBuffers())
| 0-12 | ||||||||||||||||||
| 493 | retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); never executed: retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); | 0 | ||||||||||||||||||
| 494 | if (format.stencil())
| 0-12 | ||||||||||||||||||
| 495 | retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); executed 12 times by 3 tests: retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize());Executed by:
| 12 | ||||||||||||||||||
| 496 | retFormat.setSwapInterval(format.swapInterval()); | - | ||||||||||||||||||
| 497 | retFormat.setStereo(format.stereo()); | - | ||||||||||||||||||
| 498 | retFormat.setMajorVersion(format.majorVersion()); | - | ||||||||||||||||||
| 499 | retFormat.setMinorVersion(format.minorVersion()); | - | ||||||||||||||||||
| 500 | retFormat.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>(format.profile())); | - | ||||||||||||||||||
| 501 | // QGLFormat has no way to set DeprecatedFunctions, that is, to tell that forward | - | ||||||||||||||||||
| 502 | // compatibility should not be requested. Some drivers fail to ignore the fwdcompat | - | ||||||||||||||||||
| 503 | // bit with compatibility profiles so make sure it is not set. | - | ||||||||||||||||||
| 504 | if (format.profile() == QGLFormat::CompatibilityProfile)
| 0-12 | ||||||||||||||||||
| 505 | retFormat.setOption(QSurfaceFormat::DeprecatedFunctions); never executed: retFormat.setOption(QSurfaceFormat::DeprecatedFunctions); | 0 | ||||||||||||||||||
| 506 | return retFormat; executed 12 times by 3 tests: return retFormat;Executed by:
| 12 | ||||||||||||||||||
| 507 | } | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | void QGLContextPrivate::setupSharing() { | - | ||||||||||||||||||
| 510 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 511 | QOpenGLContext *sharedContext = guiGlContext->shareContext(); | - | ||||||||||||||||||
| 512 | if (sharedContext) {
| 1-11 | ||||||||||||||||||
| 513 | QGLContext *actualSharedContext = QGLContext::fromOpenGLContext(sharedContext); | - | ||||||||||||||||||
| 514 | sharing = true; | - | ||||||||||||||||||
| 515 | QGLContextGroup::addShare(q, actualSharedContext); | - | ||||||||||||||||||
| 516 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 517 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | void QGLContextPrivate::refreshCurrentFbo() | - | ||||||||||||||||||
| 520 | { | - | ||||||||||||||||||
| 521 | QOpenGLContextPrivate *guiGlContextPrivate = | - | ||||||||||||||||||
| 522 | guiGlContext ? QOpenGLContextPrivate::get(guiGlContext) : 0;
| 0-48 | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | // if QOpenGLFramebufferObjects have been used in the mean-time, we've lost our cached value | - | ||||||||||||||||||
| 525 | if (guiGlContextPrivate && guiGlContextPrivate->qgl_current_fbo_invalid) {
| 0-48 | ||||||||||||||||||
| 526 | GLint current; | - | ||||||||||||||||||
| 527 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 528 | funcs->glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤t); | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | current_fbo = current; | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | guiGlContextPrivate->qgl_current_fbo_invalid = false; | - | ||||||||||||||||||
| 533 | } never executed: end of block | 0 | ||||||||||||||||||
| 534 | } executed 48 times by 1 test: end of blockExecuted by:
| 48 | ||||||||||||||||||
| 535 | - | |||||||||||||||||||
| 536 | void QGLContextPrivate::setCurrentFbo(GLuint fbo) | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | current_fbo = fbo; | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | QOpenGLContextPrivate *guiGlContextPrivate = | - | ||||||||||||||||||
| 541 | guiGlContext ? QOpenGLContextPrivate::get(guiGlContext) : 0;
| 0 | ||||||||||||||||||
| 542 | - | |||||||||||||||||||
| 543 | if (guiGlContextPrivate)
| 0 | ||||||||||||||||||
| 544 | guiGlContextPrivate->qgl_current_fbo_invalid = false; never executed: guiGlContextPrivate->qgl_current_fbo_invalid = false; | 0 | ||||||||||||||||||
| 545 | } never executed: end of block | 0 | ||||||||||||||||||
| 546 | - | |||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | /*! | - | ||||||||||||||||||
| 549 | \fn bool QGLFormat::doubleBuffer() const | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | Returns \c true if double buffering is enabled; otherwise returns | - | ||||||||||||||||||
| 552 | false. Double buffering is enabled by default. | - | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | \sa setDoubleBuffer() | - | ||||||||||||||||||
| 555 | */ | - | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | /*! | - | ||||||||||||||||||
| 558 | If \a enable is true sets double buffering; otherwise sets single | - | ||||||||||||||||||
| 559 | buffering. | - | ||||||||||||||||||
| 560 | - | |||||||||||||||||||
| 561 | Double buffering is enabled by default. | - | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | Double buffering is a technique where graphics are rendered on an | - | ||||||||||||||||||
| 564 | off-screen buffer and not directly to the screen. When the drawing | - | ||||||||||||||||||
| 565 | has been completed, the program calls a swapBuffers() function to | - | ||||||||||||||||||
| 566 | exchange the screen contents with the buffer. The result is | - | ||||||||||||||||||
| 567 | flicker-free drawing and often better performance. | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | Note that single buffered contexts are currently not supported | - | ||||||||||||||||||
| 570 | with EGL. | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | \sa doubleBuffer(), QGLContext::swapBuffers(), | - | ||||||||||||||||||
| 573 | QGLWidget::swapBuffers() | - | ||||||||||||||||||
| 574 | */ | - | ||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | void QGLFormat::setDoubleBuffer(bool enable) | - | ||||||||||||||||||
| 577 | { | - | ||||||||||||||||||
| 578 | setOption(enable ? QGL::DoubleBuffer : QGL::SingleBuffer); | - | ||||||||||||||||||
| 579 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | - | |||||||||||||||||||
| 582 | /*! | - | ||||||||||||||||||
| 583 | \fn bool QGLFormat::depth() const | - | ||||||||||||||||||
| 584 | - | |||||||||||||||||||
| 585 | Returns \c true if the depth buffer is enabled; otherwise returns | - | ||||||||||||||||||
| 586 | false. The depth buffer is enabled by default. | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | \sa setDepth(), setDepthBufferSize() | - | ||||||||||||||||||
| 589 | */ | - | ||||||||||||||||||
| 590 | - | |||||||||||||||||||
| 591 | /*! | - | ||||||||||||||||||
| 592 | If \a enable is true enables the depth buffer; otherwise disables | - | ||||||||||||||||||
| 593 | the depth buffer. | - | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | The depth buffer is enabled by default. | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | The purpose of a depth buffer (or Z-buffering) is to remove hidden | - | ||||||||||||||||||
| 598 | surfaces. Pixels are assigned Z values based on the distance to | - | ||||||||||||||||||
| 599 | the viewer. A pixel with a high Z value is closer to the viewer | - | ||||||||||||||||||
| 600 | than a pixel with a low Z value. This information is used to | - | ||||||||||||||||||
| 601 | decide whether to draw a pixel or not. | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | \sa depth(), setDepthBufferSize() | - | ||||||||||||||||||
| 604 | */ | - | ||||||||||||||||||
| 605 | - | |||||||||||||||||||
| 606 | void QGLFormat::setDepth(bool enable) | - | ||||||||||||||||||
| 607 | { | - | ||||||||||||||||||
| 608 | setOption(enable ? QGL::DepthBuffer : QGL::NoDepthBuffer); | - | ||||||||||||||||||
| 609 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | /*! | - | ||||||||||||||||||
| 613 | \fn bool QGLFormat::rgba() const | - | ||||||||||||||||||
| 614 | - | |||||||||||||||||||
| 615 | Returns \c true if RGBA color mode is set. Returns \c false if color | - | ||||||||||||||||||
| 616 | index mode is set. The default color mode is RGBA. | - | ||||||||||||||||||
| 617 | - | |||||||||||||||||||
| 618 | \sa setRgba() | - | ||||||||||||||||||
| 619 | */ | - | ||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | /*! | - | ||||||||||||||||||
| 622 | If \a enable is true sets RGBA mode. If \a enable is false sets | - | ||||||||||||||||||
| 623 | color index mode. | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | The default color mode is RGBA. | - | ||||||||||||||||||
| 626 | - | |||||||||||||||||||
| 627 | RGBA is the preferred mode for most OpenGL applications. In RGBA | - | ||||||||||||||||||
| 628 | color mode you specify colors as red + green + blue + alpha | - | ||||||||||||||||||
| 629 | quadruplets. | - | ||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | In color index mode you specify an index into a color lookup | - | ||||||||||||||||||
| 632 | table. | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | \sa rgba() | - | ||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | void QGLFormat::setRgba(bool enable) | - | ||||||||||||||||||
| 638 | { | - | ||||||||||||||||||
| 639 | setOption(enable ? QGL::Rgba : QGL::ColorIndex); | - | ||||||||||||||||||
| 640 | } never executed: end of block | 0 | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | /*! | - | ||||||||||||||||||
| 644 | \fn bool QGLFormat::alpha() const | - | ||||||||||||||||||
| 645 | - | |||||||||||||||||||
| 646 | Returns \c true if the alpha buffer in the framebuffer is enabled; | - | ||||||||||||||||||
| 647 | otherwise returns \c false. The alpha buffer is disabled by default. | - | ||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | \sa setAlpha(), setAlphaBufferSize() | - | ||||||||||||||||||
| 650 | */ | - | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | /*! | - | ||||||||||||||||||
| 653 | If \a enable is true enables the alpha buffer; otherwise disables | - | ||||||||||||||||||
| 654 | the alpha buffer. | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | The alpha buffer is disabled by default. | - | ||||||||||||||||||
| 657 | - | |||||||||||||||||||
| 658 | The alpha buffer is typically used for implementing transparency | - | ||||||||||||||||||
| 659 | or translucency. The A in RGBA specifies the transparency of a | - | ||||||||||||||||||
| 660 | pixel. | - | ||||||||||||||||||
| 661 | - | |||||||||||||||||||
| 662 | \sa alpha(), setAlphaBufferSize() | - | ||||||||||||||||||
| 663 | */ | - | ||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | void QGLFormat::setAlpha(bool enable) | - | ||||||||||||||||||
| 666 | { | - | ||||||||||||||||||
| 667 | setOption(enable ? QGL::AlphaChannel : QGL::NoAlphaChannel); | - | ||||||||||||||||||
| 668 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | /*! | - | ||||||||||||||||||
| 672 | \fn bool QGLFormat::accum() const | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | Returns \c true if the accumulation buffer is enabled; otherwise | - | ||||||||||||||||||
| 675 | returns \c false. The accumulation buffer is disabled by default. | - | ||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | \sa setAccum(), setAccumBufferSize() | - | ||||||||||||||||||
| 678 | */ | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | /*! | - | ||||||||||||||||||
| 681 | If \a enable is true enables the accumulation buffer; otherwise | - | ||||||||||||||||||
| 682 | disables the accumulation buffer. | - | ||||||||||||||||||
| 683 | - | |||||||||||||||||||
| 684 | The accumulation buffer is disabled by default. | - | ||||||||||||||||||
| 685 | - | |||||||||||||||||||
| 686 | The accumulation buffer is used to create blur effects and | - | ||||||||||||||||||
| 687 | multiple exposures. | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | \sa accum(), setAccumBufferSize() | - | ||||||||||||||||||
| 690 | */ | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | void QGLFormat::setAccum(bool enable) | - | ||||||||||||||||||
| 693 | { | - | ||||||||||||||||||
| 694 | setOption(enable ? QGL::AccumBuffer : QGL::NoAccumBuffer); | - | ||||||||||||||||||
| 695 | } never executed: end of block | 0 | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | /*! | - | ||||||||||||||||||
| 699 | \fn bool QGLFormat::stencil() const | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | Returns \c true if the stencil buffer is enabled; otherwise returns | - | ||||||||||||||||||
| 702 | false. The stencil buffer is enabled by default. | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | \sa setStencil(), setStencilBufferSize() | - | ||||||||||||||||||
| 705 | */ | - | ||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | /*! | - | ||||||||||||||||||
| 708 | If \a enable is true enables the stencil buffer; otherwise | - | ||||||||||||||||||
| 709 | disables the stencil buffer. | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | The stencil buffer is enabled by default. | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | The stencil buffer masks certain parts of the drawing area so that | - | ||||||||||||||||||
| 714 | masked parts are not drawn on. | - | ||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | \sa stencil(), setStencilBufferSize() | - | ||||||||||||||||||
| 717 | */ | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | void QGLFormat::setStencil(bool enable) | - | ||||||||||||||||||
| 720 | { | - | ||||||||||||||||||
| 721 | setOption(enable ? QGL::StencilBuffer: QGL::NoStencilBuffer); | - | ||||||||||||||||||
| 722 | } executed 24 times by 3 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | /*! | - | ||||||||||||||||||
| 726 | \fn bool QGLFormat::stereo() const | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | Returns \c true if stereo buffering is enabled; otherwise returns | - | ||||||||||||||||||
| 729 | false. Stereo buffering is disabled by default. | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | \sa setStereo() | - | ||||||||||||||||||
| 732 | */ | - | ||||||||||||||||||
| 733 | - | |||||||||||||||||||
| 734 | /*! | - | ||||||||||||||||||
| 735 | If \a enable is true enables stereo buffering; otherwise disables | - | ||||||||||||||||||
| 736 | stereo buffering. | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | Stereo buffering is disabled by default. | - | ||||||||||||||||||
| 739 | - | |||||||||||||||||||
| 740 | Stereo buffering provides extra color buffers to generate left-eye | - | ||||||||||||||||||
| 741 | and right-eye images. | - | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | \sa stereo() | - | ||||||||||||||||||
| 744 | */ | - | ||||||||||||||||||
| 745 | - | |||||||||||||||||||
| 746 | void QGLFormat::setStereo(bool enable) | - | ||||||||||||||||||
| 747 | { | - | ||||||||||||||||||
| 748 | setOption(enable ? QGL::StereoBuffers : QGL::NoStereoBuffers); | - | ||||||||||||||||||
| 749 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | /*! | - | ||||||||||||||||||
| 753 | \fn bool QGLFormat::directRendering() const | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | Returns \c true if direct rendering is enabled; otherwise returns | - | ||||||||||||||||||
| 756 | false. | - | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | Direct rendering is enabled by default. | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | \sa setDirectRendering() | - | ||||||||||||||||||
| 761 | */ | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | /*! | - | ||||||||||||||||||
| 764 | If \a enable is true enables direct rendering; otherwise disables | - | ||||||||||||||||||
| 765 | direct rendering. | - | ||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | Direct rendering is enabled by default. | - | ||||||||||||||||||
| 768 | - | |||||||||||||||||||
| 769 | Enabling this option will make OpenGL bypass the underlying window | - | ||||||||||||||||||
| 770 | system and render directly from hardware to the screen, if this is | - | ||||||||||||||||||
| 771 | supported by the system. | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | \sa directRendering() | - | ||||||||||||||||||
| 774 | */ | - | ||||||||||||||||||
| 775 | - | |||||||||||||||||||
| 776 | void QGLFormat::setDirectRendering(bool enable) | - | ||||||||||||||||||
| 777 | { | - | ||||||||||||||||||
| 778 | setOption(enable ? QGL::DirectRendering : QGL::IndirectRendering); | - | ||||||||||||||||||
| 779 | } never executed: end of block | 0 | ||||||||||||||||||
| 780 | - | |||||||||||||||||||
| 781 | /*! | - | ||||||||||||||||||
| 782 | \fn bool QGLFormat::sampleBuffers() const | - | ||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | Returns \c true if multisample buffer support is enabled; otherwise | - | ||||||||||||||||||
| 785 | returns \c false. | - | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | The multisample buffer is disabled by default. | - | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | \sa setSampleBuffers() | - | ||||||||||||||||||
| 790 | */ | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | /*! | - | ||||||||||||||||||
| 793 | If \a enable is true, a GL context with multisample buffer support | - | ||||||||||||||||||
| 794 | is picked; otherwise ignored. | - | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | \sa sampleBuffers(), setSamples(), samples() | - | ||||||||||||||||||
| 797 | */ | - | ||||||||||||||||||
| 798 | void QGLFormat::setSampleBuffers(bool enable) | - | ||||||||||||||||||
| 799 | { | - | ||||||||||||||||||
| 800 | setOption(enable ? QGL::SampleBuffers : QGL::NoSampleBuffers); | - | ||||||||||||||||||
| 801 | } never executed: end of block | 0 | ||||||||||||||||||
| 802 | - | |||||||||||||||||||
| 803 | /*! | - | ||||||||||||||||||
| 804 | Returns the number of samples per pixel when multisampling is | - | ||||||||||||||||||
| 805 | enabled. By default, the highest number of samples that is | - | ||||||||||||||||||
| 806 | available is used. | - | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | \sa setSampleBuffers(), sampleBuffers(), setSamples() | - | ||||||||||||||||||
| 809 | */ | - | ||||||||||||||||||
| 810 | int QGLFormat::samples() const | - | ||||||||||||||||||
| 811 | { | - | ||||||||||||||||||
| 812 | return d->numSamples; never executed: return d->numSamples; | 0 | ||||||||||||||||||
| 813 | } | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | /*! | - | ||||||||||||||||||
| 816 | Set the preferred number of samples per pixel when multisampling | - | ||||||||||||||||||
| 817 | is enabled to \a numSamples. By default, the highest number of | - | ||||||||||||||||||
| 818 | samples available is used. | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | \sa setSampleBuffers(), sampleBuffers(), samples() | - | ||||||||||||||||||
| 821 | */ | - | ||||||||||||||||||
| 822 | void QGLFormat::setSamples(int numSamples) | - | ||||||||||||||||||
| 823 | { | - | ||||||||||||||||||
| 824 | detach(); | - | ||||||||||||||||||
| 825 | if (numSamples < 0) {
| 0 | ||||||||||||||||||
| 826 | qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); | - | ||||||||||||||||||
| 827 | return; never executed: return; | 0 | ||||||||||||||||||
| 828 | } | - | ||||||||||||||||||
| 829 | d->numSamples = numSamples; | - | ||||||||||||||||||
| 830 | setSampleBuffers(numSamples > 0); | - | ||||||||||||||||||
| 831 | } never executed: end of block | 0 | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | /*! | - | ||||||||||||||||||
| 834 | \since 4.2 | - | ||||||||||||||||||
| 835 | - | |||||||||||||||||||
| 836 | Set the preferred swap interval. This can be used to sync the GL | - | ||||||||||||||||||
| 837 | drawing into a system window to the vertical refresh of the screen. | - | ||||||||||||||||||
| 838 | Setting an \a interval value of 0 will turn the vertical refresh syncing | - | ||||||||||||||||||
| 839 | off, any value higher than 0 will turn the vertical syncing on. | - | ||||||||||||||||||
| 840 | - | |||||||||||||||||||
| 841 | Under Windows and under X11, where the \c{WGL_EXT_swap_control} | - | ||||||||||||||||||
| 842 | and \c{GLX_SGI_video_sync} extensions are used, the \a interval | - | ||||||||||||||||||
| 843 | parameter can be used to set the minimum number of video frames | - | ||||||||||||||||||
| 844 | that are displayed before a buffer swap will occur. In effect, | - | ||||||||||||||||||
| 845 | setting the \a interval to 10, means there will be 10 vertical | - | ||||||||||||||||||
| 846 | retraces between every buffer swap. | - | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | Under Windows the \c{WGL_EXT_swap_control} extension has to be present, | - | ||||||||||||||||||
| 849 | and under X11 the \c{GLX_SGI_video_sync} extension has to be present. | - | ||||||||||||||||||
| 850 | */ | - | ||||||||||||||||||
| 851 | void QGLFormat::setSwapInterval(int interval) | - | ||||||||||||||||||
| 852 | { | - | ||||||||||||||||||
| 853 | detach(); | - | ||||||||||||||||||
| 854 | d->swapInterval = interval; | - | ||||||||||||||||||
| 855 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 856 | - | |||||||||||||||||||
| 857 | /*! | - | ||||||||||||||||||
| 858 | \since 4.2 | - | ||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | Returns the currently set swap interval. -1 is returned if setting | - | ||||||||||||||||||
| 861 | the swap interval isn't supported in the system GL implementation. | - | ||||||||||||||||||
| 862 | */ | - | ||||||||||||||||||
| 863 | int QGLFormat::swapInterval() const | - | ||||||||||||||||||
| 864 | { | - | ||||||||||||||||||
| 865 | return d->swapInterval; executed 12 times by 3 tests: return d->swapInterval;Executed by:
| 12 | ||||||||||||||||||
| 866 | } | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | /*! | - | ||||||||||||||||||
| 869 | \fn bool QGLFormat::hasOverlay() const | - | ||||||||||||||||||
| 870 | - | |||||||||||||||||||
| 871 | Returns \c true if overlay plane is enabled; otherwise returns \c false. | - | ||||||||||||||||||
| 872 | - | |||||||||||||||||||
| 873 | Overlay is disabled by default. | - | ||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | \sa setOverlay() | - | ||||||||||||||||||
| 876 | */ | - | ||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | /*! | - | ||||||||||||||||||
| 879 | If \a enable is true enables an overlay plane; otherwise disables | - | ||||||||||||||||||
| 880 | the overlay plane. | - | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | Enabling the overlay plane will cause QGLWidget to create an | - | ||||||||||||||||||
| 883 | additional context in an overlay plane. See the QGLWidget | - | ||||||||||||||||||
| 884 | documentation for further information. | - | ||||||||||||||||||
| 885 | - | |||||||||||||||||||
| 886 | \sa hasOverlay() | - | ||||||||||||||||||
| 887 | */ | - | ||||||||||||||||||
| 888 | - | |||||||||||||||||||
| 889 | void QGLFormat::setOverlay(bool enable) | - | ||||||||||||||||||
| 890 | { | - | ||||||||||||||||||
| 891 | setOption(enable ? QGL::HasOverlay : QGL::NoOverlay); | - | ||||||||||||||||||
| 892 | } never executed: end of block | 0 | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | /*! | - | ||||||||||||||||||
| 895 | Returns the plane of this format. The default for normal formats | - | ||||||||||||||||||
| 896 | is 0, which means the normal plane. The default for overlay | - | ||||||||||||||||||
| 897 | formats is 1, which is the first overlay plane. | - | ||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | \sa setPlane(), defaultOverlayFormat() | - | ||||||||||||||||||
| 900 | */ | - | ||||||||||||||||||
| 901 | int QGLFormat::plane() const | - | ||||||||||||||||||
| 902 | { | - | ||||||||||||||||||
| 903 | return d->pln; never executed: return d->pln; | 0 | ||||||||||||||||||
| 904 | } | - | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | /*! | - | ||||||||||||||||||
| 907 | Sets the requested plane to \a plane. 0 is the normal plane, 1 is | - | ||||||||||||||||||
| 908 | the first overlay plane, 2 is the second overlay plane, etc.; -1, | - | ||||||||||||||||||
| 909 | -2, etc. are underlay planes. | - | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | Note that in contrast to other format specifications, the plane | - | ||||||||||||||||||
| 912 | specifications will be matched exactly. This means that if you | - | ||||||||||||||||||
| 913 | specify a plane that the underlying OpenGL system cannot provide, | - | ||||||||||||||||||
| 914 | an \l{QGLWidget::isValid()}{invalid} QGLWidget will be | - | ||||||||||||||||||
| 915 | created. | - | ||||||||||||||||||
| 916 | - | |||||||||||||||||||
| 917 | \sa plane() | - | ||||||||||||||||||
| 918 | */ | - | ||||||||||||||||||
| 919 | void QGLFormat::setPlane(int plane) | - | ||||||||||||||||||
| 920 | { | - | ||||||||||||||||||
| 921 | detach(); | - | ||||||||||||||||||
| 922 | d->pln = plane; | - | ||||||||||||||||||
| 923 | } never executed: end of block | 0 | ||||||||||||||||||
| 924 | - | |||||||||||||||||||
| 925 | /*! | - | ||||||||||||||||||
| 926 | Sets the format option to \a opt. | - | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | \sa testOption() | - | ||||||||||||||||||
| 929 | */ | - | ||||||||||||||||||
| 930 | - | |||||||||||||||||||
| 931 | void QGLFormat::setOption(QGL::FormatOptions opt) | - | ||||||||||||||||||
| 932 | { | - | ||||||||||||||||||
| 933 | detach(); | - | ||||||||||||||||||
| 934 | if (opt & 0xffff)
| 24-48 | ||||||||||||||||||
| 935 | d->opts |= opt; executed 48 times by 3 tests: d->opts |= opt;Executed by:
| 48 | ||||||||||||||||||
| 936 | else | - | ||||||||||||||||||
| 937 | d->opts &= ~(opt >> 16); executed 24 times by 3 tests: d->opts &= ~(opt >> 16);Executed by:
| 24 | ||||||||||||||||||
| 938 | } | - | ||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | - | |||||||||||||||||||
| 942 | /*! | - | ||||||||||||||||||
| 943 | Returns \c true if format option \a opt is set; otherwise returns \c false. | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | \sa setOption() | - | ||||||||||||||||||
| 946 | */ | - | ||||||||||||||||||
| 947 | - | |||||||||||||||||||
| 948 | bool QGLFormat::testOption(QGL::FormatOptions opt) const | - | ||||||||||||||||||
| 949 | { | - | ||||||||||||||||||
| 950 | if (opt & 0xffff)
| 0-84 | ||||||||||||||||||
| 951 | return (d->opts & opt) != 0; executed 84 times by 3 tests: return (d->opts & opt) != 0;Executed by:
| 84 | ||||||||||||||||||
| 952 | else | - | ||||||||||||||||||
| 953 | return (d->opts & (opt >> 16)) == 0; never executed: return (d->opts & (opt >> 16)) == 0; | 0 | ||||||||||||||||||
| 954 | } | - | ||||||||||||||||||
| 955 | - | |||||||||||||||||||
| 956 | /*! | - | ||||||||||||||||||
| 957 | Set the minimum depth buffer size to \a size. | - | ||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | \sa depthBufferSize(), setDepth(), depth() | - | ||||||||||||||||||
| 960 | */ | - | ||||||||||||||||||
| 961 | void QGLFormat::setDepthBufferSize(int size) | - | ||||||||||||||||||
| 962 | { | - | ||||||||||||||||||
| 963 | detach(); | - | ||||||||||||||||||
| 964 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 965 | qWarning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); | - | ||||||||||||||||||
| 966 | return; never executed: return; | 0 | ||||||||||||||||||
| 967 | } | - | ||||||||||||||||||
| 968 | d->depthSize = size; | - | ||||||||||||||||||
| 969 | setDepth(size > 0); | - | ||||||||||||||||||
| 970 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 971 | - | |||||||||||||||||||
| 972 | /*! | - | ||||||||||||||||||
| 973 | Returns the depth buffer size. | - | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | \sa depth(), setDepth(), setDepthBufferSize() | - | ||||||||||||||||||
| 976 | */ | - | ||||||||||||||||||
| 977 | int QGLFormat::depthBufferSize() const | - | ||||||||||||||||||
| 978 | { | - | ||||||||||||||||||
| 979 | return d->depthSize; executed 12 times by 3 tests: return d->depthSize;Executed by:
| 12 | ||||||||||||||||||
| 980 | } | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | /*! | - | ||||||||||||||||||
| 983 | \since 4.2 | - | ||||||||||||||||||
| 984 | - | |||||||||||||||||||
| 985 | Set the preferred red buffer size to \a size. | - | ||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | \sa setGreenBufferSize(), setBlueBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
| 988 | */ | - | ||||||||||||||||||
| 989 | void QGLFormat::setRedBufferSize(int size) | - | ||||||||||||||||||
| 990 | { | - | ||||||||||||||||||
| 991 | detach(); | - | ||||||||||||||||||
| 992 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 993 | qWarning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); | - | ||||||||||||||||||
| 994 | return; never executed: return; | 0 | ||||||||||||||||||
| 995 | } | - | ||||||||||||||||||
| 996 | d->redSize = size; | - | ||||||||||||||||||
| 997 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 998 | - | |||||||||||||||||||
| 999 | /*! | - | ||||||||||||||||||
| 1000 | \since 4.2 | - | ||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | Returns the red buffer size. | - | ||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | \sa setRedBufferSize() | - | ||||||||||||||||||
| 1005 | */ | - | ||||||||||||||||||
| 1006 | int QGLFormat::redBufferSize() const | - | ||||||||||||||||||
| 1007 | { | - | ||||||||||||||||||
| 1008 | return d->redSize; executed 12 times by 3 tests: return d->redSize;Executed by:
| 12 | ||||||||||||||||||
| 1009 | } | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | /*! | - | ||||||||||||||||||
| 1012 | \since 4.2 | - | ||||||||||||||||||
| 1013 | - | |||||||||||||||||||
| 1014 | Set the preferred green buffer size to \a size. | - | ||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | \sa setRedBufferSize(), setBlueBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
| 1017 | */ | - | ||||||||||||||||||
| 1018 | void QGLFormat::setGreenBufferSize(int size) | - | ||||||||||||||||||
| 1019 | { | - | ||||||||||||||||||
| 1020 | detach(); | - | ||||||||||||||||||
| 1021 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 1022 | qWarning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); | - | ||||||||||||||||||
| 1023 | return; never executed: return; | 0 | ||||||||||||||||||
| 1024 | } | - | ||||||||||||||||||
| 1025 | d->greenSize = size; | - | ||||||||||||||||||
| 1026 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1027 | - | |||||||||||||||||||
| 1028 | /*! | - | ||||||||||||||||||
| 1029 | \since 4.2 | - | ||||||||||||||||||
| 1030 | - | |||||||||||||||||||
| 1031 | Returns the green buffer size. | - | ||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | \sa setGreenBufferSize() | - | ||||||||||||||||||
| 1034 | */ | - | ||||||||||||||||||
| 1035 | int QGLFormat::greenBufferSize() const | - | ||||||||||||||||||
| 1036 | { | - | ||||||||||||||||||
| 1037 | return d->greenSize; executed 12 times by 3 tests: return d->greenSize;Executed by:
| 12 | ||||||||||||||||||
| 1038 | } | - | ||||||||||||||||||
| 1039 | - | |||||||||||||||||||
| 1040 | /*! | - | ||||||||||||||||||
| 1041 | \since 4.2 | - | ||||||||||||||||||
| 1042 | - | |||||||||||||||||||
| 1043 | Set the preferred blue buffer size to \a size. | - | ||||||||||||||||||
| 1044 | - | |||||||||||||||||||
| 1045 | \sa setRedBufferSize(), setGreenBufferSize(), setAlphaBufferSize() | - | ||||||||||||||||||
| 1046 | */ | - | ||||||||||||||||||
| 1047 | void QGLFormat::setBlueBufferSize(int size) | - | ||||||||||||||||||
| 1048 | { | - | ||||||||||||||||||
| 1049 | detach(); | - | ||||||||||||||||||
| 1050 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 1051 | qWarning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); | - | ||||||||||||||||||
| 1052 | return; never executed: return; | 0 | ||||||||||||||||||
| 1053 | } | - | ||||||||||||||||||
| 1054 | d->blueSize = size; | - | ||||||||||||||||||
| 1055 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | /*! | - | ||||||||||||||||||
| 1058 | \since 4.2 | - | ||||||||||||||||||
| 1059 | - | |||||||||||||||||||
| 1060 | Returns the blue buffer size. | - | ||||||||||||||||||
| 1061 | - | |||||||||||||||||||
| 1062 | \sa setBlueBufferSize() | - | ||||||||||||||||||
| 1063 | */ | - | ||||||||||||||||||
| 1064 | int QGLFormat::blueBufferSize() const | - | ||||||||||||||||||
| 1065 | { | - | ||||||||||||||||||
| 1066 | return d->blueSize; executed 12 times by 3 tests: return d->blueSize;Executed by:
| 12 | ||||||||||||||||||
| 1067 | } | - | ||||||||||||||||||
| 1068 | - | |||||||||||||||||||
| 1069 | /*! | - | ||||||||||||||||||
| 1070 | Set the preferred alpha buffer size to \a size. | - | ||||||||||||||||||
| 1071 | This function implicitly enables the alpha channel. | - | ||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | \sa setRedBufferSize(), setGreenBufferSize(), alphaBufferSize() | - | ||||||||||||||||||
| 1074 | */ | - | ||||||||||||||||||
| 1075 | void QGLFormat::setAlphaBufferSize(int size) | - | ||||||||||||||||||
| 1076 | { | - | ||||||||||||||||||
| 1077 | detach(); | - | ||||||||||||||||||
| 1078 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 1079 | qWarning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); | - | ||||||||||||||||||
| 1080 | return; never executed: return; | 0 | ||||||||||||||||||
| 1081 | } | - | ||||||||||||||||||
| 1082 | d->alphaSize = size; | - | ||||||||||||||||||
| 1083 | setAlpha(size > 0); | - | ||||||||||||||||||
| 1084 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1085 | - | |||||||||||||||||||
| 1086 | /*! | - | ||||||||||||||||||
| 1087 | Returns the alpha buffer size. | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | \sa alpha(), setAlpha(), setAlphaBufferSize() | - | ||||||||||||||||||
| 1090 | */ | - | ||||||||||||||||||
| 1091 | int QGLFormat::alphaBufferSize() const | - | ||||||||||||||||||
| 1092 | { | - | ||||||||||||||||||
| 1093 | return d->alphaSize; never executed: return d->alphaSize; | 0 | ||||||||||||||||||
| 1094 | } | - | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | /*! | - | ||||||||||||||||||
| 1097 | Set the preferred accumulation buffer size, where \a size is the | - | ||||||||||||||||||
| 1098 | bit depth for each RGBA component. | - | ||||||||||||||||||
| 1099 | - | |||||||||||||||||||
| 1100 | \sa accum(), setAccum(), accumBufferSize() | - | ||||||||||||||||||
| 1101 | */ | - | ||||||||||||||||||
| 1102 | void QGLFormat::setAccumBufferSize(int size) | - | ||||||||||||||||||
| 1103 | { | - | ||||||||||||||||||
| 1104 | detach(); | - | ||||||||||||||||||
| 1105 | if (size < 0) {
| 0 | ||||||||||||||||||
| 1106 | qWarning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); | - | ||||||||||||||||||
| 1107 | return; never executed: return; | 0 | ||||||||||||||||||
| 1108 | } | - | ||||||||||||||||||
| 1109 | d->accumSize = size; | - | ||||||||||||||||||
| 1110 | setAccum(size > 0); | - | ||||||||||||||||||
| 1111 | } never executed: end of block | 0 | ||||||||||||||||||
| 1112 | - | |||||||||||||||||||
| 1113 | /*! | - | ||||||||||||||||||
| 1114 | Returns the accumulation buffer size. | - | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | \sa setAccumBufferSize(), accum(), setAccum() | - | ||||||||||||||||||
| 1117 | */ | - | ||||||||||||||||||
| 1118 | int QGLFormat::accumBufferSize() const | - | ||||||||||||||||||
| 1119 | { | - | ||||||||||||||||||
| 1120 | return d->accumSize; never executed: return d->accumSize; | 0 | ||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||
| 1122 | - | |||||||||||||||||||
| 1123 | /*! | - | ||||||||||||||||||
| 1124 | Set the preferred stencil buffer size to \a size. | - | ||||||||||||||||||
| 1125 | - | |||||||||||||||||||
| 1126 | \sa stencilBufferSize(), setStencil(), stencil() | - | ||||||||||||||||||
| 1127 | */ | - | ||||||||||||||||||
| 1128 | void QGLFormat::setStencilBufferSize(int size) | - | ||||||||||||||||||
| 1129 | { | - | ||||||||||||||||||
| 1130 | detach(); | - | ||||||||||||||||||
| 1131 | if (size < 0) {
| 0-12 | ||||||||||||||||||
| 1132 | qWarning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); | - | ||||||||||||||||||
| 1133 | return; never executed: return; | 0 | ||||||||||||||||||
| 1134 | } | - | ||||||||||||||||||
| 1135 | d->stencilSize = size; | - | ||||||||||||||||||
| 1136 | setStencil(size > 0); | - | ||||||||||||||||||
| 1137 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | /*! | - | ||||||||||||||||||
| 1140 | Returns the stencil buffer size. | - | ||||||||||||||||||
| 1141 | - | |||||||||||||||||||
| 1142 | \sa stencil(), setStencil(), setStencilBufferSize() | - | ||||||||||||||||||
| 1143 | */ | - | ||||||||||||||||||
| 1144 | int QGLFormat::stencilBufferSize() const | - | ||||||||||||||||||
| 1145 | { | - | ||||||||||||||||||
| 1146 | return d->stencilSize; executed 12 times by 3 tests: return d->stencilSize;Executed by:
| 12 | ||||||||||||||||||
| 1147 | } | - | ||||||||||||||||||
| 1148 | - | |||||||||||||||||||
| 1149 | /*! | - | ||||||||||||||||||
| 1150 | \since 4.7 | - | ||||||||||||||||||
| 1151 | - | |||||||||||||||||||
| 1152 | Set the OpenGL version to the \a major and \a minor numbers. If a | - | ||||||||||||||||||
| 1153 | context compatible with the requested OpenGL version cannot be | - | ||||||||||||||||||
| 1154 | created, a context compatible with version 1.x is created instead. | - | ||||||||||||||||||
| 1155 | - | |||||||||||||||||||
| 1156 | \sa majorVersion(), minorVersion() | - | ||||||||||||||||||
| 1157 | */ | - | ||||||||||||||||||
| 1158 | void QGLFormat::setVersion(int major, int minor) | - | ||||||||||||||||||
| 1159 | { | - | ||||||||||||||||||
| 1160 | if (major < 1 || minor < 0) {
| 0-12 | ||||||||||||||||||
| 1161 | qWarning("QGLFormat::setVersion: Cannot set zero or negative version number %d.%d", major, minor); | - | ||||||||||||||||||
| 1162 | return; never executed: return; | 0 | ||||||||||||||||||
| 1163 | } | - | ||||||||||||||||||
| 1164 | detach(); | - | ||||||||||||||||||
| 1165 | d->majorVersion = major; | - | ||||||||||||||||||
| 1166 | d->minorVersion = minor; | - | ||||||||||||||||||
| 1167 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | /*! | - | ||||||||||||||||||
| 1170 | \since 4.7 | - | ||||||||||||||||||
| 1171 | - | |||||||||||||||||||
| 1172 | Returns the OpenGL major version. | - | ||||||||||||||||||
| 1173 | - | |||||||||||||||||||
| 1174 | \sa setVersion(), minorVersion() | - | ||||||||||||||||||
| 1175 | */ | - | ||||||||||||||||||
| 1176 | int QGLFormat::majorVersion() const | - | ||||||||||||||||||
| 1177 | { | - | ||||||||||||||||||
| 1178 | return d->majorVersion; executed 12 times by 3 tests: return d->majorVersion;Executed by:
| 12 | ||||||||||||||||||
| 1179 | } | - | ||||||||||||||||||
| 1180 | - | |||||||||||||||||||
| 1181 | /*! | - | ||||||||||||||||||
| 1182 | \since 4.7 | - | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | Returns the OpenGL minor version. | - | ||||||||||||||||||
| 1185 | - | |||||||||||||||||||
| 1186 | \sa setVersion(), majorVersion() | - | ||||||||||||||||||
| 1187 | */ | - | ||||||||||||||||||
| 1188 | int QGLFormat::minorVersion() const | - | ||||||||||||||||||
| 1189 | { | - | ||||||||||||||||||
| 1190 | return d->minorVersion; executed 12 times by 3 tests: return d->minorVersion;Executed by:
| 12 | ||||||||||||||||||
| 1191 | } | - | ||||||||||||||||||
| 1192 | - | |||||||||||||||||||
| 1193 | /*! | - | ||||||||||||||||||
| 1194 | \enum QGLFormat::OpenGLContextProfile | - | ||||||||||||||||||
| 1195 | \since 4.7 | - | ||||||||||||||||||
| 1196 | - | |||||||||||||||||||
| 1197 | This enum describes the OpenGL context profiles that can be | - | ||||||||||||||||||
| 1198 | specified for contexts implementing OpenGL version 3.2 or | - | ||||||||||||||||||
| 1199 | higher. These profiles are different from OpenGL ES profiles. | - | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | \value NoProfile OpenGL version is lower than 3.2. | - | ||||||||||||||||||
| 1202 | \value CoreProfile Functionality deprecated in OpenGL version 3.0 is not available. | - | ||||||||||||||||||
| 1203 | \value CompatibilityProfile Functionality from earlier OpenGL versions is available. | - | ||||||||||||||||||
| 1204 | */ | - | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | /*! | - | ||||||||||||||||||
| 1207 | \since 4.7 | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | Set the OpenGL context profile to \a profile. The \a profile is | - | ||||||||||||||||||
| 1210 | ignored if the requested OpenGL version is less than 3.2. | - | ||||||||||||||||||
| 1211 | - | |||||||||||||||||||
| 1212 | \sa profile() | - | ||||||||||||||||||
| 1213 | */ | - | ||||||||||||||||||
| 1214 | void QGLFormat::setProfile(OpenGLContextProfile profile) | - | ||||||||||||||||||
| 1215 | { | - | ||||||||||||||||||
| 1216 | detach(); | - | ||||||||||||||||||
| 1217 | d->profile = profile; | - | ||||||||||||||||||
| 1218 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | /*! | - | ||||||||||||||||||
| 1221 | \since 4.7 | - | ||||||||||||||||||
| 1222 | - | |||||||||||||||||||
| 1223 | Returns the OpenGL context profile. | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | \sa setProfile() | - | ||||||||||||||||||
| 1226 | */ | - | ||||||||||||||||||
| 1227 | QGLFormat::OpenGLContextProfile QGLFormat::profile() const | - | ||||||||||||||||||
| 1228 | { | - | ||||||||||||||||||
| 1229 | return d->profile; executed 24 times by 3 tests: return d->profile;Executed by:
| 24 | ||||||||||||||||||
| 1230 | } | - | ||||||||||||||||||
| 1231 | - | |||||||||||||||||||
| 1232 | - | |||||||||||||||||||
| 1233 | /*! | - | ||||||||||||||||||
| 1234 | \fn bool QGLFormat::hasOpenGL() | - | ||||||||||||||||||
| 1235 | - | |||||||||||||||||||
| 1236 | Returns \c true if the window system has any OpenGL support; | - | ||||||||||||||||||
| 1237 | otherwise returns \c false. | - | ||||||||||||||||||
| 1238 | - | |||||||||||||||||||
| 1239 | \warning This function must not be called until the QApplication | - | ||||||||||||||||||
| 1240 | object has been created. | - | ||||||||||||||||||
| 1241 | */ | - | ||||||||||||||||||
| 1242 | bool QGLFormat::hasOpenGL() | - | ||||||||||||||||||
| 1243 | { | - | ||||||||||||||||||
| 1244 | return QApplicationPrivate::platformIntegration() executed 1 time by 1 test: return QApplicationPrivate::platformIntegration() ->hasCapability(QPlatformIntegration::OpenGL);Executed by:
| 1 | ||||||||||||||||||
| 1245 | ->hasCapability(QPlatformIntegration::OpenGL); executed 1 time by 1 test: return QApplicationPrivate::platformIntegration() ->hasCapability(QPlatformIntegration::OpenGL);Executed by:
| 1 | ||||||||||||||||||
| 1246 | } | - | ||||||||||||||||||
| 1247 | - | |||||||||||||||||||
| 1248 | /*! | - | ||||||||||||||||||
| 1249 | \fn bool QGLFormat::hasOpenGLOverlays() | - | ||||||||||||||||||
| 1250 | - | |||||||||||||||||||
| 1251 | Returns \c true if the window system supports OpenGL overlays; | - | ||||||||||||||||||
| 1252 | otherwise returns \c false. | - | ||||||||||||||||||
| 1253 | - | |||||||||||||||||||
| 1254 | \warning This function must not be called until the QApplication | - | ||||||||||||||||||
| 1255 | object has been created. | - | ||||||||||||||||||
| 1256 | */ | - | ||||||||||||||||||
| 1257 | bool QGLFormat::hasOpenGLOverlays() | - | ||||||||||||||||||
| 1258 | { | - | ||||||||||||||||||
| 1259 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1260 | } | - | ||||||||||||||||||
| 1261 | - | |||||||||||||||||||
| 1262 | QGLFormat::OpenGLVersionFlags Q_AUTOTEST_EXPORT qOpenGLVersionFlagsFromString(const QString &versionString) | - | ||||||||||||||||||
| 1263 | { | - | ||||||||||||||||||
| 1264 | QGLFormat::OpenGLVersionFlags versionFlags = QGLFormat::OpenGL_Version_None; | - | ||||||||||||||||||
| 1265 | - | |||||||||||||||||||
| 1266 | if (versionString.startsWith(QLatin1String("OpenGL ES"))) {
| 0-1 | ||||||||||||||||||
| 1267 | const auto parts = versionString.splitRef(QLatin1Char(' ')); | - | ||||||||||||||||||
| 1268 | if (parts.size() >= 3) {
| 0 | ||||||||||||||||||
| 1269 | if (parts[2].startsWith(QLatin1String("1."))) {
| 0 | ||||||||||||||||||
| 1270 | if (parts[1].endsWith(QLatin1String("-CM"))) {
| 0 | ||||||||||||||||||
| 1271 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_0 | | - | ||||||||||||||||||
| 1272 | QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - | ||||||||||||||||||
| 1273 | if (parts[2].startsWith(QLatin1String("1.1")))
| 0 | ||||||||||||||||||
| 1274 | versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | never executed: versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
| 1275 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; never executed: versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 | QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
| 1276 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1277 | // Not -CM, must be CL, CommonLite | - | ||||||||||||||||||
| 1278 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_0; | - | ||||||||||||||||||
| 1279 | if (parts[2].startsWith(QLatin1String("1.1")))
| 0 | ||||||||||||||||||
| 1280 | versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; never executed: versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1; | 0 | ||||||||||||||||||
| 1281 | } never executed: end of block | 0 | ||||||||||||||||||
| 1282 | } else { | - | ||||||||||||||||||
| 1283 | // OpenGL ES version 2.0 or higher | - | ||||||||||||||||||
| 1284 | versionFlags |= QGLFormat::OpenGL_ES_Version_2_0; | - | ||||||||||||||||||
| 1285 | } never executed: end of block | 0 | ||||||||||||||||||
| 1286 | } else { | - | ||||||||||||||||||
| 1287 | // if < 3 parts to the name, it is an unrecognised OpenGL ES | - | ||||||||||||||||||
| 1288 | qWarning("Unrecognised OpenGL ES version"); | - | ||||||||||||||||||
| 1289 | } never executed: end of block | 0 | ||||||||||||||||||
| 1290 | } else { | - | ||||||||||||||||||
| 1291 | // not ES, regular OpenGL, the version numbers are first in the string | - | ||||||||||||||||||
| 1292 | if (versionString.startsWith(QLatin1String("1."))) {
| 0-1 | ||||||||||||||||||
| 1293 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
| 1294 | case '5': never executed: case '5': | 0 | ||||||||||||||||||
| 1295 | versionFlags |= QGLFormat::OpenGL_Version_1_5; | - | ||||||||||||||||||
| 1296 | // fall through | - | ||||||||||||||||||
| 1297 | case '4': code before this statement never executed: case '4':never executed: case '4': | 0 | ||||||||||||||||||
| 1298 | versionFlags |= QGLFormat::OpenGL_Version_1_4; | - | ||||||||||||||||||
| 1299 | // fall through | - | ||||||||||||||||||
| 1300 | case '3': code before this statement never executed: case '3':never executed: case '3': | 0 | ||||||||||||||||||
| 1301 | versionFlags |= QGLFormat::OpenGL_Version_1_3; | - | ||||||||||||||||||
| 1302 | // fall through | - | ||||||||||||||||||
| 1303 | case '2': code before this statement never executed: case '2':never executed: case '2': | 0 | ||||||||||||||||||
| 1304 | versionFlags |= QGLFormat::OpenGL_Version_1_2; | - | ||||||||||||||||||
| 1305 | // fall through | - | ||||||||||||||||||
| 1306 | case '1': code before this statement never executed: case '1':never executed: case '1': | 0 | ||||||||||||||||||
| 1307 | versionFlags |= QGLFormat::OpenGL_Version_1_1; | - | ||||||||||||||||||
| 1308 | // fall through | - | ||||||||||||||||||
| 1309 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||
| 1310 | break; never executed: break; | 0 | ||||||||||||||||||
| 1311 | } | - | ||||||||||||||||||
| 1312 | } else if (versionString.startsWith(QLatin1String("2."))) {
| 0-1 | ||||||||||||||||||
| 1313 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
| 1314 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
| 1315 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
| 1316 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
| 1317 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
| 1318 | QGLFormat::OpenGL_Version_2_0; | - | ||||||||||||||||||
| 1319 | if (versionString[2].toLatin1() == '1')
| 0 | ||||||||||||||||||
| 1320 | versionFlags |= QGLFormat::OpenGL_Version_2_1; never executed: versionFlags |= QGLFormat::OpenGL_Version_2_1; | 0 | ||||||||||||||||||
| 1321 | } else if (versionString.startsWith(QLatin1String("3."))) { never executed: end of block
| 0-1 | ||||||||||||||||||
| 1322 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
| 1323 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
| 1324 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
| 1325 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
| 1326 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
| 1327 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
| 1328 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
| 1329 | QGLFormat::OpenGL_Version_3_0; | - | ||||||||||||||||||
| 1330 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
| 1331 | case '3': never executed: case '3': | 0 | ||||||||||||||||||
| 1332 | versionFlags |= QGLFormat::OpenGL_Version_3_3; | - | ||||||||||||||||||
| 1333 | // fall through | - | ||||||||||||||||||
| 1334 | case '2': code before this statement never executed: case '2':never executed: case '2': | 0 | ||||||||||||||||||
| 1335 | versionFlags |= QGLFormat::OpenGL_Version_3_2; | - | ||||||||||||||||||
| 1336 | // fall through | - | ||||||||||||||||||
| 1337 | case '1': code before this statement never executed: case '1':never executed: case '1': | 0 | ||||||||||||||||||
| 1338 | versionFlags |= QGLFormat::OpenGL_Version_3_1; | - | ||||||||||||||||||
| 1339 | // fall through | - | ||||||||||||||||||
| 1340 | case '0': code before this statement never executed: case '0':executed 1 time by 1 test: case '0':Executed by:
| 0-1 | ||||||||||||||||||
| 1341 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 1342 | default: never executed: default: | 0 | ||||||||||||||||||
| 1343 | versionFlags |= QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
| 1344 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
| 1345 | QGLFormat::OpenGL_Version_3_3; | - | ||||||||||||||||||
| 1346 | break; never executed: break; | 0 | ||||||||||||||||||
| 1347 | } | - | ||||||||||||||||||
| 1348 | } else if (versionString.startsWith(QLatin1String("4."))) {
| 0 | ||||||||||||||||||
| 1349 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
| 1350 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
| 1351 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
| 1352 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
| 1353 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
| 1354 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
| 1355 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
| 1356 | QGLFormat::OpenGL_Version_3_0 | | - | ||||||||||||||||||
| 1357 | QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
| 1358 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
| 1359 | QGLFormat::OpenGL_Version_3_3 | | - | ||||||||||||||||||
| 1360 | QGLFormat::OpenGL_Version_4_0; | - | ||||||||||||||||||
| 1361 | switch (versionString[2].toLatin1()) { | - | ||||||||||||||||||
| 1362 | case '3': never executed: case '3': | 0 | ||||||||||||||||||
| 1363 | versionFlags |= QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
| 1364 | // fall through | - | ||||||||||||||||||
| 1365 | case '2': code before this statement never executed: case '2':never executed: case '2': | 0 | ||||||||||||||||||
| 1366 | versionFlags |= QGLFormat::OpenGL_Version_4_2; | - | ||||||||||||||||||
| 1367 | // fall through | - | ||||||||||||||||||
| 1368 | case '1': code before this statement never executed: case '1':never executed: case '1': | 0 | ||||||||||||||||||
| 1369 | versionFlags |= QGLFormat::OpenGL_Version_4_1; | - | ||||||||||||||||||
| 1370 | // fall through | - | ||||||||||||||||||
| 1371 | case '0': code before this statement never executed: case '0':never executed: case '0': | 0 | ||||||||||||||||||
| 1372 | break; never executed: break; | 0 | ||||||||||||||||||
| 1373 | default: never executed: default: | 0 | ||||||||||||||||||
| 1374 | versionFlags |= QGLFormat::OpenGL_Version_4_1 | | - | ||||||||||||||||||
| 1375 | QGLFormat::OpenGL_Version_4_2 | | - | ||||||||||||||||||
| 1376 | QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
| 1377 | break; never executed: break; | 0 | ||||||||||||||||||
| 1378 | } | - | ||||||||||||||||||
| 1379 | } else { | - | ||||||||||||||||||
| 1380 | versionFlags |= QGLFormat::OpenGL_Version_1_1 | | - | ||||||||||||||||||
| 1381 | QGLFormat::OpenGL_Version_1_2 | | - | ||||||||||||||||||
| 1382 | QGLFormat::OpenGL_Version_1_3 | | - | ||||||||||||||||||
| 1383 | QGLFormat::OpenGL_Version_1_4 | | - | ||||||||||||||||||
| 1384 | QGLFormat::OpenGL_Version_1_5 | | - | ||||||||||||||||||
| 1385 | QGLFormat::OpenGL_Version_2_0 | | - | ||||||||||||||||||
| 1386 | QGLFormat::OpenGL_Version_2_1 | | - | ||||||||||||||||||
| 1387 | QGLFormat::OpenGL_Version_3_0 | | - | ||||||||||||||||||
| 1388 | QGLFormat::OpenGL_Version_3_1 | | - | ||||||||||||||||||
| 1389 | QGLFormat::OpenGL_Version_3_2 | | - | ||||||||||||||||||
| 1390 | QGLFormat::OpenGL_Version_3_3 | | - | ||||||||||||||||||
| 1391 | QGLFormat::OpenGL_Version_4_0 | | - | ||||||||||||||||||
| 1392 | QGLFormat::OpenGL_Version_4_1 | | - | ||||||||||||||||||
| 1393 | QGLFormat::OpenGL_Version_4_2 | | - | ||||||||||||||||||
| 1394 | QGLFormat::OpenGL_Version_4_3; | - | ||||||||||||||||||
| 1395 | } never executed: end of block | 0 | ||||||||||||||||||
| 1396 | } | - | ||||||||||||||||||
| 1397 | return versionFlags; executed 1 time by 1 test: return versionFlags;Executed by:
| 1 | ||||||||||||||||||
| 1398 | } | - | ||||||||||||||||||
| 1399 | - | |||||||||||||||||||
| 1400 | /*! | - | ||||||||||||||||||
| 1401 | \enum QGLFormat::OpenGLVersionFlag | - | ||||||||||||||||||
| 1402 | \since 4.2 | - | ||||||||||||||||||
| 1403 | - | |||||||||||||||||||
| 1404 | This enum describes the various OpenGL versions that are | - | ||||||||||||||||||
| 1405 | recognized by Qt. Use the QGLFormat::openGLVersionFlags() function | - | ||||||||||||||||||
| 1406 | to identify which versions that are supported at runtime. | - | ||||||||||||||||||
| 1407 | - | |||||||||||||||||||
| 1408 | \value OpenGL_Version_None If no OpenGL is present or if no OpenGL context is current. | - | ||||||||||||||||||
| 1409 | - | |||||||||||||||||||
| 1410 | \value OpenGL_Version_1_1 OpenGL version 1.1 or higher is present. | - | ||||||||||||||||||
| 1411 | - | |||||||||||||||||||
| 1412 | \value OpenGL_Version_1_2 OpenGL version 1.2 or higher is present. | - | ||||||||||||||||||
| 1413 | - | |||||||||||||||||||
| 1414 | \value OpenGL_Version_1_3 OpenGL version 1.3 or higher is present. | - | ||||||||||||||||||
| 1415 | - | |||||||||||||||||||
| 1416 | \value OpenGL_Version_1_4 OpenGL version 1.4 or higher is present. | - | ||||||||||||||||||
| 1417 | - | |||||||||||||||||||
| 1418 | \value OpenGL_Version_1_5 OpenGL version 1.5 or higher is present. | - | ||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | \value OpenGL_Version_2_0 OpenGL version 2.0 or higher is present. | - | ||||||||||||||||||
| 1421 | Note that version 2.0 supports all the functionality of version 1.5. | - | ||||||||||||||||||
| 1422 | - | |||||||||||||||||||
| 1423 | \value OpenGL_Version_2_1 OpenGL version 2.1 or higher is present. | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | \value OpenGL_Version_3_0 OpenGL version 3.0 or higher is present. | - | ||||||||||||||||||
| 1426 | - | |||||||||||||||||||
| 1427 | \value OpenGL_Version_3_1 OpenGL version 3.1 or higher is present. | - | ||||||||||||||||||
| 1428 | Note that OpenGL version 3.1 or higher does not necessarily support all the features of | - | ||||||||||||||||||
| 1429 | version 3.0 and lower. | - | ||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | \value OpenGL_Version_3_2 OpenGL version 3.2 or higher is present. | - | ||||||||||||||||||
| 1432 | - | |||||||||||||||||||
| 1433 | \value OpenGL_Version_3_3 OpenGL version 3.3 or higher is present. | - | ||||||||||||||||||
| 1434 | - | |||||||||||||||||||
| 1435 | \value OpenGL_Version_4_0 OpenGL version 4.0 or higher is present. | - | ||||||||||||||||||
| 1436 | - | |||||||||||||||||||
| 1437 | \value OpenGL_Version_4_1 OpenGL version 4.1 or higher is present. | - | ||||||||||||||||||
| 1438 | - | |||||||||||||||||||
| 1439 | \value OpenGL_Version_4_2 OpenGL version 4.2 or higher is present. | - | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | \value OpenGL_Version_4_3 OpenGL version 4.3 or higher is present. | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | \value OpenGL_ES_CommonLite_Version_1_0 OpenGL ES version 1.0 Common Lite or higher is present. | - | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | \value OpenGL_ES_Common_Version_1_0 OpenGL ES version 1.0 Common or higher is present. | - | ||||||||||||||||||
| 1446 | The Common profile supports all the features of Common Lite. | - | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | \value OpenGL_ES_CommonLite_Version_1_1 OpenGL ES version 1.1 Common Lite or higher is present. | - | ||||||||||||||||||
| 1449 | - | |||||||||||||||||||
| 1450 | \value OpenGL_ES_Common_Version_1_1 OpenGL ES version 1.1 Common or higher is present. | - | ||||||||||||||||||
| 1451 | The Common profile supports all the features of Common Lite. | - | ||||||||||||||||||
| 1452 | - | |||||||||||||||||||
| 1453 | \value OpenGL_ES_Version_2_0 OpenGL ES version 2.0 or higher is present. | - | ||||||||||||||||||
| 1454 | Note that OpenGL ES version 2.0 does not support all the features of OpenGL ES 1.x. | - | ||||||||||||||||||
| 1455 | So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned. | - | ||||||||||||||||||
| 1456 | - | |||||||||||||||||||
| 1457 | See also \l{http://www.opengl.org} for more information about the different | - | ||||||||||||||||||
| 1458 | revisions of OpenGL. | - | ||||||||||||||||||
| 1459 | - | |||||||||||||||||||
| 1460 | \sa openGLVersionFlags() | - | ||||||||||||||||||
| 1461 | */ | - | ||||||||||||||||||
| 1462 | - | |||||||||||||||||||
| 1463 | /*! | - | ||||||||||||||||||
| 1464 | \since 4.2 | - | ||||||||||||||||||
| 1465 | - | |||||||||||||||||||
| 1466 | Identifies, at runtime, which OpenGL versions that are supported | - | ||||||||||||||||||
| 1467 | by the current platform. | - | ||||||||||||||||||
| 1468 | - | |||||||||||||||||||
| 1469 | Note that if OpenGL version 1.5 is supported, its predecessors | - | ||||||||||||||||||
| 1470 | (i.e., version 1.4 and lower) are also supported. To identify the | - | ||||||||||||||||||
| 1471 | support of a particular feature, like multi texturing, test for | - | ||||||||||||||||||
| 1472 | the version in which the feature was first introduced (i.e., | - | ||||||||||||||||||
| 1473 | version 1.3 in the case of multi texturing) to adapt to the largest | - | ||||||||||||||||||
| 1474 | possible group of runtime platforms. | - | ||||||||||||||||||
| 1475 | - | |||||||||||||||||||
| 1476 | This function needs a valid current OpenGL context to work; | - | ||||||||||||||||||
| 1477 | otherwise it will return OpenGL_Version_None. | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | \sa hasOpenGL(), hasOpenGLOverlays() | - | ||||||||||||||||||
| 1480 | */ | - | ||||||||||||||||||
| 1481 | QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags() | - | ||||||||||||||||||
| 1482 | { | - | ||||||||||||||||||
| 1483 | static bool cachedDefault = false; | - | ||||||||||||||||||
| 1484 | static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None; | - | ||||||||||||||||||
| 1485 | QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
| 1486 | QGLTemporaryContext *tmpContext = 0; | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | if (currentCtx && currentCtx->d_func()->version_flags_cached)
| 0-2 | ||||||||||||||||||
| 1489 | return currentCtx->d_func()->version_flags; executed 1 time by 1 test: return currentCtx->d_func()->version_flags;Executed by:
| 1 | ||||||||||||||||||
| 1490 | - | |||||||||||||||||||
| 1491 | if (!currentCtx) {
| 0-1 | ||||||||||||||||||
| 1492 | if (cachedDefault) {
| 0 | ||||||||||||||||||
| 1493 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 | ||||||||||||||||||
| 1494 | } else { | - | ||||||||||||||||||
| 1495 | if (!hasOpenGL())
| 0 | ||||||||||||||||||
| 1496 | return defaultVersionFlags; never executed: return defaultVersionFlags; | 0 | ||||||||||||||||||
| 1497 | tmpContext = new QGLTemporaryContext; | - | ||||||||||||||||||
| 1498 | cachedDefault = true; | - | ||||||||||||||||||
| 1499 | } never executed: end of block | 0 | ||||||||||||||||||
| 1500 | } | - | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | QString versionString(QLatin1String(reinterpret_cast<const char*>(qgl_functions()->glGetString(GL_VERSION)))); | - | ||||||||||||||||||
| 1503 | OpenGLVersionFlags versionFlags = qOpenGLVersionFlagsFromString(versionString); | - | ||||||||||||||||||
| 1504 | if (currentCtx) {
| 0-1 | ||||||||||||||||||
| 1505 | currentCtx->d_func()->version_flags_cached = true; | - | ||||||||||||||||||
| 1506 | currentCtx->d_func()->version_flags = versionFlags; | - | ||||||||||||||||||
| 1507 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1508 | if (tmpContext) {
| 0-1 | ||||||||||||||||||
| 1509 | defaultVersionFlags = versionFlags; | - | ||||||||||||||||||
| 1510 | delete tmpContext; | - | ||||||||||||||||||
| 1511 | } never executed: end of block | 0 | ||||||||||||||||||
| 1512 | - | |||||||||||||||||||
| 1513 | return versionFlags; executed 1 time by 1 test: return versionFlags;Executed by:
| 1 | ||||||||||||||||||
| 1514 | } | - | ||||||||||||||||||
| 1515 | - | |||||||||||||||||||
| 1516 | - | |||||||||||||||||||
| 1517 | /*! | - | ||||||||||||||||||
| 1518 | Returns the default QGLFormat for the application. All QGLWidget | - | ||||||||||||||||||
| 1519 | objects that are created use this format unless another format is | - | ||||||||||||||||||
| 1520 | specified, e.g. when they are constructed. | - | ||||||||||||||||||
| 1521 | - | |||||||||||||||||||
| 1522 | If no special default format has been set using | - | ||||||||||||||||||
| 1523 | setDefaultFormat(), the default format is the same as that created | - | ||||||||||||||||||
| 1524 | with QGLFormat(). | - | ||||||||||||||||||
| 1525 | - | |||||||||||||||||||
| 1526 | \sa setDefaultFormat() | - | ||||||||||||||||||
| 1527 | */ | - | ||||||||||||||||||
| 1528 | - | |||||||||||||||||||
| 1529 | QGLFormat QGLFormat::defaultFormat() | - | ||||||||||||||||||
| 1530 | { | - | ||||||||||||||||||
| 1531 | return *qgl_default_format(); executed 12 times by 3 tests: return *qgl_default_format();Executed by:
| 12 | ||||||||||||||||||
| 1532 | } | - | ||||||||||||||||||
| 1533 | - | |||||||||||||||||||
| 1534 | /*! | - | ||||||||||||||||||
| 1535 | Sets a new default QGLFormat for the application to \a f. For | - | ||||||||||||||||||
| 1536 | example, to set single buffering as the default instead of double | - | ||||||||||||||||||
| 1537 | buffering, your main() might contain code like this: | - | ||||||||||||||||||
| 1538 | \snippet code/src_opengl_qgl.cpp 4 | - | ||||||||||||||||||
| 1539 | - | |||||||||||||||||||
| 1540 | \sa defaultFormat() | - | ||||||||||||||||||
| 1541 | */ | - | ||||||||||||||||||
| 1542 | - | |||||||||||||||||||
| 1543 | void QGLFormat::setDefaultFormat(const QGLFormat &f) | - | ||||||||||||||||||
| 1544 | { | - | ||||||||||||||||||
| 1545 | *qgl_default_format() = f; | - | ||||||||||||||||||
| 1546 | } never executed: end of block | 0 | ||||||||||||||||||
| 1547 | - | |||||||||||||||||||
| 1548 | - | |||||||||||||||||||
| 1549 | /*! | - | ||||||||||||||||||
| 1550 | Returns the default QGLFormat for overlay contexts. | - | ||||||||||||||||||
| 1551 | - | |||||||||||||||||||
| 1552 | The default overlay format is: | - | ||||||||||||||||||
| 1553 | \list | - | ||||||||||||||||||
| 1554 | \li \l{setDoubleBuffer()}{Double buffer:} Disabled. | - | ||||||||||||||||||
| 1555 | \li \l{setDepth()}{Depth buffer:} Disabled. | - | ||||||||||||||||||
| 1556 | \li \l{setRgba()}{RGBA:} Disabled (i.e., color index enabled). | - | ||||||||||||||||||
| 1557 | \li \l{setAlpha()}{Alpha channel:} Disabled. | - | ||||||||||||||||||
| 1558 | \li \l{setAccum()}{Accumulator buffer:} Disabled. | - | ||||||||||||||||||
| 1559 | \li \l{setStencil()}{Stencil buffer:} Disabled. | - | ||||||||||||||||||
| 1560 | \li \l{setStereo()}{Stereo:} Disabled. | - | ||||||||||||||||||
| 1561 | \li \l{setDirectRendering()}{Direct rendering:} Enabled. | - | ||||||||||||||||||
| 1562 | \li \l{setOverlay()}{Overlay:} Disabled. | - | ||||||||||||||||||
| 1563 | \li \l{setSampleBuffers()}{Multisample buffers:} Disabled. | - | ||||||||||||||||||
| 1564 | \li \l{setPlane()}{Plane:} 1 (i.e., first overlay plane). | - | ||||||||||||||||||
| 1565 | \endlist | - | ||||||||||||||||||
| 1566 | - | |||||||||||||||||||
| 1567 | \sa setDefaultFormat() | - | ||||||||||||||||||
| 1568 | */ | - | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | QGLFormat QGLFormat::defaultOverlayFormat() | - | ||||||||||||||||||
| 1571 | { | - | ||||||||||||||||||
| 1572 | return *defaultOverlayFormatInstance(); never executed: return *defaultOverlayFormatInstance(); | 0 | ||||||||||||||||||
| 1573 | } | - | ||||||||||||||||||
| 1574 | - | |||||||||||||||||||
| 1575 | /*! | - | ||||||||||||||||||
| 1576 | Sets a new default QGLFormat for overlay contexts to \a f. This | - | ||||||||||||||||||
| 1577 | format is used whenever a QGLWidget is created with a format that | - | ||||||||||||||||||
| 1578 | hasOverlay() enabled. | - | ||||||||||||||||||
| 1579 | - | |||||||||||||||||||
| 1580 | For example, to get a double buffered overlay context (if | - | ||||||||||||||||||
| 1581 | available), use code like this: | - | ||||||||||||||||||
| 1582 | - | |||||||||||||||||||
| 1583 | \snippet code/src_opengl_qgl.cpp 5 | - | ||||||||||||||||||
| 1584 | - | |||||||||||||||||||
| 1585 | As usual, you can find out after widget creation whether the | - | ||||||||||||||||||
| 1586 | underlying OpenGL system was able to provide the requested | - | ||||||||||||||||||
| 1587 | specification: | - | ||||||||||||||||||
| 1588 | - | |||||||||||||||||||
| 1589 | \snippet code/src_opengl_qgl.cpp 6 | - | ||||||||||||||||||
| 1590 | - | |||||||||||||||||||
| 1591 | \sa defaultOverlayFormat() | - | ||||||||||||||||||
| 1592 | */ | - | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | void QGLFormat::setDefaultOverlayFormat(const QGLFormat &f) | - | ||||||||||||||||||
| 1595 | { | - | ||||||||||||||||||
| 1596 | QGLFormat *defaultFormat = defaultOverlayFormatInstance(); | - | ||||||||||||||||||
| 1597 | *defaultFormat = f; | - | ||||||||||||||||||
| 1598 | // Make sure the user doesn't request that the overlays themselves | - | ||||||||||||||||||
| 1599 | // have overlays, since it is unlikely that the system supports | - | ||||||||||||||||||
| 1600 | // infinitely many planes... | - | ||||||||||||||||||
| 1601 | defaultFormat->setOverlay(false); | - | ||||||||||||||||||
| 1602 | } never executed: end of block | 0 | ||||||||||||||||||
| 1603 | - | |||||||||||||||||||
| 1604 | - | |||||||||||||||||||
| 1605 | /*! | - | ||||||||||||||||||
| 1606 | Returns \c true if all the options of the two QGLFormat objects | - | ||||||||||||||||||
| 1607 | \a a and \a b are equal; otherwise returns \c false. | - | ||||||||||||||||||
| 1608 | - | |||||||||||||||||||
| 1609 | \relates QGLFormat | - | ||||||||||||||||||
| 1610 | */ | - | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | bool operator==(const QGLFormat& a, const QGLFormat& b) | - | ||||||||||||||||||
| 1613 | { | - | ||||||||||||||||||
| 1614 | return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1615 | && a.d->pln == b.d->pln never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1616 | && a.d->alphaSize == b.d->alphaSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1617 | && a.d->accumSize == b.d->accumSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1618 | && a.d->stencilSize == b.d->stencilSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1619 | && a.d->depthSize == b.d->depthSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1620 | && a.d->redSize == b.d->redSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1621 | && a.d->greenSize == b.d->greenSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1622 | && a.d->blueSize == b.d->blueSize never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1623 | && a.d->numSamples == b.d->numSamples never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1624 | && a.d->swapInterval == b.d->swapInterval never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1625 | && a.d->majorVersion == b.d->majorVersion never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1626 | && a.d->minorVersion == b.d->minorVersion never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1627 | && a.d->profile == b.d->profile); never executed: return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize && a.d->depthSize == b.d->depthSize && a.d->redSize == b.d->...nSize == b.d->greenSize && a.d->blueSize == b.d->blueSize && a.d->numSamples == b.d->numSamples && a.d->swapInterval == b.d->swapInterval && a.d->majorVersion == b.d->majorVersion && a.d->minorVersion == b.d->minorVersion && a.d->profile == b.d->profile); | 0 | ||||||||||||||||||
| 1628 | } | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
| 1631 | QDebug operator<<(QDebug dbg, const QGLFormat &f) | - | ||||||||||||||||||
| 1632 | { | - | ||||||||||||||||||
| 1633 | const QGLFormatPrivate * const d = f.d; | - | ||||||||||||||||||
| 1634 | - | |||||||||||||||||||
| 1635 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 1636 | dbg.nospace() << "QGLFormat(" | - | ||||||||||||||||||
| 1637 | << "options " << d->opts | - | ||||||||||||||||||
| 1638 | << ", plane " << d->pln | - | ||||||||||||||||||
| 1639 | << ", depthBufferSize " << d->depthSize | - | ||||||||||||||||||
| 1640 | << ", accumBufferSize " << d->accumSize | - | ||||||||||||||||||
| 1641 | << ", stencilBufferSize " << d->stencilSize | - | ||||||||||||||||||
| 1642 | << ", redBufferSize " << d->redSize | - | ||||||||||||||||||
| 1643 | << ", greenBufferSize " << d->greenSize | - | ||||||||||||||||||
| 1644 | << ", blueBufferSize " << d->blueSize | - | ||||||||||||||||||
| 1645 | << ", alphaBufferSize " << d->alphaSize | - | ||||||||||||||||||
| 1646 | << ", samples " << d->numSamples | - | ||||||||||||||||||
| 1647 | << ", swapInterval " << d->swapInterval | - | ||||||||||||||||||
| 1648 | << ", majorVersion " << d->majorVersion | - | ||||||||||||||||||
| 1649 | << ", minorVersion " << d->minorVersion | - | ||||||||||||||||||
| 1650 | << ", profile " << d->profile | - | ||||||||||||||||||
| 1651 | << ')'; | - | ||||||||||||||||||
| 1652 | - | |||||||||||||||||||
| 1653 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||
| 1654 | } | - | ||||||||||||||||||
| 1655 | #endif | - | ||||||||||||||||||
| 1656 | - | |||||||||||||||||||
| 1657 | - | |||||||||||||||||||
| 1658 | /*! | - | ||||||||||||||||||
| 1659 | Returns \c false if all the options of the two QGLFormat objects | - | ||||||||||||||||||
| 1660 | \a a and \a b are equal; otherwise returns \c true. | - | ||||||||||||||||||
| 1661 | - | |||||||||||||||||||
| 1662 | \relates QGLFormat | - | ||||||||||||||||||
| 1663 | */ | - | ||||||||||||||||||
| 1664 | - | |||||||||||||||||||
| 1665 | bool operator!=(const QGLFormat& a, const QGLFormat& b) | - | ||||||||||||||||||
| 1666 | { | - | ||||||||||||||||||
| 1667 | return !(a == b); never executed: return !(a == b); | 0 | ||||||||||||||||||
| 1668 | } | - | ||||||||||||||||||
| 1669 | - | |||||||||||||||||||
| 1670 | struct QGLContextGroupList { | - | ||||||||||||||||||
| 1671 | QGLContextGroupList() | - | ||||||||||||||||||
| 1672 | : m_mutex(QMutex::Recursive) | - | ||||||||||||||||||
| 1673 | { | - | ||||||||||||||||||
| 1674 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 1675 | - | |||||||||||||||||||
| 1676 | void append(QGLContextGroup *group) { | - | ||||||||||||||||||
| 1677 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
| 1678 | m_list.append(group); | - | ||||||||||||||||||
| 1679 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1680 | - | |||||||||||||||||||
| 1681 | void remove(QGLContextGroup *group) { | - | ||||||||||||||||||
| 1682 | QMutexLocker locker(&m_mutex); | - | ||||||||||||||||||
| 1683 | m_list.removeOne(group); | - | ||||||||||||||||||
| 1684 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1685 | - | |||||||||||||||||||
| 1686 | QList<QGLContextGroup *> m_list; | - | ||||||||||||||||||
| 1687 | QMutex m_mutex; | - | ||||||||||||||||||
| 1688 | }; | - | ||||||||||||||||||
| 1689 | - | |||||||||||||||||||
| 1690 | Q_GLOBAL_STATIC(QGLContextGroupList, qt_context_groups) executed 3 times by 3 tests: end of blockExecuted by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 24 times by 3 tests: return &holder.value;Executed by:
| 0-24 | ||||||||||||||||||
| 1691 | - | |||||||||||||||||||
| 1692 | /***************************************************************************** | - | ||||||||||||||||||
| 1693 | QGLContext implementation | - | ||||||||||||||||||
| 1694 | *****************************************************************************/ | - | ||||||||||||||||||
| 1695 | - | |||||||||||||||||||
| 1696 | QGLContextGroup::QGLContextGroup(const QGLContext *context) | - | ||||||||||||||||||
| 1697 | : m_context(context), m_refs(1) | - | ||||||||||||||||||
| 1698 | { | - | ||||||||||||||||||
| 1699 | qt_context_groups()->append(this); | - | ||||||||||||||||||
| 1700 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1701 | - | |||||||||||||||||||
| 1702 | QGLContextGroup::~QGLContextGroup() | - | ||||||||||||||||||
| 1703 | { | - | ||||||||||||||||||
| 1704 | qt_context_groups()->remove(this); | - | ||||||||||||||||||
| 1705 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1706 | - | |||||||||||||||||||
| 1707 | const QGLContext *qt_gl_transfer_context(const QGLContext *ctx) | - | ||||||||||||||||||
| 1708 | { | - | ||||||||||||||||||
| 1709 | if (!ctx)
| 0 | ||||||||||||||||||
| 1710 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1711 | QList<const QGLContext *> shares | - | ||||||||||||||||||
| 1712 | (QGLContextPrivate::contextGroup(ctx)->shares()); | - | ||||||||||||||||||
| 1713 | if (shares.size() >= 2)
| 0 | ||||||||||||||||||
| 1714 | return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0); never executed: return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0); | 0 | ||||||||||||||||||
| 1715 | else | - | ||||||||||||||||||
| 1716 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1717 | } | - | ||||||||||||||||||
| 1718 | - | |||||||||||||||||||
| 1719 | QGLContextPrivate::QGLContextPrivate(QGLContext *context) | - | ||||||||||||||||||
| 1720 | : internal_context(false) | - | ||||||||||||||||||
| 1721 | , q_ptr(context) | - | ||||||||||||||||||
| 1722 | , texture_destroyer(0) | - | ||||||||||||||||||
| 1723 | , functions(0) | - | ||||||||||||||||||
| 1724 | { | - | ||||||||||||||||||
| 1725 | group = new QGLContextGroup(context); | - | ||||||||||||||||||
| 1726 | - | |||||||||||||||||||
| 1727 | texture_destroyer = new QGLTextureDestroyer; | - | ||||||||||||||||||
| 1728 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1729 | - | |||||||||||||||||||
| 1730 | QGLContextPrivate::~QGLContextPrivate() | - | ||||||||||||||||||
| 1731 | { | - | ||||||||||||||||||
| 1732 | delete functions; | - | ||||||||||||||||||
| 1733 | - | |||||||||||||||||||
| 1734 | if (!group->m_refs.deref()) {
| 1-11 | ||||||||||||||||||
| 1735 | Q_ASSERT(group->context() == q_ptr); | - | ||||||||||||||||||
| 1736 | delete group; | - | ||||||||||||||||||
| 1737 | } executed 11 times by 3 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 1738 | - | |||||||||||||||||||
| 1739 | delete texture_destroyer; | - | ||||||||||||||||||
| 1740 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1741 | - | |||||||||||||||||||
| 1742 | void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) | - | ||||||||||||||||||
| 1743 | { | - | ||||||||||||||||||
| 1744 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 1745 | glFormat = reqFormat = format; | - | ||||||||||||||||||
| 1746 | valid = false; | - | ||||||||||||||||||
| 1747 | q->setDevice(dev); | - | ||||||||||||||||||
| 1748 | - | |||||||||||||||||||
| 1749 | guiGlContext = 0; | - | ||||||||||||||||||
| 1750 | ownContext = false; | - | ||||||||||||||||||
| 1751 | fbo = 0; | - | ||||||||||||||||||
| 1752 | crWin = false; | - | ||||||||||||||||||
| 1753 | initDone = false; | - | ||||||||||||||||||
| 1754 | sharing = false; | - | ||||||||||||||||||
| 1755 | max_texture_size = -1; | - | ||||||||||||||||||
| 1756 | version_flags_cached = false; | - | ||||||||||||||||||
| 1757 | version_flags = QGLFormat::OpenGL_Version_None; | - | ||||||||||||||||||
| 1758 | current_fbo = 0; | - | ||||||||||||||||||
| 1759 | default_fbo = 0; | - | ||||||||||||||||||
| 1760 | active_engine = 0; | - | ||||||||||||||||||
| 1761 | workaround_needsFullClearOnEveryFrame = false; | - | ||||||||||||||||||
| 1762 | workaround_brokenFBOReadBack = false; | - | ||||||||||||||||||
| 1763 | workaround_brokenTexSubImage = false; | - | ||||||||||||||||||
| 1764 | workaroundsCached = false; | - | ||||||||||||||||||
| 1765 | - | |||||||||||||||||||
| 1766 | workaround_brokenTextureFromPixmap = false; | - | ||||||||||||||||||
| 1767 | workaround_brokenTextureFromPixmap_init = false; | - | ||||||||||||||||||
| 1768 | - | |||||||||||||||||||
| 1769 | workaround_brokenAlphaTexSubImage = false; | - | ||||||||||||||||||
| 1770 | workaround_brokenAlphaTexSubImage_init = false; | - | ||||||||||||||||||
| 1771 | - | |||||||||||||||||||
| 1772 | for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
| 12-36 | ||||||||||||||||||
| 1773 | vertexAttributeArraysEnabledState[i] = false; executed 36 times by 3 tests: vertexAttributeArraysEnabledState[i] = false;Executed by:
| 36 | ||||||||||||||||||
| 1774 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1775 | - | |||||||||||||||||||
| 1776 | QGLContext* QGLContext::currentCtx = 0; | - | ||||||||||||||||||
| 1777 | - | |||||||||||||||||||
| 1778 | /* | - | ||||||||||||||||||
| 1779 | QGLTemporaryContext implementation | - | ||||||||||||||||||
| 1780 | */ | - | ||||||||||||||||||
| 1781 | class QGLTemporaryContextPrivate | - | ||||||||||||||||||
| 1782 | { | - | ||||||||||||||||||
| 1783 | public: | - | ||||||||||||||||||
| 1784 | QWindow *window; | - | ||||||||||||||||||
| 1785 | QOpenGLContext *context; | - | ||||||||||||||||||
| 1786 | - | |||||||||||||||||||
| 1787 | QGLContext *oldContext; | - | ||||||||||||||||||
| 1788 | }; | - | ||||||||||||||||||
| 1789 | - | |||||||||||||||||||
| 1790 | QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) | - | ||||||||||||||||||
| 1791 | : d(new QGLTemporaryContextPrivate) | - | ||||||||||||||||||
| 1792 | { | - | ||||||||||||||||||
| 1793 | d->oldContext = const_cast<QGLContext *>(QGLContext::currentContext()); | - | ||||||||||||||||||
| 1794 | - | |||||||||||||||||||
| 1795 | d->window = new QWindow; | - | ||||||||||||||||||
| 1796 | d->window->setSurfaceType(QWindow::OpenGLSurface); | - | ||||||||||||||||||
| 1797 | d->window->setGeometry(QRect(0, 0, 3, 3)); | - | ||||||||||||||||||
| 1798 | d->window->create(); | - | ||||||||||||||||||
| 1799 | - | |||||||||||||||||||
| 1800 | d->context = new QOpenGLContext; | - | ||||||||||||||||||
| 1801 | #if !defined(QT_OPENGL_ES) | - | ||||||||||||||||||
| 1802 | if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
| 0 | ||||||||||||||||||
| 1803 | // On desktop, request latest released version | - | ||||||||||||||||||
| 1804 | QSurfaceFormat format; | - | ||||||||||||||||||
| 1805 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||
| 1806 | // OS X is limited to OpenGL 3.2 Core Profile at present | - | ||||||||||||||||||
| 1807 | // so set that here. If we use compatibility profile it | - | ||||||||||||||||||
| 1808 | // only reports 2.x contexts. | - | ||||||||||||||||||
| 1809 | format.setMajorVersion(3); | - | ||||||||||||||||||
| 1810 | format.setMinorVersion(2); | - | ||||||||||||||||||
| 1811 | format.setProfile(QSurfaceFormat::CoreProfile); | - | ||||||||||||||||||
| 1812 | #else | - | ||||||||||||||||||
| 1813 | format.setMajorVersion(4); | - | ||||||||||||||||||
| 1814 | format.setMinorVersion(3); | - | ||||||||||||||||||
| 1815 | #endif | - | ||||||||||||||||||
| 1816 | d->context->setFormat(format); | - | ||||||||||||||||||
| 1817 | } never executed: end of block | 0 | ||||||||||||||||||
| 1818 | #endif // QT_OPENGL_ES | - | ||||||||||||||||||
| 1819 | d->context->create(); | - | ||||||||||||||||||
| 1820 | d->context->makeCurrent(d->window); | - | ||||||||||||||||||
| 1821 | } never executed: end of block | 0 | ||||||||||||||||||
| 1822 | - | |||||||||||||||||||
| 1823 | QGLTemporaryContext::~QGLTemporaryContext() | - | ||||||||||||||||||
| 1824 | { | - | ||||||||||||||||||
| 1825 | if (d->oldContext)
| 0 | ||||||||||||||||||
| 1826 | d->oldContext->makeCurrent(); never executed: d->oldContext->makeCurrent(); | 0 | ||||||||||||||||||
| 1827 | - | |||||||||||||||||||
| 1828 | delete d->context; | - | ||||||||||||||||||
| 1829 | delete d->window; | - | ||||||||||||||||||
| 1830 | } never executed: end of block | 0 | ||||||||||||||||||
| 1831 | - | |||||||||||||||||||
| 1832 | /* | - | ||||||||||||||||||
| 1833 | Read back the contents of the currently bound framebuffer, used in | - | ||||||||||||||||||
| 1834 | QGLWidget::grabFrameBuffer(), QGLPixelbuffer::toImage() and | - | ||||||||||||||||||
| 1835 | QGLFramebufferObject::toImage() | - | ||||||||||||||||||
| 1836 | */ | - | ||||||||||||||||||
| 1837 | - | |||||||||||||||||||
| 1838 | static void convertFromGLImage(QImage &img, int w, int h, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
| 1839 | { | - | ||||||||||||||||||
| 1840 | Q_ASSERT(!img.isNull()); | - | ||||||||||||||||||
| 1841 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
| 1842 | // OpenGL gives RGBA; Qt wants ARGB | - | ||||||||||||||||||
| 1843 | uint *p = (uint*)img.bits(); | - | ||||||||||||||||||
| 1844 | uint *end = p + w*h; | - | ||||||||||||||||||
| 1845 | if (alpha_format && include_alpha) {
| 0 | ||||||||||||||||||
| 1846 | while (p < end) {
| 0 | ||||||||||||||||||
| 1847 | uint a = *p << 24; | - | ||||||||||||||||||
| 1848 | *p = (*p >> 8) | a; | - | ||||||||||||||||||
| 1849 | p++; | - | ||||||||||||||||||
| 1850 | } never executed: end of block | 0 | ||||||||||||||||||
| 1851 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1852 | // This is an old legacy fix for PowerPC based Macs, which | - | ||||||||||||||||||
| 1853 | // we shouldn't remove | - | ||||||||||||||||||
| 1854 | while (p < end) {
| 0 | ||||||||||||||||||
| 1855 | *p = 0xff000000 | (*p>>8); | - | ||||||||||||||||||
| 1856 | ++p; | - | ||||||||||||||||||
| 1857 | } never executed: end of block | 0 | ||||||||||||||||||
| 1858 | } never executed: end of block | 0 | ||||||||||||||||||
| 1859 | } else { | - | ||||||||||||||||||
| 1860 | // OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB | - | ||||||||||||||||||
| 1861 | for (int y = 0; y < h; y++) {
| 0 | ||||||||||||||||||
| 1862 | uint *q = (uint*)img.scanLine(y); | - | ||||||||||||||||||
| 1863 | for (int x=0; x < w; ++x) {
| 0 | ||||||||||||||||||
| 1864 | const uint pixel = *q; | - | ||||||||||||||||||
| 1865 | if (alpha_format && include_alpha) {
| 0 | ||||||||||||||||||
| 1866 | *q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | - | ||||||||||||||||||
| 1867 | | (pixel & 0xff00ff00); | - | ||||||||||||||||||
| 1868 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1869 | *q = 0xff000000 | ((pixel << 16) & 0xff0000) | - | ||||||||||||||||||
| 1870 | | ((pixel >> 16) & 0xff) | (pixel & 0x00ff00); | - | ||||||||||||||||||
| 1871 | } never executed: end of block | 0 | ||||||||||||||||||
| 1872 | - | |||||||||||||||||||
| 1873 | q++; | - | ||||||||||||||||||
| 1874 | } never executed: end of block | 0 | ||||||||||||||||||
| 1875 | } never executed: end of block | 0 | ||||||||||||||||||
| 1876 | - | |||||||||||||||||||
| 1877 | } never executed: end of block | 0 | ||||||||||||||||||
| 1878 | img = img.mirrored(); | - | ||||||||||||||||||
| 1879 | } never executed: end of block | 0 | ||||||||||||||||||
| 1880 | - | |||||||||||||||||||
| 1881 | QImage qt_gl_read_frame_buffer(const QSize &size, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
| 1882 | { | - | ||||||||||||||||||
| 1883 | QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32_Premultiplied | - | ||||||||||||||||||
| 1884 | : QImage::Format_RGB32); | - | ||||||||||||||||||
| 1885 | if (img.isNull())
| 0 | ||||||||||||||||||
| 1886 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
| 1887 | int w = size.width(); | - | ||||||||||||||||||
| 1888 | int h = size.height(); | - | ||||||||||||||||||
| 1889 | qgl_functions()->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); | - | ||||||||||||||||||
| 1890 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - | ||||||||||||||||||
| 1891 | return img; never executed: return img; | 0 | ||||||||||||||||||
| 1892 | } | - | ||||||||||||||||||
| 1893 | - | |||||||||||||||||||
| 1894 | QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha) | - | ||||||||||||||||||
| 1895 | { | - | ||||||||||||||||||
| 1896 | QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); | - | ||||||||||||||||||
| 1897 | if (img.isNull())
| 0 | ||||||||||||||||||
| 1898 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
| 1899 | int w = size.width(); | - | ||||||||||||||||||
| 1900 | int h = size.height(); | - | ||||||||||||||||||
| 1901 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 1902 | if (!QOpenGLContext::currentContext()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 1903 | - | |||||||||||||||||||
| 1904 | qgl1_functions()->glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); | - | ||||||||||||||||||
| 1905 | } never executed: end of block | 0 | ||||||||||||||||||
| 1906 | #endif // QT_OPENGL_ES | - | ||||||||||||||||||
| 1907 | convertFromGLImage(img, w, h, alpha_format, include_alpha); | - | ||||||||||||||||||
| 1908 | return img; never executed: return img; | 0 | ||||||||||||||||||
| 1909 | } | - | ||||||||||||||||||
| 1910 | - | |||||||||||||||||||
| 1911 | Q_GLOBAL_STATIC(QGLTextureCache, qt_gl_texture_cache) executed 3 times by 3 tests: end of blockExecuted by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 12 times by 3 tests: return &holder.value;Executed by:
| 0-12 | ||||||||||||||||||
| 1912 | - | |||||||||||||||||||
| 1913 | QGLTextureCache::QGLTextureCache() | - | ||||||||||||||||||
| 1914 | : m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though | - | ||||||||||||||||||
| 1915 | { | - | ||||||||||||||||||
| 1916 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapModificationHook(cleanupTexturesForPixampData); | - | ||||||||||||||||||
| 1917 | QImagePixmapCleanupHooks::instance()->addPlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - | ||||||||||||||||||
| 1918 | QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey); | - | ||||||||||||||||||
| 1919 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 1920 | - | |||||||||||||||||||
| 1921 | QGLTextureCache::~QGLTextureCache() | - | ||||||||||||||||||
| 1922 | { | - | ||||||||||||||||||
| 1923 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapModificationHook(cleanupTexturesForPixampData); | - | ||||||||||||||||||
| 1924 | QImagePixmapCleanupHooks::instance()->removePlatformPixmapDestructionHook(cleanupBeforePixmapDestruction); | - | ||||||||||||||||||
| 1925 | QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey); | - | ||||||||||||||||||
| 1926 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 1927 | - | |||||||||||||||||||
| 1928 | void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost) | - | ||||||||||||||||||
| 1929 | { | - | ||||||||||||||||||
| 1930 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
| 1931 | const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; | - | ||||||||||||||||||
| 1932 | m_cache.insert(cacheKey, texture, cost); | - | ||||||||||||||||||
| 1933 | } never executed: end of block | 0 | ||||||||||||||||||
| 1934 | - | |||||||||||||||||||
| 1935 | void QGLTextureCache::remove(qint64 key) | - | ||||||||||||||||||
| 1936 | { | - | ||||||||||||||||||
| 1937 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
| 1938 | QMutexLocker groupLocker(&qt_context_groups()->m_mutex); | - | ||||||||||||||||||
| 1939 | QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin(); | - | ||||||||||||||||||
| 1940 | while (it != qt_context_groups()->m_list.constEnd()) {
| 0 | ||||||||||||||||||
| 1941 | const QGLTextureCacheKey cacheKey = {key, *it}; | - | ||||||||||||||||||
| 1942 | m_cache.remove(cacheKey); | - | ||||||||||||||||||
| 1943 | ++it; | - | ||||||||||||||||||
| 1944 | } never executed: end of block | 0 | ||||||||||||||||||
| 1945 | } never executed: end of block | 0 | ||||||||||||||||||
| 1946 | - | |||||||||||||||||||
| 1947 | bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId) | - | ||||||||||||||||||
| 1948 | { | - | ||||||||||||||||||
| 1949 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
| 1950 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - | ||||||||||||||||||
| 1951 | for (int i = 0; i < keys.size(); ++i) {
| 0 | ||||||||||||||||||
| 1952 | QGLTexture *tex = m_cache.object(keys.at(i)); | - | ||||||||||||||||||
| 1953 | if (tex->id == textureId && tex->context == ctx) {
| 0 | ||||||||||||||||||
| 1954 | tex->options |= QGLContext::MemoryManagedBindOption; // forces a glDeleteTextures() call | - | ||||||||||||||||||
| 1955 | m_cache.remove(keys.at(i)); | - | ||||||||||||||||||
| 1956 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1957 | } | - | ||||||||||||||||||
| 1958 | } never executed: end of block | 0 | ||||||||||||||||||
| 1959 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1960 | } | - | ||||||||||||||||||
| 1961 | - | |||||||||||||||||||
| 1962 | void QGLTextureCache::removeContextTextures(QGLContext* ctx) | - | ||||||||||||||||||
| 1963 | { | - | ||||||||||||||||||
| 1964 | QWriteLocker locker(&m_lock); | - | ||||||||||||||||||
| 1965 | QList<QGLTextureCacheKey> keys = m_cache.keys(); | - | ||||||||||||||||||
| 1966 | for (int i = 0; i < keys.size(); ++i) {
| 0-12 | ||||||||||||||||||
| 1967 | const QGLTextureCacheKey &key = keys.at(i); | - | ||||||||||||||||||
| 1968 | if (m_cache.object(key)->context == ctx)
| 0 | ||||||||||||||||||
| 1969 | m_cache.remove(key); never executed: m_cache.remove(key); | 0 | ||||||||||||||||||
| 1970 | } never executed: end of block | 0 | ||||||||||||||||||
| 1971 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1972 | - | |||||||||||||||||||
| 1973 | /* | - | ||||||||||||||||||
| 1974 | a hook that removes textures from the cache when a pixmap/image | - | ||||||||||||||||||
| 1975 | is deref'ed | - | ||||||||||||||||||
| 1976 | */ | - | ||||||||||||||||||
| 1977 | void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey) | - | ||||||||||||||||||
| 1978 | { | - | ||||||||||||||||||
| 1979 | qt_gl_texture_cache()->remove(cacheKey); | - | ||||||||||||||||||
| 1980 | } never executed: end of block | 0 | ||||||||||||||||||
| 1981 | - | |||||||||||||||||||
| 1982 | - | |||||||||||||||||||
| 1983 | void QGLTextureCache::cleanupTexturesForPixampData(QPlatformPixmap* pmd) | - | ||||||||||||||||||
| 1984 | { | - | ||||||||||||||||||
| 1985 | cleanupTexturesForCacheKey(pmd->cacheKey()); | - | ||||||||||||||||||
| 1986 | } never executed: end of block | 0 | ||||||||||||||||||
| 1987 | - | |||||||||||||||||||
| 1988 | void QGLTextureCache::cleanupBeforePixmapDestruction(QPlatformPixmap* pmd) | - | ||||||||||||||||||
| 1989 | { | - | ||||||||||||||||||
| 1990 | // Remove any bound textures first: | - | ||||||||||||||||||
| 1991 | cleanupTexturesForPixampData(pmd); | - | ||||||||||||||||||
| 1992 | } never executed: end of block | 0 | ||||||||||||||||||
| 1993 | - | |||||||||||||||||||
| 1994 | QGLTextureCache *QGLTextureCache::instance() | - | ||||||||||||||||||
| 1995 | { | - | ||||||||||||||||||
| 1996 | return qt_gl_texture_cache(); executed 12 times by 3 tests: return qt_gl_texture_cache();Executed by:
| 12 | ||||||||||||||||||
| 1997 | } | - | ||||||||||||||||||
| 1998 | - | |||||||||||||||||||
| 1999 | // DDS format structure | - | ||||||||||||||||||
| 2000 | struct DDSFormat { | - | ||||||||||||||||||
| 2001 | quint32 dwSize; | - | ||||||||||||||||||
| 2002 | quint32 dwFlags; | - | ||||||||||||||||||
| 2003 | quint32 dwHeight; | - | ||||||||||||||||||
| 2004 | quint32 dwWidth; | - | ||||||||||||||||||
| 2005 | quint32 dwLinearSize; | - | ||||||||||||||||||
| 2006 | quint32 dummy1; | - | ||||||||||||||||||
| 2007 | quint32 dwMipMapCount; | - | ||||||||||||||||||
| 2008 | quint32 dummy2[11]; | - | ||||||||||||||||||
| 2009 | struct { | - | ||||||||||||||||||
| 2010 | quint32 dummy3[2]; | - | ||||||||||||||||||
| 2011 | quint32 dwFourCC; | - | ||||||||||||||||||
| 2012 | quint32 dummy4[5]; | - | ||||||||||||||||||
| 2013 | } ddsPixelFormat; | - | ||||||||||||||||||
| 2014 | }; | - | ||||||||||||||||||
| 2015 | - | |||||||||||||||||||
| 2016 | // compressed texture pixel formats | - | ||||||||||||||||||
| 2017 | #define FOURCC_DXT1 0x31545844 | - | ||||||||||||||||||
| 2018 | #define FOURCC_DXT2 0x32545844 | - | ||||||||||||||||||
| 2019 | #define FOURCC_DXT3 0x33545844 | - | ||||||||||||||||||
| 2020 | #define FOURCC_DXT4 0x34545844 | - | ||||||||||||||||||
| 2021 | #define FOURCC_DXT5 0x35545844 | - | ||||||||||||||||||
| 2022 | - | |||||||||||||||||||
| 2023 | // ####TODO Properly #ifdef this class to use #define symbols actually defined | - | ||||||||||||||||||
| 2024 | // by system GL includes | - | ||||||||||||||||||
| 2025 | #ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT | - | ||||||||||||||||||
| 2026 | #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 | - | ||||||||||||||||||
| 2027 | #endif | - | ||||||||||||||||||
| 2028 | - | |||||||||||||||||||
| 2029 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT | - | ||||||||||||||||||
| 2030 | #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 | - | ||||||||||||||||||
| 2031 | #endif | - | ||||||||||||||||||
| 2032 | - | |||||||||||||||||||
| 2033 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT | - | ||||||||||||||||||
| 2034 | #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 | - | ||||||||||||||||||
| 2035 | #endif | - | ||||||||||||||||||
| 2036 | - | |||||||||||||||||||
| 2037 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT | - | ||||||||||||||||||
| 2038 | #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 | - | ||||||||||||||||||
| 2039 | #endif | - | ||||||||||||||||||
| 2040 | - | |||||||||||||||||||
| 2041 | #ifndef GL_GENERATE_MIPMAP_SGIS | - | ||||||||||||||||||
| 2042 | #define GL_GENERATE_MIPMAP_SGIS 0x8191 | - | ||||||||||||||||||
| 2043 | #define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 | - | ||||||||||||||||||
| 2044 | #endif | - | ||||||||||||||||||
| 2045 | - | |||||||||||||||||||
| 2046 | /*! | - | ||||||||||||||||||
| 2047 | \class QGLContext | - | ||||||||||||||||||
| 2048 | \inmodule QtOpenGL | - | ||||||||||||||||||
| 2049 | \obsolete | - | ||||||||||||||||||
| 2050 | - | |||||||||||||||||||
| 2051 | \brief The QGLContext class encapsulates an OpenGL rendering context. | - | ||||||||||||||||||
| 2052 | - | |||||||||||||||||||
| 2053 | An OpenGL rendering context is a complete set of OpenGL state | - | ||||||||||||||||||
| 2054 | variables. The rendering context's \l {QGL::FormatOption} {format} | - | ||||||||||||||||||
| 2055 | is set in the constructor, but it can also be set later with | - | ||||||||||||||||||
| 2056 | setFormat(). The format options that are actually set are returned | - | ||||||||||||||||||
| 2057 | by format(); the options you asked for are returned by | - | ||||||||||||||||||
| 2058 | requestedFormat(). Note that after a QGLContext object has been | - | ||||||||||||||||||
| 2059 | constructed, the actual OpenGL context must be created by | - | ||||||||||||||||||
| 2060 | explicitly calling the \l{create()} | - | ||||||||||||||||||
| 2061 | function. The makeCurrent() function makes this context the | - | ||||||||||||||||||
| 2062 | current rendering context. You can make \e no context current | - | ||||||||||||||||||
| 2063 | using doneCurrent(). The reset() function will reset the context | - | ||||||||||||||||||
| 2064 | and make it invalid. | - | ||||||||||||||||||
| 2065 | - | |||||||||||||||||||
| 2066 | You can examine properties of the context with, e.g. isValid(), | - | ||||||||||||||||||
| 2067 | isSharing(), initialized(), windowCreated() and | - | ||||||||||||||||||
| 2068 | overlayTransparentColor(). | - | ||||||||||||||||||
| 2069 | - | |||||||||||||||||||
| 2070 | If you're using double buffering you can swap the screen contents | - | ||||||||||||||||||
| 2071 | with the off-screen buffer using swapBuffers(). | - | ||||||||||||||||||
| 2072 | - | |||||||||||||||||||
| 2073 | Please note that QGLContext is not thread safe. | - | ||||||||||||||||||
| 2074 | */ | - | ||||||||||||||||||
| 2075 | - | |||||||||||||||||||
| 2076 | /*! | - | ||||||||||||||||||
| 2077 | \enum QGLContext::BindOption | - | ||||||||||||||||||
| 2078 | \since 4.6 | - | ||||||||||||||||||
| 2079 | - | |||||||||||||||||||
| 2080 | A set of options to decide how to bind a texture using bindTexture(). | - | ||||||||||||||||||
| 2081 | - | |||||||||||||||||||
| 2082 | \value NoBindOption Don't do anything, pass the texture straight | - | ||||||||||||||||||
| 2083 | through. | - | ||||||||||||||||||
| 2084 | - | |||||||||||||||||||
| 2085 | \value InvertedYBindOption Specifies that the texture should be flipped | - | ||||||||||||||||||
| 2086 | over the X axis so that the texture coordinate 0,0 corresponds to | - | ||||||||||||||||||
| 2087 | the top left corner. Inverting the texture implies a deep copy | - | ||||||||||||||||||
| 2088 | prior to upload. | - | ||||||||||||||||||
| 2089 | - | |||||||||||||||||||
| 2090 | \value MipmapBindOption Specifies that bindTexture() should try | - | ||||||||||||||||||
| 2091 | to generate mipmaps. If the GL implementation supports the \c | - | ||||||||||||||||||
| 2092 | GL_SGIS_generate_mipmap extension, mipmaps will be automatically | - | ||||||||||||||||||
| 2093 | generated for the texture. Mipmap generation is only supported for | - | ||||||||||||||||||
| 2094 | the \c GL_TEXTURE_2D target. | - | ||||||||||||||||||
| 2095 | - | |||||||||||||||||||
| 2096 | \value PremultipliedAlphaBindOption Specifies that the image should be | - | ||||||||||||||||||
| 2097 | uploaded with premultiplied alpha and does a conversion accordingly. | - | ||||||||||||||||||
| 2098 | - | |||||||||||||||||||
| 2099 | \value LinearFilteringBindOption Specifies that the texture filtering | - | ||||||||||||||||||
| 2100 | should be set to GL_LINEAR. Default is GL_NEAREST. If mipmap is | - | ||||||||||||||||||
| 2101 | also enabled, filtering will be set to GL_LINEAR_MIPMAP_LINEAR. | - | ||||||||||||||||||
| 2102 | - | |||||||||||||||||||
| 2103 | \value DefaultBindOption In Qt 4.5 and earlier, bindTexture() | - | ||||||||||||||||||
| 2104 | would mirror the image and automatically generate mipmaps. This | - | ||||||||||||||||||
| 2105 | option helps preserve this default behavior. | - | ||||||||||||||||||
| 2106 | - | |||||||||||||||||||
| 2107 | \omitvalue CanFlipNativePixmapBindOption Used by x11 from pixmap to choose | - | ||||||||||||||||||
| 2108 | whether or not it can bind the pixmap upside down or not. | - | ||||||||||||||||||
| 2109 | - | |||||||||||||||||||
| 2110 | \omitvalue MemoryManagedBindOption Used by paint engines to | - | ||||||||||||||||||
| 2111 | indicate that the pixmap should be memory managed along side with | - | ||||||||||||||||||
| 2112 | the pixmap/image that it stems from, e.g. installing destruction | - | ||||||||||||||||||
| 2113 | hooks in them. | - | ||||||||||||||||||
| 2114 | - | |||||||||||||||||||
| 2115 | \omitvalue TemporarilyCachedBindOption Used by paint engines on some | - | ||||||||||||||||||
| 2116 | platforms to indicate that the pixmap or image texture is possibly | - | ||||||||||||||||||
| 2117 | cached only temporarily and must be destroyed immediately after the use. | - | ||||||||||||||||||
| 2118 | - | |||||||||||||||||||
| 2119 | \omitvalue InternalBindOption | - | ||||||||||||||||||
| 2120 | */ | - | ||||||||||||||||||
| 2121 | - | |||||||||||||||||||
| 2122 | /*! | - | ||||||||||||||||||
| 2123 | \obsolete | - | ||||||||||||||||||
| 2124 | - | |||||||||||||||||||
| 2125 | Constructs an OpenGL context for the given paint \a device, which | - | ||||||||||||||||||
| 2126 | can be a widget or a pixmap. The \a format specifies several | - | ||||||||||||||||||
| 2127 | display options for the context. | - | ||||||||||||||||||
| 2128 | - | |||||||||||||||||||
| 2129 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
| 2130 | features requested in \a format, the nearest subset of features | - | ||||||||||||||||||
| 2131 | will be used. After creation, the format() method will return the | - | ||||||||||||||||||
| 2132 | actual format obtained. | - | ||||||||||||||||||
| 2133 | - | |||||||||||||||||||
| 2134 | Note that after a QGLContext object has been constructed, \l | - | ||||||||||||||||||
| 2135 | create() must be called explicitly to create the actual OpenGL | - | ||||||||||||||||||
| 2136 | context. The context will be \l {isValid()}{invalid} if it was not | - | ||||||||||||||||||
| 2137 | possible to obtain a GL context at all. | - | ||||||||||||||||||
| 2138 | */ | - | ||||||||||||||||||
| 2139 | - | |||||||||||||||||||
| 2140 | QGLContext::QGLContext(const QGLFormat &format, QPaintDevice *device) | - | ||||||||||||||||||
| 2141 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
| 2142 | { | - | ||||||||||||||||||
| 2143 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2144 | d->init(device, format); | - | ||||||||||||||||||
| 2145 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 2146 | - | |||||||||||||||||||
| 2147 | /*! | - | ||||||||||||||||||
| 2148 | Constructs an OpenGL context with the given \a format which | - | ||||||||||||||||||
| 2149 | specifies several display options for the context. | - | ||||||||||||||||||
| 2150 | - | |||||||||||||||||||
| 2151 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
| 2152 | features requested in \a format, the nearest subset of features | - | ||||||||||||||||||
| 2153 | will be used. After creation, the format() method will return the | - | ||||||||||||||||||
| 2154 | actual format obtained. | - | ||||||||||||||||||
| 2155 | - | |||||||||||||||||||
| 2156 | Note that after a QGLContext object has been constructed, \l | - | ||||||||||||||||||
| 2157 | create() must be called explicitly to create the actual OpenGL | - | ||||||||||||||||||
| 2158 | context. The context will be \l {isValid()}{invalid} if it was not | - | ||||||||||||||||||
| 2159 | possible to obtain a GL context at all. | - | ||||||||||||||||||
| 2160 | - | |||||||||||||||||||
| 2161 | \sa format(), isValid() | - | ||||||||||||||||||
| 2162 | */ | - | ||||||||||||||||||
| 2163 | QGLContext::QGLContext(const QGLFormat &format) | - | ||||||||||||||||||
| 2164 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
| 2165 | { | - | ||||||||||||||||||
| 2166 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2167 | d->init(0, format); | - | ||||||||||||||||||
| 2168 | } never executed: end of block | 0 | ||||||||||||||||||
| 2169 | - | |||||||||||||||||||
| 2170 | static void qDeleteQGLContext(void *handle) | - | ||||||||||||||||||
| 2171 | { | - | ||||||||||||||||||
| 2172 | QGLContext *context = static_cast<QGLContext *>(handle); | - | ||||||||||||||||||
| 2173 | delete context; | - | ||||||||||||||||||
| 2174 | } never executed: end of block | 0 | ||||||||||||||||||
| 2175 | - | |||||||||||||||||||
| 2176 | QGLContext::QGLContext(QOpenGLContext *context) | - | ||||||||||||||||||
| 2177 | : d_ptr(new QGLContextPrivate(this)) | - | ||||||||||||||||||
| 2178 | { | - | ||||||||||||||||||
| 2179 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2180 | d->init(0, QGLFormat::fromSurfaceFormat(context->format())); | - | ||||||||||||||||||
| 2181 | d->guiGlContext = context; | - | ||||||||||||||||||
| 2182 | d->guiGlContext->setQGLContextHandle(this, qDeleteQGLContext); | - | ||||||||||||||||||
| 2183 | d->ownContext = false; | - | ||||||||||||||||||
| 2184 | d->valid = context->isValid(); | - | ||||||||||||||||||
| 2185 | d->setupSharing(); | - | ||||||||||||||||||
| 2186 | } never executed: end of block | 0 | ||||||||||||||||||
| 2187 | - | |||||||||||||||||||
| 2188 | /*! | - | ||||||||||||||||||
| 2189 | Returns the OpenGL context handle. | - | ||||||||||||||||||
| 2190 | */ | - | ||||||||||||||||||
| 2191 | QOpenGLContext *QGLContext::contextHandle() const | - | ||||||||||||||||||
| 2192 | { | - | ||||||||||||||||||
| 2193 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 2194 | return d->guiGlContext; executed 102 times by 3 tests: return d->guiGlContext;Executed by:
| 102 | ||||||||||||||||||
| 2195 | } | - | ||||||||||||||||||
| 2196 | - | |||||||||||||||||||
| 2197 | /*! | - | ||||||||||||||||||
| 2198 | Returns an OpenGL context for the window context specified by the \a context | - | ||||||||||||||||||
| 2199 | parameter. | - | ||||||||||||||||||
| 2200 | */ | - | ||||||||||||||||||
| 2201 | QGLContext *QGLContext::fromOpenGLContext(QOpenGLContext *context) | - | ||||||||||||||||||
| 2202 | { | - | ||||||||||||||||||
| 2203 | if (!context)
| 0-80 | ||||||||||||||||||
| 2204 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2205 | if (context->qGLContextHandle()) {
| 0-80 | ||||||||||||||||||
| 2206 | return reinterpret_cast<QGLContext *>(context->qGLContextHandle()); executed 80 times by 3 tests: return reinterpret_cast<QGLContext *>(context->qGLContextHandle());Executed by:
| 80 | ||||||||||||||||||
| 2207 | } | - | ||||||||||||||||||
| 2208 | QGLContext *glContext = new QGLContext(context); | - | ||||||||||||||||||
| 2209 | //Don't call create on context. This can cause the platformFormat to be set on the widget, which | - | ||||||||||||||||||
| 2210 | //will cause the platformWindow to be recreated. | - | ||||||||||||||||||
| 2211 | return glContext; never executed: return glContext; | 0 | ||||||||||||||||||
| 2212 | } | - | ||||||||||||||||||
| 2213 | - | |||||||||||||||||||
| 2214 | /*! | - | ||||||||||||||||||
| 2215 | Destroys the OpenGL context and frees its resources. | - | ||||||||||||||||||
| 2216 | */ | - | ||||||||||||||||||
| 2217 | - | |||||||||||||||||||
| 2218 | QGLContext::~QGLContext() | - | ||||||||||||||||||
| 2219 | { | - | ||||||||||||||||||
| 2220 | // remove any textures cached in this context | - | ||||||||||||||||||
| 2221 | QGLTextureCache::instance()->removeContextTextures(this); | - | ||||||||||||||||||
| 2222 | - | |||||||||||||||||||
| 2223 | // clean up resources specific to this context | - | ||||||||||||||||||
| 2224 | d_ptr->cleanup(); | - | ||||||||||||||||||
| 2225 | - | |||||||||||||||||||
| 2226 | QGLSignalProxy::instance()->emitAboutToDestroyContext(this); | - | ||||||||||||||||||
| 2227 | reset(); | - | ||||||||||||||||||
| 2228 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 2229 | - | |||||||||||||||||||
| 2230 | void QGLContextPrivate::cleanup() | - | ||||||||||||||||||
| 2231 | { | - | ||||||||||||||||||
| 2232 | } | - | ||||||||||||||||||
| 2233 | - | |||||||||||||||||||
| 2234 | #define ctx q_ptr | - | ||||||||||||||||||
| 2235 | void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) | - | ||||||||||||||||||
| 2236 | { | - | ||||||||||||||||||
| 2237 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2238 | Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT); | - | ||||||||||||||||||
| 2239 | #ifdef glEnableVertexAttribArray | - | ||||||||||||||||||
| 2240 | Q_ASSERT(glEnableVertexAttribArray); | - | ||||||||||||||||||
| 2241 | #endif | - | ||||||||||||||||||
| 2242 | - | |||||||||||||||||||
| 2243 | if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
| 3-27 | ||||||||||||||||||
| 2244 | q->functions()->glDisableVertexAttribArray(arrayIndex); executed 3 times by 1 test: q->functions()->glDisableVertexAttribArray(arrayIndex);Executed by:
| 3 | ||||||||||||||||||
| 2245 | - | |||||||||||||||||||
| 2246 | if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled)
| 3-27 | ||||||||||||||||||
| 2247 | q->functions()->glEnableVertexAttribArray(arrayIndex); executed 3 times by 1 test: q->functions()->glEnableVertexAttribArray(arrayIndex);Executed by:
| 3 | ||||||||||||||||||
| 2248 | - | |||||||||||||||||||
| 2249 | vertexAttributeArraysEnabledState[arrayIndex] = enabled; | - | ||||||||||||||||||
| 2250 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 2251 | - | |||||||||||||||||||
| 2252 | void QGLContextPrivate::syncGlState() | - | ||||||||||||||||||
| 2253 | { | - | ||||||||||||||||||
| 2254 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2255 | #ifdef glEnableVertexAttribArray | - | ||||||||||||||||||
| 2256 | Q_ASSERT(glEnableVertexAttribArray); | - | ||||||||||||||||||
| 2257 | #endif | - | ||||||||||||||||||
| 2258 | for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
| 3-9 | ||||||||||||||||||
| 2259 | if (vertexAttributeArraysEnabledState[i])
| 0-9 | ||||||||||||||||||
| 2260 | q->functions()->glEnableVertexAttribArray(i); never executed: q->functions()->glEnableVertexAttribArray(i); | 0 | ||||||||||||||||||
| 2261 | else | - | ||||||||||||||||||
| 2262 | q->functions()->glDisableVertexAttribArray(i); executed 9 times by 1 test: q->functions()->glDisableVertexAttribArray(i);Executed by:
| 9 | ||||||||||||||||||
| 2263 | } | - | ||||||||||||||||||
| 2264 | - | |||||||||||||||||||
| 2265 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2266 | #undef ctx | - | ||||||||||||||||||
| 2267 | - | |||||||||||||||||||
| 2268 | void QGLContextPrivate::swapRegion(const QRegion &) | - | ||||||||||||||||||
| 2269 | { | - | ||||||||||||||||||
| 2270 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2271 | q->swapBuffers(); | - | ||||||||||||||||||
| 2272 | } never executed: end of block | 0 | ||||||||||||||||||
| 2273 | - | |||||||||||||||||||
| 2274 | /*! | - | ||||||||||||||||||
| 2275 | \overload | - | ||||||||||||||||||
| 2276 | - | |||||||||||||||||||
| 2277 | Reads the compressed texture file \a fileName and generates a 2D GL | - | ||||||||||||||||||
| 2278 | texture from it. | - | ||||||||||||||||||
| 2279 | - | |||||||||||||||||||
| 2280 | This function can load DirectDrawSurface (DDS) textures in the | - | ||||||||||||||||||
| 2281 | DXT1, DXT3 and DXT5 DDS formats if the \c GL_ARB_texture_compression | - | ||||||||||||||||||
| 2282 | and \c GL_EXT_texture_compression_s3tc extensions are supported. | - | ||||||||||||||||||
| 2283 | - | |||||||||||||||||||
| 2284 | Since 4.6.1, textures in the ETC1 format can be loaded if the | - | ||||||||||||||||||
| 2285 | \c GL_OES_compressed_ETC1_RGB8_texture extension is supported | - | ||||||||||||||||||
| 2286 | and the ETC1 texture has been encapsulated in the PVR container format. | - | ||||||||||||||||||
| 2287 | Also, textures in the PVRTC2 and PVRTC4 formats can be loaded | - | ||||||||||||||||||
| 2288 | if the \c GL_IMG_texture_compression_pvrtc extension is supported. | - | ||||||||||||||||||
| 2289 | - | |||||||||||||||||||
| 2290 | \sa deleteTexture() | - | ||||||||||||||||||
| 2291 | */ | - | ||||||||||||||||||
| 2292 | - | |||||||||||||||||||
| 2293 | GLuint QGLContext::bindTexture(const QString &fileName) | - | ||||||||||||||||||
| 2294 | { | - | ||||||||||||||||||
| 2295 | QGLTexture texture(this); | - | ||||||||||||||||||
| 2296 | QSize size = texture.bindCompressedTexture(fileName); | - | ||||||||||||||||||
| 2297 | if (!size.isValid())
| 0 | ||||||||||||||||||
| 2298 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2299 | return texture.id; never executed: return texture.id; | 0 | ||||||||||||||||||
| 2300 | } | - | ||||||||||||||||||
| 2301 | - | |||||||||||||||||||
| 2302 | static inline QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format) | - | ||||||||||||||||||
| 2303 | { | - | ||||||||||||||||||
| 2304 | if (texture_format == GL_BGRA) {
| 0 | ||||||||||||||||||
| 2305 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
| 2306 | return ((src_pixel << 24) & 0xff000000) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
| 2307 | | ((src_pixel >> 24) & 0x000000ff) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
| 2308 | | ((src_pixel << 8) & 0x00ff0000) never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
| 2309 | | ((src_pixel >> 8) & 0x0000ff00); never executed: return ((src_pixel << 24) & 0xff000000) | ((src_pixel >> 24) & 0x000000ff) | ((src_pixel << 8) & 0x00ff0000) | ((src_pixel >> 8) & 0x0000ff00); | 0 | ||||||||||||||||||
| 2310 | } else { | - | ||||||||||||||||||
| 2311 | return src_pixel; never executed: return src_pixel; | 0 | ||||||||||||||||||
| 2312 | } | - | ||||||||||||||||||
| 2313 | } else { // GL_RGBA | - | ||||||||||||||||||
| 2314 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
| 2315 | return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); never executed: return (src_pixel << 8) | ((src_pixel >> 24) & 0xff); | 0 | ||||||||||||||||||
| 2316 | } else { | - | ||||||||||||||||||
| 2317 | return ((src_pixel << 16) & 0xff0000) never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
| 2318 | | ((src_pixel >> 16) & 0xff) never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
| 2319 | | (src_pixel & 0xff00ff00); never executed: return ((src_pixel << 16) & 0xff0000) | ((src_pixel >> 16) & 0xff) | (src_pixel & 0xff00ff00); | 0 | ||||||||||||||||||
| 2320 | } | - | ||||||||||||||||||
| 2321 | } | - | ||||||||||||||||||
| 2322 | } | - | ||||||||||||||||||
| 2323 | - | |||||||||||||||||||
| 2324 | static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format) | - | ||||||||||||||||||
| 2325 | { | - | ||||||||||||||||||
| 2326 | Q_ASSERT(dst.depth() == 32); | - | ||||||||||||||||||
| 2327 | Q_ASSERT(img.depth() == 32); | - | ||||||||||||||||||
| 2328 | - | |||||||||||||||||||
| 2329 | if (dst.size() != img.size()) {
| 0 | ||||||||||||||||||
| 2330 | int target_width = dst.width(); | - | ||||||||||||||||||
| 2331 | int target_height = dst.height(); | - | ||||||||||||||||||
| 2332 | qreal sx = target_width / qreal(img.width()); | - | ||||||||||||||||||
| 2333 | qreal sy = target_height / qreal(img.height()); | - | ||||||||||||||||||
| 2334 | - | |||||||||||||||||||
| 2335 | quint32 *dest = (quint32 *) dst.scanLine(0); // NB! avoid detach here | - | ||||||||||||||||||
| 2336 | const uchar *srcPixels = img.constScanLine(img.height() - 1); | - | ||||||||||||||||||
| 2337 | int sbpl = img.bytesPerLine(); | - | ||||||||||||||||||
| 2338 | int dbpl = dst.bytesPerLine(); | - | ||||||||||||||||||
| 2339 | - | |||||||||||||||||||
| 2340 | int ix = int(0x00010000 / sx); | - | ||||||||||||||||||
| 2341 | int iy = int(0x00010000 / sy); | - | ||||||||||||||||||
| 2342 | - | |||||||||||||||||||
| 2343 | quint32 basex = int(0.5 * ix); | - | ||||||||||||||||||
| 2344 | quint32 srcy = int(0.5 * iy); | - | ||||||||||||||||||
| 2345 | - | |||||||||||||||||||
| 2346 | // scale, swizzle and mirror in one loop | - | ||||||||||||||||||
| 2347 | while (target_height--) {
| 0 | ||||||||||||||||||
| 2348 | const uint *src = (const quint32 *) (srcPixels - (srcy >> 16) * sbpl); | - | ||||||||||||||||||
| 2349 | int srcx = basex; | - | ||||||||||||||||||
| 2350 | for (int x=0; x<target_width; ++x) {
| 0 | ||||||||||||||||||
| 2351 | dest[x] = qt_gl_convertToGLFormatHelper(src[srcx >> 16], texture_format); | - | ||||||||||||||||||
| 2352 | srcx += ix; | - | ||||||||||||||||||
| 2353 | } never executed: end of block | 0 | ||||||||||||||||||
| 2354 | dest = (quint32 *)(((uchar *) dest) + dbpl); | - | ||||||||||||||||||
| 2355 | srcy += iy; | - | ||||||||||||||||||
| 2356 | } never executed: end of block | 0 | ||||||||||||||||||
| 2357 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2358 | const int width = img.width(); | - | ||||||||||||||||||
| 2359 | const int height = img.height(); | - | ||||||||||||||||||
| 2360 | const uint *p = (const uint*) img.scanLine(img.height() - 1); | - | ||||||||||||||||||
| 2361 | uint *q = (uint*) dst.scanLine(0); | - | ||||||||||||||||||
| 2362 | - | |||||||||||||||||||
| 2363 | if (texture_format == GL_BGRA) {
| 0 | ||||||||||||||||||
| 2364 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
| 2365 | // mirror + swizzle | - | ||||||||||||||||||
| 2366 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2367 | const uint *end = p + width; | - | ||||||||||||||||||
| 2368 | while (p < end) {
| 0 | ||||||||||||||||||
| 2369 | *q = ((*p << 24) & 0xff000000) | - | ||||||||||||||||||
| 2370 | | ((*p >> 24) & 0x000000ff) | - | ||||||||||||||||||
| 2371 | | ((*p << 8) & 0x00ff0000) | - | ||||||||||||||||||
| 2372 | | ((*p >> 8) & 0x0000ff00); | - | ||||||||||||||||||
| 2373 | p++; | - | ||||||||||||||||||
| 2374 | q++; | - | ||||||||||||||||||
| 2375 | } never executed: end of block | 0 | ||||||||||||||||||
| 2376 | p -= 2 * width; | - | ||||||||||||||||||
| 2377 | } never executed: end of block | 0 | ||||||||||||||||||
| 2378 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2379 | const uint bytesPerLine = img.bytesPerLine(); | - | ||||||||||||||||||
| 2380 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2381 | memcpy(q, p, bytesPerLine); | - | ||||||||||||||||||
| 2382 | q += width; | - | ||||||||||||||||||
| 2383 | p -= width; | - | ||||||||||||||||||
| 2384 | } never executed: end of block | 0 | ||||||||||||||||||
| 2385 | } never executed: end of block | 0 | ||||||||||||||||||
| 2386 | } else { | - | ||||||||||||||||||
| 2387 | if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
| 0 | ||||||||||||||||||
| 2388 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2389 | const uint *end = p + width; | - | ||||||||||||||||||
| 2390 | while (p < end) {
| 0 | ||||||||||||||||||
| 2391 | *q = (*p << 8) | ((*p >> 24) & 0xff); | - | ||||||||||||||||||
| 2392 | p++; | - | ||||||||||||||||||
| 2393 | q++; | - | ||||||||||||||||||
| 2394 | } never executed: end of block | 0 | ||||||||||||||||||
| 2395 | p -= 2 * width; | - | ||||||||||||||||||
| 2396 | } never executed: end of block | 0 | ||||||||||||||||||
| 2397 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2398 | for (int i=0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2399 | const uint *end = p + width; | - | ||||||||||||||||||
| 2400 | while (p < end) {
| 0 | ||||||||||||||||||
| 2401 | *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); | - | ||||||||||||||||||
| 2402 | p++; | - | ||||||||||||||||||
| 2403 | q++; | - | ||||||||||||||||||
| 2404 | } never executed: end of block | 0 | ||||||||||||||||||
| 2405 | p -= 2 * width; | - | ||||||||||||||||||
| 2406 | } never executed: end of block | 0 | ||||||||||||||||||
| 2407 | } never executed: end of block | 0 | ||||||||||||||||||
| 2408 | } | - | ||||||||||||||||||
| 2409 | } | - | ||||||||||||||||||
| 2410 | } | - | ||||||||||||||||||
| 2411 | - | |||||||||||||||||||
| 2412 | /*! \internal */ | - | ||||||||||||||||||
| 2413 | QGLTexture *QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint format, | - | ||||||||||||||||||
| 2414 | QGLContext::BindOptions options) | - | ||||||||||||||||||
| 2415 | { | - | ||||||||||||||||||
| 2416 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2417 | - | |||||||||||||||||||
| 2418 | const qint64 key = image.cacheKey(); | - | ||||||||||||||||||
| 2419 | QGLTexture *texture = textureCacheLookup(key, target); | - | ||||||||||||||||||
| 2420 | if (texture) {
| 0 | ||||||||||||||||||
| 2421 | if (image.paintingActive()) {
| 0 | ||||||||||||||||||
| 2422 | // A QPainter is active on the image - take the safe route and replace the texture. | - | ||||||||||||||||||
| 2423 | q->deleteTexture(texture->id); | - | ||||||||||||||||||
| 2424 | texture = 0; | - | ||||||||||||||||||
| 2425 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2426 | qgl_functions()->glBindTexture(target, texture->id); | - | ||||||||||||||||||
| 2427 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2428 | } | - | ||||||||||||||||||
| 2429 | } | - | ||||||||||||||||||
| 2430 | - | |||||||||||||||||||
| 2431 | if (!texture)
| 0 | ||||||||||||||||||
| 2432 | texture = bindTexture(image, target, format, key, options); never executed: texture = bindTexture(image, target, format, key, options); | 0 | ||||||||||||||||||
| 2433 | // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null | - | ||||||||||||||||||
| 2434 | Q_ASSERT(texture); | - | ||||||||||||||||||
| 2435 | - | |||||||||||||||||||
| 2436 | // Enable the cleanup hooks for this image so that the texture cache entry is removed when the | - | ||||||||||||||||||
| 2437 | // image gets deleted: | - | ||||||||||||||||||
| 2438 | QImagePixmapCleanupHooks::enableCleanupHooks(image); | - | ||||||||||||||||||
| 2439 | - | |||||||||||||||||||
| 2440 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2441 | } | - | ||||||||||||||||||
| 2442 | - | |||||||||||||||||||
| 2443 | // #define QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2444 | - | |||||||||||||||||||
| 2445 | // ####TODO Properly #ifdef this file to use #define symbols actually defined | - | ||||||||||||||||||
| 2446 | // by OpenGL/ES includes | - | ||||||||||||||||||
| 2447 | #ifndef GL_UNSIGNED_INT_8_8_8_8_REV | - | ||||||||||||||||||
| 2448 | #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 | - | ||||||||||||||||||
| 2449 | #endif | - | ||||||||||||||||||
| 2450 | - | |||||||||||||||||||
| 2451 | // map from Qt's ARGB endianness-dependent format to GL's big-endian RGBA layout | - | ||||||||||||||||||
| 2452 | static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type) | - | ||||||||||||||||||
| 2453 | { | - | ||||||||||||||||||
| 2454 | const int width = img.width(); | - | ||||||||||||||||||
| 2455 | const int height = img.height(); | - | ||||||||||||||||||
| 2456 | - | |||||||||||||||||||
| 2457 | if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV
| 0 | ||||||||||||||||||
| 2458 | || (pixel_type == GL_UNSIGNED_BYTE && QSysInfo::ByteOrder == QSysInfo::LittleEndian))
| 0 | ||||||||||||||||||
| 2459 | { | - | ||||||||||||||||||
| 2460 | for (int i = 0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2461 | uint *p = (uint *) img.scanLine(i); | - | ||||||||||||||||||
| 2462 | for (int x = 0; x < width; ++x)
| 0 | ||||||||||||||||||
| 2463 | p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); never executed: p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); | 0 | ||||||||||||||||||
| 2464 | } never executed: end of block | 0 | ||||||||||||||||||
| 2465 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2466 | for (int i = 0; i < height; ++i) {
| 0 | ||||||||||||||||||
| 2467 | uint *p = (uint *) img.scanLine(i); | - | ||||||||||||||||||
| 2468 | for (int x = 0; x < width; ++x)
| 0 | ||||||||||||||||||
| 2469 | p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); never executed: p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff); | 0 | ||||||||||||||||||
| 2470 | } never executed: end of block | 0 | ||||||||||||||||||
| 2471 | } never executed: end of block | 0 | ||||||||||||||||||
| 2472 | } | - | ||||||||||||||||||
| 2473 | - | |||||||||||||||||||
| 2474 | QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint internalFormat, | - | ||||||||||||||||||
| 2475 | const qint64 key, QGLContext::BindOptions options) | - | ||||||||||||||||||
| 2476 | { | - | ||||||||||||||||||
| 2477 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2478 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 2479 | - | |||||||||||||||||||
| 2480 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2481 | printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x, key=%llx\n", | - | ||||||||||||||||||
| 2482 | image.width(), image.height(), internalFormat, int(options), key); | - | ||||||||||||||||||
| 2483 | QTime time; | - | ||||||||||||||||||
| 2484 | time.start(); | - | ||||||||||||||||||
| 2485 | #endif | - | ||||||||||||||||||
| 2486 | - | |||||||||||||||||||
| 2487 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 2488 | // Reset the gl error stack...git | - | ||||||||||||||||||
| 2489 | while (funcs->glGetError() != GL_NO_ERROR) ; never executed: ;
| 0 | ||||||||||||||||||
| 2490 | #endif | - | ||||||||||||||||||
| 2491 | - | |||||||||||||||||||
| 2492 | // Scale the pixmap if needed. GL textures needs to have the | - | ||||||||||||||||||
| 2493 | // dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL | - | ||||||||||||||||||
| 2494 | // 2.0 or use the GL_TEXTURE_RECTANGLE texture target | - | ||||||||||||||||||
| 2495 | int tx_w = qNextPowerOfTwo(image.width() - 1); | - | ||||||||||||||||||
| 2496 | int tx_h = qNextPowerOfTwo(image.height() - 1); | - | ||||||||||||||||||
| 2497 | - | |||||||||||||||||||
| 2498 | QImage img = image; | - | ||||||||||||||||||
| 2499 | - | |||||||||||||||||||
| 2500 | if (!qgl_extensions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)
| 0 | ||||||||||||||||||
| 2501 | && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0)
| 0 | ||||||||||||||||||
| 2502 | && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height())))
| 0 | ||||||||||||||||||
| 2503 | { | - | ||||||||||||||||||
| 2504 | img = img.scaled(tx_w, tx_h); | - | ||||||||||||||||||
| 2505 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2506 | printf(" - upscaled to %dx%d (%d ms)\n", tx_w, tx_h, time.elapsed()); | - | ||||||||||||||||||
| 2507 | - | |||||||||||||||||||
| 2508 | #endif | - | ||||||||||||||||||
| 2509 | } never executed: end of block | 0 | ||||||||||||||||||
| 2510 | - | |||||||||||||||||||
| 2511 | GLuint filtering = options & QGLContext::LinearFilteringBindOption ? GL_LINEAR : GL_NEAREST;
| 0 | ||||||||||||||||||
| 2512 | - | |||||||||||||||||||
| 2513 | GLuint tx_id; | - | ||||||||||||||||||
| 2514 | funcs->glGenTextures(1, &tx_id); | - | ||||||||||||||||||
| 2515 | funcs->glBindTexture(target, tx_id); | - | ||||||||||||||||||
| 2516 | funcs->glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filtering); | - | ||||||||||||||||||
| 2517 | - | |||||||||||||||||||
| 2518 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 2519 | bool genMipmap = !ctx->isOpenGLES(); | - | ||||||||||||||||||
| 2520 | if (glFormat.directRendering()
| 0 | ||||||||||||||||||
| 2521 | && (qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::GenerateMipmap))
| 0 | ||||||||||||||||||
| 2522 | && target == GL_TEXTURE_2D
| 0 | ||||||||||||||||||
| 2523 | && (options & QGLContext::MipmapBindOption))
| 0 | ||||||||||||||||||
| 2524 | { | - | ||||||||||||||||||
| 2525 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 2526 | if (genMipmap) {
| 0 | ||||||||||||||||||
| 2527 | funcs->glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); | - | ||||||||||||||||||
| 2528 | funcs->glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); | - | ||||||||||||||||||
| 2529 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2530 | funcs->glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); | - | ||||||||||||||||||
| 2531 | genMipmap = true; | - | ||||||||||||||||||
| 2532 | } never executed: end of block | 0 | ||||||||||||||||||
| 2533 | #else | - | ||||||||||||||||||
| 2534 | funcs->glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); | - | ||||||||||||||||||
| 2535 | genMipmap = true; | - | ||||||||||||||||||
| 2536 | #endif | - | ||||||||||||||||||
| 2537 | funcs->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, options & QGLContext::LinearFilteringBindOption | - | ||||||||||||||||||
| 2538 | ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST); | - | ||||||||||||||||||
| 2539 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2540 | printf(" - generating mipmaps (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2541 | #endif | - | ||||||||||||||||||
| 2542 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2543 | funcs->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filtering); | - | ||||||||||||||||||
| 2544 | } never executed: end of block | 0 | ||||||||||||||||||
| 2545 | - | |||||||||||||||||||
| 2546 | QImage::Format target_format = img.format(); | - | ||||||||||||||||||
| 2547 | bool premul = options & QGLContext::PremultipliedAlphaBindOption; | - | ||||||||||||||||||
| 2548 | bool needsbyteswap = true; | - | ||||||||||||||||||
| 2549 | GLenum externalFormat; | - | ||||||||||||||||||
| 2550 | GLuint pixel_type; | - | ||||||||||||||||||
| 2551 | if (target_format == QImage::Format_RGBA8888
| 0 | ||||||||||||||||||
| 2552 | || target_format == QImage::Format_RGBA8888_Premultiplied
| 0 | ||||||||||||||||||
| 2553 | || target_format == QImage::Format_RGBX8888) {
| 0 | ||||||||||||||||||
| 2554 | externalFormat = GL_RGBA; | - | ||||||||||||||||||
| 2555 | pixel_type = GL_UNSIGNED_BYTE; | - | ||||||||||||||||||
| 2556 | needsbyteswap = false; | - | ||||||||||||||||||
| 2557 | } else if (qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::BGRATextureFormat)) { never executed: end of block
| 0 | ||||||||||||||||||
| 2558 | externalFormat = GL_BGRA; | - | ||||||||||||||||||
| 2559 | needsbyteswap = false; | - | ||||||||||||||||||
| 2560 | if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2)
| 0 | ||||||||||||||||||
| 2561 | pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV; never executed: pixel_type = 0x8367; | 0 | ||||||||||||||||||
| 2562 | else | - | ||||||||||||||||||
| 2563 | pixel_type = GL_UNSIGNED_BYTE; never executed: pixel_type = 0x1401; | 0 | ||||||||||||||||||
| 2564 | } else { | - | ||||||||||||||||||
| 2565 | externalFormat = GL_RGBA; | - | ||||||||||||||||||
| 2566 | pixel_type = GL_UNSIGNED_BYTE; | - | ||||||||||||||||||
| 2567 | } never executed: end of block | 0 | ||||||||||||||||||
| 2568 | - | |||||||||||||||||||
| 2569 | switch (target_format) { | - | ||||||||||||||||||
| 2570 | case QImage::Format_ARGB32: never executed: case QImage::Format_ARGB32: | 0 | ||||||||||||||||||
| 2571 | if (premul) {
| 0 | ||||||||||||||||||
| 2572 | img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||
| 2573 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2574 | printf(" - converted ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
| 2575 | #endif | - | ||||||||||||||||||
| 2576 | } never executed: end of block | 0 | ||||||||||||||||||
| 2577 | break; never executed: break; | 0 | ||||||||||||||||||
| 2578 | case QImage::Format_ARGB32_Premultiplied: never executed: case QImage::Format_ARGB32_Premultiplied: | 0 | ||||||||||||||||||
| 2579 | if (!premul) {
| 0 | ||||||||||||||||||
| 2580 | img = img.convertToFormat(target_format = QImage::Format_ARGB32); | - | ||||||||||||||||||
| 2581 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2582 | printf(" - converted ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2583 | #endif | - | ||||||||||||||||||
| 2584 | } never executed: end of block | 0 | ||||||||||||||||||
| 2585 | break; never executed: break; | 0 | ||||||||||||||||||
| 2586 | case QImage::Format_RGBA8888: never executed: case QImage::Format_RGBA8888: | 0 | ||||||||||||||||||
| 2587 | if (premul) {
| 0 | ||||||||||||||||||
| 2588 | img = img.convertToFormat(target_format = QImage::Format_RGBA8888_Premultiplied); | - | ||||||||||||||||||
| 2589 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2590 | printf(" - converted RGBA8888 -> RGBA8888_Premultiplied (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
| 2591 | #endif | - | ||||||||||||||||||
| 2592 | } never executed: end of block | 0 | ||||||||||||||||||
| 2593 | break; never executed: break; | 0 | ||||||||||||||||||
| 2594 | case QImage::Format_RGBA8888_Premultiplied: never executed: case QImage::Format_RGBA8888_Premultiplied: | 0 | ||||||||||||||||||
| 2595 | if (!premul) {
| 0 | ||||||||||||||||||
| 2596 | img = img.convertToFormat(target_format = QImage::Format_RGBA8888); | - | ||||||||||||||||||
| 2597 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2598 | printf(" - converted RGBA8888_Premultiplied -> RGBA8888 (%d ms) \n", time.elapsed()); | - | ||||||||||||||||||
| 2599 | #endif | - | ||||||||||||||||||
| 2600 | } never executed: end of block | 0 | ||||||||||||||||||
| 2601 | break; never executed: break; | 0 | ||||||||||||||||||
| 2602 | case QImage::Format_RGB16: never executed: case QImage::Format_RGB16: | 0 | ||||||||||||||||||
| 2603 | pixel_type = GL_UNSIGNED_SHORT_5_6_5; | - | ||||||||||||||||||
| 2604 | externalFormat = GL_RGB; | - | ||||||||||||||||||
| 2605 | internalFormat = GL_RGB; | - | ||||||||||||||||||
| 2606 | needsbyteswap = false; | - | ||||||||||||||||||
| 2607 | break; never executed: break; | 0 | ||||||||||||||||||
| 2608 | case QImage::Format_RGB32: never executed: case QImage::Format_RGB32: | 0 | ||||||||||||||||||
| 2609 | case QImage::Format_RGBX8888: never executed: case QImage::Format_RGBX8888: | 0 | ||||||||||||||||||
| 2610 | break; never executed: break; | 0 | ||||||||||||||||||
| 2611 | default: never executed: default: | 0 | ||||||||||||||||||
| 2612 | // Ideally more formats would be converted directly to an RGBA8888 format, | - | ||||||||||||||||||
| 2613 | // but we are only guaranteed to have a fast conversion to an ARGB format. | - | ||||||||||||||||||
| 2614 | if (img.hasAlphaChannel()) {
| 0 | ||||||||||||||||||
| 2615 | img = img.convertToFormat(premul | - | ||||||||||||||||||
| 2616 | ? QImage::Format_ARGB32_Premultiplied | - | ||||||||||||||||||
| 2617 | : QImage::Format_ARGB32); | - | ||||||||||||||||||
| 2618 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2619 | printf(" - converted to 32-bit alpha format (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2620 | #endif | - | ||||||||||||||||||
| 2621 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2622 | img = img.convertToFormat(QImage::Format_RGB32); | - | ||||||||||||||||||
| 2623 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2624 | printf(" - converted to 32-bit (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2625 | #endif | - | ||||||||||||||||||
| 2626 | } never executed: end of block | 0 | ||||||||||||||||||
| 2627 | } | - | ||||||||||||||||||
| 2628 | - | |||||||||||||||||||
| 2629 | if (options & QGLContext::InvertedYBindOption) {
| 0 | ||||||||||||||||||
| 2630 | if (img.isDetached()) {
| 0 | ||||||||||||||||||
| 2631 | int ipl = img.bytesPerLine() / 4; | - | ||||||||||||||||||
| 2632 | int h = img.height(); | - | ||||||||||||||||||
| 2633 | for (int y=0; y<h/2; ++y) {
| 0 | ||||||||||||||||||
| 2634 | int *a = (int *) img.scanLine(y); | - | ||||||||||||||||||
| 2635 | int *b = (int *) img.scanLine(h - y - 1); | - | ||||||||||||||||||
| 2636 | for (int x=0; x<ipl; ++x)
| 0 | ||||||||||||||||||
| 2637 | qSwap(a[x], b[x]); never executed: qSwap(a[x], b[x]); | 0 | ||||||||||||||||||
| 2638 | } never executed: end of block | 0 | ||||||||||||||||||
| 2639 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2640 | // Create a new image and copy across. If we use the | - | ||||||||||||||||||
| 2641 | // above in-place code then a full copy of the image is | - | ||||||||||||||||||
| 2642 | // made before the lines are swapped, which processes the | - | ||||||||||||||||||
| 2643 | // data twice. This version should only do it once. | - | ||||||||||||||||||
| 2644 | img = img.mirrored(); | - | ||||||||||||||||||
| 2645 | } never executed: end of block | 0 | ||||||||||||||||||
| 2646 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2647 | printf(" - flipped bits over y (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2648 | #endif | - | ||||||||||||||||||
| 2649 | } | - | ||||||||||||||||||
| 2650 | - | |||||||||||||||||||
| 2651 | if (needsbyteswap) {
| 0 | ||||||||||||||||||
| 2652 | // The only case where we end up with a depth different from | - | ||||||||||||||||||
| 2653 | // 32 in the switch above is for the RGB16 case, where we do | - | ||||||||||||||||||
| 2654 | // not need a byteswap. | - | ||||||||||||||||||
| 2655 | Q_ASSERT(img.depth() == 32); | - | ||||||||||||||||||
| 2656 | qgl_byteSwapImage(img, pixel_type); | - | ||||||||||||||||||
| 2657 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2658 | printf(" - did byte swapping (%d ms)\n", time.elapsed()); | - | ||||||||||||||||||
| 2659 | #endif | - | ||||||||||||||||||
| 2660 | } never executed: end of block | 0 | ||||||||||||||||||
| 2661 | if (ctx->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 2662 | // OpenGL/ES requires that the internal and external formats be | - | ||||||||||||||||||
| 2663 | // identical. | - | ||||||||||||||||||
| 2664 | internalFormat = externalFormat; | - | ||||||||||||||||||
| 2665 | } never executed: end of block | 0 | ||||||||||||||||||
| 2666 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2667 | printf(" - uploading, image.format=%d, externalFormat=0x%x, internalFormat=0x%x, pixel_type=0x%x\n", | - | ||||||||||||||||||
| 2668 | img.format(), externalFormat, internalFormat, pixel_type); | - | ||||||||||||||||||
| 2669 | #endif | - | ||||||||||||||||||
| 2670 | - | |||||||||||||||||||
| 2671 | const QImage &constRef = img; // to avoid detach in bits()... | - | ||||||||||||||||||
| 2672 | funcs->glTexImage2D(target, 0, internalFormat, img.width(), img.height(), 0, externalFormat, | - | ||||||||||||||||||
| 2673 | pixel_type, constRef.bits()); | - | ||||||||||||||||||
| 2674 | if (genMipmap && ctx->isOpenGLES())
| 0 | ||||||||||||||||||
| 2675 | q->functions()->glGenerateMipmap(target); never executed: q->functions()->glGenerateMipmap(target); | 0 | ||||||||||||||||||
| 2676 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 2677 | GLenum error = funcs->glGetError(); | - | ||||||||||||||||||
| 2678 | if (error != GL_NO_ERROR) {
| 0 | ||||||||||||||||||
| 2679 | qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target); | - | ||||||||||||||||||
| 2680 | } never executed: end of block | 0 | ||||||||||||||||||
| 2681 | #endif | - | ||||||||||||||||||
| 2682 | - | |||||||||||||||||||
| 2683 | #ifdef QGL_BIND_TEXTURE_DEBUG | - | ||||||||||||||||||
| 2684 | static int totalUploadTime = 0; | - | ||||||||||||||||||
| 2685 | totalUploadTime += time.elapsed(); | - | ||||||||||||||||||
| 2686 | printf(" - upload done in %d ms, (accumulated: %d ms)\n", time.elapsed(), totalUploadTime); | - | ||||||||||||||||||
| 2687 | #endif | - | ||||||||||||||||||
| 2688 | - | |||||||||||||||||||
| 2689 | - | |||||||||||||||||||
| 2690 | // this assumes the size of a texture is always smaller than the max cache size | - | ||||||||||||||||||
| 2691 | int cost = img.width()*img.height()*4/1024; | - | ||||||||||||||||||
| 2692 | QGLTexture *texture = new QGLTexture(q, tx_id, target, options); | - | ||||||||||||||||||
| 2693 | QGLTextureCache::instance()->insert(q, key, texture, cost); | - | ||||||||||||||||||
| 2694 | - | |||||||||||||||||||
| 2695 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2696 | } | - | ||||||||||||||||||
| 2697 | - | |||||||||||||||||||
| 2698 | QGLTexture *QGLContextPrivate::textureCacheLookup(const qint64 key, GLenum target) | - | ||||||||||||||||||
| 2699 | { | - | ||||||||||||||||||
| 2700 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2701 | QGLTexture *texture = QGLTextureCache::instance()->getTexture(q, key); | - | ||||||||||||||||||
| 2702 | if (texture && texture->target == target
| 0 | ||||||||||||||||||
| 2703 | && (texture->context == q || QGLContext::areSharing(q, texture->context)))
| 0 | ||||||||||||||||||
| 2704 | { | - | ||||||||||||||||||
| 2705 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2706 | } | - | ||||||||||||||||||
| 2707 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2708 | } | - | ||||||||||||||||||
| 2709 | - | |||||||||||||||||||
| 2710 | /*! \internal */ | - | ||||||||||||||||||
| 2711 | QGLTexture *QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options) | - | ||||||||||||||||||
| 2712 | { | - | ||||||||||||||||||
| 2713 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2714 | QPlatformPixmap *pd = pixmap.handle(); | - | ||||||||||||||||||
| 2715 | Q_UNUSED(pd); | - | ||||||||||||||||||
| 2716 | - | |||||||||||||||||||
| 2717 | const qint64 key = pixmap.cacheKey(); | - | ||||||||||||||||||
| 2718 | QGLTexture *texture = textureCacheLookup(key, target); | - | ||||||||||||||||||
| 2719 | if (texture) {
| 0 | ||||||||||||||||||
| 2720 | if (pixmap.paintingActive()) {
| 0 | ||||||||||||||||||
| 2721 | // A QPainter is active on the pixmap - take the safe route and replace the texture. | - | ||||||||||||||||||
| 2722 | q->deleteTexture(texture->id); | - | ||||||||||||||||||
| 2723 | texture = 0; | - | ||||||||||||||||||
| 2724 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2725 | qgl_functions()->glBindTexture(target, texture->id); | - | ||||||||||||||||||
| 2726 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2727 | } | - | ||||||||||||||||||
| 2728 | } | - | ||||||||||||||||||
| 2729 | - | |||||||||||||||||||
| 2730 | if (!texture) {
| 0 | ||||||||||||||||||
| 2731 | QImage image; | - | ||||||||||||||||||
| 2732 | QPaintEngine* paintEngine = pixmap.paintEngine(); | - | ||||||||||||||||||
| 2733 | if (!paintEngine || paintEngine->type() != QPaintEngine::Raster)
| 0 | ||||||||||||||||||
| 2734 | image = pixmap.toImage(); never executed: image = pixmap.toImage(); | 0 | ||||||||||||||||||
| 2735 | else { | - | ||||||||||||||||||
| 2736 | // QRasterPixmapData::toImage() will deep-copy the backing QImage if there's an active QPainter on it. | - | ||||||||||||||||||
| 2737 | // For performance reasons, we don't want that here, so we temporarily redirect the paint engine. | - | ||||||||||||||||||
| 2738 | QPaintDevice* currentPaintDevice = paintEngine->paintDevice(); | - | ||||||||||||||||||
| 2739 | paintEngine->setPaintDevice(0); | - | ||||||||||||||||||
| 2740 | image = pixmap.toImage(); | - | ||||||||||||||||||
| 2741 | paintEngine->setPaintDevice(currentPaintDevice); | - | ||||||||||||||||||
| 2742 | } never executed: end of block | 0 | ||||||||||||||||||
| 2743 | - | |||||||||||||||||||
| 2744 | // If the system depth is 16 and the pixmap doesn't have an alpha channel | - | ||||||||||||||||||
| 2745 | // then we convert it to RGB16 in the hope that it gets uploaded as a 16 | - | ||||||||||||||||||
| 2746 | // bit texture which is much faster to access than a 32-bit one. | - | ||||||||||||||||||
| 2747 | if (pixmap.depth() == 16 && !image.hasAlphaChannel() )
| 0 | ||||||||||||||||||
| 2748 | image = image.convertToFormat(QImage::Format_RGB16); never executed: image = image.convertToFormat(QImage::Format_RGB16); | 0 | ||||||||||||||||||
| 2749 | texture = bindTexture(image, target, format, key, options); | - | ||||||||||||||||||
| 2750 | } never executed: end of block | 0 | ||||||||||||||||||
| 2751 | // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null | - | ||||||||||||||||||
| 2752 | Q_ASSERT(texture); | - | ||||||||||||||||||
| 2753 | - | |||||||||||||||||||
| 2754 | if (texture->id > 0)
| 0 | ||||||||||||||||||
| 2755 | QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); never executed: QImagePixmapCleanupHooks::enableCleanupHooks(pixmap); | 0 | ||||||||||||||||||
| 2756 | - | |||||||||||||||||||
| 2757 | return texture; never executed: return texture; | 0 | ||||||||||||||||||
| 2758 | } | - | ||||||||||||||||||
| 2759 | - | |||||||||||||||||||
| 2760 | /*! \internal */ | - | ||||||||||||||||||
| 2761 | int QGLContextPrivate::maxTextureSize() | - | ||||||||||||||||||
| 2762 | { | - | ||||||||||||||||||
| 2763 | if (max_texture_size != -1)
| 0 | ||||||||||||||||||
| 2764 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 2765 | - | |||||||||||||||||||
| 2766 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 2767 | funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | - | ||||||||||||||||||
| 2768 | - | |||||||||||||||||||
| 2769 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 2770 | Q_Q(QGLContext); | - | ||||||||||||||||||
| 2771 | if (!q->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 2772 | GLenum proxy = GL_PROXY_TEXTURE_2D; | - | ||||||||||||||||||
| 2773 | - | |||||||||||||||||||
| 2774 | GLint size; | - | ||||||||||||||||||
| 2775 | GLint next = 64; | - | ||||||||||||||||||
| 2776 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
| 2777 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 2778 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); | - | ||||||||||||||||||
| 2779 | if (size == 0) {
| 0 | ||||||||||||||||||
| 2780 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 2781 | } | - | ||||||||||||||||||
| 2782 | do { | - | ||||||||||||||||||
| 2783 | size = next; | - | ||||||||||||||||||
| 2784 | next = size * 2; | - | ||||||||||||||||||
| 2785 | - | |||||||||||||||||||
| 2786 | if (next > max_texture_size)
| 0 | ||||||||||||||||||
| 2787 | break; never executed: break; | 0 | ||||||||||||||||||
| 2788 | funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | - | ||||||||||||||||||
| 2789 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); | - | ||||||||||||||||||
| 2790 | } while (next > size); never executed: end of block
| 0 | ||||||||||||||||||
| 2791 | - | |||||||||||||||||||
| 2792 | max_texture_size = size; | - | ||||||||||||||||||
| 2793 | } never executed: end of block | 0 | ||||||||||||||||||
| 2794 | #endif | - | ||||||||||||||||||
| 2795 | - | |||||||||||||||||||
| 2796 | return max_texture_size; never executed: return max_texture_size; | 0 | ||||||||||||||||||
| 2797 | } | - | ||||||||||||||||||
| 2798 | - | |||||||||||||||||||
| 2799 | /*! | - | ||||||||||||||||||
| 2800 | Returns a QGLFunctions object that is initialized for this context. | - | ||||||||||||||||||
| 2801 | */ | - | ||||||||||||||||||
| 2802 | QGLFunctions *QGLContext::functions() const | - | ||||||||||||||||||
| 2803 | { | - | ||||||||||||||||||
| 2804 | QGLContextPrivate *d = const_cast<QGLContextPrivate *>(d_func()); | - | ||||||||||||||||||
| 2805 | if (!d->functions) {
| 1-14 | ||||||||||||||||||
| 2806 | d->functions = new QGLFunctions(this); | - | ||||||||||||||||||
| 2807 | d->functions->initializeGLFunctions(this); | - | ||||||||||||||||||
| 2808 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2809 | return d->functions; executed 15 times by 1 test: return d->functions;Executed by:
| 15 | ||||||||||||||||||
| 2810 | } | - | ||||||||||||||||||
| 2811 | - | |||||||||||||||||||
| 2812 | /*! | - | ||||||||||||||||||
| 2813 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
| 2814 | on \a image. The generated texture id is returned and can be used in | - | ||||||||||||||||||
| 2815 | later \c glBindTexture() calls. | - | ||||||||||||||||||
| 2816 | - | |||||||||||||||||||
| 2817 | \overload | - | ||||||||||||||||||
| 2818 | */ | - | ||||||||||||||||||
| 2819 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format) | - | ||||||||||||||||||
| 2820 | { | - | ||||||||||||||||||
| 2821 | if (image.isNull())
| 0 | ||||||||||||||||||
| 2822 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2823 | - | |||||||||||||||||||
| 2824 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2825 | QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption); | - | ||||||||||||||||||
| 2826 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
| 2827 | } | - | ||||||||||||||||||
| 2828 | - | |||||||||||||||||||
| 2829 | /*! | - | ||||||||||||||||||
| 2830 | \since 4.6 | - | ||||||||||||||||||
| 2831 | - | |||||||||||||||||||
| 2832 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
| 2833 | on \a image. The generated texture id is returned and can be used | - | ||||||||||||||||||
| 2834 | in later \c glBindTexture() calls. | - | ||||||||||||||||||
| 2835 | - | |||||||||||||||||||
| 2836 | The \a target parameter specifies the texture target. The default | - | ||||||||||||||||||
| 2837 | target is \c GL_TEXTURE_2D. | - | ||||||||||||||||||
| 2838 | - | |||||||||||||||||||
| 2839 | The \a format parameter sets the internal format for the | - | ||||||||||||||||||
| 2840 | texture. The default format is \c GL_RGBA. | - | ||||||||||||||||||
| 2841 | - | |||||||||||||||||||
| 2842 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
| 2843 | bind the texture to the context. | - | ||||||||||||||||||
| 2844 | - | |||||||||||||||||||
| 2845 | The texture that is generated is cached, so multiple calls to | - | ||||||||||||||||||
| 2846 | bindTexture() with the same QImage will return the same texture | - | ||||||||||||||||||
| 2847 | id. | - | ||||||||||||||||||
| 2848 | - | |||||||||||||||||||
| 2849 | Note that we assume default values for the glPixelStore() and | - | ||||||||||||||||||
| 2850 | glPixelTransfer() parameters. | - | ||||||||||||||||||
| 2851 | - | |||||||||||||||||||
| 2852 | \sa deleteTexture() | - | ||||||||||||||||||
| 2853 | */ | - | ||||||||||||||||||
| 2854 | GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format, BindOptions options) | - | ||||||||||||||||||
| 2855 | { | - | ||||||||||||||||||
| 2856 | if (image.isNull())
| 0 | ||||||||||||||||||
| 2857 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2858 | - | |||||||||||||||||||
| 2859 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2860 | QGLTexture *texture = d->bindTexture(image, target, format, options); | - | ||||||||||||||||||
| 2861 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
| 2862 | } | - | ||||||||||||||||||
| 2863 | - | |||||||||||||||||||
| 2864 | /*! \overload | - | ||||||||||||||||||
| 2865 | - | |||||||||||||||||||
| 2866 | Generates and binds a 2D GL texture based on \a pixmap. | - | ||||||||||||||||||
| 2867 | */ | - | ||||||||||||||||||
| 2868 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - | ||||||||||||||||||
| 2869 | { | - | ||||||||||||||||||
| 2870 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
| 2871 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2872 | - | |||||||||||||||||||
| 2873 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2874 | QGLTexture *texture = d->bindTexture(pixmap, target, format, DefaultBindOption); | - | ||||||||||||||||||
| 2875 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
| 2876 | } | - | ||||||||||||||||||
| 2877 | - | |||||||||||||||||||
| 2878 | /*! | - | ||||||||||||||||||
| 2879 | \overload | - | ||||||||||||||||||
| 2880 | \since 4.6 | - | ||||||||||||||||||
| 2881 | - | |||||||||||||||||||
| 2882 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
| 2883 | on \a pixmap. | - | ||||||||||||||||||
| 2884 | */ | - | ||||||||||||||||||
| 2885 | GLuint QGLContext::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, BindOptions options) | - | ||||||||||||||||||
| 2886 | { | - | ||||||||||||||||||
| 2887 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
| 2888 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 2889 | - | |||||||||||||||||||
| 2890 | Q_D(QGLContext); | - | ||||||||||||||||||
| 2891 | QGLTexture *texture = d->bindTexture(pixmap, target, format, options); | - | ||||||||||||||||||
| 2892 | return texture->id; never executed: return texture->id; | 0 | ||||||||||||||||||
| 2893 | } | - | ||||||||||||||||||
| 2894 | - | |||||||||||||||||||
| 2895 | /*! | - | ||||||||||||||||||
| 2896 | Removes the texture identified by \a id from the texture cache, | - | ||||||||||||||||||
| 2897 | and calls glDeleteTextures() to delete the texture from the | - | ||||||||||||||||||
| 2898 | context. | - | ||||||||||||||||||
| 2899 | - | |||||||||||||||||||
| 2900 | \sa bindTexture() | - | ||||||||||||||||||
| 2901 | */ | - | ||||||||||||||||||
| 2902 | void QGLContext::deleteTexture(GLuint id) | - | ||||||||||||||||||
| 2903 | { | - | ||||||||||||||||||
| 2904 | if (QGLTextureCache::instance()->remove(this, id))
| 0 | ||||||||||||||||||
| 2905 | return; never executed: return; | 0 | ||||||||||||||||||
| 2906 | qgl_functions()->glDeleteTextures(1, &id); | - | ||||||||||||||||||
| 2907 | } never executed: end of block | 0 | ||||||||||||||||||
| 2908 | - | |||||||||||||||||||
| 2909 | void qt_add_rect_to_array(const QRectF &r, GLfloat *array) | - | ||||||||||||||||||
| 2910 | { | - | ||||||||||||||||||
| 2911 | qreal left = r.left(); | - | ||||||||||||||||||
| 2912 | qreal right = r.right(); | - | ||||||||||||||||||
| 2913 | qreal top = r.top(); | - | ||||||||||||||||||
| 2914 | qreal bottom = r.bottom(); | - | ||||||||||||||||||
| 2915 | - | |||||||||||||||||||
| 2916 | array[0] = left; | - | ||||||||||||||||||
| 2917 | array[1] = top; | - | ||||||||||||||||||
| 2918 | array[2] = right; | - | ||||||||||||||||||
| 2919 | array[3] = top; | - | ||||||||||||||||||
| 2920 | array[4] = right; | - | ||||||||||||||||||
| 2921 | array[5] = bottom; | - | ||||||||||||||||||
| 2922 | array[6] = left; | - | ||||||||||||||||||
| 2923 | array[7] = bottom; | - | ||||||||||||||||||
| 2924 | } never executed: end of block | 0 | ||||||||||||||||||
| 2925 | - | |||||||||||||||||||
| 2926 | void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array) | - | ||||||||||||||||||
| 2927 | { | - | ||||||||||||||||||
| 2928 | array[0] = x1; | - | ||||||||||||||||||
| 2929 | array[1] = y1; | - | ||||||||||||||||||
| 2930 | array[2] = x2; | - | ||||||||||||||||||
| 2931 | array[3] = y1; | - | ||||||||||||||||||
| 2932 | array[4] = x2; | - | ||||||||||||||||||
| 2933 | array[5] = y2; | - | ||||||||||||||||||
| 2934 | array[6] = x1; | - | ||||||||||||||||||
| 2935 | array[7] = y2; | - | ||||||||||||||||||
| 2936 | } never executed: end of block | 0 | ||||||||||||||||||
| 2937 | - | |||||||||||||||||||
| 2938 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 2939 | - | |||||||||||||||||||
| 2940 | static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget) | - | ||||||||||||||||||
| 2941 | { | - | ||||||||||||||||||
| 2942 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 2943 | GLfloat tx = 1.0f; | - | ||||||||||||||||||
| 2944 | GLfloat ty = 1.0f; | - | ||||||||||||||||||
| 2945 | - | |||||||||||||||||||
| 2946 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 2947 | Q_UNUSED(textureWidth); | - | ||||||||||||||||||
| 2948 | Q_UNUSED(textureHeight); | - | ||||||||||||||||||
| 2949 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
| 2950 | #else | - | ||||||||||||||||||
| 2951 | if (textureTarget != GL_TEXTURE_2D && !QOpenGLContext::currentContext()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 2952 | if (textureWidth == -1 || textureHeight == -1) {
| 0 | ||||||||||||||||||
| 2953 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 2954 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); | - | ||||||||||||||||||
| 2955 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); | - | ||||||||||||||||||
| 2956 | } never executed: end of block | 0 | ||||||||||||||||||
| 2957 | - | |||||||||||||||||||
| 2958 | tx = GLfloat(textureWidth); | - | ||||||||||||||||||
| 2959 | ty = GLfloat(textureHeight); | - | ||||||||||||||||||
| 2960 | } never executed: end of block | 0 | ||||||||||||||||||
| 2961 | #endif | - | ||||||||||||||||||
| 2962 | - | |||||||||||||||||||
| 2963 | GLfloat texCoordArray[4*2] = { | - | ||||||||||||||||||
| 2964 | 0, ty, tx, ty, tx, 0, 0, 0 | - | ||||||||||||||||||
| 2965 | }; | - | ||||||||||||||||||
| 2966 | - | |||||||||||||||||||
| 2967 | GLfloat vertexArray[4*2]; | - | ||||||||||||||||||
| 2968 | qt_add_rect_to_array(target, vertexArray); | - | ||||||||||||||||||
| 2969 | - | |||||||||||||||||||
| 2970 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 2971 | gl1funcs->glVertexPointer(2, GL_FLOAT, 0, vertexArray); | - | ||||||||||||||||||
| 2972 | gl1funcs->glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); | - | ||||||||||||||||||
| 2973 | - | |||||||||||||||||||
| 2974 | gl1funcs->glEnableClientState(GL_VERTEX_ARRAY); | - | ||||||||||||||||||
| 2975 | gl1funcs->glEnableClientState(GL_TEXTURE_COORD_ARRAY); | - | ||||||||||||||||||
| 2976 | funcs->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | - | ||||||||||||||||||
| 2977 | - | |||||||||||||||||||
| 2978 | gl1funcs->glDisableClientState(GL_VERTEX_ARRAY); | - | ||||||||||||||||||
| 2979 | gl1funcs->glDisableClientState(GL_TEXTURE_COORD_ARRAY); | - | ||||||||||||||||||
| 2980 | } never executed: end of block | 0 | ||||||||||||||||||
| 2981 | - | |||||||||||||||||||
| 2982 | #endif // !QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 2983 | - | |||||||||||||||||||
| 2984 | /*! | - | ||||||||||||||||||
| 2985 | \since 4.4 | - | ||||||||||||||||||
| 2986 | - | |||||||||||||||||||
| 2987 | This function supports the following use cases: | - | ||||||||||||||||||
| 2988 | - | |||||||||||||||||||
| 2989 | \list | - | ||||||||||||||||||
| 2990 | \li On OpenGL and OpenGL ES 1.x it draws the given texture, \a textureId, | - | ||||||||||||||||||
| 2991 | to the given target rectangle, \a target, in OpenGL model space. The | - | ||||||||||||||||||
| 2992 | \a textureTarget should be a 2D texture target. | - | ||||||||||||||||||
| 2993 | \li On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a | - | ||||||||||||||||||
| 2994 | beginNativePainting / endNativePainting block, and uses the | - | ||||||||||||||||||
| 2995 | engine with type QPaintEngine::OpenGL2, the function will draw the given | - | ||||||||||||||||||
| 2996 | texture, \a textureId, to the given target rectangle, \a target, | - | ||||||||||||||||||
| 2997 | respecting the current painter state. This will let you draw a texture | - | ||||||||||||||||||
| 2998 | with the clip, transform, render hints, and composition mode set by the | - | ||||||||||||||||||
| 2999 | painter. Note that the texture target needs to be GL_TEXTURE_2D for this | - | ||||||||||||||||||
| 3000 | use case, and that this is the only supported use case under OpenGL ES 2.x. | - | ||||||||||||||||||
| 3001 | \endlist | - | ||||||||||||||||||
| 3002 | - | |||||||||||||||||||
| 3003 | */ | - | ||||||||||||||||||
| 3004 | void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
| 3005 | { | - | ||||||||||||||||||
| 3006 | #if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 3007 | if (d_ptr->active_engine &&
| 0 | ||||||||||||||||||
| 3008 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
| 0 | ||||||||||||||||||
| 3009 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - | ||||||||||||||||||
| 3010 | if (!eng->isNativePaintingActive()) {
| 0 | ||||||||||||||||||
| 3011 | QRectF src(0, 0, target.width(), target.height()); | - | ||||||||||||||||||
| 3012 | QSize size(target.width(), target.height()); | - | ||||||||||||||||||
| 3013 | if (eng->drawTexture(target, textureId, size, src))
| 0 | ||||||||||||||||||
| 3014 | return; never executed: return; | 0 | ||||||||||||||||||
| 3015 | } never executed: end of block | 0 | ||||||||||||||||||
| 3016 | } never executed: end of block | 0 | ||||||||||||||||||
| 3017 | #endif | - | ||||||||||||||||||
| 3018 | - | |||||||||||||||||||
| 3019 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 3020 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 3021 | if (!contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 3022 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 3023 | if (textureTarget != GL_TEXTURE_2D) { | - | ||||||||||||||||||
| 3024 | qWarning("QGLContext::drawTexture(): texture target must be GL_TEXTURE_2D on OpenGL ES"); | - | ||||||||||||||||||
| 3025 | return; | - | ||||||||||||||||||
| 3026 | } | - | ||||||||||||||||||
| 3027 | #else | - | ||||||||||||||||||
| 3028 | const bool wasEnabled = funcs->glIsEnabled(GL_TEXTURE_2D); | - | ||||||||||||||||||
| 3029 | GLint oldTexture; | - | ||||||||||||||||||
| 3030 | funcs->glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); | - | ||||||||||||||||||
| 3031 | #endif | - | ||||||||||||||||||
| 3032 | - | |||||||||||||||||||
| 3033 | funcs->glEnable(textureTarget); | - | ||||||||||||||||||
| 3034 | funcs->glBindTexture(textureTarget, textureId); | - | ||||||||||||||||||
| 3035 | - | |||||||||||||||||||
| 3036 | qDrawTextureRect(target, -1, -1, textureTarget); | - | ||||||||||||||||||
| 3037 | - | |||||||||||||||||||
| 3038 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 3039 | funcs->glDisable(textureTarget); | - | ||||||||||||||||||
| 3040 | #else | - | ||||||||||||||||||
| 3041 | if (!wasEnabled)
| 0 | ||||||||||||||||||
| 3042 | funcs->glDisable(textureTarget); never executed: funcs->glDisable(textureTarget); | 0 | ||||||||||||||||||
| 3043 | funcs->glBindTexture(textureTarget, oldTexture); | - | ||||||||||||||||||
| 3044 | #endif | - | ||||||||||||||||||
| 3045 | return; never executed: return; | 0 | ||||||||||||||||||
| 3046 | } | - | ||||||||||||||||||
| 3047 | #else | - | ||||||||||||||||||
| 3048 | Q_UNUSED(target); | - | ||||||||||||||||||
| 3049 | Q_UNUSED(textureId); | - | ||||||||||||||||||
| 3050 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
| 3051 | #endif | - | ||||||||||||||||||
| 3052 | qWarning("drawTexture() with OpenGL ES 2.0 requires an active OpenGL2 paint engine"); | - | ||||||||||||||||||
| 3053 | } never executed: end of block | 0 | ||||||||||||||||||
| 3054 | - | |||||||||||||||||||
| 3055 | /*! | - | ||||||||||||||||||
| 3056 | \since 4.4 | - | ||||||||||||||||||
| 3057 | - | |||||||||||||||||||
| 3058 | This function supports the following use cases: | - | ||||||||||||||||||
| 3059 | - | |||||||||||||||||||
| 3060 | \list | - | ||||||||||||||||||
| 3061 | \li By default it draws the given texture, \a textureId, | - | ||||||||||||||||||
| 3062 | at the given \a point in OpenGL model space. The | - | ||||||||||||||||||
| 3063 | \a textureTarget should be a 2D texture target. | - | ||||||||||||||||||
| 3064 | \li If a painter is active, not inside a | - | ||||||||||||||||||
| 3065 | beginNativePainting / endNativePainting block, and uses the | - | ||||||||||||||||||
| 3066 | engine with type QPaintEngine::OpenGL2, the function will draw the given | - | ||||||||||||||||||
| 3067 | texture, \a textureId, at the given \a point, | - | ||||||||||||||||||
| 3068 | respecting the current painter state. This will let you draw a texture | - | ||||||||||||||||||
| 3069 | with the clip, transform, render hints, and composition mode set by the | - | ||||||||||||||||||
| 3070 | painter. Note that the texture target needs to be GL_TEXTURE_2D for this | - | ||||||||||||||||||
| 3071 | use case. | - | ||||||||||||||||||
| 3072 | \endlist | - | ||||||||||||||||||
| 3073 | - | |||||||||||||||||||
| 3074 | \note This function is not supported under any version of OpenGL ES. | - | ||||||||||||||||||
| 3075 | */ | - | ||||||||||||||||||
| 3076 | void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
| 3077 | { | - | ||||||||||||||||||
| 3078 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 3079 | Q_UNUSED(point); | - | ||||||||||||||||||
| 3080 | Q_UNUSED(textureId); | - | ||||||||||||||||||
| 3081 | Q_UNUSED(textureTarget); | - | ||||||||||||||||||
| 3082 | #else | - | ||||||||||||||||||
| 3083 | if (!contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 3084 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 3085 | const bool wasEnabled = funcs->glIsEnabled(GL_TEXTURE_2D); | - | ||||||||||||||||||
| 3086 | GLint oldTexture; | - | ||||||||||||||||||
| 3087 | funcs->glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); | - | ||||||||||||||||||
| 3088 | - | |||||||||||||||||||
| 3089 | funcs->glEnable(textureTarget); | - | ||||||||||||||||||
| 3090 | funcs->glBindTexture(textureTarget, textureId); | - | ||||||||||||||||||
| 3091 | - | |||||||||||||||||||
| 3092 | GLint textureWidth; | - | ||||||||||||||||||
| 3093 | GLint textureHeight; | - | ||||||||||||||||||
| 3094 | - | |||||||||||||||||||
| 3095 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 3096 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth); | - | ||||||||||||||||||
| 3097 | gl1funcs->glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight); | - | ||||||||||||||||||
| 3098 | - | |||||||||||||||||||
| 3099 | if (d_ptr->active_engine &&
| 0 | ||||||||||||||||||
| 3100 | d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
| 0 | ||||||||||||||||||
| 3101 | QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine); | - | ||||||||||||||||||
| 3102 | if (!eng->isNativePaintingActive()) {
| 0 | ||||||||||||||||||
| 3103 | QRectF dest(point, QSizeF(textureWidth, textureHeight)); | - | ||||||||||||||||||
| 3104 | QRectF src(0, 0, textureWidth, textureHeight); | - | ||||||||||||||||||
| 3105 | QSize size(textureWidth, textureHeight); | - | ||||||||||||||||||
| 3106 | if (eng->drawTexture(dest, textureId, size, src))
| 0 | ||||||||||||||||||
| 3107 | return; never executed: return; | 0 | ||||||||||||||||||
| 3108 | } never executed: end of block | 0 | ||||||||||||||||||
| 3109 | } never executed: end of block | 0 | ||||||||||||||||||
| 3110 | - | |||||||||||||||||||
| 3111 | qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget); | - | ||||||||||||||||||
| 3112 | - | |||||||||||||||||||
| 3113 | if (!wasEnabled)
| 0 | ||||||||||||||||||
| 3114 | funcs->glDisable(textureTarget); never executed: funcs->glDisable(textureTarget); | 0 | ||||||||||||||||||
| 3115 | funcs->glBindTexture(textureTarget, oldTexture); | - | ||||||||||||||||||
| 3116 | return; never executed: return; | 0 | ||||||||||||||||||
| 3117 | } | - | ||||||||||||||||||
| 3118 | #endif | - | ||||||||||||||||||
| 3119 | qWarning("drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES, use rect version instead"); | - | ||||||||||||||||||
| 3120 | } never executed: end of block | 0 | ||||||||||||||||||
| 3121 | - | |||||||||||||||||||
| 3122 | /*! | - | ||||||||||||||||||
| 3123 | This function sets the limit for the texture cache to \a size, | - | ||||||||||||||||||
| 3124 | expressed in kilobytes. | - | ||||||||||||||||||
| 3125 | - | |||||||||||||||||||
| 3126 | By default, the cache limit is approximately 64 MB. | - | ||||||||||||||||||
| 3127 | - | |||||||||||||||||||
| 3128 | \sa textureCacheLimit() | - | ||||||||||||||||||
| 3129 | */ | - | ||||||||||||||||||
| 3130 | void QGLContext::setTextureCacheLimit(int size) | - | ||||||||||||||||||
| 3131 | { | - | ||||||||||||||||||
| 3132 | QGLTextureCache::instance()->setMaxCost(size); | - | ||||||||||||||||||
| 3133 | } never executed: end of block | 0 | ||||||||||||||||||
| 3134 | - | |||||||||||||||||||
| 3135 | /*! | - | ||||||||||||||||||
| 3136 | Returns the current texture cache limit in kilobytes. | - | ||||||||||||||||||
| 3137 | - | |||||||||||||||||||
| 3138 | \sa setTextureCacheLimit() | - | ||||||||||||||||||
| 3139 | */ | - | ||||||||||||||||||
| 3140 | int QGLContext::textureCacheLimit() | - | ||||||||||||||||||
| 3141 | { | - | ||||||||||||||||||
| 3142 | return QGLTextureCache::instance()->maxCost(); never executed: return QGLTextureCache::instance()->maxCost(); | 0 | ||||||||||||||||||
| 3143 | } | - | ||||||||||||||||||
| 3144 | - | |||||||||||||||||||
| 3145 | - | |||||||||||||||||||
| 3146 | /*! | - | ||||||||||||||||||
| 3147 | \fn QGLFormat QGLContext::format() const | - | ||||||||||||||||||
| 3148 | - | |||||||||||||||||||
| 3149 | Returns the frame buffer format that was obtained (this may be a | - | ||||||||||||||||||
| 3150 | subset of what was requested). | - | ||||||||||||||||||
| 3151 | - | |||||||||||||||||||
| 3152 | \sa requestedFormat() | - | ||||||||||||||||||
| 3153 | */ | - | ||||||||||||||||||
| 3154 | - | |||||||||||||||||||
| 3155 | /*! | - | ||||||||||||||||||
| 3156 | \fn QGLFormat QGLContext::requestedFormat() const | - | ||||||||||||||||||
| 3157 | - | |||||||||||||||||||
| 3158 | Returns the frame buffer format that was originally requested in | - | ||||||||||||||||||
| 3159 | the constructor or setFormat(). | - | ||||||||||||||||||
| 3160 | - | |||||||||||||||||||
| 3161 | \sa format() | - | ||||||||||||||||||
| 3162 | */ | - | ||||||||||||||||||
| 3163 | - | |||||||||||||||||||
| 3164 | /*! | - | ||||||||||||||||||
| 3165 | Sets a \a format for this context. The context is \l{reset()}{reset}. | - | ||||||||||||||||||
| 3166 | - | |||||||||||||||||||
| 3167 | Call create() to create a new GL context that tries to match the | - | ||||||||||||||||||
| 3168 | new format. | - | ||||||||||||||||||
| 3169 | - | |||||||||||||||||||
| 3170 | \snippet code/src_opengl_qgl.cpp 7 | - | ||||||||||||||||||
| 3171 | - | |||||||||||||||||||
| 3172 | \sa format(), reset(), create() | - | ||||||||||||||||||
| 3173 | */ | - | ||||||||||||||||||
| 3174 | - | |||||||||||||||||||
| 3175 | void QGLContext::setFormat(const QGLFormat &format) | - | ||||||||||||||||||
| 3176 | { | - | ||||||||||||||||||
| 3177 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3178 | reset(); | - | ||||||||||||||||||
| 3179 | d->glFormat = d->reqFormat = format; | - | ||||||||||||||||||
| 3180 | } never executed: end of block | 0 | ||||||||||||||||||
| 3181 | - | |||||||||||||||||||
| 3182 | /*! | - | ||||||||||||||||||
| 3183 | \internal | - | ||||||||||||||||||
| 3184 | */ | - | ||||||||||||||||||
| 3185 | void QGLContext::setDevice(QPaintDevice *pDev) | - | ||||||||||||||||||
| 3186 | { | - | ||||||||||||||||||
| 3187 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3188 | // Do not touch the valid flag here. The context is either a new one and | - | ||||||||||||||||||
| 3189 | // valid is not yet set or it is adapted from a valid QOpenGLContext in which | - | ||||||||||||||||||
| 3190 | // case it must remain valid. | - | ||||||||||||||||||
| 3191 | d->paintDevice = pDev; | - | ||||||||||||||||||
| 3192 | if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget
| 0-12 | ||||||||||||||||||
| 3193 | && d->paintDevice->devType() != QInternal::Pixmap
| 0 | ||||||||||||||||||
| 3194 | && d->paintDevice->devType() != QInternal::Pbuffer)) {
| 0 | ||||||||||||||||||
| 3195 | qWarning("QGLContext: Unsupported paint device type"); | - | ||||||||||||||||||
| 3196 | } never executed: end of block | 0 | ||||||||||||||||||
| 3197 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3198 | - | |||||||||||||||||||
| 3199 | /*! | - | ||||||||||||||||||
| 3200 | \fn bool QGLContext::isValid() const | - | ||||||||||||||||||
| 3201 | - | |||||||||||||||||||
| 3202 | Returns \c true if a GL rendering context has been successfully | - | ||||||||||||||||||
| 3203 | created; otherwise returns \c false. | - | ||||||||||||||||||
| 3204 | */ | - | ||||||||||||||||||
| 3205 | - | |||||||||||||||||||
| 3206 | /*! | - | ||||||||||||||||||
| 3207 | \fn void QGLContext::setValid(bool valid) | - | ||||||||||||||||||
| 3208 | \internal | - | ||||||||||||||||||
| 3209 | - | |||||||||||||||||||
| 3210 | Forces the GL rendering context to be valid. | - | ||||||||||||||||||
| 3211 | */ | - | ||||||||||||||||||
| 3212 | - | |||||||||||||||||||
| 3213 | /*! | - | ||||||||||||||||||
| 3214 | \fn bool QGLContext::isSharing() const | - | ||||||||||||||||||
| 3215 | - | |||||||||||||||||||
| 3216 | Returns \c true if this context is sharing its GL context with | - | ||||||||||||||||||
| 3217 | another QGLContext, otherwise false is returned. Note that context | - | ||||||||||||||||||
| 3218 | sharing might not be supported between contexts with different | - | ||||||||||||||||||
| 3219 | formats. | - | ||||||||||||||||||
| 3220 | */ | - | ||||||||||||||||||
| 3221 | - | |||||||||||||||||||
| 3222 | /*! | - | ||||||||||||||||||
| 3223 | Returns \c true if \a context1 and \a context2 are sharing their | - | ||||||||||||||||||
| 3224 | GL resources such as textures, shader programs, etc; | - | ||||||||||||||||||
| 3225 | otherwise returns \c false. | - | ||||||||||||||||||
| 3226 | - | |||||||||||||||||||
| 3227 | \since 4.6 | - | ||||||||||||||||||
| 3228 | */ | - | ||||||||||||||||||
| 3229 | bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *context2) | - | ||||||||||||||||||
| 3230 | { | - | ||||||||||||||||||
| 3231 | if (!context1 || !context2)
| 0-4 | ||||||||||||||||||
| 3232 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 3233 | return context1->d_ptr->group == context2->d_ptr->group; executed 4 times by 1 test: return context1->d_ptr->group == context2->d_ptr->group;Executed by:
| 4 | ||||||||||||||||||
| 3234 | } | - | ||||||||||||||||||
| 3235 | - | |||||||||||||||||||
| 3236 | /*! | - | ||||||||||||||||||
| 3237 | \fn bool QGLContext::deviceIsPixmap() const | - | ||||||||||||||||||
| 3238 | - | |||||||||||||||||||
| 3239 | Returns \c true if the paint device of this context is a pixmap; | - | ||||||||||||||||||
| 3240 | otherwise returns \c false. | - | ||||||||||||||||||
| 3241 | - | |||||||||||||||||||
| 3242 | Since Qt 5 the paint device is never actually a pixmap. renderPixmap() is | - | ||||||||||||||||||
| 3243 | however still simulated using framebuffer objects and readbacks, and this | - | ||||||||||||||||||
| 3244 | function will return \c true in this case. | - | ||||||||||||||||||
| 3245 | */ | - | ||||||||||||||||||
| 3246 | - | |||||||||||||||||||
| 3247 | /*! | - | ||||||||||||||||||
| 3248 | \fn bool QGLContext::windowCreated() const | - | ||||||||||||||||||
| 3249 | - | |||||||||||||||||||
| 3250 | Returns \c true if a window has been created for this context; | - | ||||||||||||||||||
| 3251 | otherwise returns \c false. | - | ||||||||||||||||||
| 3252 | - | |||||||||||||||||||
| 3253 | \sa setWindowCreated() | - | ||||||||||||||||||
| 3254 | */ | - | ||||||||||||||||||
| 3255 | - | |||||||||||||||||||
| 3256 | /*! | - | ||||||||||||||||||
| 3257 | \fn void QGLContext::setWindowCreated(bool on) | - | ||||||||||||||||||
| 3258 | - | |||||||||||||||||||
| 3259 | If \a on is true the context has had a window created for it. If | - | ||||||||||||||||||
| 3260 | \a on is false no window has been created for the context. | - | ||||||||||||||||||
| 3261 | - | |||||||||||||||||||
| 3262 | \sa windowCreated() | - | ||||||||||||||||||
| 3263 | */ | - | ||||||||||||||||||
| 3264 | - | |||||||||||||||||||
| 3265 | /*! | - | ||||||||||||||||||
| 3266 | \fn uint QGLContext::colorIndex(const QColor& c) const | - | ||||||||||||||||||
| 3267 | - | |||||||||||||||||||
| 3268 | \internal | - | ||||||||||||||||||
| 3269 | - | |||||||||||||||||||
| 3270 | Returns a colormap index for the color c, in ColorIndex mode. Used | - | ||||||||||||||||||
| 3271 | by qglColor() and qglClearColor(). | - | ||||||||||||||||||
| 3272 | */ | - | ||||||||||||||||||
| 3273 | uint QGLContext::colorIndex(const QColor&) const | - | ||||||||||||||||||
| 3274 | { | - | ||||||||||||||||||
| 3275 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 3276 | } | - | ||||||||||||||||||
| 3277 | - | |||||||||||||||||||
| 3278 | /*! | - | ||||||||||||||||||
| 3279 | \fn bool QGLContext::initialized() const | - | ||||||||||||||||||
| 3280 | - | |||||||||||||||||||
| 3281 | Returns \c true if this context has been initialized, i.e. if | - | ||||||||||||||||||
| 3282 | QGLWidget::initializeGL() has been performed on it; otherwise | - | ||||||||||||||||||
| 3283 | returns \c false. | - | ||||||||||||||||||
| 3284 | - | |||||||||||||||||||
| 3285 | \sa setInitialized() | - | ||||||||||||||||||
| 3286 | */ | - | ||||||||||||||||||
| 3287 | - | |||||||||||||||||||
| 3288 | /*! | - | ||||||||||||||||||
| 3289 | \fn void QGLContext::setInitialized(bool on) | - | ||||||||||||||||||
| 3290 | - | |||||||||||||||||||
| 3291 | If \a on is true the context has been initialized, i.e. | - | ||||||||||||||||||
| 3292 | QGLContext::setInitialized() has been called on it. If \a on is | - | ||||||||||||||||||
| 3293 | false the context has not been initialized. | - | ||||||||||||||||||
| 3294 | - | |||||||||||||||||||
| 3295 | \sa initialized() | - | ||||||||||||||||||
| 3296 | */ | - | ||||||||||||||||||
| 3297 | - | |||||||||||||||||||
| 3298 | /*! | - | ||||||||||||||||||
| 3299 | \fn const QGLContext* QGLContext::currentContext() | - | ||||||||||||||||||
| 3300 | - | |||||||||||||||||||
| 3301 | Returns the current context, i.e. the context to which any OpenGL | - | ||||||||||||||||||
| 3302 | commands will currently be directed. Returns 0 if no context is | - | ||||||||||||||||||
| 3303 | current. | - | ||||||||||||||||||
| 3304 | - | |||||||||||||||||||
| 3305 | \sa makeCurrent() | - | ||||||||||||||||||
| 3306 | */ | - | ||||||||||||||||||
| 3307 | - | |||||||||||||||||||
| 3308 | /*! | - | ||||||||||||||||||
| 3309 | \fn QColor QGLContext::overlayTransparentColor() const | - | ||||||||||||||||||
| 3310 | - | |||||||||||||||||||
| 3311 | If this context is a valid context in an overlay plane, returns | - | ||||||||||||||||||
| 3312 | the plane's transparent color. Otherwise returns an \l{QColor::isValid()}{invalid} color. | - | ||||||||||||||||||
| 3313 | - | |||||||||||||||||||
| 3314 | The returned color's \l{QColormap::pixel()}{pixel} value is | - | ||||||||||||||||||
| 3315 | the index of the transparent color in the colormap of the overlay | - | ||||||||||||||||||
| 3316 | plane. (Naturally, the color's RGB values are meaningless.) | - | ||||||||||||||||||
| 3317 | - | |||||||||||||||||||
| 3318 | The returned QColor object will generally work as expected only | - | ||||||||||||||||||
| 3319 | when passed as the argument to QGLWidget::qglColor() or | - | ||||||||||||||||||
| 3320 | QGLWidget::qglClearColor(). Under certain circumstances it can | - | ||||||||||||||||||
| 3321 | also be used to draw transparent graphics with a QPainter. | - | ||||||||||||||||||
| 3322 | */ | - | ||||||||||||||||||
| 3323 | QColor QGLContext::overlayTransparentColor() const | - | ||||||||||||||||||
| 3324 | { | - | ||||||||||||||||||
| 3325 | return QColor(); // Invalid color never executed: return QColor(); | 0 | ||||||||||||||||||
| 3326 | } | - | ||||||||||||||||||
| 3327 | - | |||||||||||||||||||
| 3328 | /*! | - | ||||||||||||||||||
| 3329 | Creates the GL context. Returns \c true if it was successful in | - | ||||||||||||||||||
| 3330 | creating a valid GL rendering context on the paint device | - | ||||||||||||||||||
| 3331 | specified in the constructor; otherwise returns \c false (i.e. the | - | ||||||||||||||||||
| 3332 | context is invalid). | - | ||||||||||||||||||
| 3333 | - | |||||||||||||||||||
| 3334 | If the OpenGL implementation on your system does not support the requested | - | ||||||||||||||||||
| 3335 | version of OpenGL context, then QGLContext will try to create the closest | - | ||||||||||||||||||
| 3336 | matching version. The actual created context properties can be queried | - | ||||||||||||||||||
| 3337 | using the QGLFormat returned by the format() function. For example, if | - | ||||||||||||||||||
| 3338 | you request a context that supports OpenGL 4.3 Core profile but the driver | - | ||||||||||||||||||
| 3339 | and/or hardware only supports version 3.2 Core profile contexts then you will | - | ||||||||||||||||||
| 3340 | get a 3.2 Core profile context. | - | ||||||||||||||||||
| 3341 | - | |||||||||||||||||||
| 3342 | After successful creation, format() returns the set of features of | - | ||||||||||||||||||
| 3343 | the created GL rendering context. | - | ||||||||||||||||||
| 3344 | - | |||||||||||||||||||
| 3345 | If \a shareContext points to a valid QGLContext, this method will | - | ||||||||||||||||||
| 3346 | try to establish OpenGL display list and texture object sharing | - | ||||||||||||||||||
| 3347 | between this context and the \a shareContext. Note that this may | - | ||||||||||||||||||
| 3348 | fail if the two contexts have different \l {format()} {formats}. | - | ||||||||||||||||||
| 3349 | Use isSharing() to see if sharing is in effect. | - | ||||||||||||||||||
| 3350 | - | |||||||||||||||||||
| 3351 | \warning Implementation note: initialization of C++ class | - | ||||||||||||||||||
| 3352 | members usually takes place in the class constructor. QGLContext | - | ||||||||||||||||||
| 3353 | is an exception because it must be simple to customize. The | - | ||||||||||||||||||
| 3354 | virtual functions chooseContext() (and chooseVisual() for X11) can | - | ||||||||||||||||||
| 3355 | be reimplemented in a subclass to select a particular context. The | - | ||||||||||||||||||
| 3356 | problem is that virtual functions are not properly called during | - | ||||||||||||||||||
| 3357 | construction (even though this is correct C++) because C++ | - | ||||||||||||||||||
| 3358 | constructs class hierarchies from the bottom up. For this reason | - | ||||||||||||||||||
| 3359 | we need a create() function. | - | ||||||||||||||||||
| 3360 | - | |||||||||||||||||||
| 3361 | \sa chooseContext(), format(), isValid() | - | ||||||||||||||||||
| 3362 | */ | - | ||||||||||||||||||
| 3363 | - | |||||||||||||||||||
| 3364 | bool QGLContext::create(const QGLContext* shareContext) | - | ||||||||||||||||||
| 3365 | { | - | ||||||||||||||||||
| 3366 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3367 | if (!d->paintDevice && !d->guiGlContext)
| 0-12 | ||||||||||||||||||
| 3368 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 3369 | - | |||||||||||||||||||
| 3370 | reset(); | - | ||||||||||||||||||
| 3371 | d->valid = chooseContext(shareContext); | - | ||||||||||||||||||
| 3372 | if (d->valid && d->paintDevice && d->paintDevice->devType() == QInternal::Widget) {
| 0-12 | ||||||||||||||||||
| 3373 | QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice)); | - | ||||||||||||||||||
| 3374 | wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer(); | - | ||||||||||||||||||
| 3375 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3376 | return d->valid; executed 12 times by 3 tests: return d->valid;Executed by:
| 12 | ||||||||||||||||||
| 3377 | } | - | ||||||||||||||||||
| 3378 | - | |||||||||||||||||||
| 3379 | bool QGLContext::isValid() const | - | ||||||||||||||||||
| 3380 | { | - | ||||||||||||||||||
| 3381 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3382 | return d->valid; executed 16 times by 3 tests: return d->valid;Executed by:
| 16 | ||||||||||||||||||
| 3383 | } | - | ||||||||||||||||||
| 3384 | - | |||||||||||||||||||
| 3385 | void QGLContext::setValid(bool valid) | - | ||||||||||||||||||
| 3386 | { | - | ||||||||||||||||||
| 3387 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3388 | d->valid = valid; | - | ||||||||||||||||||
| 3389 | } never executed: end of block | 0 | ||||||||||||||||||
| 3390 | - | |||||||||||||||||||
| 3391 | bool QGLContext::isSharing() const | - | ||||||||||||||||||
| 3392 | { | - | ||||||||||||||||||
| 3393 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3394 | return d->group->isSharing(); executed 1 time by 1 test: return d->group->isSharing();Executed by:
| 1 | ||||||||||||||||||
| 3395 | } | - | ||||||||||||||||||
| 3396 | - | |||||||||||||||||||
| 3397 | QGLFormat QGLContext::format() const | - | ||||||||||||||||||
| 3398 | { | - | ||||||||||||||||||
| 3399 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3400 | return d->glFormat; executed 12 times by 3 tests: return d->glFormat;Executed by:
| 12 | ||||||||||||||||||
| 3401 | } | - | ||||||||||||||||||
| 3402 | - | |||||||||||||||||||
| 3403 | QGLFormat QGLContext::requestedFormat() const | - | ||||||||||||||||||
| 3404 | { | - | ||||||||||||||||||
| 3405 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3406 | return d->reqFormat; never executed: return d->reqFormat; | 0 | ||||||||||||||||||
| 3407 | } | - | ||||||||||||||||||
| 3408 | - | |||||||||||||||||||
| 3409 | QPaintDevice* QGLContext::device() const | - | ||||||||||||||||||
| 3410 | { | - | ||||||||||||||||||
| 3411 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3412 | return d->paintDevice; executed 24 times by 3 tests: return d->paintDevice;Executed by:
| 24 | ||||||||||||||||||
| 3413 | } | - | ||||||||||||||||||
| 3414 | - | |||||||||||||||||||
| 3415 | bool QGLContext::deviceIsPixmap() const | - | ||||||||||||||||||
| 3416 | { | - | ||||||||||||||||||
| 3417 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3418 | return !d->readback_target_size.isEmpty(); never executed: return !d->readback_target_size.isEmpty(); | 0 | ||||||||||||||||||
| 3419 | } | - | ||||||||||||||||||
| 3420 | - | |||||||||||||||||||
| 3421 | - | |||||||||||||||||||
| 3422 | bool QGLContext::windowCreated() const | - | ||||||||||||||||||
| 3423 | { | - | ||||||||||||||||||
| 3424 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3425 | return d->crWin; never executed: return d->crWin; | 0 | ||||||||||||||||||
| 3426 | } | - | ||||||||||||||||||
| 3427 | - | |||||||||||||||||||
| 3428 | - | |||||||||||||||||||
| 3429 | void QGLContext::setWindowCreated(bool on) | - | ||||||||||||||||||
| 3430 | { | - | ||||||||||||||||||
| 3431 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3432 | d->crWin = on; | - | ||||||||||||||||||
| 3433 | } never executed: end of block | 0 | ||||||||||||||||||
| 3434 | - | |||||||||||||||||||
| 3435 | bool QGLContext::initialized() const | - | ||||||||||||||||||
| 3436 | { | - | ||||||||||||||||||
| 3437 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3438 | return d->initDone; never executed: return d->initDone; | 0 | ||||||||||||||||||
| 3439 | } | - | ||||||||||||||||||
| 3440 | - | |||||||||||||||||||
| 3441 | void QGLContext::setInitialized(bool on) | - | ||||||||||||||||||
| 3442 | { | - | ||||||||||||||||||
| 3443 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3444 | d->initDone = on; | - | ||||||||||||||||||
| 3445 | } never executed: end of block | 0 | ||||||||||||||||||
| 3446 | - | |||||||||||||||||||
| 3447 | const QGLContext* QGLContext::currentContext() | - | ||||||||||||||||||
| 3448 | { | - | ||||||||||||||||||
| 3449 | if (const QOpenGLContext *threadContext = QOpenGLContext::currentContext()) {
| 0-70 | ||||||||||||||||||
| 3450 | return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext)); executed 70 times by 3 tests: return QGLContext::fromOpenGLContext(const_cast<QOpenGLContext *>(threadContext));Executed by:
| 70 | ||||||||||||||||||
| 3451 | } | - | ||||||||||||||||||
| 3452 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 3453 | } | - | ||||||||||||||||||
| 3454 | - | |||||||||||||||||||
| 3455 | void QGLContextPrivate::setCurrentContext(QGLContext *context) | - | ||||||||||||||||||
| 3456 | { | - | ||||||||||||||||||
| 3457 | Q_UNUSED(context); | - | ||||||||||||||||||
| 3458 | } never executed: end of block | 0 | ||||||||||||||||||
| 3459 | - | |||||||||||||||||||
| 3460 | /*! | - | ||||||||||||||||||
| 3461 | Moves the QGLContext to the given \a thread. | - | ||||||||||||||||||
| 3462 | - | |||||||||||||||||||
| 3463 | Enables calling swapBuffers() and makeCurrent() on the context in | - | ||||||||||||||||||
| 3464 | the given thread. | - | ||||||||||||||||||
| 3465 | */ | - | ||||||||||||||||||
| 3466 | void QGLContext::moveToThread(QThread *thread) | - | ||||||||||||||||||
| 3467 | { | - | ||||||||||||||||||
| 3468 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3469 | if (d->guiGlContext)
| 0 | ||||||||||||||||||
| 3470 | d->guiGlContext->moveToThread(thread); never executed: d->guiGlContext->moveToThread(thread); | 0 | ||||||||||||||||||
| 3471 | } never executed: end of block | 0 | ||||||||||||||||||
| 3472 | - | |||||||||||||||||||
| 3473 | /*! | - | ||||||||||||||||||
| 3474 | \fn bool QGLContext::chooseContext(const QGLContext* shareContext = 0) | - | ||||||||||||||||||
| 3475 | - | |||||||||||||||||||
| 3476 | This semi-internal function is called by create(). It creates a | - | ||||||||||||||||||
| 3477 | system-dependent OpenGL handle that matches the format() of \a | - | ||||||||||||||||||
| 3478 | shareContext as closely as possible, returning true if successful | - | ||||||||||||||||||
| 3479 | or false if a suitable handle could not be found. | - | ||||||||||||||||||
| 3480 | - | |||||||||||||||||||
| 3481 | On Windows, it calls the virtual function choosePixelFormat(), | - | ||||||||||||||||||
| 3482 | which finds a matching pixel format identifier. On X11, it calls | - | ||||||||||||||||||
| 3483 | the virtual function chooseVisual() which finds an appropriate X | - | ||||||||||||||||||
| 3484 | visual. On other platforms it may work differently. | - | ||||||||||||||||||
| 3485 | */ | - | ||||||||||||||||||
| 3486 | bool QGLContext::chooseContext(const QGLContext* shareContext) | - | ||||||||||||||||||
| 3487 | { | - | ||||||||||||||||||
| 3488 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3489 | if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) {
| 0-12 | ||||||||||||||||||
| 3490 | // Unlike in Qt 4, the only possible target is a widget backed by an OpenGL-based | - | ||||||||||||||||||
| 3491 | // QWindow. Pixmaps in particular are not supported anymore as paint devices since | - | ||||||||||||||||||
| 3492 | // starting from Qt 5 QPixmap is raster-backed on almost all platforms. | - | ||||||||||||||||||
| 3493 | d->valid = false; | - | ||||||||||||||||||
| 3494 | }else { never executed: end of block | 0 | ||||||||||||||||||
| 3495 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
| 3496 | QGLFormat glformat = format(); | - | ||||||||||||||||||
| 3497 | QSurfaceFormat winFormat = QGLFormat::toSurfaceFormat(glformat); | - | ||||||||||||||||||
| 3498 | if (widget->testAttribute(Qt::WA_TranslucentBackground))
| 0-12 | ||||||||||||||||||
| 3499 | winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8)); never executed: winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8)); | 0 | ||||||||||||||||||
| 3500 | - | |||||||||||||||||||
| 3501 | QWindow *window = widget->windowHandle(); | - | ||||||||||||||||||
| 3502 | if (!window->handle()
| 0-12 | ||||||||||||||||||
| 3503 | || window->surfaceType() != QWindow::OpenGLSurface
| 0 | ||||||||||||||||||
| 3504 | || window->requestedFormat() != winFormat)
| 0 | ||||||||||||||||||
| 3505 | { | - | ||||||||||||||||||
| 3506 | window->setSurfaceType(QWindow::OpenGLSurface); | - | ||||||||||||||||||
| 3507 | window->setFormat(winFormat); | - | ||||||||||||||||||
| 3508 | window->destroy(); | - | ||||||||||||||||||
| 3509 | window->create(); | - | ||||||||||||||||||
| 3510 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3511 | - | |||||||||||||||||||
| 3512 | if (d->ownContext)
| 0-12 | ||||||||||||||||||
| 3513 | delete d->guiGlContext; never executed: delete d->guiGlContext; | 0 | ||||||||||||||||||
| 3514 | d->ownContext = true; | - | ||||||||||||||||||
| 3515 | QOpenGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0;
| 1-11 | ||||||||||||||||||
| 3516 | d->guiGlContext = new QOpenGLContext; | - | ||||||||||||||||||
| 3517 | d->guiGlContext->setFormat(winFormat); | - | ||||||||||||||||||
| 3518 | d->guiGlContext->setShareContext(shareGlContext); | - | ||||||||||||||||||
| 3519 | d->valid = d->guiGlContext->create(); | - | ||||||||||||||||||
| 3520 | - | |||||||||||||||||||
| 3521 | if (d->valid)
| 0-12 | ||||||||||||||||||
| 3522 | d->guiGlContext->setQGLContextHandle(this, 0); executed 12 times by 3 tests: d->guiGlContext->setQGLContextHandle(this, 0);Executed by:
| 12 | ||||||||||||||||||
| 3523 | - | |||||||||||||||||||
| 3524 | d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format()); | - | ||||||||||||||||||
| 3525 | d->setupSharing(); | - | ||||||||||||||||||
| 3526 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3527 | - | |||||||||||||||||||
| 3528 | - | |||||||||||||||||||
| 3529 | return d->valid; executed 12 times by 3 tests: return d->valid;Executed by:
| 12 | ||||||||||||||||||
| 3530 | } | - | ||||||||||||||||||
| 3531 | - | |||||||||||||||||||
| 3532 | /*! | - | ||||||||||||||||||
| 3533 | \fn void QGLContext::reset() | - | ||||||||||||||||||
| 3534 | - | |||||||||||||||||||
| 3535 | Resets the context and makes it invalid. | - | ||||||||||||||||||
| 3536 | - | |||||||||||||||||||
| 3537 | \sa create(), isValid() | - | ||||||||||||||||||
| 3538 | */ | - | ||||||||||||||||||
| 3539 | void QGLContext::reset() | - | ||||||||||||||||||
| 3540 | { | - | ||||||||||||||||||
| 3541 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3542 | if (!d->valid)
| 12 | ||||||||||||||||||
| 3543 | return; executed 12 times by 3 tests: return;Executed by:
| 12 | ||||||||||||||||||
| 3544 | d->cleanup(); | - | ||||||||||||||||||
| 3545 | - | |||||||||||||||||||
| 3546 | d->crWin = false; | - | ||||||||||||||||||
| 3547 | d->sharing = false; | - | ||||||||||||||||||
| 3548 | d->valid = false; | - | ||||||||||||||||||
| 3549 | d->transpColor = QColor(); | - | ||||||||||||||||||
| 3550 | d->initDone = false; | - | ||||||||||||||||||
| 3551 | QGLContextGroup::removeShare(this); | - | ||||||||||||||||||
| 3552 | if (d->guiGlContext) {
| 0-12 | ||||||||||||||||||
| 3553 | if (QOpenGLContext::currentContext() == d->guiGlContext)
| 1-11 | ||||||||||||||||||
| 3554 | doneCurrent(); executed 11 times by 3 tests: doneCurrent();Executed by:
| 11 | ||||||||||||||||||
| 3555 | if (d->ownContext) {
| 0-12 | ||||||||||||||||||
| 3556 | if (d->guiGlContext->thread() == QThread::currentThread())
| 0-12 | ||||||||||||||||||
| 3557 | delete d->guiGlContext; executed 12 times by 3 tests: delete d->guiGlContext;Executed by:
| 12 | ||||||||||||||||||
| 3558 | else | - | ||||||||||||||||||
| 3559 | d->guiGlContext->deleteLater(); never executed: d->guiGlContext->deleteLater(); | 0 | ||||||||||||||||||
| 3560 | } else | - | ||||||||||||||||||
| 3561 | d->guiGlContext->setQGLContextHandle(0,0); never executed: d->guiGlContext->setQGLContextHandle(0,0); | 0 | ||||||||||||||||||
| 3562 | d->guiGlContext = 0; | - | ||||||||||||||||||
| 3563 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3564 | d->ownContext = false; | - | ||||||||||||||||||
| 3565 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3566 | - | |||||||||||||||||||
| 3567 | /*! | - | ||||||||||||||||||
| 3568 | \fn void QGLContext::makeCurrent() | - | ||||||||||||||||||
| 3569 | - | |||||||||||||||||||
| 3570 | Makes this context the current OpenGL rendering context. All GL | - | ||||||||||||||||||
| 3571 | functions you call operate on this context until another context | - | ||||||||||||||||||
| 3572 | is made current. | - | ||||||||||||||||||
| 3573 | - | |||||||||||||||||||
| 3574 | In some very rare cases the underlying call may fail. If this | - | ||||||||||||||||||
| 3575 | occurs an error message is output to stderr. | - | ||||||||||||||||||
| 3576 | - | |||||||||||||||||||
| 3577 | If you call this from a thread other than the main UI thread, | - | ||||||||||||||||||
| 3578 | make sure you've first pushed the context to the relevant thread | - | ||||||||||||||||||
| 3579 | from the UI thread using moveToThread(). | - | ||||||||||||||||||
| 3580 | */ | - | ||||||||||||||||||
| 3581 | void QGLContext::makeCurrent() | - | ||||||||||||||||||
| 3582 | { | - | ||||||||||||||||||
| 3583 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3584 | if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
| 0-15 | ||||||||||||||||||
| 3585 | return; never executed: return; | 0 | ||||||||||||||||||
| 3586 | - | |||||||||||||||||||
| 3587 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
| 3588 | if (!widget->windowHandle())
| 0-15 | ||||||||||||||||||
| 3589 | return; never executed: return; | 0 | ||||||||||||||||||
| 3590 | - | |||||||||||||||||||
| 3591 | if (d->guiGlContext->makeCurrent(widget->windowHandle())) {
| 0-15 | ||||||||||||||||||
| 3592 | if (!d->workaroundsCached) {
| 3-12 | ||||||||||||||||||
| 3593 | d->workaroundsCached = true; | - | ||||||||||||||||||
| 3594 | const char *renderer = reinterpret_cast<const char *>(d->guiGlContext->functions()->glGetString(GL_RENDERER)); | - | ||||||||||||||||||
| 3595 | if (renderer && strstr(renderer, "Mali")) {
| 0-12 | ||||||||||||||||||
| 3596 | d->workaround_brokenFBOReadBack = true; | - | ||||||||||||||||||
| 3597 | } never executed: end of block | 0 | ||||||||||||||||||
| 3598 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3599 | } executed 15 times by 3 tests: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 3600 | } executed 15 times by 3 tests: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 3601 | - | |||||||||||||||||||
| 3602 | /*! | - | ||||||||||||||||||
| 3603 | \fn void QGLContext::swapBuffers() const | - | ||||||||||||||||||
| 3604 | - | |||||||||||||||||||
| 3605 | Call this to finish a frame of OpenGL rendering, and make sure to | - | ||||||||||||||||||
| 3606 | call makeCurrent() again before you begin a new frame. | - | ||||||||||||||||||
| 3607 | */ | - | ||||||||||||||||||
| 3608 | void QGLContext::swapBuffers() const | - | ||||||||||||||||||
| 3609 | { | - | ||||||||||||||||||
| 3610 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 3611 | if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
| 0-3 | ||||||||||||||||||
| 3612 | return; never executed: return; | 0 | ||||||||||||||||||
| 3613 | - | |||||||||||||||||||
| 3614 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); | - | ||||||||||||||||||
| 3615 | if (!widget->windowHandle())
| 0-3 | ||||||||||||||||||
| 3616 | return; never executed: return; | 0 | ||||||||||||||||||
| 3617 | - | |||||||||||||||||||
| 3618 | d->guiGlContext->swapBuffers(widget->windowHandle()); | - | ||||||||||||||||||
| 3619 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 3620 | - | |||||||||||||||||||
| 3621 | /*! | - | ||||||||||||||||||
| 3622 | \fn void QGLContext::doneCurrent() | - | ||||||||||||||||||
| 3623 | - | |||||||||||||||||||
| 3624 | Makes no GL context the current context. Normally, you do not need | - | ||||||||||||||||||
| 3625 | to call this function; QGLContext calls it as necessary. | - | ||||||||||||||||||
| 3626 | */ | - | ||||||||||||||||||
| 3627 | void QGLContext::doneCurrent() | - | ||||||||||||||||||
| 3628 | { | - | ||||||||||||||||||
| 3629 | Q_D(QGLContext); | - | ||||||||||||||||||
| 3630 | d->guiGlContext->doneCurrent(); | - | ||||||||||||||||||
| 3631 | } executed 11 times by 3 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 3632 | - | |||||||||||||||||||
| 3633 | /*! | - | ||||||||||||||||||
| 3634 | \fn QPaintDevice* QGLContext::device() const | - | ||||||||||||||||||
| 3635 | - | |||||||||||||||||||
| 3636 | Returns the paint device set for this context. | - | ||||||||||||||||||
| 3637 | - | |||||||||||||||||||
| 3638 | \sa QGLContext::QGLContext() | - | ||||||||||||||||||
| 3639 | */ | - | ||||||||||||||||||
| 3640 | - | |||||||||||||||||||
| 3641 | /***************************************************************************** | - | ||||||||||||||||||
| 3642 | QGLWidget implementation | - | ||||||||||||||||||
| 3643 | *****************************************************************************/ | - | ||||||||||||||||||
| 3644 | - | |||||||||||||||||||
| 3645 | - | |||||||||||||||||||
| 3646 | /*! | - | ||||||||||||||||||
| 3647 | \class QGLWidget | - | ||||||||||||||||||
| 3648 | \inmodule QtOpenGL | - | ||||||||||||||||||
| 3649 | \obsolete | - | ||||||||||||||||||
| 3650 | - | |||||||||||||||||||
| 3651 | \brief The QGLWidget class is a widget for rendering OpenGL graphics. | - | ||||||||||||||||||
| 3652 | - | |||||||||||||||||||
| 3653 | QGLWidget provides functionality for displaying OpenGL graphics | - | ||||||||||||||||||
| 3654 | integrated into a Qt application. It is very simple to use. You | - | ||||||||||||||||||
| 3655 | inherit from it and use the subclass like any other QWidget, | - | ||||||||||||||||||
| 3656 | except that you have the choice between using QPainter and | - | ||||||||||||||||||
| 3657 | standard OpenGL rendering commands. | - | ||||||||||||||||||
| 3658 | - | |||||||||||||||||||
| 3659 | \note This class is part of the legacy \l {Qt OpenGL} module and, | - | ||||||||||||||||||
| 3660 | like the other \c QGL classes, should be avoided in the new | - | ||||||||||||||||||
| 3661 | applications. Instead, starting from Qt 5.4, prefer using | - | ||||||||||||||||||
| 3662 | QOpenGLWidget and the \c QOpenGL classes. | - | ||||||||||||||||||
| 3663 | - | |||||||||||||||||||
| 3664 | QGLWidget provides three convenient virtual functions that you can | - | ||||||||||||||||||
| 3665 | reimplement in your subclass to perform the typical OpenGL tasks: | - | ||||||||||||||||||
| 3666 | - | |||||||||||||||||||
| 3667 | \list | - | ||||||||||||||||||
| 3668 | \li paintGL() - Renders the OpenGL scene. Gets called whenever the widget | - | ||||||||||||||||||
| 3669 | needs to be updated. | - | ||||||||||||||||||
| 3670 | \li resizeGL() - Sets up the OpenGL viewport, projection, etc. Gets | - | ||||||||||||||||||
| 3671 | called whenever the widget has been resized (and also when it | - | ||||||||||||||||||
| 3672 | is shown for the first time because all newly created widgets get a | - | ||||||||||||||||||
| 3673 | resize event automatically). | - | ||||||||||||||||||
| 3674 | \li initializeGL() - Sets up the OpenGL rendering context, defines display | - | ||||||||||||||||||
| 3675 | lists, etc. Gets called once before the first time resizeGL() or | - | ||||||||||||||||||
| 3676 | paintGL() is called. | - | ||||||||||||||||||
| 3677 | \endlist | - | ||||||||||||||||||
| 3678 | - | |||||||||||||||||||
| 3679 | Here is a rough outline of how a QGLWidget subclass might look: | - | ||||||||||||||||||
| 3680 | - | |||||||||||||||||||
| 3681 | \snippet code/src_opengl_qgl.cpp 8 | - | ||||||||||||||||||
| 3682 | - | |||||||||||||||||||
| 3683 | If you need to trigger a repaint from places other than paintGL() | - | ||||||||||||||||||
| 3684 | (a typical example is when using \l{QTimer}{timers} to | - | ||||||||||||||||||
| 3685 | animate scenes), you should call the widget's updateGL() function. | - | ||||||||||||||||||
| 3686 | - | |||||||||||||||||||
| 3687 | Your widget's OpenGL rendering context is made current when | - | ||||||||||||||||||
| 3688 | paintGL(), resizeGL(), or initializeGL() is called. If you need to | - | ||||||||||||||||||
| 3689 | call the standard OpenGL API functions from other places (e.g. in | - | ||||||||||||||||||
| 3690 | your widget's constructor or in your own paint functions), you | - | ||||||||||||||||||
| 3691 | must call makeCurrent() first. | - | ||||||||||||||||||
| 3692 | - | |||||||||||||||||||
| 3693 | QGLWidget provides functions for requesting a new display | - | ||||||||||||||||||
| 3694 | \l{QGLFormat}{format} and you can also create widgets with | - | ||||||||||||||||||
| 3695 | customized rendering \l{QGLContext}{contexts}. | - | ||||||||||||||||||
| 3696 | - | |||||||||||||||||||
| 3697 | You can also share OpenGL display lists between QGLWidget objects (see | - | ||||||||||||||||||
| 3698 | the documentation of the QGLWidget constructors for details). | - | ||||||||||||||||||
| 3699 | - | |||||||||||||||||||
| 3700 | Note that under Windows, the QGLContext belonging to a QGLWidget | - | ||||||||||||||||||
| 3701 | has to be recreated when the QGLWidget is reparented. This is | - | ||||||||||||||||||
| 3702 | necessary due to limitations on the Windows platform. This will | - | ||||||||||||||||||
| 3703 | most likely cause problems for users that have subclassed and | - | ||||||||||||||||||
| 3704 | installed their own QGLContext on a QGLWidget. It is possible to | - | ||||||||||||||||||
| 3705 | work around this issue by putting the QGLWidget inside a dummy | - | ||||||||||||||||||
| 3706 | widget and then reparenting the dummy widget, instead of the | - | ||||||||||||||||||
| 3707 | QGLWidget. This will side-step the issue altogether, and is what | - | ||||||||||||||||||
| 3708 | we recommend for users that need this kind of functionality. | - | ||||||||||||||||||
| 3709 | - | |||||||||||||||||||
| 3710 | On \macos, when Qt is built with Cocoa support, a QGLWidget | - | ||||||||||||||||||
| 3711 | can't have any sibling widgets placed ontop of itself. This is due | - | ||||||||||||||||||
| 3712 | to limitations in the Cocoa API and is not supported by Apple. | - | ||||||||||||||||||
| 3713 | - | |||||||||||||||||||
| 3714 | \section1 Overlays | - | ||||||||||||||||||
| 3715 | - | |||||||||||||||||||
| 3716 | The QGLWidget creates a GL overlay context in addition to the | - | ||||||||||||||||||
| 3717 | normal context if overlays are supported by the underlying system. | - | ||||||||||||||||||
| 3718 | - | |||||||||||||||||||
| 3719 | If you want to use overlays, you specify it in the | - | ||||||||||||||||||
| 3720 | \l{QGLFormat}{format}. (Note: Overlay must be requested in the format | - | ||||||||||||||||||
| 3721 | passed to the QGLWidget constructor.) Your GL widget should also | - | ||||||||||||||||||
| 3722 | implement some or all of these virtual methods: | - | ||||||||||||||||||
| 3723 | - | |||||||||||||||||||
| 3724 | \list | - | ||||||||||||||||||
| 3725 | \li paintOverlayGL() | - | ||||||||||||||||||
| 3726 | \li resizeOverlayGL() | - | ||||||||||||||||||
| 3727 | \li initializeOverlayGL() | - | ||||||||||||||||||
| 3728 | \endlist | - | ||||||||||||||||||
| 3729 | - | |||||||||||||||||||
| 3730 | These methods work in the same way as the normal paintGL() etc. | - | ||||||||||||||||||
| 3731 | functions, except that they will be called when the overlay | - | ||||||||||||||||||
| 3732 | context is made current. You can explicitly make the overlay | - | ||||||||||||||||||
| 3733 | context current by using makeOverlayCurrent(), and you can access | - | ||||||||||||||||||
| 3734 | the overlay context directly (e.g. to ask for its transparent | - | ||||||||||||||||||
| 3735 | color) by calling overlayContext(). | - | ||||||||||||||||||
| 3736 | - | |||||||||||||||||||
| 3737 | On X servers in which the default visual is in an overlay plane, | - | ||||||||||||||||||
| 3738 | non-GL Qt windows can also be used for overlays. | - | ||||||||||||||||||
| 3739 | - | |||||||||||||||||||
| 3740 | \section1 Painting Techniques | - | ||||||||||||||||||
| 3741 | - | |||||||||||||||||||
| 3742 | As described above, subclass QGLWidget to render pure 3D content in the | - | ||||||||||||||||||
| 3743 | following way: | - | ||||||||||||||||||
| 3744 | - | |||||||||||||||||||
| 3745 | \list | - | ||||||||||||||||||
| 3746 | \li Reimplement the QGLWidget::initializeGL() and QGLWidget::resizeGL() to | - | ||||||||||||||||||
| 3747 | set up the OpenGL state and provide a perspective transformation. | - | ||||||||||||||||||
| 3748 | \li Reimplement QGLWidget::paintGL() to paint the 3D scene, calling only | - | ||||||||||||||||||
| 3749 | OpenGL functions to draw on the widget. | - | ||||||||||||||||||
| 3750 | \endlist | - | ||||||||||||||||||
| 3751 | - | |||||||||||||||||||
| 3752 | It is also possible to draw 2D graphics onto a QGLWidget subclass, it is necessary | - | ||||||||||||||||||
| 3753 | to reimplement QGLWidget::paintEvent() and do the following: | - | ||||||||||||||||||
| 3754 | - | |||||||||||||||||||
| 3755 | \list | - | ||||||||||||||||||
| 3756 | \li Construct a QPainter object. | - | ||||||||||||||||||
| 3757 | \li Initialize it for use on the widget with the QPainter::begin() function. | - | ||||||||||||||||||
| 3758 | \li Draw primitives using QPainter's member functions. | - | ||||||||||||||||||
| 3759 | \li Call QPainter::end() to finish painting. | - | ||||||||||||||||||
| 3760 | \endlist | - | ||||||||||||||||||
| 3761 | - | |||||||||||||||||||
| 3762 | \section1 Threading | - | ||||||||||||||||||
| 3763 | - | |||||||||||||||||||
| 3764 | As of Qt version 4.8, support for doing threaded GL rendering has | - | ||||||||||||||||||
| 3765 | been improved. There are three scenarios that we currently support: | - | ||||||||||||||||||
| 3766 | \list | - | ||||||||||||||||||
| 3767 | \li 1. Buffer swapping in a thread. | - | ||||||||||||||||||
| 3768 | - | |||||||||||||||||||
| 3769 | Swapping buffers in a double buffered context may be a | - | ||||||||||||||||||
| 3770 | synchronous, locking call that may be a costly operation in some | - | ||||||||||||||||||
| 3771 | GL implementations. Especially so on embedded devices. It's not | - | ||||||||||||||||||
| 3772 | optimal to have the CPU idling while the GPU is doing a buffer | - | ||||||||||||||||||
| 3773 | swap. In those cases it is possible to do the rendering in the | - | ||||||||||||||||||
| 3774 | main thread and do the actual buffer swap in a separate | - | ||||||||||||||||||
| 3775 | thread. This can be done with the following steps: | - | ||||||||||||||||||
| 3776 | - | |||||||||||||||||||
| 3777 | 1. Call doneCurrent() in the main thread when the rendering is | - | ||||||||||||||||||
| 3778 | finished. | - | ||||||||||||||||||
| 3779 | - | |||||||||||||||||||
| 3780 | 2. Call QGLContext::moveToThread(swapThread) to transfer ownership | - | ||||||||||||||||||
| 3781 | of the context to the swapping thread. | - | ||||||||||||||||||
| 3782 | - | |||||||||||||||||||
| 3783 | 3. Notify the swapping thread that it can grab the context. | - | ||||||||||||||||||
| 3784 | - | |||||||||||||||||||
| 3785 | 4. Make the rendering context current in the swapping thread with | - | ||||||||||||||||||
| 3786 | makeCurrent() and then call swapBuffers(). | - | ||||||||||||||||||
| 3787 | - | |||||||||||||||||||
| 3788 | 5. Call doneCurrent() in the swapping thread. | - | ||||||||||||||||||
| 3789 | - | |||||||||||||||||||
| 3790 | 6. Call QGLContext::moveToThread(qApp->thread()) and notify the | - | ||||||||||||||||||
| 3791 | main thread that swapping is done. | - | ||||||||||||||||||
| 3792 | - | |||||||||||||||||||
| 3793 | Doing this will free up the main thread so that it can continue | - | ||||||||||||||||||
| 3794 | with, for example, handling UI events or network requests. Even if | - | ||||||||||||||||||
| 3795 | there is a context swap involved, it may be preferable compared to | - | ||||||||||||||||||
| 3796 | having the main thread wait while the GPU finishes the swap | - | ||||||||||||||||||
| 3797 | operation. Note that this is highly implementation dependent. | - | ||||||||||||||||||
| 3798 | - | |||||||||||||||||||
| 3799 | \li 2. Texture uploading in a thread. | - | ||||||||||||||||||
| 3800 | - | |||||||||||||||||||
| 3801 | Doing texture uploads in a thread may be very useful for | - | ||||||||||||||||||
| 3802 | applications handling large amounts of images that needs to be | - | ||||||||||||||||||
| 3803 | displayed, like for instance a photo gallery application. This is | - | ||||||||||||||||||
| 3804 | supported in Qt through the existing bindTexture() API. A simple | - | ||||||||||||||||||
| 3805 | way of doing this is to create two sharing QGLWidgets. One is made | - | ||||||||||||||||||
| 3806 | current in the main GUI thread, while the other is made current in | - | ||||||||||||||||||
| 3807 | the texture upload thread. The widget in the uploading thread is | - | ||||||||||||||||||
| 3808 | never shown, it is only used for sharing textures with the main | - | ||||||||||||||||||
| 3809 | thread. For each texture that is bound via bindTexture(), notify | - | ||||||||||||||||||
| 3810 | the main thread so that it can start using the texture. | - | ||||||||||||||||||
| 3811 | - | |||||||||||||||||||
| 3812 | \li 3. Using QPainter to draw into a QGLWidget in a thread. | - | ||||||||||||||||||
| 3813 | - | |||||||||||||||||||
| 3814 | In Qt 4.8, it is possible to draw into a QGLWidget using a | - | ||||||||||||||||||
| 3815 | QPainter in a separate thread. Note that this is also possible for | - | ||||||||||||||||||
| 3816 | QGLPixelBuffers and QGLFramebufferObjects. Since this is only | - | ||||||||||||||||||
| 3817 | supported in the GL 2 paint engine, OpenGL 2.0 or OpenGL ES 2.0 is | - | ||||||||||||||||||
| 3818 | required. | - | ||||||||||||||||||
| 3819 | - | |||||||||||||||||||
| 3820 | QGLWidgets can only be created in the main GUI thread. This means | - | ||||||||||||||||||
| 3821 | a call to doneCurrent() is necessary to release the GL context | - | ||||||||||||||||||
| 3822 | from the main thread, before the widget can be drawn into by | - | ||||||||||||||||||
| 3823 | another thread. You then need to call QGLContext::moveToThread() | - | ||||||||||||||||||
| 3824 | to transfer ownership of the context to the thread in which you | - | ||||||||||||||||||
| 3825 | want to make it current. | - | ||||||||||||||||||
| 3826 | Also, the main GUI thread will dispatch resize and | - | ||||||||||||||||||
| 3827 | paint events to a QGLWidget when the widget is resized, or parts | - | ||||||||||||||||||
| 3828 | of it becomes exposed or needs redrawing. It is therefore | - | ||||||||||||||||||
| 3829 | necessary to handle those events because the default | - | ||||||||||||||||||
| 3830 | implementations inside QGLWidget will try to make the QGLWidget's | - | ||||||||||||||||||
| 3831 | context current, which again will interfere with any threads | - | ||||||||||||||||||
| 3832 | rendering into the widget. Reimplement QGLWidget::paintEvent() and | - | ||||||||||||||||||
| 3833 | QGLWidget::resizeEvent() to notify the rendering thread that a | - | ||||||||||||||||||
| 3834 | resize or update is necessary, and be careful not to call the base | - | ||||||||||||||||||
| 3835 | class implementation. If you are rendering an animation, it might | - | ||||||||||||||||||
| 3836 | not be necessary to handle the paint event at all since the | - | ||||||||||||||||||
| 3837 | rendering thread is doing regular updates. Then it would be enough | - | ||||||||||||||||||
| 3838 | to reimplement QGLWidget::paintEvent() to do nothing. | - | ||||||||||||||||||
| 3839 | - | |||||||||||||||||||
| 3840 | \endlist | - | ||||||||||||||||||
| 3841 | - | |||||||||||||||||||
| 3842 | As a general rule when doing threaded rendering: be aware that | - | ||||||||||||||||||
| 3843 | binding and releasing contexts in different threads have to be | - | ||||||||||||||||||
| 3844 | synchronized by the user. A GL rendering context can only be | - | ||||||||||||||||||
| 3845 | current in one thread at any time. If you try to open a QPainter | - | ||||||||||||||||||
| 3846 | on a QGLWidget and the widget's rendering context is current in | - | ||||||||||||||||||
| 3847 | another thread, it will fail. | - | ||||||||||||||||||
| 3848 | - | |||||||||||||||||||
| 3849 | In addition to this, rendering using raw GL calls in a separate | - | ||||||||||||||||||
| 3850 | thread is supported. | - | ||||||||||||||||||
| 3851 | - | |||||||||||||||||||
| 3852 | \e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other | - | ||||||||||||||||||
| 3853 | countries.} | - | ||||||||||||||||||
| 3854 | - | |||||||||||||||||||
| 3855 | \sa QOpenGLWidget, QGLPixelBuffer | - | ||||||||||||||||||
| 3856 | */ | - | ||||||||||||||||||
| 3857 | - | |||||||||||||||||||
| 3858 | /*! | - | ||||||||||||||||||
| 3859 | Constructs an OpenGL widget with a \a parent widget. | - | ||||||||||||||||||
| 3860 | - | |||||||||||||||||||
| 3861 | The \l{QGLFormat::defaultFormat()}{default format} is | - | ||||||||||||||||||
| 3862 | used. The widget will be \l{isValid()}{invalid} if the | - | ||||||||||||||||||
| 3863 | system has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
| 3864 | - | |||||||||||||||||||
| 3865 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
| 3866 | to the QWidget constructor. | - | ||||||||||||||||||
| 3867 | - | |||||||||||||||||||
| 3868 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
| 3869 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
| 3870 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
| 3871 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
| 3872 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
| 3873 | - | |||||||||||||||||||
| 3874 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
| 3875 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
| 3876 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
| 3877 | - | |||||||||||||||||||
| 3878 | \sa QGLFormat::defaultFormat(), {Textures Example} | - | ||||||||||||||||||
| 3879 | */ | - | ||||||||||||||||||
| 3880 | - | |||||||||||||||||||
| 3881 | QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f) | - | ||||||||||||||||||
| 3882 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
| 3883 | { | - | ||||||||||||||||||
| 3884 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 3885 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
| 3886 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
| 3887 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
| 3888 | d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget); | - | ||||||||||||||||||
| 3889 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3890 | - | |||||||||||||||||||
| 3891 | /*! | - | ||||||||||||||||||
| 3892 | \internal | - | ||||||||||||||||||
| 3893 | */ | - | ||||||||||||||||||
| 3894 | QGLWidget::QGLWidget(QGLWidgetPrivate &dd, const QGLFormat &format, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f) | - | ||||||||||||||||||
| 3895 | : QWidget(dd, parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
| 3896 | { | - | ||||||||||||||||||
| 3897 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 3898 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
| 3899 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
| 3900 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
| 3901 | d->init(new QGLContext(format, this), shareWidget); | - | ||||||||||||||||||
| 3902 | - | |||||||||||||||||||
| 3903 | } never executed: end of block | 0 | ||||||||||||||||||
| 3904 | - | |||||||||||||||||||
| 3905 | - | |||||||||||||||||||
| 3906 | /*! | - | ||||||||||||||||||
| 3907 | Constructs an OpenGL widget with parent \a parent. | - | ||||||||||||||||||
| 3908 | - | |||||||||||||||||||
| 3909 | The \a format argument specifies the desired | - | ||||||||||||||||||
| 3910 | \l{QGLFormat}{rendering options}. | - | ||||||||||||||||||
| 3911 | If the underlying OpenGL/Window system | - | ||||||||||||||||||
| 3912 | cannot satisfy all the features requested in \a format, the | - | ||||||||||||||||||
| 3913 | nearest subset of features will be used. After creation, the | - | ||||||||||||||||||
| 3914 | format() method will return the actual format obtained. | - | ||||||||||||||||||
| 3915 | - | |||||||||||||||||||
| 3916 | The widget will be \l{isValid()}{invalid} if the system | - | ||||||||||||||||||
| 3917 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
| 3918 | - | |||||||||||||||||||
| 3919 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
| 3920 | to the QWidget constructor. | - | ||||||||||||||||||
| 3921 | - | |||||||||||||||||||
| 3922 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
| 3923 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
| 3924 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
| 3925 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
| 3926 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
| 3927 | - | |||||||||||||||||||
| 3928 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
| 3929 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
| 3930 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
| 3931 | - | |||||||||||||||||||
| 3932 | \sa QGLFormat::defaultFormat(), isValid() | - | ||||||||||||||||||
| 3933 | */ | - | ||||||||||||||||||
| 3934 | - | |||||||||||||||||||
| 3935 | QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* shareWidget, | - | ||||||||||||||||||
| 3936 | Qt::WindowFlags f) | - | ||||||||||||||||||
| 3937 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
| 3938 | { | - | ||||||||||||||||||
| 3939 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 3940 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
| 3941 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
| 3942 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
| 3943 | d->init(new QGLContext(format, this), shareWidget); | - | ||||||||||||||||||
| 3944 | } never executed: end of block | 0 | ||||||||||||||||||
| 3945 | - | |||||||||||||||||||
| 3946 | /*! | - | ||||||||||||||||||
| 3947 | Constructs an OpenGL widget with parent \a parent. | - | ||||||||||||||||||
| 3948 | - | |||||||||||||||||||
| 3949 | The \a context argument is a pointer to the QGLContext that | - | ||||||||||||||||||
| 3950 | you wish to be bound to this widget. This allows you to pass in | - | ||||||||||||||||||
| 3951 | your own QGLContext sub-classes. | - | ||||||||||||||||||
| 3952 | - | |||||||||||||||||||
| 3953 | The widget will be \l{isValid()}{invalid} if the system | - | ||||||||||||||||||
| 3954 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
| 3955 | - | |||||||||||||||||||
| 3956 | The \a parent and widget flag, \a f, arguments are passed | - | ||||||||||||||||||
| 3957 | to the QWidget constructor. | - | ||||||||||||||||||
| 3958 | - | |||||||||||||||||||
| 3959 | If \a shareWidget is a valid QGLWidget, this widget will share | - | ||||||||||||||||||
| 3960 | OpenGL display lists and texture objects with \a shareWidget. But | - | ||||||||||||||||||
| 3961 | if \a shareWidget and this widget have different \l {format()} | - | ||||||||||||||||||
| 3962 | {formats}, sharing might not be possible. You can check whether | - | ||||||||||||||||||
| 3963 | sharing is in effect by calling isSharing(). | - | ||||||||||||||||||
| 3964 | - | |||||||||||||||||||
| 3965 | The initialization of OpenGL rendering state, etc. should be done | - | ||||||||||||||||||
| 3966 | by overriding the initializeGL() function, rather than in the | - | ||||||||||||||||||
| 3967 | constructor of your QGLWidget subclass. | - | ||||||||||||||||||
| 3968 | - | |||||||||||||||||||
| 3969 | \sa QGLFormat::defaultFormat(), isValid() | - | ||||||||||||||||||
| 3970 | */ | - | ||||||||||||||||||
| 3971 | QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, const QGLWidget *shareWidget, | - | ||||||||||||||||||
| 3972 | Qt::WindowFlags f) | - | ||||||||||||||||||
| 3973 | : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC) | - | ||||||||||||||||||
| 3974 | { | - | ||||||||||||||||||
| 3975 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 3976 | setAttribute(Qt::WA_PaintOnScreen); | - | ||||||||||||||||||
| 3977 | setAttribute(Qt::WA_NoSystemBackground); | - | ||||||||||||||||||
| 3978 | setAutoFillBackground(true); // for compatibility | - | ||||||||||||||||||
| 3979 | d->init(context, shareWidget); | - | ||||||||||||||||||
| 3980 | } never executed: end of block | 0 | ||||||||||||||||||
| 3981 | - | |||||||||||||||||||
| 3982 | /*! | - | ||||||||||||||||||
| 3983 | Destroys the widget. | - | ||||||||||||||||||
| 3984 | */ | - | ||||||||||||||||||
| 3985 | - | |||||||||||||||||||
| 3986 | QGLWidget::~QGLWidget() | - | ||||||||||||||||||
| 3987 | { | - | ||||||||||||||||||
| 3988 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 3989 | delete d->glcx; | - | ||||||||||||||||||
| 3990 | d->glcx = 0; | - | ||||||||||||||||||
| 3991 | d->cleanupColormaps(); | - | ||||||||||||||||||
| 3992 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 3993 | - | |||||||||||||||||||
| 3994 | /*! | - | ||||||||||||||||||
| 3995 | \fn QGLFormat QGLWidget::format() const | - | ||||||||||||||||||
| 3996 | - | |||||||||||||||||||
| 3997 | Returns the format of the contained GL rendering context. | - | ||||||||||||||||||
| 3998 | */ | - | ||||||||||||||||||
| 3999 | - | |||||||||||||||||||
| 4000 | /*! | - | ||||||||||||||||||
| 4001 | \fn bool QGLWidget::doubleBuffer() const | - | ||||||||||||||||||
| 4002 | - | |||||||||||||||||||
| 4003 | Returns \c true if the contained GL rendering context has double | - | ||||||||||||||||||
| 4004 | buffering; otherwise returns \c false. | - | ||||||||||||||||||
| 4005 | - | |||||||||||||||||||
| 4006 | \sa QGLFormat::doubleBuffer() | - | ||||||||||||||||||
| 4007 | */ | - | ||||||||||||||||||
| 4008 | - | |||||||||||||||||||
| 4009 | /*! | - | ||||||||||||||||||
| 4010 | \fn void QGLWidget::setAutoBufferSwap(bool on) | - | ||||||||||||||||||
| 4011 | - | |||||||||||||||||||
| 4012 | If \a on is true automatic GL buffer swapping is switched on; | - | ||||||||||||||||||
| 4013 | otherwise it is switched off. | - | ||||||||||||||||||
| 4014 | - | |||||||||||||||||||
| 4015 | If \a on is true and the widget is using a double-buffered format, | - | ||||||||||||||||||
| 4016 | the background and foreground GL buffers will automatically be | - | ||||||||||||||||||
| 4017 | swapped after each paintGL() call. | - | ||||||||||||||||||
| 4018 | - | |||||||||||||||||||
| 4019 | The buffer auto-swapping is on by default. | - | ||||||||||||||||||
| 4020 | - | |||||||||||||||||||
| 4021 | \sa autoBufferSwap(), doubleBuffer(), swapBuffers() | - | ||||||||||||||||||
| 4022 | */ | - | ||||||||||||||||||
| 4023 | - | |||||||||||||||||||
| 4024 | /*! | - | ||||||||||||||||||
| 4025 | \fn bool QGLWidget::autoBufferSwap() const | - | ||||||||||||||||||
| 4026 | - | |||||||||||||||||||
| 4027 | Returns \c true if the widget is doing automatic GL buffer swapping; | - | ||||||||||||||||||
| 4028 | otherwise returns \c false. | - | ||||||||||||||||||
| 4029 | - | |||||||||||||||||||
| 4030 | \sa setAutoBufferSwap() | - | ||||||||||||||||||
| 4031 | */ | - | ||||||||||||||||||
| 4032 | - | |||||||||||||||||||
| 4033 | /*! | - | ||||||||||||||||||
| 4034 | \fn QFunctionPointer QGLContext::getProcAddress(const QString &proc) const | - | ||||||||||||||||||
| 4035 | - | |||||||||||||||||||
| 4036 | Returns a function pointer to the GL extension function passed in | - | ||||||||||||||||||
| 4037 | \a proc. 0 is returned if a pointer to the function could not be | - | ||||||||||||||||||
| 4038 | obtained. | - | ||||||||||||||||||
| 4039 | */ | - | ||||||||||||||||||
| 4040 | QFunctionPointer QGLContext::getProcAddress(const QString &procName) const | - | ||||||||||||||||||
| 4041 | { | - | ||||||||||||||||||
| 4042 | Q_D(const QGLContext); | - | ||||||||||||||||||
| 4043 | return d->guiGlContext->getProcAddress(procName.toLatin1()); never executed: return d->guiGlContext->getProcAddress(procName.toLatin1()); | 0 | ||||||||||||||||||
| 4044 | } | - | ||||||||||||||||||
| 4045 | - | |||||||||||||||||||
| 4046 | /*! | - | ||||||||||||||||||
| 4047 | \fn bool QGLWidget::isValid() const | - | ||||||||||||||||||
| 4048 | - | |||||||||||||||||||
| 4049 | Returns \c true if the widget has a valid GL rendering context; | - | ||||||||||||||||||
| 4050 | otherwise returns \c false. A widget will be invalid if the system | - | ||||||||||||||||||
| 4051 | has no \l{QGLFormat::hasOpenGL()}{OpenGL support}. | - | ||||||||||||||||||
| 4052 | */ | - | ||||||||||||||||||
| 4053 | - | |||||||||||||||||||
| 4054 | bool QGLWidget::isValid() const | - | ||||||||||||||||||
| 4055 | { | - | ||||||||||||||||||
| 4056 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 4057 | return d->glcx && d->glcx->isValid(); executed 3 times by 1 test: return d->glcx && d->glcx->isValid();Executed by:
| 3 | ||||||||||||||||||
| 4058 | } | - | ||||||||||||||||||
| 4059 | - | |||||||||||||||||||
| 4060 | /*! | - | ||||||||||||||||||
| 4061 | \fn bool QGLWidget::isSharing() const | - | ||||||||||||||||||
| 4062 | - | |||||||||||||||||||
| 4063 | Returns \c true if this widget's GL context is shared with another GL | - | ||||||||||||||||||
| 4064 | context, otherwise false is returned. Context sharing might not be | - | ||||||||||||||||||
| 4065 | possible if the widgets use different formats. | - | ||||||||||||||||||
| 4066 | - | |||||||||||||||||||
| 4067 | \sa format() | - | ||||||||||||||||||
| 4068 | */ | - | ||||||||||||||||||
| 4069 | - | |||||||||||||||||||
| 4070 | bool QGLWidget::isSharing() const | - | ||||||||||||||||||
| 4071 | { | - | ||||||||||||||||||
| 4072 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 4073 | return d->glcx->isSharing(); executed 1 time by 1 test: return d->glcx->isSharing();Executed by:
| 1 | ||||||||||||||||||
| 4074 | } | - | ||||||||||||||||||
| 4075 | - | |||||||||||||||||||
| 4076 | /*! | - | ||||||||||||||||||
| 4077 | \fn void QGLWidget::makeCurrent() | - | ||||||||||||||||||
| 4078 | - | |||||||||||||||||||
| 4079 | Makes this widget the current widget for OpenGL operations, i.e. | - | ||||||||||||||||||
| 4080 | makes the widget's rendering context the current OpenGL rendering | - | ||||||||||||||||||
| 4081 | context. | - | ||||||||||||||||||
| 4082 | */ | - | ||||||||||||||||||
| 4083 | - | |||||||||||||||||||
| 4084 | void QGLWidget::makeCurrent() | - | ||||||||||||||||||
| 4085 | { | - | ||||||||||||||||||
| 4086 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4087 | d->glcx->makeCurrent(); | - | ||||||||||||||||||
| 4088 | } executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 4089 | - | |||||||||||||||||||
| 4090 | /*! | - | ||||||||||||||||||
| 4091 | \fn void QGLWidget::doneCurrent() | - | ||||||||||||||||||
| 4092 | - | |||||||||||||||||||
| 4093 | Makes no GL context the current context. Normally, you do not need | - | ||||||||||||||||||
| 4094 | to call this function; QGLContext calls it as necessary. However, | - | ||||||||||||||||||
| 4095 | it may be useful in multithreaded environments. | - | ||||||||||||||||||
| 4096 | */ | - | ||||||||||||||||||
| 4097 | - | |||||||||||||||||||
| 4098 | void QGLWidget::doneCurrent() | - | ||||||||||||||||||
| 4099 | { | - | ||||||||||||||||||
| 4100 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4101 | d->glcx->doneCurrent(); | - | ||||||||||||||||||
| 4102 | } never executed: end of block | 0 | ||||||||||||||||||
| 4103 | - | |||||||||||||||||||
| 4104 | /*! | - | ||||||||||||||||||
| 4105 | \fn void QGLWidget::swapBuffers() | - | ||||||||||||||||||
| 4106 | - | |||||||||||||||||||
| 4107 | Swaps the screen contents with an off-screen buffer. This only | - | ||||||||||||||||||
| 4108 | works if the widget's format specifies double buffer mode. | - | ||||||||||||||||||
| 4109 | - | |||||||||||||||||||
| 4110 | Normally, there is no need to explicitly call this function | - | ||||||||||||||||||
| 4111 | because it is done automatically after each widget repaint, i.e. | - | ||||||||||||||||||
| 4112 | each time after paintGL() has been executed. | - | ||||||||||||||||||
| 4113 | - | |||||||||||||||||||
| 4114 | \sa doubleBuffer(), setAutoBufferSwap(), QGLFormat::setDoubleBuffer() | - | ||||||||||||||||||
| 4115 | */ | - | ||||||||||||||||||
| 4116 | - | |||||||||||||||||||
| 4117 | void QGLWidget::swapBuffers() | - | ||||||||||||||||||
| 4118 | { | - | ||||||||||||||||||
| 4119 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4120 | d->glcx->swapBuffers(); | - | ||||||||||||||||||
| 4121 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 4122 | - | |||||||||||||||||||
| 4123 | - | |||||||||||||||||||
| 4124 | /*! | - | ||||||||||||||||||
| 4125 | \fn const QGLContext* QGLWidget::overlayContext() const | - | ||||||||||||||||||
| 4126 | - | |||||||||||||||||||
| 4127 | Returns the overlay context of this widget, or 0 if this widget | - | ||||||||||||||||||
| 4128 | has no overlay. | - | ||||||||||||||||||
| 4129 | - | |||||||||||||||||||
| 4130 | \sa context() | - | ||||||||||||||||||
| 4131 | */ | - | ||||||||||||||||||
| 4132 | const QGLContext* QGLWidget::overlayContext() const | - | ||||||||||||||||||
| 4133 | { | - | ||||||||||||||||||
| 4134 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 4135 | } | - | ||||||||||||||||||
| 4136 | - | |||||||||||||||||||
| 4137 | /*! | - | ||||||||||||||||||
| 4138 | \fn void QGLWidget::makeOverlayCurrent() | - | ||||||||||||||||||
| 4139 | - | |||||||||||||||||||
| 4140 | Makes the overlay context of this widget current. Use this if you | - | ||||||||||||||||||
| 4141 | need to issue OpenGL commands to the overlay context outside of | - | ||||||||||||||||||
| 4142 | initializeOverlayGL(), resizeOverlayGL(), and paintOverlayGL(). | - | ||||||||||||||||||
| 4143 | - | |||||||||||||||||||
| 4144 | Does nothing if this widget has no overlay. | - | ||||||||||||||||||
| 4145 | - | |||||||||||||||||||
| 4146 | \sa makeCurrent() | - | ||||||||||||||||||
| 4147 | */ | - | ||||||||||||||||||
| 4148 | void QGLWidget::makeOverlayCurrent() | - | ||||||||||||||||||
| 4149 | { | - | ||||||||||||||||||
| 4150 | } | - | ||||||||||||||||||
| 4151 | - | |||||||||||||||||||
| 4152 | /*! | - | ||||||||||||||||||
| 4153 | \obsolete | - | ||||||||||||||||||
| 4154 | - | |||||||||||||||||||
| 4155 | Sets a new format for this widget. | - | ||||||||||||||||||
| 4156 | - | |||||||||||||||||||
| 4157 | If the underlying OpenGL/Window system cannot satisfy all the | - | ||||||||||||||||||
| 4158 | features requested in \a format, the nearest subset of features will | - | ||||||||||||||||||
| 4159 | be used. After creation, the format() method will return the actual | - | ||||||||||||||||||
| 4160 | rendering context format obtained. | - | ||||||||||||||||||
| 4161 | - | |||||||||||||||||||
| 4162 | The widget will be assigned a new QGLContext, and the initializeGL() | - | ||||||||||||||||||
| 4163 | function will be executed for this new context before the first | - | ||||||||||||||||||
| 4164 | resizeGL() or paintGL(). | - | ||||||||||||||||||
| 4165 | - | |||||||||||||||||||
| 4166 | This method will try to keep display list and texture object sharing | - | ||||||||||||||||||
| 4167 | in effect with other QGLWidget objects, but changing the format might make | - | ||||||||||||||||||
| 4168 | sharing impossible. Use isSharing() to see if sharing is still in | - | ||||||||||||||||||
| 4169 | effect. | - | ||||||||||||||||||
| 4170 | - | |||||||||||||||||||
| 4171 | \sa format(), isSharing(), isValid() | - | ||||||||||||||||||
| 4172 | */ | - | ||||||||||||||||||
| 4173 | - | |||||||||||||||||||
| 4174 | void QGLWidget::setFormat(const QGLFormat &format) | - | ||||||||||||||||||
| 4175 | { | - | ||||||||||||||||||
| 4176 | setContext(new QGLContext(format,this)); | - | ||||||||||||||||||
| 4177 | } never executed: end of block | 0 | ||||||||||||||||||
| 4178 | - | |||||||||||||||||||
| 4179 | - | |||||||||||||||||||
| 4180 | - | |||||||||||||||||||
| 4181 | - | |||||||||||||||||||
| 4182 | /*! | - | ||||||||||||||||||
| 4183 | \fn QGLContext *QGLWidget::context() const | - | ||||||||||||||||||
| 4184 | - | |||||||||||||||||||
| 4185 | Returns the context of this widget. | - | ||||||||||||||||||
| 4186 | - | |||||||||||||||||||
| 4187 | It is possible that the context is not valid (see isValid()), for | - | ||||||||||||||||||
| 4188 | example, if the underlying hardware does not support the format | - | ||||||||||||||||||
| 4189 | attributes that were requested. | - | ||||||||||||||||||
| 4190 | */ | - | ||||||||||||||||||
| 4191 | - | |||||||||||||||||||
| 4192 | /*! | - | ||||||||||||||||||
| 4193 | \fn void QGLWidget::setContext(QGLContext *context, | - | ||||||||||||||||||
| 4194 | const QGLContext* shareContext, | - | ||||||||||||||||||
| 4195 | bool deleteOldContext) | - | ||||||||||||||||||
| 4196 | \obsolete | - | ||||||||||||||||||
| 4197 | - | |||||||||||||||||||
| 4198 | Sets a new context for this widget. The QGLContext \a context must | - | ||||||||||||||||||
| 4199 | be created using \e new. QGLWidget will delete \a context when | - | ||||||||||||||||||
| 4200 | another context is set or when the widget is destroyed. | - | ||||||||||||||||||
| 4201 | - | |||||||||||||||||||
| 4202 | If \a context is invalid, QGLContext::create() is performed on | - | ||||||||||||||||||
| 4203 | it. The initializeGL() function will then be executed for the new | - | ||||||||||||||||||
| 4204 | context before the first resizeGL() or paintGL(). | - | ||||||||||||||||||
| 4205 | - | |||||||||||||||||||
| 4206 | If \a context is invalid, this method will try to keep display list | - | ||||||||||||||||||
| 4207 | and texture object sharing in effect, or (if \a shareContext points | - | ||||||||||||||||||
| 4208 | to a valid context) start display list and texture object sharing | - | ||||||||||||||||||
| 4209 | with that context, but sharing might be impossible if the two | - | ||||||||||||||||||
| 4210 | contexts have different \l {format()} {formats}. Use isSharing() to | - | ||||||||||||||||||
| 4211 | see whether sharing is in effect. | - | ||||||||||||||||||
| 4212 | - | |||||||||||||||||||
| 4213 | If \a deleteOldContext is true (the default), the existing context | - | ||||||||||||||||||
| 4214 | will be deleted. You may use false here if you have kept a pointer | - | ||||||||||||||||||
| 4215 | to the old context (as returned by context()), and want to restore | - | ||||||||||||||||||
| 4216 | that context later. | - | ||||||||||||||||||
| 4217 | - | |||||||||||||||||||
| 4218 | \note This function is obsolete and should no longer be used. If you were | - | ||||||||||||||||||
| 4219 | using it to recreate the context for a QGLWidget, you should instead create a | - | ||||||||||||||||||
| 4220 | new QGLWidget or use the QOpenGLContext API in conjunction with QWindow. | - | ||||||||||||||||||
| 4221 | There is currently no officially supported way to substitute QGLWidget's | - | ||||||||||||||||||
| 4222 | context with your own implementation of QGLContext. | - | ||||||||||||||||||
| 4223 | - | |||||||||||||||||||
| 4224 | \sa context(), isSharing() | - | ||||||||||||||||||
| 4225 | */ | - | ||||||||||||||||||
| 4226 | void QGLWidget::setContext(QGLContext *context, | - | ||||||||||||||||||
| 4227 | const QGLContext* shareContext, | - | ||||||||||||||||||
| 4228 | bool deleteOldContext) | - | ||||||||||||||||||
| 4229 | { | - | ||||||||||||||||||
| 4230 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4231 | if (context == 0) {
| 0-12 | ||||||||||||||||||
| 4232 | qWarning("QGLWidget::setContext: Cannot set null context"); | - | ||||||||||||||||||
| 4233 | return; never executed: return; | 0 | ||||||||||||||||||
| 4234 | } | - | ||||||||||||||||||
| 4235 | - | |||||||||||||||||||
| 4236 | if (context->device() == 0) // a context may refere to more than 1 window.
| 0-12 | ||||||||||||||||||
| 4237 | context->setDevice(this); //but its better to point to 1 of them than none of them. never executed: context->setDevice(this); | 0 | ||||||||||||||||||
| 4238 | - | |||||||||||||||||||
| 4239 | QGLContext* oldcx = d->glcx; | - | ||||||||||||||||||
| 4240 | d->glcx = context; | - | ||||||||||||||||||
| 4241 | - | |||||||||||||||||||
| 4242 | if (!d->glcx->isValid())
| 0-12 | ||||||||||||||||||
| 4243 | d->glcx->create(shareContext ? shareContext : oldcx); executed 12 times by 3 tests: d->glcx->create(shareContext ? shareContext : oldcx);Executed by:
| 12 | ||||||||||||||||||
| 4244 | - | |||||||||||||||||||
| 4245 | if (deleteOldContext)
| 0-12 | ||||||||||||||||||
| 4246 | delete oldcx; executed 12 times by 3 tests: delete oldcx;Executed by:
| 12 | ||||||||||||||||||
| 4247 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 4248 | - | |||||||||||||||||||
| 4249 | /*! | - | ||||||||||||||||||
| 4250 | \fn void QGLWidget::updateGL() | - | ||||||||||||||||||
| 4251 | - | |||||||||||||||||||
| 4252 | Updates the widget by calling glDraw(). | - | ||||||||||||||||||
| 4253 | */ | - | ||||||||||||||||||
| 4254 | - | |||||||||||||||||||
| 4255 | void QGLWidget::updateGL() | - | ||||||||||||||||||
| 4256 | { | - | ||||||||||||||||||
| 4257 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4258 | const bool targetIsOffscreen = !d->glcx->d_ptr->readback_target_size.isEmpty(); | - | ||||||||||||||||||
| 4259 | if (updatesEnabled() && (testAttribute(Qt::WA_Mapped) || targetIsOffscreen))
| 0 | ||||||||||||||||||
| 4260 | glDraw(); never executed: glDraw(); | 0 | ||||||||||||||||||
| 4261 | } never executed: end of block | 0 | ||||||||||||||||||
| 4262 | - | |||||||||||||||||||
| 4263 | - | |||||||||||||||||||
| 4264 | /*! | - | ||||||||||||||||||
| 4265 | \fn void QGLWidget::updateOverlayGL() | - | ||||||||||||||||||
| 4266 | - | |||||||||||||||||||
| 4267 | Updates the widget's overlay (if any). Will cause the virtual | - | ||||||||||||||||||
| 4268 | function paintOverlayGL() to be executed. | - | ||||||||||||||||||
| 4269 | - | |||||||||||||||||||
| 4270 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
| 4271 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
| 4272 | */ | - | ||||||||||||||||||
| 4273 | void QGLWidget::updateOverlayGL() | - | ||||||||||||||||||
| 4274 | { | - | ||||||||||||||||||
| 4275 | } | - | ||||||||||||||||||
| 4276 | - | |||||||||||||||||||
| 4277 | /*! | - | ||||||||||||||||||
| 4278 | This virtual function is called once before the first call to | - | ||||||||||||||||||
| 4279 | paintGL() or resizeGL(), and then once whenever the widget has | - | ||||||||||||||||||
| 4280 | been assigned a new QGLContext. Reimplement it in a subclass. | - | ||||||||||||||||||
| 4281 | - | |||||||||||||||||||
| 4282 | This function should set up any required OpenGL context rendering | - | ||||||||||||||||||
| 4283 | flags, defining display lists, etc. | - | ||||||||||||||||||
| 4284 | - | |||||||||||||||||||
| 4285 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
| 4286 | been done when this function is called. | - | ||||||||||||||||||
| 4287 | */ | - | ||||||||||||||||||
| 4288 | - | |||||||||||||||||||
| 4289 | void QGLWidget::initializeGL() | - | ||||||||||||||||||
| 4290 | { | - | ||||||||||||||||||
| 4291 | } | - | ||||||||||||||||||
| 4292 | - | |||||||||||||||||||
| 4293 | - | |||||||||||||||||||
| 4294 | /*! | - | ||||||||||||||||||
| 4295 | This virtual function is called whenever the widget needs to be | - | ||||||||||||||||||
| 4296 | painted. Reimplement it in a subclass. | - | ||||||||||||||||||
| 4297 | - | |||||||||||||||||||
| 4298 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
| 4299 | been done when this function is called. | - | ||||||||||||||||||
| 4300 | */ | - | ||||||||||||||||||
| 4301 | - | |||||||||||||||||||
| 4302 | void QGLWidget::paintGL() | - | ||||||||||||||||||
| 4303 | { | - | ||||||||||||||||||
| 4304 | qgl_functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | - | ||||||||||||||||||
| 4305 | } never executed: end of block | 0 | ||||||||||||||||||
| 4306 | - | |||||||||||||||||||
| 4307 | - | |||||||||||||||||||
| 4308 | /*! | - | ||||||||||||||||||
| 4309 | \fn void QGLWidget::resizeGL(int width , int height) | - | ||||||||||||||||||
| 4310 | - | |||||||||||||||||||
| 4311 | This virtual function is called whenever the widget has been | - | ||||||||||||||||||
| 4312 | resized. The new size is passed in \a width and \a height. | - | ||||||||||||||||||
| 4313 | Reimplement it in a subclass. | - | ||||||||||||||||||
| 4314 | - | |||||||||||||||||||
| 4315 | There is no need to call makeCurrent() because this has already | - | ||||||||||||||||||
| 4316 | been done when this function is called. | - | ||||||||||||||||||
| 4317 | */ | - | ||||||||||||||||||
| 4318 | - | |||||||||||||||||||
| 4319 | void QGLWidget::resizeGL(int, int) | - | ||||||||||||||||||
| 4320 | { | - | ||||||||||||||||||
| 4321 | } | - | ||||||||||||||||||
| 4322 | - | |||||||||||||||||||
| 4323 | - | |||||||||||||||||||
| 4324 | - | |||||||||||||||||||
| 4325 | /*! | - | ||||||||||||||||||
| 4326 | This virtual function is used in the same manner as initializeGL() | - | ||||||||||||||||||
| 4327 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
| 4328 | the widget's main context. This means that initializeOverlayGL() | - | ||||||||||||||||||
| 4329 | is called once before the first call to paintOverlayGL() or | - | ||||||||||||||||||
| 4330 | resizeOverlayGL(). Reimplement it in a subclass. | - | ||||||||||||||||||
| 4331 | - | |||||||||||||||||||
| 4332 | This function should set up any required OpenGL context rendering | - | ||||||||||||||||||
| 4333 | flags, defining display lists, etc. for the overlay context. | - | ||||||||||||||||||
| 4334 | - | |||||||||||||||||||
| 4335 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
| 4336 | already been done when this function is called. | - | ||||||||||||||||||
| 4337 | */ | - | ||||||||||||||||||
| 4338 | - | |||||||||||||||||||
| 4339 | void QGLWidget::initializeOverlayGL() | - | ||||||||||||||||||
| 4340 | { | - | ||||||||||||||||||
| 4341 | } | - | ||||||||||||||||||
| 4342 | - | |||||||||||||||||||
| 4343 | - | |||||||||||||||||||
| 4344 | /*! | - | ||||||||||||||||||
| 4345 | This virtual function is used in the same manner as paintGL() | - | ||||||||||||||||||
| 4346 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
| 4347 | the widget's main context. This means that paintOverlayGL() is | - | ||||||||||||||||||
| 4348 | called whenever the widget's overlay needs to be painted. | - | ||||||||||||||||||
| 4349 | Reimplement it in a subclass. | - | ||||||||||||||||||
| 4350 | - | |||||||||||||||||||
| 4351 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
| 4352 | already been done when this function is called. | - | ||||||||||||||||||
| 4353 | */ | - | ||||||||||||||||||
| 4354 | - | |||||||||||||||||||
| 4355 | void QGLWidget::paintOverlayGL() | - | ||||||||||||||||||
| 4356 | { | - | ||||||||||||||||||
| 4357 | } | - | ||||||||||||||||||
| 4358 | - | |||||||||||||||||||
| 4359 | - | |||||||||||||||||||
| 4360 | /*! | - | ||||||||||||||||||
| 4361 | \fn void QGLWidget::resizeOverlayGL(int width , int height) | - | ||||||||||||||||||
| 4362 | - | |||||||||||||||||||
| 4363 | This virtual function is used in the same manner as paintGL() | - | ||||||||||||||||||
| 4364 | except that it operates on the widget's overlay context instead of | - | ||||||||||||||||||
| 4365 | the widget's main context. This means that resizeOverlayGL() is | - | ||||||||||||||||||
| 4366 | called whenever the widget has been resized. The new size is | - | ||||||||||||||||||
| 4367 | passed in \a width and \a height. Reimplement it in a subclass. | - | ||||||||||||||||||
| 4368 | - | |||||||||||||||||||
| 4369 | There is no need to call makeOverlayCurrent() because this has | - | ||||||||||||||||||
| 4370 | already been done when this function is called. | - | ||||||||||||||||||
| 4371 | */ | - | ||||||||||||||||||
| 4372 | - | |||||||||||||||||||
| 4373 | void QGLWidget::resizeOverlayGL(int, int) | - | ||||||||||||||||||
| 4374 | { | - | ||||||||||||||||||
| 4375 | } | - | ||||||||||||||||||
| 4376 | - | |||||||||||||||||||
| 4377 | /*!\reimp | - | ||||||||||||||||||
| 4378 | */ | - | ||||||||||||||||||
| 4379 | bool QGLWidget::event(QEvent *e) | - | ||||||||||||||||||
| 4380 | { | - | ||||||||||||||||||
| 4381 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4382 | - | |||||||||||||||||||
| 4383 | // A re-parent will destroy the window and re-create it. We should not reset the context while it happens. | - | ||||||||||||||||||
| 4384 | if (e->type() == QEvent::ParentAboutToChange)
| 0-29 | ||||||||||||||||||
| 4385 | d->parent_changing = true; never executed: d->parent_changing = true; | 0 | ||||||||||||||||||
| 4386 | - | |||||||||||||||||||
| 4387 | if (e->type() == QEvent::ParentChange)
| 1-28 | ||||||||||||||||||
| 4388 | d->parent_changing = false; executed 1 time by 1 test: d->parent_changing = false;Executed by:
| 1 | ||||||||||||||||||
| 4389 | - | |||||||||||||||||||
| 4390 | return QWidget::event(e); executed 29 times by 3 tests: return QWidget::event(e);Executed by:
| 29 | ||||||||||||||||||
| 4391 | } | - | ||||||||||||||||||
| 4392 | - | |||||||||||||||||||
| 4393 | /*! | - | ||||||||||||||||||
| 4394 | \fn void QGLWidget::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||
| 4395 | - | |||||||||||||||||||
| 4396 | Handles paint events passed in the \a event parameter. Will cause | - | ||||||||||||||||||
| 4397 | the virtual paintGL() function to be called. | - | ||||||||||||||||||
| 4398 | - | |||||||||||||||||||
| 4399 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
| 4400 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
| 4401 | */ | - | ||||||||||||||||||
| 4402 | - | |||||||||||||||||||
| 4403 | void QGLWidget::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
| 4404 | { | - | ||||||||||||||||||
| 4405 | if (updatesEnabled()) {
| 0 | ||||||||||||||||||
| 4406 | glDraw(); | - | ||||||||||||||||||
| 4407 | updateOverlayGL(); | - | ||||||||||||||||||
| 4408 | } never executed: end of block | 0 | ||||||||||||||||||
| 4409 | } never executed: end of block | 0 | ||||||||||||||||||
| 4410 | - | |||||||||||||||||||
| 4411 | - | |||||||||||||||||||
| 4412 | /*! | - | ||||||||||||||||||
| 4413 | \fn void QGLWidget::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
| 4414 | - | |||||||||||||||||||
| 4415 | Handles resize events that are passed in the \a event parameter. | - | ||||||||||||||||||
| 4416 | Calls the virtual function resizeGL(). | - | ||||||||||||||||||
| 4417 | */ | - | ||||||||||||||||||
| 4418 | void QGLWidget::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||
| 4419 | { | - | ||||||||||||||||||
| 4420 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4421 | - | |||||||||||||||||||
| 4422 | QWidget::resizeEvent(e); | - | ||||||||||||||||||
| 4423 | if (!isValid())
| 0 | ||||||||||||||||||
| 4424 | return; never executed: return; | 0 | ||||||||||||||||||
| 4425 | makeCurrent(); | - | ||||||||||||||||||
| 4426 | if (!d->glcx->initialized())
| 0 | ||||||||||||||||||
| 4427 | glInit(); never executed: glInit(); | 0 | ||||||||||||||||||
| 4428 | const qreal scaleFactor = (window() && window()->windowHandle()) ?
| 0 | ||||||||||||||||||
| 4429 | window()->windowHandle()->devicePixelRatio() : 1.0; | - | ||||||||||||||||||
| 4430 | - | |||||||||||||||||||
| 4431 | resizeGL(width() * scaleFactor, height() * scaleFactor); | - | ||||||||||||||||||
| 4432 | } never executed: end of block | 0 | ||||||||||||||||||
| 4433 | - | |||||||||||||||||||
| 4434 | /*! | - | ||||||||||||||||||
| 4435 | Renders the current scene on a pixmap and returns the pixmap. | - | ||||||||||||||||||
| 4436 | - | |||||||||||||||||||
| 4437 | You can use this method on both visible and invisible QGLWidget objects. | - | ||||||||||||||||||
| 4438 | - | |||||||||||||||||||
| 4439 | Internally the function renders into a framebuffer object and performs pixel | - | ||||||||||||||||||
| 4440 | readback. This has a performance penalty, meaning that this function is not | - | ||||||||||||||||||
| 4441 | suitable to be called at a high frequency. | - | ||||||||||||||||||
| 4442 | - | |||||||||||||||||||
| 4443 | After creating and binding the framebuffer object, the function will call | - | ||||||||||||||||||
| 4444 | initializeGL(), resizeGL(), and paintGL(). On the next normal update | - | ||||||||||||||||||
| 4445 | initializeGL() and resizeGL() will be triggered again since the size of the | - | ||||||||||||||||||
| 4446 | destination pixmap and the QGLWidget's size may differ. | - | ||||||||||||||||||
| 4447 | - | |||||||||||||||||||
| 4448 | The size of the pixmap will be \a w pixels wide and \a h pixels high unless | - | ||||||||||||||||||
| 4449 | one of these parameters is 0 (the default), in which case the pixmap will | - | ||||||||||||||||||
| 4450 | have the same size as the widget. | - | ||||||||||||||||||
| 4451 | - | |||||||||||||||||||
| 4452 | Care must be taken when using framebuffer objects in paintGL() in | - | ||||||||||||||||||
| 4453 | combination with this function. To switch back to the default framebuffer, | - | ||||||||||||||||||
| 4454 | use QGLFramebufferObject::bindDefault(). Binding FBO 0 is wrong since | - | ||||||||||||||||||
| 4455 | renderPixmap() uses a custom framebuffer instead of the one provided by the | - | ||||||||||||||||||
| 4456 | windowing system. | - | ||||||||||||||||||
| 4457 | - | |||||||||||||||||||
| 4458 | \a useContext is ignored. Historically this parameter enabled the usage of | - | ||||||||||||||||||
| 4459 | the existing GL context. This is not supported anymore since additional | - | ||||||||||||||||||
| 4460 | contexts are never created. | - | ||||||||||||||||||
| 4461 | - | |||||||||||||||||||
| 4462 | Overlays are not rendered onto the pixmap. | - | ||||||||||||||||||
| 4463 | - | |||||||||||||||||||
| 4464 | If the GL rendering context and the desktop have different bit | - | ||||||||||||||||||
| 4465 | depths, the result will most likely look surprising. | - | ||||||||||||||||||
| 4466 | - | |||||||||||||||||||
| 4467 | Note that the creation of display lists, modifications of the view | - | ||||||||||||||||||
| 4468 | frustum etc. should be done from within initializeGL(). If this is | - | ||||||||||||||||||
| 4469 | not done, the temporary QGLContext will not be initialized | - | ||||||||||||||||||
| 4470 | properly, and the rendered pixmap may be incomplete/corrupted. | - | ||||||||||||||||||
| 4471 | */ | - | ||||||||||||||||||
| 4472 | - | |||||||||||||||||||
| 4473 | QPixmap QGLWidget::renderPixmap(int w, int h, bool useContext) | - | ||||||||||||||||||
| 4474 | { | - | ||||||||||||||||||
| 4475 | Q_UNUSED(useContext); | - | ||||||||||||||||||
| 4476 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4477 | - | |||||||||||||||||||
| 4478 | QSize sz = size(); | - | ||||||||||||||||||
| 4479 | if ((w > 0) && (h > 0))
| 0 | ||||||||||||||||||
| 4480 | sz = QSize(w, h); never executed: sz = QSize(w, h); | 0 | ||||||||||||||||||
| 4481 | - | |||||||||||||||||||
| 4482 | QPixmap pm; | - | ||||||||||||||||||
| 4483 | if (d->glcx->isValid()) {
| 0 | ||||||||||||||||||
| 4484 | d->glcx->makeCurrent(); | - | ||||||||||||||||||
| 4485 | QGLFramebufferObject fbo(sz, QGLFramebufferObject::CombinedDepthStencil); | - | ||||||||||||||||||
| 4486 | fbo.bind(); | - | ||||||||||||||||||
| 4487 | d->glcx->setInitialized(false); | - | ||||||||||||||||||
| 4488 | uint prevDefaultFbo = d->glcx->d_ptr->default_fbo; | - | ||||||||||||||||||
| 4489 | d->glcx->d_ptr->default_fbo = fbo.handle(); | - | ||||||||||||||||||
| 4490 | d->glcx->d_ptr->readback_target_size = sz; | - | ||||||||||||||||||
| 4491 | updateGL(); | - | ||||||||||||||||||
| 4492 | fbo.release(); | - | ||||||||||||||||||
| 4493 | pm = QPixmap::fromImage(fbo.toImage()); | - | ||||||||||||||||||
| 4494 | d->glcx->d_ptr->default_fbo = prevDefaultFbo; | - | ||||||||||||||||||
| 4495 | d->glcx->setInitialized(false); | - | ||||||||||||||||||
| 4496 | d->glcx->d_ptr->readback_target_size = QSize(); | - | ||||||||||||||||||
| 4497 | } never executed: end of block | 0 | ||||||||||||||||||
| 4498 | - | |||||||||||||||||||
| 4499 | return pm; never executed: return pm; | 0 | ||||||||||||||||||
| 4500 | } | - | ||||||||||||||||||
| 4501 | - | |||||||||||||||||||
| 4502 | /*! | - | ||||||||||||||||||
| 4503 | Returns an image of the frame buffer. If \a withAlpha is true the | - | ||||||||||||||||||
| 4504 | alpha channel is included. | - | ||||||||||||||||||
| 4505 | - | |||||||||||||||||||
| 4506 | Depending on your hardware, you can explicitly select which color | - | ||||||||||||||||||
| 4507 | buffer to grab with a glReadBuffer() call before calling this | - | ||||||||||||||||||
| 4508 | function. | - | ||||||||||||||||||
| 4509 | - | |||||||||||||||||||
| 4510 | On QNX the back buffer is not preserved when swapBuffers() is called. The back buffer | - | ||||||||||||||||||
| 4511 | where this function reads from, might thus not contain the same content as the front buffer. | - | ||||||||||||||||||
| 4512 | In order to retrieve what is currently visible on the screen, swapBuffers() | - | ||||||||||||||||||
| 4513 | has to be executed prior to this function call. | - | ||||||||||||||||||
| 4514 | */ | - | ||||||||||||||||||
| 4515 | QImage QGLWidget::grabFrameBuffer(bool withAlpha) | - | ||||||||||||||||||
| 4516 | { | - | ||||||||||||||||||
| 4517 | makeCurrent(); | - | ||||||||||||||||||
| 4518 | QImage res; | - | ||||||||||||||||||
| 4519 | qreal pixelRatio = devicePixelRatioF(); | - | ||||||||||||||||||
| 4520 | int w = pixelRatio * width(); | - | ||||||||||||||||||
| 4521 | int h = pixelRatio * height(); | - | ||||||||||||||||||
| 4522 | if (format().rgba())
| 0 | ||||||||||||||||||
| 4523 | res = qt_gl_read_frame_buffer(QSize(w, h), format().alpha(), withAlpha); never executed: res = qt_gl_read_frame_buffer(QSize(w, h), format().alpha(), withAlpha); | 0 | ||||||||||||||||||
| 4524 | res.setDevicePixelRatio(pixelRatio); | - | ||||||||||||||||||
| 4525 | return res; never executed: return res; | 0 | ||||||||||||||||||
| 4526 | } | - | ||||||||||||||||||
| 4527 | - | |||||||||||||||||||
| 4528 | - | |||||||||||||||||||
| 4529 | - | |||||||||||||||||||
| 4530 | /*! | - | ||||||||||||||||||
| 4531 | Initializes OpenGL for this widget's context. Calls the virtual | - | ||||||||||||||||||
| 4532 | function initializeGL(). | - | ||||||||||||||||||
| 4533 | */ | - | ||||||||||||||||||
| 4534 | - | |||||||||||||||||||
| 4535 | void QGLWidget::glInit() | - | ||||||||||||||||||
| 4536 | { | - | ||||||||||||||||||
| 4537 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4538 | if (!isValid())
| 0 | ||||||||||||||||||
| 4539 | return; never executed: return; | 0 | ||||||||||||||||||
| 4540 | makeCurrent(); | - | ||||||||||||||||||
| 4541 | initializeGL(); | - | ||||||||||||||||||
| 4542 | d->glcx->setInitialized(true); | - | ||||||||||||||||||
| 4543 | } never executed: end of block | 0 | ||||||||||||||||||
| 4544 | - | |||||||||||||||||||
| 4545 | - | |||||||||||||||||||
| 4546 | /*! | - | ||||||||||||||||||
| 4547 | Executes the virtual function paintGL(). | - | ||||||||||||||||||
| 4548 | - | |||||||||||||||||||
| 4549 | The widget's rendering context will become the current context and | - | ||||||||||||||||||
| 4550 | initializeGL() will be called if it hasn't already been called. | - | ||||||||||||||||||
| 4551 | */ | - | ||||||||||||||||||
| 4552 | - | |||||||||||||||||||
| 4553 | void QGLWidget::glDraw() | - | ||||||||||||||||||
| 4554 | { | - | ||||||||||||||||||
| 4555 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4556 | if (!isValid())
| 0 | ||||||||||||||||||
| 4557 | return; never executed: return; | 0 | ||||||||||||||||||
| 4558 | makeCurrent(); | - | ||||||||||||||||||
| 4559 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 4560 | if (d->glcx->deviceIsPixmap() && !d->glcx->contextHandle()->isOpenGLES())
| 0 | ||||||||||||||||||
| 4561 | qgl1_functions()->glDrawBuffer(GL_FRONT); never executed: qgl1_functions()->glDrawBuffer(0x0404); | 0 | ||||||||||||||||||
| 4562 | #endif | - | ||||||||||||||||||
| 4563 | QSize readback_target_size = d->glcx->d_ptr->readback_target_size; | - | ||||||||||||||||||
| 4564 | if (!d->glcx->initialized()) {
| 0 | ||||||||||||||||||
| 4565 | glInit(); | - | ||||||||||||||||||
| 4566 | const qreal scaleFactor = (window() && window()->windowHandle()) ?
| 0 | ||||||||||||||||||
| 4567 | window()->windowHandle()->devicePixelRatio() : 1.0; | - | ||||||||||||||||||
| 4568 | int w, h; | - | ||||||||||||||||||
| 4569 | if (readback_target_size.isEmpty()) {
| 0 | ||||||||||||||||||
| 4570 | w = d->glcx->device()->width() * scaleFactor; | - | ||||||||||||||||||
| 4571 | h = d->glcx->device()->height() * scaleFactor; | - | ||||||||||||||||||
| 4572 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 4573 | w = readback_target_size.width(); | - | ||||||||||||||||||
| 4574 | h = readback_target_size.height(); | - | ||||||||||||||||||
| 4575 | } never executed: end of block | 0 | ||||||||||||||||||
| 4576 | resizeGL(w, h); // New context needs this "resize" | - | ||||||||||||||||||
| 4577 | } never executed: end of block | 0 | ||||||||||||||||||
| 4578 | paintGL(); | - | ||||||||||||||||||
| 4579 | if (doubleBuffer() && readback_target_size.isEmpty()) {
| 0 | ||||||||||||||||||
| 4580 | if (d->autoSwap)
| 0 | ||||||||||||||||||
| 4581 | swapBuffers(); never executed: swapBuffers(); | 0 | ||||||||||||||||||
| 4582 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 4583 | qgl_functions()->glFlush(); | - | ||||||||||||||||||
| 4584 | } never executed: end of block | 0 | ||||||||||||||||||
| 4585 | } | - | ||||||||||||||||||
| 4586 | - | |||||||||||||||||||
| 4587 | /*! | - | ||||||||||||||||||
| 4588 | Convenience function for specifying a drawing color to OpenGL. | - | ||||||||||||||||||
| 4589 | Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) | - | ||||||||||||||||||
| 4590 | with the color \a c. Applies to this widgets GL context. | - | ||||||||||||||||||
| 4591 | - | |||||||||||||||||||
| 4592 | \note This function is not supported on OpenGL/ES 2.0 systems. | - | ||||||||||||||||||
| 4593 | - | |||||||||||||||||||
| 4594 | \sa qglClearColor(), QGLContext::currentContext(), QColor | - | ||||||||||||||||||
| 4595 | */ | - | ||||||||||||||||||
| 4596 | - | |||||||||||||||||||
| 4597 | void QGLWidget::qglColor(const QColor& c) const | - | ||||||||||||||||||
| 4598 | { | - | ||||||||||||||||||
| 4599 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 4600 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 4601 | qgl_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
| 4602 | #else | - | ||||||||||||||||||
| 4603 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 4604 | const QGLContext *ctx = QGLContext::currentContext(); | - | ||||||||||||||||||
| 4605 | if (ctx && !ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 4606 | if (ctx->format().rgba())
| 0 | ||||||||||||||||||
| 4607 | qgl1_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: qgl1_functions()->glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 | ||||||||||||||||||
| 4608 | else if (!d->cmap.isEmpty()) { // QGLColormap in use?
| 0 | ||||||||||||||||||
| 4609 | int i = d->cmap.find(c.rgb()); | - | ||||||||||||||||||
| 4610 | if (i < 0)
| 0 | ||||||||||||||||||
| 4611 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 | ||||||||||||||||||
| 4612 | qgl1_functions()->glIndexi(i); | - | ||||||||||||||||||
| 4613 | } else never executed: end of block | 0 | ||||||||||||||||||
| 4614 | qgl1_functions()->glIndexi(ctx->colorIndex(c)); never executed: qgl1_functions()->glIndexi(ctx->colorIndex(c)); | 0 | ||||||||||||||||||
| 4615 | } | - | ||||||||||||||||||
| 4616 | #endif //QT_OPENGL_ES | - | ||||||||||||||||||
| 4617 | #else | - | ||||||||||||||||||
| 4618 | Q_UNUSED(c); | - | ||||||||||||||||||
| 4619 | #endif //QT_OPENGL_ES_2 | - | ||||||||||||||||||
| 4620 | } never executed: end of block | 0 | ||||||||||||||||||
| 4621 | - | |||||||||||||||||||
| 4622 | /*! | - | ||||||||||||||||||
| 4623 | Convenience function for specifying the clearing color to OpenGL. | - | ||||||||||||||||||
| 4624 | Calls glClearColor (in RGBA mode) or glClearIndex (in color-index | - | ||||||||||||||||||
| 4625 | mode) with the color \a c. Applies to this widgets GL context. | - | ||||||||||||||||||
| 4626 | - | |||||||||||||||||||
| 4627 | \sa qglColor(), QGLContext::currentContext(), QColor | - | ||||||||||||||||||
| 4628 | */ | - | ||||||||||||||||||
| 4629 | - | |||||||||||||||||||
| 4630 | void QGLWidget::qglClearColor(const QColor& c) const | - | ||||||||||||||||||
| 4631 | { | - | ||||||||||||||||||
| 4632 | #ifdef QT_OPENGL_ES | - | ||||||||||||||||||
| 4633 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
| 4634 | #else | - | ||||||||||||||||||
| 4635 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 4636 | const QGLContext *ctx = QGLContext::currentContext(); | - | ||||||||||||||||||
| 4637 | if (ctx && !ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 4638 | if (ctx->format().rgba())
| 0 | ||||||||||||||||||
| 4639 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); never executed: qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | 0 | ||||||||||||||||||
| 4640 | else if (!d->cmap.isEmpty()) { // QGLColormap in use?
| 0 | ||||||||||||||||||
| 4641 | int i = d->cmap.find(c.rgb()); | - | ||||||||||||||||||
| 4642 | if (i < 0)
| 0 | ||||||||||||||||||
| 4643 | i = d->cmap.findNearest(c.rgb()); never executed: i = d->cmap.findNearest(c.rgb()); | 0 | ||||||||||||||||||
| 4644 | qgl1_functions()->glClearIndex(i); | - | ||||||||||||||||||
| 4645 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 4646 | qgl1_functions()->glClearIndex(ctx->colorIndex(c)); | - | ||||||||||||||||||
| 4647 | } never executed: end of block | 0 | ||||||||||||||||||
| 4648 | } else { | - | ||||||||||||||||||
| 4649 | qgl_functions()->glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||
| 4650 | } never executed: end of block | 0 | ||||||||||||||||||
| 4651 | #endif | - | ||||||||||||||||||
| 4652 | } | - | ||||||||||||||||||
| 4653 | - | |||||||||||||||||||
| 4654 | - | |||||||||||||||||||
| 4655 | /*! | - | ||||||||||||||||||
| 4656 | Converts the image \a img into the unnamed format expected by | - | ||||||||||||||||||
| 4657 | OpenGL functions such as glTexImage2D(). The returned image is not | - | ||||||||||||||||||
| 4658 | usable as a QImage, but QImage::width(), QImage::height() and | - | ||||||||||||||||||
| 4659 | QImage::bits() may be used with OpenGL. The GL format used is | - | ||||||||||||||||||
| 4660 | \c GL_RGBA. | - | ||||||||||||||||||
| 4661 | - | |||||||||||||||||||
| 4662 | \omit ### | - | ||||||||||||||||||
| 4663 | - | |||||||||||||||||||
| 4664 | \l opengl/texture example | - | ||||||||||||||||||
| 4665 | The following few lines are from the texture example. Most of the | - | ||||||||||||||||||
| 4666 | code is irrelevant, so we just quote the relevant bits: | - | ||||||||||||||||||
| 4667 | - | |||||||||||||||||||
| 4668 | \quotefromfile opengl/texture/gltexobj.cpp | - | ||||||||||||||||||
| 4669 | \skipto tex1 | - | ||||||||||||||||||
| 4670 | \printline tex1 | - | ||||||||||||||||||
| 4671 | \printline gllogo.bmp | - | ||||||||||||||||||
| 4672 | - | |||||||||||||||||||
| 4673 | We create \e tex1 (and another variable) for OpenGL, and load a real | - | ||||||||||||||||||
| 4674 | image into \e buf. | - | ||||||||||||||||||
| 4675 | - | |||||||||||||||||||
| 4676 | \skipto convertToGLFormat | - | ||||||||||||||||||
| 4677 | \printline convertToGLFormat | - | ||||||||||||||||||
| 4678 | - | |||||||||||||||||||
| 4679 | A few lines later, we convert \e buf into OpenGL format and store it | - | ||||||||||||||||||
| 4680 | in \e tex1. | - | ||||||||||||||||||
| 4681 | - | |||||||||||||||||||
| 4682 | \skipto glTexImage2D | - | ||||||||||||||||||
| 4683 | \printline glTexImage2D | - | ||||||||||||||||||
| 4684 | \printline tex1.bits | - | ||||||||||||||||||
| 4685 | - | |||||||||||||||||||
| 4686 | Note the dimension restrictions for texture images as described in | - | ||||||||||||||||||
| 4687 | the glTexImage2D() documentation. The width must be 2^m + 2*border | - | ||||||||||||||||||
| 4688 | and the height 2^n + 2*border where m and n are integers and | - | ||||||||||||||||||
| 4689 | border is either 0 or 1. | - | ||||||||||||||||||
| 4690 | - | |||||||||||||||||||
| 4691 | Another function in the same example uses \e tex1 with OpenGL. | - | ||||||||||||||||||
| 4692 | - | |||||||||||||||||||
| 4693 | \endomit | - | ||||||||||||||||||
| 4694 | */ | - | ||||||||||||||||||
| 4695 | - | |||||||||||||||||||
| 4696 | QImage QGLWidget::convertToGLFormat(const QImage& img) | - | ||||||||||||||||||
| 4697 | { | - | ||||||||||||||||||
| 4698 | QImage res(img.size(), QImage::Format_ARGB32); | - | ||||||||||||||||||
| 4699 | convertToGLFormatHelper(res, img.convertToFormat(QImage::Format_ARGB32), GL_RGBA); | - | ||||||||||||||||||
| 4700 | return res; never executed: return res; | 0 | ||||||||||||||||||
| 4701 | } | - | ||||||||||||||||||
| 4702 | - | |||||||||||||||||||
| 4703 | - | |||||||||||||||||||
| 4704 | /*! | - | ||||||||||||||||||
| 4705 | \fn QGLColormap & QGLWidget::colormap() const | - | ||||||||||||||||||
| 4706 | - | |||||||||||||||||||
| 4707 | Returns the colormap for this widget. | - | ||||||||||||||||||
| 4708 | - | |||||||||||||||||||
| 4709 | Usually it is only top-level widgets that can have different | - | ||||||||||||||||||
| 4710 | colormaps installed. Asking for the colormap of a child widget | - | ||||||||||||||||||
| 4711 | will return the colormap for the child's top-level widget. | - | ||||||||||||||||||
| 4712 | - | |||||||||||||||||||
| 4713 | If no colormap has been set for this widget, the QGLColormap | - | ||||||||||||||||||
| 4714 | returned will be empty. | - | ||||||||||||||||||
| 4715 | - | |||||||||||||||||||
| 4716 | \sa setColormap(), QGLColormap::isEmpty() | - | ||||||||||||||||||
| 4717 | */ | - | ||||||||||||||||||
| 4718 | const QGLColormap & QGLWidget::colormap() const | - | ||||||||||||||||||
| 4719 | { | - | ||||||||||||||||||
| 4720 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 4721 | return d->cmap; never executed: return d->cmap; | 0 | ||||||||||||||||||
| 4722 | } | - | ||||||||||||||||||
| 4723 | - | |||||||||||||||||||
| 4724 | /*! | - | ||||||||||||||||||
| 4725 | \fn void QGLWidget::setColormap(const QGLColormap & cmap) | - | ||||||||||||||||||
| 4726 | - | |||||||||||||||||||
| 4727 | Set the colormap for this widget to \a cmap. Usually it is only | - | ||||||||||||||||||
| 4728 | top-level widgets that can have colormaps installed. | - | ||||||||||||||||||
| 4729 | - | |||||||||||||||||||
| 4730 | \sa colormap() | - | ||||||||||||||||||
| 4731 | */ | - | ||||||||||||||||||
| 4732 | void QGLWidget::setColormap(const QGLColormap & c) | - | ||||||||||||||||||
| 4733 | { | - | ||||||||||||||||||
| 4734 | Q_UNUSED(c); | - | ||||||||||||||||||
| 4735 | } never executed: end of block | 0 | ||||||||||||||||||
| 4736 | - | |||||||||||||||||||
| 4737 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 4738 | - | |||||||||||||||||||
| 4739 | static void qt_save_gl_state() | - | ||||||||||||||||||
| 4740 | { | - | ||||||||||||||||||
| 4741 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 4742 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 4743 | - | |||||||||||||||||||
| 4744 | gl1funcs->glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); | - | ||||||||||||||||||
| 4745 | gl1funcs->glPushAttrib(GL_ALL_ATTRIB_BITS); | - | ||||||||||||||||||
| 4746 | gl1funcs->glMatrixMode(GL_TEXTURE); | - | ||||||||||||||||||
| 4747 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
| 4748 | gl1funcs->glLoadIdentity(); | - | ||||||||||||||||||
| 4749 | gl1funcs->glMatrixMode(GL_PROJECTION); | - | ||||||||||||||||||
| 4750 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
| 4751 | gl1funcs->glMatrixMode(GL_MODELVIEW); | - | ||||||||||||||||||
| 4752 | gl1funcs->glPushMatrix(); | - | ||||||||||||||||||
| 4753 | - | |||||||||||||||||||
| 4754 | gl1funcs->glShadeModel(GL_FLAT); | - | ||||||||||||||||||
| 4755 | funcs->glDisable(GL_CULL_FACE); | - | ||||||||||||||||||
| 4756 | funcs->glDisable(GL_LIGHTING); | - | ||||||||||||||||||
| 4757 | funcs->glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||
| 4758 | funcs->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||
| 4759 | funcs->glEnable(GL_BLEND); | - | ||||||||||||||||||
| 4760 | funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||
| 4761 | } never executed: end of block | 0 | ||||||||||||||||||
| 4762 | - | |||||||||||||||||||
| 4763 | static void qt_restore_gl_state() | - | ||||||||||||||||||
| 4764 | { | - | ||||||||||||||||||
| 4765 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 4766 | - | |||||||||||||||||||
| 4767 | gl1funcs->glMatrixMode(GL_TEXTURE); | - | ||||||||||||||||||
| 4768 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
| 4769 | gl1funcs->glMatrixMode(GL_PROJECTION); | - | ||||||||||||||||||
| 4770 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
| 4771 | gl1funcs->glMatrixMode(GL_MODELVIEW); | - | ||||||||||||||||||
| 4772 | gl1funcs->glPopMatrix(); | - | ||||||||||||||||||
| 4773 | gl1funcs->glPopAttrib(); | - | ||||||||||||||||||
| 4774 | gl1funcs->glPopClientAttrib(); | - | ||||||||||||||||||
| 4775 | } never executed: end of block | 0 | ||||||||||||||||||
| 4776 | - | |||||||||||||||||||
| 4777 | static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, | - | ||||||||||||||||||
| 4778 | const QFont &font) | - | ||||||||||||||||||
| 4779 | { | - | ||||||||||||||||||
| 4780 | GLfloat color[4]; | - | ||||||||||||||||||
| 4781 | qgl_functions()->glGetFloatv(GL_CURRENT_COLOR, &color[0]); | - | ||||||||||||||||||
| 4782 | - | |||||||||||||||||||
| 4783 | QColor col; | - | ||||||||||||||||||
| 4784 | col.setRgbF(color[0], color[1], color[2],color[3]); | - | ||||||||||||||||||
| 4785 | QPen old_pen = p->pen(); | - | ||||||||||||||||||
| 4786 | QFont old_font = p->font(); | - | ||||||||||||||||||
| 4787 | - | |||||||||||||||||||
| 4788 | p->setPen(col); | - | ||||||||||||||||||
| 4789 | p->setFont(font); | - | ||||||||||||||||||
| 4790 | p->drawText(x, y, str); | - | ||||||||||||||||||
| 4791 | - | |||||||||||||||||||
| 4792 | p->setPen(old_pen); | - | ||||||||||||||||||
| 4793 | p->setFont(old_font); | - | ||||||||||||||||||
| 4794 | } never executed: end of block | 0 | ||||||||||||||||||
| 4795 | - | |||||||||||||||||||
| 4796 | #endif // !QT_OPENGL_ES | - | ||||||||||||||||||
| 4797 | - | |||||||||||||||||||
| 4798 | /*! | - | ||||||||||||||||||
| 4799 | Renders the string \a str into the GL context of this widget. | - | ||||||||||||||||||
| 4800 | - | |||||||||||||||||||
| 4801 | \a x and \a y are specified in window coordinates, with the origin | - | ||||||||||||||||||
| 4802 | in the upper left-hand corner of the window. If \a font is not | - | ||||||||||||||||||
| 4803 | specified, the currently set application font will be used to | - | ||||||||||||||||||
| 4804 | render the string. To change the color of the rendered text you can | - | ||||||||||||||||||
| 4805 | use the glColor() call (or the qglColor() convenience function), | - | ||||||||||||||||||
| 4806 | just before the renderText() call. | - | ||||||||||||||||||
| 4807 | - | |||||||||||||||||||
| 4808 | \note This function clears the stencil buffer. | - | ||||||||||||||||||
| 4809 | - | |||||||||||||||||||
| 4810 | \note This function is not supported on OpenGL/ES systems. | - | ||||||||||||||||||
| 4811 | - | |||||||||||||||||||
| 4812 | \note This function temporarily disables depth-testing when the | - | ||||||||||||||||||
| 4813 | text is drawn. | - | ||||||||||||||||||
| 4814 | - | |||||||||||||||||||
| 4815 | \note This function can only be used inside a | - | ||||||||||||||||||
| 4816 | QPainter::beginNativePainting()/QPainter::endNativePainting() block | - | ||||||||||||||||||
| 4817 | if a painter is active on the QGLWidget. | - | ||||||||||||||||||
| 4818 | */ | - | ||||||||||||||||||
| 4819 | - | |||||||||||||||||||
| 4820 | void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font) | - | ||||||||||||||||||
| 4821 | { | - | ||||||||||||||||||
| 4822 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 4823 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4824 | if (!d->glcx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 4825 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4826 | if (str.isEmpty() || !isValid())
| 0 | ||||||||||||||||||
| 4827 | return; never executed: return; | 0 | ||||||||||||||||||
| 4828 | - | |||||||||||||||||||
| 4829 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 4830 | GLint view[4]; | - | ||||||||||||||||||
| 4831 | bool use_scissor_testing = funcs->glIsEnabled(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4832 | if (!use_scissor_testing)
| 0 | ||||||||||||||||||
| 4833 | funcs->glGetIntegerv(GL_VIEWPORT, &view[0]); never executed: funcs->glGetIntegerv(0x0BA2, &view[0]); | 0 | ||||||||||||||||||
| 4834 | int width = d->glcx->device()->width(); | - | ||||||||||||||||||
| 4835 | int height = d->glcx->device()->height(); | - | ||||||||||||||||||
| 4836 | bool auto_swap = autoBufferSwap(); | - | ||||||||||||||||||
| 4837 | - | |||||||||||||||||||
| 4838 | QPaintEngine *engine = paintEngine(); | - | ||||||||||||||||||
| 4839 | - | |||||||||||||||||||
| 4840 | qt_save_gl_state(); | - | ||||||||||||||||||
| 4841 | - | |||||||||||||||||||
| 4842 | QPainter *p; | - | ||||||||||||||||||
| 4843 | bool reuse_painter = false; | - | ||||||||||||||||||
| 4844 | if (engine->isActive()) {
| 0 | ||||||||||||||||||
| 4845 | reuse_painter = true; | - | ||||||||||||||||||
| 4846 | p = engine->painter(); | - | ||||||||||||||||||
| 4847 | - | |||||||||||||||||||
| 4848 | funcs->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||
| 4849 | funcs->glViewport(0, 0, width, height); | - | ||||||||||||||||||
| 4850 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 4851 | setAutoBufferSwap(false); | - | ||||||||||||||||||
| 4852 | // disable glClear() as a result of QPainter::begin() | - | ||||||||||||||||||
| 4853 | d->disable_clear_on_painter_begin = true; | - | ||||||||||||||||||
| 4854 | p = new QPainter(this); | - | ||||||||||||||||||
| 4855 | } never executed: end of block | 0 | ||||||||||||||||||
| 4856 | - | |||||||||||||||||||
| 4857 | QRect viewport(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
| 4858 | if (!use_scissor_testing && viewport != rect()) {
| 0 | ||||||||||||||||||
| 4859 | // if the user hasn't set a scissor box, we set one that | - | ||||||||||||||||||
| 4860 | // covers the current viewport | - | ||||||||||||||||||
| 4861 | funcs->glScissor(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
| 4862 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4863 | } else if (use_scissor_testing) { never executed: end of block
| 0 | ||||||||||||||||||
| 4864 | // use the scissor box set by the user | - | ||||||||||||||||||
| 4865 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4866 | } never executed: end of block | 0 | ||||||||||||||||||
| 4867 | - | |||||||||||||||||||
| 4868 | qt_gl_draw_text(p, x, y, str, font); | - | ||||||||||||||||||
| 4869 | - | |||||||||||||||||||
| 4870 | if (!reuse_painter) {
| 0 | ||||||||||||||||||
| 4871 | p->end(); | - | ||||||||||||||||||
| 4872 | delete p; | - | ||||||||||||||||||
| 4873 | setAutoBufferSwap(auto_swap); | - | ||||||||||||||||||
| 4874 | d->disable_clear_on_painter_begin = false; | - | ||||||||||||||||||
| 4875 | } never executed: end of block | 0 | ||||||||||||||||||
| 4876 | - | |||||||||||||||||||
| 4877 | qt_restore_gl_state(); | - | ||||||||||||||||||
| 4878 | - | |||||||||||||||||||
| 4879 | return; never executed: return; | 0 | ||||||||||||||||||
| 4880 | } | - | ||||||||||||||||||
| 4881 | #else // QT_OPENGL_ES | - | ||||||||||||||||||
| 4882 | Q_UNUSED(x); | - | ||||||||||||||||||
| 4883 | Q_UNUSED(y); | - | ||||||||||||||||||
| 4884 | Q_UNUSED(str); | - | ||||||||||||||||||
| 4885 | Q_UNUSED(font); | - | ||||||||||||||||||
| 4886 | #endif | - | ||||||||||||||||||
| 4887 | qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); | - | ||||||||||||||||||
| 4888 | } never executed: end of block | 0 | ||||||||||||||||||
| 4889 | - | |||||||||||||||||||
| 4890 | /*! \overload | - | ||||||||||||||||||
| 4891 | - | |||||||||||||||||||
| 4892 | \a x, \a y and \a z are specified in scene or object coordinates | - | ||||||||||||||||||
| 4893 | relative to the currently set projection and model matrices. This | - | ||||||||||||||||||
| 4894 | can be useful if you want to annotate models with text labels and | - | ||||||||||||||||||
| 4895 | have the labels move with the model as it is rotated etc. | - | ||||||||||||||||||
| 4896 | - | |||||||||||||||||||
| 4897 | \note This function is not supported on OpenGL/ES systems. | - | ||||||||||||||||||
| 4898 | - | |||||||||||||||||||
| 4899 | \note If depth testing is enabled before this function is called, | - | ||||||||||||||||||
| 4900 | then the drawn text will be depth-tested against the models that | - | ||||||||||||||||||
| 4901 | have already been drawn in the scene. Use \c{glDisable(GL_DEPTH_TEST)} | - | ||||||||||||||||||
| 4902 | before calling this function to annotate the models without | - | ||||||||||||||||||
| 4903 | depth-testing the text. | - | ||||||||||||||||||
| 4904 | - | |||||||||||||||||||
| 4905 | \note This function can only be used inside a | - | ||||||||||||||||||
| 4906 | QPainter::beginNativePainting()/QPainter::endNativePainting() block | - | ||||||||||||||||||
| 4907 | if a painter is active on the QGLWidget. | - | ||||||||||||||||||
| 4908 | */ | - | ||||||||||||||||||
| 4909 | void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font) | - | ||||||||||||||||||
| 4910 | { | - | ||||||||||||||||||
| 4911 | #ifndef QT_OPENGL_ES | - | ||||||||||||||||||
| 4912 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4913 | if (!d->glcx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||
| 4914 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 4915 | if (str.isEmpty() || !isValid())
| 0 | ||||||||||||||||||
| 4916 | return; never executed: return; | 0 | ||||||||||||||||||
| 4917 | - | |||||||||||||||||||
| 4918 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 4919 | bool auto_swap = autoBufferSwap(); | - | ||||||||||||||||||
| 4920 | - | |||||||||||||||||||
| 4921 | int width = d->glcx->device()->width(); | - | ||||||||||||||||||
| 4922 | int height = d->glcx->device()->height(); | - | ||||||||||||||||||
| 4923 | GLdouble model[4 * 4], proj[4 * 4]; | - | ||||||||||||||||||
| 4924 | GLint view[4]; | - | ||||||||||||||||||
| 4925 | QOpenGLFunctions_1_1 *gl1funcs = qgl1_functions(); | - | ||||||||||||||||||
| 4926 | gl1funcs->glGetDoublev(GL_MODELVIEW_MATRIX, &model[0]); | - | ||||||||||||||||||
| 4927 | gl1funcs->glGetDoublev(GL_PROJECTION_MATRIX, &proj[0]); | - | ||||||||||||||||||
| 4928 | funcs->glGetIntegerv(GL_VIEWPORT, &view[0]); | - | ||||||||||||||||||
| 4929 | GLdouble win_x = 0, win_y = 0, win_z = 0; | - | ||||||||||||||||||
| 4930 | qgluProject(x, y, z, &model[0], &proj[0], &view[0], | - | ||||||||||||||||||
| 4931 | &win_x, &win_y, &win_z); | - | ||||||||||||||||||
| 4932 | const int dpr = d->glcx->device()->devicePixelRatioF(); | - | ||||||||||||||||||
| 4933 | win_x /= dpr; | - | ||||||||||||||||||
| 4934 | win_y /= dpr; | - | ||||||||||||||||||
| 4935 | win_y = height - win_y; // y is inverted | - | ||||||||||||||||||
| 4936 | - | |||||||||||||||||||
| 4937 | QPaintEngine *engine = paintEngine(); | - | ||||||||||||||||||
| 4938 | - | |||||||||||||||||||
| 4939 | QPainter *p; | - | ||||||||||||||||||
| 4940 | bool reuse_painter = false; | - | ||||||||||||||||||
| 4941 | bool use_depth_testing = funcs->glIsEnabled(GL_DEPTH_TEST); | - | ||||||||||||||||||
| 4942 | bool use_scissor_testing = funcs->glIsEnabled(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4943 | - | |||||||||||||||||||
| 4944 | qt_save_gl_state(); | - | ||||||||||||||||||
| 4945 | - | |||||||||||||||||||
| 4946 | if (engine->isActive()) {
| 0 | ||||||||||||||||||
| 4947 | reuse_painter = true; | - | ||||||||||||||||||
| 4948 | p = engine->painter(); | - | ||||||||||||||||||
| 4949 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 4950 | setAutoBufferSwap(false); | - | ||||||||||||||||||
| 4951 | // disable glClear() as a result of QPainter::begin() | - | ||||||||||||||||||
| 4952 | d->disable_clear_on_painter_begin = true; | - | ||||||||||||||||||
| 4953 | p = new QPainter(this); | - | ||||||||||||||||||
| 4954 | } never executed: end of block | 0 | ||||||||||||||||||
| 4955 | - | |||||||||||||||||||
| 4956 | QRect viewport(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
| 4957 | if (!use_scissor_testing && viewport != rect()) {
| 0 | ||||||||||||||||||
| 4958 | funcs->glScissor(view[0], view[1], view[2], view[3]); | - | ||||||||||||||||||
| 4959 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4960 | } else if (use_scissor_testing) { never executed: end of block
| 0 | ||||||||||||||||||
| 4961 | funcs->glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||
| 4962 | } never executed: end of block | 0 | ||||||||||||||||||
| 4963 | funcs->glViewport(0, 0, width * dpr, height * dpr); | - | ||||||||||||||||||
| 4964 | gl1funcs->glAlphaFunc(GL_GREATER, 0.0); | - | ||||||||||||||||||
| 4965 | funcs->glEnable(GL_ALPHA_TEST); | - | ||||||||||||||||||
| 4966 | if (use_depth_testing)
| 0 | ||||||||||||||||||
| 4967 | funcs->glEnable(GL_DEPTH_TEST); never executed: funcs->glEnable(0x0B71); | 0 | ||||||||||||||||||
| 4968 | - | |||||||||||||||||||
| 4969 | // The only option in Qt 5 is the shader-based OpenGL 2 paint engine. | - | ||||||||||||||||||
| 4970 | // Setting fixed pipeline transformations is futile. Instead, pass the | - | ||||||||||||||||||
| 4971 | // extra values directly and let the engine figure the matrices out. | - | ||||||||||||||||||
| 4972 | static_cast<QGL2PaintEngineEx *>(p->paintEngine())->setTranslateZ(-win_z); | - | ||||||||||||||||||
| 4973 | - | |||||||||||||||||||
| 4974 | qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); | - | ||||||||||||||||||
| 4975 | - | |||||||||||||||||||
| 4976 | static_cast<QGL2PaintEngineEx *>(p->paintEngine())->setTranslateZ(0); | - | ||||||||||||||||||
| 4977 | - | |||||||||||||||||||
| 4978 | if (!reuse_painter) {
| 0 | ||||||||||||||||||
| 4979 | p->end(); | - | ||||||||||||||||||
| 4980 | delete p; | - | ||||||||||||||||||
| 4981 | setAutoBufferSwap(auto_swap); | - | ||||||||||||||||||
| 4982 | d->disable_clear_on_painter_begin = false; | - | ||||||||||||||||||
| 4983 | } never executed: end of block | 0 | ||||||||||||||||||
| 4984 | - | |||||||||||||||||||
| 4985 | qt_restore_gl_state(); | - | ||||||||||||||||||
| 4986 | - | |||||||||||||||||||
| 4987 | return; never executed: return; | 0 | ||||||||||||||||||
| 4988 | } | - | ||||||||||||||||||
| 4989 | #else // QT_OPENGL_ES | - | ||||||||||||||||||
| 4990 | Q_UNUSED(x); | - | ||||||||||||||||||
| 4991 | Q_UNUSED(y); | - | ||||||||||||||||||
| 4992 | Q_UNUSED(z); | - | ||||||||||||||||||
| 4993 | Q_UNUSED(str); | - | ||||||||||||||||||
| 4994 | Q_UNUSED(font); | - | ||||||||||||||||||
| 4995 | #endif | - | ||||||||||||||||||
| 4996 | qWarning("QGLWidget::renderText is not supported under OpenGL/ES"); | - | ||||||||||||||||||
| 4997 | } never executed: end of block | 0 | ||||||||||||||||||
| 4998 | - | |||||||||||||||||||
| 4999 | QGLFormat QGLWidget::format() const | - | ||||||||||||||||||
| 5000 | { | - | ||||||||||||||||||
| 5001 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 5002 | return d->glcx->format(); never executed: return d->glcx->format(); | 0 | ||||||||||||||||||
| 5003 | } | - | ||||||||||||||||||
| 5004 | - | |||||||||||||||||||
| 5005 | QGLContext *QGLWidget::context() const | - | ||||||||||||||||||
| 5006 | { | - | ||||||||||||||||||
| 5007 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 5008 | return d->glcx; executed 56 times by 2 tests: return d->glcx;Executed by:
| 56 | ||||||||||||||||||
| 5009 | } | - | ||||||||||||||||||
| 5010 | - | |||||||||||||||||||
| 5011 | bool QGLWidget::doubleBuffer() const | - | ||||||||||||||||||
| 5012 | { | - | ||||||||||||||||||
| 5013 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 5014 | return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); never executed: return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer); | 0 | ||||||||||||||||||
| 5015 | } | - | ||||||||||||||||||
| 5016 | - | |||||||||||||||||||
| 5017 | void QGLWidget::setAutoBufferSwap(bool on) | - | ||||||||||||||||||
| 5018 | { | - | ||||||||||||||||||
| 5019 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5020 | d->autoSwap = on; | - | ||||||||||||||||||
| 5021 | } never executed: end of block | 0 | ||||||||||||||||||
| 5022 | - | |||||||||||||||||||
| 5023 | bool QGLWidget::autoBufferSwap() const | - | ||||||||||||||||||
| 5024 | { | - | ||||||||||||||||||
| 5025 | Q_D(const QGLWidget); | - | ||||||||||||||||||
| 5026 | return d->autoSwap; executed 3 times by 1 test: return d->autoSwap;Executed by:
| 3 | ||||||||||||||||||
| 5027 | } | - | ||||||||||||||||||
| 5028 | - | |||||||||||||||||||
| 5029 | /*! | - | ||||||||||||||||||
| 5030 | Calls QGLContext:::bindTexture(\a image, \a target, \a format) on the currently | - | ||||||||||||||||||
| 5031 | set context. | - | ||||||||||||||||||
| 5032 | - | |||||||||||||||||||
| 5033 | \sa deleteTexture() | - | ||||||||||||||||||
| 5034 | */ | - | ||||||||||||||||||
| 5035 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format) | - | ||||||||||||||||||
| 5036 | { | - | ||||||||||||||||||
| 5037 | if (image.isNull())
| 0 | ||||||||||||||||||
| 5038 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 5039 | - | |||||||||||||||||||
| 5040 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5041 | return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption); | 0 | ||||||||||||||||||
| 5042 | } | - | ||||||||||||||||||
| 5043 | - | |||||||||||||||||||
| 5044 | /*! | - | ||||||||||||||||||
| 5045 | \overload | - | ||||||||||||||||||
| 5046 | \since 4.6 | - | ||||||||||||||||||
| 5047 | - | |||||||||||||||||||
| 5048 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
| 5049 | bind the texture to the context. | - | ||||||||||||||||||
| 5050 | */ | - | ||||||||||||||||||
| 5051 | GLuint QGLWidget::bindTexture(const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options) | - | ||||||||||||||||||
| 5052 | { | - | ||||||||||||||||||
| 5053 | if (image.isNull())
| 0 | ||||||||||||||||||
| 5054 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 5055 | - | |||||||||||||||||||
| 5056 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5057 | return d->glcx->bindTexture(image, target, format, options); never executed: return d->glcx->bindTexture(image, target, format, options); | 0 | ||||||||||||||||||
| 5058 | } | - | ||||||||||||||||||
| 5059 | - | |||||||||||||||||||
| 5060 | - | |||||||||||||||||||
| 5061 | /*! | - | ||||||||||||||||||
| 5062 | Calls QGLContext:::bindTexture(\a pixmap, \a target, \a format) on the currently | - | ||||||||||||||||||
| 5063 | set context. | - | ||||||||||||||||||
| 5064 | - | |||||||||||||||||||
| 5065 | \sa deleteTexture() | - | ||||||||||||||||||
| 5066 | */ | - | ||||||||||||||||||
| 5067 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format) | - | ||||||||||||||||||
| 5068 | { | - | ||||||||||||||||||
| 5069 | if (pixmap.isNull())
| 0 | ||||||||||||||||||
| 5070 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 5071 | - | |||||||||||||||||||
| 5072 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5073 | return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); never executed: return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption); | 0 | ||||||||||||||||||
| 5074 | } | - | ||||||||||||||||||
| 5075 | - | |||||||||||||||||||
| 5076 | /*! | - | ||||||||||||||||||
| 5077 | \overload | - | ||||||||||||||||||
| 5078 | \since 4.6 | - | ||||||||||||||||||
| 5079 | - | |||||||||||||||||||
| 5080 | Generates and binds a 2D GL texture to the current context, based | - | ||||||||||||||||||
| 5081 | on \a pixmap. The generated texture id is returned and can be used in | - | ||||||||||||||||||
| 5082 | - | |||||||||||||||||||
| 5083 | The binding \a options are a set of options used to decide how to | - | ||||||||||||||||||
| 5084 | bind the texture to the context. | - | ||||||||||||||||||
| 5085 | */ | - | ||||||||||||||||||
| 5086 | GLuint QGLWidget::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, | - | ||||||||||||||||||
| 5087 | QGLContext::BindOptions options) | - | ||||||||||||||||||
| 5088 | { | - | ||||||||||||||||||
| 5089 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5090 | return d->glcx->bindTexture(pixmap, target, format, options); never executed: return d->glcx->bindTexture(pixmap, target, format, options); | 0 | ||||||||||||||||||
| 5091 | } | - | ||||||||||||||||||
| 5092 | - | |||||||||||||||||||
| 5093 | /*! \overload | - | ||||||||||||||||||
| 5094 | - | |||||||||||||||||||
| 5095 | Calls QGLContext::bindTexture(\a fileName) on the currently set context. | - | ||||||||||||||||||
| 5096 | - | |||||||||||||||||||
| 5097 | \sa deleteTexture() | - | ||||||||||||||||||
| 5098 | */ | - | ||||||||||||||||||
| 5099 | GLuint QGLWidget::bindTexture(const QString &fileName) | - | ||||||||||||||||||
| 5100 | { | - | ||||||||||||||||||
| 5101 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5102 | return d->glcx->bindTexture(fileName); never executed: return d->glcx->bindTexture(fileName); | 0 | ||||||||||||||||||
| 5103 | } | - | ||||||||||||||||||
| 5104 | - | |||||||||||||||||||
| 5105 | /*! | - | ||||||||||||||||||
| 5106 | Calls QGLContext::deleteTexture(\a id) on the currently set | - | ||||||||||||||||||
| 5107 | context. | - | ||||||||||||||||||
| 5108 | - | |||||||||||||||||||
| 5109 | \sa bindTexture() | - | ||||||||||||||||||
| 5110 | */ | - | ||||||||||||||||||
| 5111 | void QGLWidget::deleteTexture(GLuint id) | - | ||||||||||||||||||
| 5112 | { | - | ||||||||||||||||||
| 5113 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5114 | d->glcx->deleteTexture(id); | - | ||||||||||||||||||
| 5115 | } never executed: end of block | 0 | ||||||||||||||||||
| 5116 | - | |||||||||||||||||||
| 5117 | /*! | - | ||||||||||||||||||
| 5118 | \since 4.4 | - | ||||||||||||||||||
| 5119 | - | |||||||||||||||||||
| 5120 | Calls the corresponding QGLContext::drawTexture() with | - | ||||||||||||||||||
| 5121 | \a target, \a textureId, and \a textureTarget for this | - | ||||||||||||||||||
| 5122 | widget's context. | - | ||||||||||||||||||
| 5123 | */ | - | ||||||||||||||||||
| 5124 | void QGLWidget::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
| 5125 | { | - | ||||||||||||||||||
| 5126 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5127 | d->glcx->drawTexture(target, textureId, textureTarget); | - | ||||||||||||||||||
| 5128 | } never executed: end of block | 0 | ||||||||||||||||||
| 5129 | - | |||||||||||||||||||
| 5130 | /*! | - | ||||||||||||||||||
| 5131 | \since 4.4 | - | ||||||||||||||||||
| 5132 | - | |||||||||||||||||||
| 5133 | Calls the corresponding QGLContext::drawTexture() with | - | ||||||||||||||||||
| 5134 | \a point, \a textureId, and \a textureTarget for this | - | ||||||||||||||||||
| 5135 | widget's context. | - | ||||||||||||||||||
| 5136 | */ | - | ||||||||||||||||||
| 5137 | void QGLWidget::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) | - | ||||||||||||||||||
| 5138 | { | - | ||||||||||||||||||
| 5139 | Q_D(QGLWidget); | - | ||||||||||||||||||
| 5140 | d->glcx->drawTexture(point, textureId, textureTarget); | - | ||||||||||||||||||
| 5141 | } never executed: end of block | 0 | ||||||||||||||||||
| 5142 | - | |||||||||||||||||||
| 5143 | Q_GLOBAL_STATIC(QGLEngineThreadStorage<QGL2PaintEngineEx>, qt_gl_2_engine) executed 1 time by 1 test: end of blockExecuted by:
executed 1 time by 1 test: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 15 times by 1 test: return &holder.value;Executed by:
| 0-15 | ||||||||||||||||||
| 5144 | - | |||||||||||||||||||
| 5145 | Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine() | - | ||||||||||||||||||
| 5146 | { | - | ||||||||||||||||||
| 5147 | return qt_gl_2_engine()->engine(); executed 15 times by 1 test: return qt_gl_2_engine()->engine();Executed by:
| 15 | ||||||||||||||||||
| 5148 | } | - | ||||||||||||||||||
| 5149 | - | |||||||||||||||||||
| 5150 | /*! | - | ||||||||||||||||||
| 5151 | \internal | - | ||||||||||||||||||
| 5152 | - | |||||||||||||||||||
| 5153 | Returns the GL widget's paint engine. | - | ||||||||||||||||||
| 5154 | */ | - | ||||||||||||||||||
| 5155 | QPaintEngine *QGLWidget::paintEngine() const | - | ||||||||||||||||||
| 5156 | { | - | ||||||||||||||||||
| 5157 | return qt_qgl_paint_engine(); executed 15 times by 1 test: return qt_qgl_paint_engine();Executed by:
| 15 | ||||||||||||||||||
| 5158 | } | - | ||||||||||||||||||
| 5159 | - | |||||||||||||||||||
| 5160 | void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget *shareWidget) | - | ||||||||||||||||||
| 5161 | { | - | ||||||||||||||||||
| 5162 | initContext(context, shareWidget); | - | ||||||||||||||||||
| 5163 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 5164 | - | |||||||||||||||||||
| 5165 | /* | - | ||||||||||||||||||
| 5166 | This is the shared initialization for all platforms. Called from QGLWidgetPrivate::init() | - | ||||||||||||||||||
| 5167 | */ | - | ||||||||||||||||||
| 5168 | void QGLWidgetPrivate::initContext(QGLContext *context, const QGLWidget* shareWidget) | - | ||||||||||||||||||
| 5169 | { | - | ||||||||||||||||||
| 5170 | Q_Q(QGLWidget); | - | ||||||||||||||||||
| 5171 | - | |||||||||||||||||||
| 5172 | glDevice.setWidget(q); | - | ||||||||||||||||||
| 5173 | - | |||||||||||||||||||
| 5174 | glcx = 0; | - | ||||||||||||||||||
| 5175 | autoSwap = true; | - | ||||||||||||||||||
| 5176 | - | |||||||||||||||||||
| 5177 | if (context && !context->device())
| 0-12 | ||||||||||||||||||
| 5178 | context->setDevice(q); never executed: context->setDevice(q); | 0 | ||||||||||||||||||
| 5179 | q->setContext(context, shareWidget ? shareWidget->context() : 0); | - | ||||||||||||||||||
| 5180 | - | |||||||||||||||||||
| 5181 | if (!glcx)
| 0-12 | ||||||||||||||||||
| 5182 | glcx = new QGLContext(QGLFormat::defaultFormat(), q); never executed: glcx = new QGLContext(QGLFormat::defaultFormat(), q); | 0 | ||||||||||||||||||
| 5183 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 5184 | - | |||||||||||||||||||
| 5185 | bool QGLWidgetPrivate::renderCxPm(QPixmap*) | - | ||||||||||||||||||
| 5186 | { | - | ||||||||||||||||||
| 5187 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 5188 | } | - | ||||||||||||||||||
| 5189 | - | |||||||||||||||||||
| 5190 | /*! \internal | - | ||||||||||||||||||
| 5191 | Free up any allocated colormaps. This fn is only called for | - | ||||||||||||||||||
| 5192 | top-level widgets. | - | ||||||||||||||||||
| 5193 | */ | - | ||||||||||||||||||
| 5194 | void QGLWidgetPrivate::cleanupColormaps() | - | ||||||||||||||||||
| 5195 | { | - | ||||||||||||||||||
| 5196 | } | - | ||||||||||||||||||
| 5197 | - | |||||||||||||||||||
| 5198 | Q_GLOBAL_STATIC(QString, qt_gl_lib_name) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 5199 | - | |||||||||||||||||||
| 5200 | void qt_set_gl_library_name(const QString& name) | - | ||||||||||||||||||
| 5201 | { | - | ||||||||||||||||||
| 5202 | qt_gl_lib_name()->operator=(name); | - | ||||||||||||||||||
| 5203 | } never executed: end of block | 0 | ||||||||||||||||||
| 5204 | - | |||||||||||||||||||
| 5205 | const QString qt_gl_library_name() | - | ||||||||||||||||||
| 5206 | { | - | ||||||||||||||||||
| 5207 | if (qt_gl_lib_name()->isNull()) {
| 0 | ||||||||||||||||||
| 5208 | # if defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||
| 5209 | return QLatin1String("GLESv2"); | - | ||||||||||||||||||
| 5210 | # else | - | ||||||||||||||||||
| 5211 | return QLatin1String("GL"); never executed: return QLatin1String("GL"); | 0 | ||||||||||||||||||
| 5212 | # endif | - | ||||||||||||||||||
| 5213 | } | - | ||||||||||||||||||
| 5214 | return *qt_gl_lib_name(); never executed: return *qt_gl_lib_name(); | 0 | ||||||||||||||||||
| 5215 | } | - | ||||||||||||||||||
| 5216 | - | |||||||||||||||||||
| 5217 | void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) { | - | ||||||||||||||||||
| 5218 | Q_ASSERT(context && share); | - | ||||||||||||||||||
| 5219 | if (context->d_ptr->group == share->d_ptr->group)
| 0-1 | ||||||||||||||||||
| 5220 | return; never executed: return; | 0 | ||||||||||||||||||
| 5221 | - | |||||||||||||||||||
| 5222 | // Make sure 'context' is not already shared with another group of contexts. | - | ||||||||||||||||||
| 5223 | Q_ASSERT(context->d_ptr->group->m_refs.load() == 1); | - | ||||||||||||||||||
| 5224 | - | |||||||||||||||||||
| 5225 | // Free 'context' group resources and make it use the same resources as 'share'. | - | ||||||||||||||||||
| 5226 | QGLContextGroup *group = share->d_ptr->group; | - | ||||||||||||||||||
| 5227 | delete context->d_ptr->group; | - | ||||||||||||||||||
| 5228 | context->d_ptr->group = group; | - | ||||||||||||||||||
| 5229 | group->m_refs.ref(); | - | ||||||||||||||||||
| 5230 | - | |||||||||||||||||||
| 5231 | // Maintain a list of all the contexts in each group of sharing contexts. | - | ||||||||||||||||||
| 5232 | // The list is empty if the "share" context wasn't sharing already. | - | ||||||||||||||||||
| 5233 | if (group->m_shares.isEmpty())
| 0-1 | ||||||||||||||||||
| 5234 | group->m_shares.append(share); executed 1 time by 1 test: group->m_shares.append(share);Executed by:
| 1 | ||||||||||||||||||
| 5235 | group->m_shares.append(context); | - | ||||||||||||||||||
| 5236 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 5237 | - | |||||||||||||||||||
| 5238 | void QGLContextGroup::removeShare(const QGLContext *context) { | - | ||||||||||||||||||
| 5239 | // Remove the context from the group. | - | ||||||||||||||||||
| 5240 | QGLContextGroup *group = context->d_ptr->group; | - | ||||||||||||||||||
| 5241 | if (group->m_shares.isEmpty())
| 1-11 | ||||||||||||||||||
| 5242 | return; executed 11 times by 3 tests: return;Executed by:
| 11 | ||||||||||||||||||
| 5243 | group->m_shares.removeAll(context); | - | ||||||||||||||||||
| 5244 | - | |||||||||||||||||||
| 5245 | // Update context group representative. | - | ||||||||||||||||||
| 5246 | Q_ASSERT(group->m_shares.size() != 0); | - | ||||||||||||||||||
| 5247 | if (group->m_context == context)
| 0-1 | ||||||||||||||||||
| 5248 | group->m_context = group->m_shares.at(0); executed 1 time by 1 test: group->m_context = group->m_shares.at(0);Executed by:
| 1 | ||||||||||||||||||
| 5249 | - | |||||||||||||||||||
| 5250 | // If there is only one context left, then make the list empty. | - | ||||||||||||||||||
| 5251 | if (group->m_shares.size() == 1)
| 0-1 | ||||||||||||||||||
| 5252 | group->m_shares.clear(); executed 1 time by 1 test: group->m_shares.clear();Executed by:
| 1 | ||||||||||||||||||
| 5253 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 5254 | - | |||||||||||||||||||
| 5255 | QSize QGLTexture::bindCompressedTexture | - | ||||||||||||||||||
| 5256 | (const QString& fileName, const char *format) | - | ||||||||||||||||||
| 5257 | { | - | ||||||||||||||||||
| 5258 | QFile file(fileName); | - | ||||||||||||||||||
| 5259 | if (!file.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
| 5260 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5261 | QByteArray contents = file.readAll(); | - | ||||||||||||||||||
| 5262 | file.close(); | - | ||||||||||||||||||
| 5263 | return bindCompressedTexture never executed: return bindCompressedTexture (contents.constData(), contents.size(), format); | 0 | ||||||||||||||||||
| 5264 | (contents.constData(), contents.size(), format); never executed: return bindCompressedTexture (contents.constData(), contents.size(), format); | 0 | ||||||||||||||||||
| 5265 | } | - | ||||||||||||||||||
| 5266 | - | |||||||||||||||||||
| 5267 | // PVR header format for container files that store textures compressed | - | ||||||||||||||||||
| 5268 | // with the ETC1, PVRTC2, and PVRTC4 encodings. Format information from the | - | ||||||||||||||||||
| 5269 | // PowerVR SDK at http://www.imgtec.com/powervr/insider/powervr-sdk.asp | - | ||||||||||||||||||
| 5270 | // "PVRTexTool Reference Manual, version 1.11f". | - | ||||||||||||||||||
| 5271 | struct PvrHeader | - | ||||||||||||||||||
| 5272 | { | - | ||||||||||||||||||
| 5273 | quint32 headerSize; | - | ||||||||||||||||||
| 5274 | quint32 height; | - | ||||||||||||||||||
| 5275 | quint32 width; | - | ||||||||||||||||||
| 5276 | quint32 mipMapCount; | - | ||||||||||||||||||
| 5277 | quint32 flags; | - | ||||||||||||||||||
| 5278 | quint32 dataSize; | - | ||||||||||||||||||
| 5279 | quint32 bitsPerPixel; | - | ||||||||||||||||||
| 5280 | quint32 redMask; | - | ||||||||||||||||||
| 5281 | quint32 greenMask; | - | ||||||||||||||||||
| 5282 | quint32 blueMask; | - | ||||||||||||||||||
| 5283 | quint32 alphaMask; | - | ||||||||||||||||||
| 5284 | quint32 magic; | - | ||||||||||||||||||
| 5285 | quint32 surfaceCount; | - | ||||||||||||||||||
| 5286 | }; | - | ||||||||||||||||||
| 5287 | - | |||||||||||||||||||
| 5288 | #define PVR_MAGIC 0x21525650 // "PVR!" in little-endian | - | ||||||||||||||||||
| 5289 | - | |||||||||||||||||||
| 5290 | #define PVR_FORMAT_MASK 0x000000FF | - | ||||||||||||||||||
| 5291 | #define PVR_FORMAT_PVRTC2 0x00000018 | - | ||||||||||||||||||
| 5292 | #define PVR_FORMAT_PVRTC4 0x00000019 | - | ||||||||||||||||||
| 5293 | #define PVR_FORMAT_ETC1 0x00000036 | - | ||||||||||||||||||
| 5294 | - | |||||||||||||||||||
| 5295 | #define PVR_HAS_MIPMAPS 0x00000100 | - | ||||||||||||||||||
| 5296 | #define PVR_TWIDDLED 0x00000200 | - | ||||||||||||||||||
| 5297 | #define PVR_NORMAL_MAP 0x00000400 | - | ||||||||||||||||||
| 5298 | #define PVR_BORDER_ADDED 0x00000800 | - | ||||||||||||||||||
| 5299 | #define PVR_CUBE_MAP 0x00001000 | - | ||||||||||||||||||
| 5300 | #define PVR_FALSE_COLOR_MIPMAPS 0x00002000 | - | ||||||||||||||||||
| 5301 | #define PVR_VOLUME_TEXTURE 0x00004000 | - | ||||||||||||||||||
| 5302 | #define PVR_ALPHA_IN_TEXTURE 0x00008000 | - | ||||||||||||||||||
| 5303 | #define PVR_VERTICAL_FLIP 0x00010000 | - | ||||||||||||||||||
| 5304 | - | |||||||||||||||||||
| 5305 | #ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG | - | ||||||||||||||||||
| 5306 | #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 | - | ||||||||||||||||||
| 5307 | #define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 | - | ||||||||||||||||||
| 5308 | #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 | - | ||||||||||||||||||
| 5309 | #define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 | - | ||||||||||||||||||
| 5310 | #endif | - | ||||||||||||||||||
| 5311 | - | |||||||||||||||||||
| 5312 | #ifndef GL_ETC1_RGB8_OES | - | ||||||||||||||||||
| 5313 | #define GL_ETC1_RGB8_OES 0x8D64 | - | ||||||||||||||||||
| 5314 | #endif | - | ||||||||||||||||||
| 5315 | - | |||||||||||||||||||
| 5316 | bool QGLTexture::canBindCompressedTexture | - | ||||||||||||||||||
| 5317 | (const char *buf, int len, const char *format, bool *hasAlpha) | - | ||||||||||||||||||
| 5318 | { | - | ||||||||||||||||||
| 5319 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) {
| 0 | ||||||||||||||||||
| 5320 | // Compressed texture loading only supported on little-endian | - | ||||||||||||||||||
| 5321 | // systems such as x86 and ARM at the moment. | - | ||||||||||||||||||
| 5322 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 5323 | } | - | ||||||||||||||||||
| 5324 | if (!format) {
| 0 | ||||||||||||||||||
| 5325 | // Auto-detect the format from the header. | - | ||||||||||||||||||
| 5326 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) {
| 0 | ||||||||||||||||||
| 5327 | *hasAlpha = true; | - | ||||||||||||||||||
| 5328 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 5329 | } else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) {
| 0 | ||||||||||||||||||
| 5330 | const PvrHeader *pvrHeader = | - | ||||||||||||||||||
| 5331 | reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
| 5332 | *hasAlpha = (pvrHeader->alphaMask != 0); | - | ||||||||||||||||||
| 5333 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 5334 | } | - | ||||||||||||||||||
| 5335 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 5336 | // Validate the format against the header. | - | ||||||||||||||||||
| 5337 | if (!qstricmp(format, "DDS")) {
| 0 | ||||||||||||||||||
| 5338 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) {
| 0 | ||||||||||||||||||
| 5339 | *hasAlpha = true; | - | ||||||||||||||||||
| 5340 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 5341 | } | - | ||||||||||||||||||
| 5342 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never executed: end of block
| 0 | ||||||||||||||||||
| 5343 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) {
| 0 | ||||||||||||||||||
| 5344 | const PvrHeader *pvrHeader = | - | ||||||||||||||||||
| 5345 | reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
| 5346 | *hasAlpha = (pvrHeader->alphaMask != 0); | - | ||||||||||||||||||
| 5347 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 5348 | } | - | ||||||||||||||||||
| 5349 | } never executed: end of block | 0 | ||||||||||||||||||
| 5350 | } never executed: end of block | 0 | ||||||||||||||||||
| 5351 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 5352 | } | - | ||||||||||||||||||
| 5353 | - | |||||||||||||||||||
| 5354 | #define ctx QGLContext::currentContext() | - | ||||||||||||||||||
| 5355 | - | |||||||||||||||||||
| 5356 | QSize QGLTexture::bindCompressedTexture | - | ||||||||||||||||||
| 5357 | (const char *buf, int len, const char *format) | - | ||||||||||||||||||
| 5358 | { | - | ||||||||||||||||||
| 5359 | if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) {
| 0 | ||||||||||||||||||
| 5360 | // Compressed texture loading only supported on little-endian | - | ||||||||||||||||||
| 5361 | // systems such as x86 and ARM at the moment. | - | ||||||||||||||||||
| 5362 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5363 | } | - | ||||||||||||||||||
| 5364 | if (!format) {
| 0 | ||||||||||||||||||
| 5365 | // Auto-detect the format from the header. | - | ||||||||||||||||||
| 5366 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4))
| 0 | ||||||||||||||||||
| 5367 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 | ||||||||||||||||||
| 5368 | else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4))
| 0 | ||||||||||||||||||
| 5369 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 | ||||||||||||||||||
| 5370 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 5371 | // Validate the format against the header. | - | ||||||||||||||||||
| 5372 | if (!qstricmp(format, "DDS")) {
| 0 | ||||||||||||||||||
| 5373 | if (len >= 4 && !qstrncmp(buf, "DDS ", 4))
| 0 | ||||||||||||||||||
| 5374 | return bindCompressedTextureDDS(buf, len); never executed: return bindCompressedTextureDDS(buf, len); | 0 | ||||||||||||||||||
| 5375 | } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { never executed: end of block
| 0 | ||||||||||||||||||
| 5376 | if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4))
| 0 | ||||||||||||||||||
| 5377 | return bindCompressedTexturePVR(buf, len); never executed: return bindCompressedTexturePVR(buf, len); | 0 | ||||||||||||||||||
| 5378 | } never executed: end of block | 0 | ||||||||||||||||||
| 5379 | } never executed: end of block | 0 | ||||||||||||||||||
| 5380 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5381 | } | - | ||||||||||||||||||
| 5382 | - | |||||||||||||||||||
| 5383 | QSize QGLTexture::bindCompressedTextureDDS(const char *buf, int len) | - | ||||||||||||||||||
| 5384 | { | - | ||||||||||||||||||
| 5385 | // We only support 2D texture loading at present. | - | ||||||||||||||||||
| 5386 | if (target != GL_TEXTURE_2D)
| 0 | ||||||||||||||||||
| 5387 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5388 | - | |||||||||||||||||||
| 5389 | // Bail out if the necessary extension is not present. | - | ||||||||||||||||||
| 5390 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::DDSTextureCompression)) {
| 0 | ||||||||||||||||||
| 5391 | qWarning("QGLContext::bindTexture(): DDS texture compression is not supported."); | - | ||||||||||||||||||
| 5392 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5393 | } | - | ||||||||||||||||||
| 5394 | - | |||||||||||||||||||
| 5395 | const DDSFormat *ddsHeader = reinterpret_cast<const DDSFormat *>(buf + 4); | - | ||||||||||||||||||
| 5396 | if (!ddsHeader->dwLinearSize) {
| 0 | ||||||||||||||||||
| 5397 | qWarning("QGLContext::bindTexture(): DDS image size is not valid."); | - | ||||||||||||||||||
| 5398 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5399 | } | - | ||||||||||||||||||
| 5400 | - | |||||||||||||||||||
| 5401 | int blockSize = 16; | - | ||||||||||||||||||
| 5402 | GLenum format; | - | ||||||||||||||||||
| 5403 | - | |||||||||||||||||||
| 5404 | switch(ddsHeader->ddsPixelFormat.dwFourCC) { | - | ||||||||||||||||||
| 5405 | case FOURCC_DXT1: never executed: case 0x31545844: | 0 | ||||||||||||||||||
| 5406 | format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; | - | ||||||||||||||||||
| 5407 | blockSize = 8; | - | ||||||||||||||||||
| 5408 | break; never executed: break; | 0 | ||||||||||||||||||
| 5409 | case FOURCC_DXT3: never executed: case 0x33545844: | 0 | ||||||||||||||||||
| 5410 | format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; | - | ||||||||||||||||||
| 5411 | break; never executed: break; | 0 | ||||||||||||||||||
| 5412 | case FOURCC_DXT5: never executed: case 0x35545844: | 0 | ||||||||||||||||||
| 5413 | format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | - | ||||||||||||||||||
| 5414 | break; never executed: break; | 0 | ||||||||||||||||||
| 5415 | default: never executed: default: | 0 | ||||||||||||||||||
| 5416 | qWarning("QGLContext::bindTexture(): DDS image format not supported."); | - | ||||||||||||||||||
| 5417 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5418 | } | - | ||||||||||||||||||
| 5419 | - | |||||||||||||||||||
| 5420 | const GLubyte *pixels = | - | ||||||||||||||||||
| 5421 | reinterpret_cast<const GLubyte *>(buf + ddsHeader->dwSize + 4); | - | ||||||||||||||||||
| 5422 | - | |||||||||||||||||||
| 5423 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 5424 | funcs->glGenTextures(1, &id); | - | ||||||||||||||||||
| 5425 | funcs->glBindTexture(GL_TEXTURE_2D, id); | - | ||||||||||||||||||
| 5426 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
| 5427 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||
| 5428 | - | |||||||||||||||||||
| 5429 | int size; | - | ||||||||||||||||||
| 5430 | int offset = 0; | - | ||||||||||||||||||
| 5431 | int available = len - int(ddsHeader->dwSize + 4); | - | ||||||||||||||||||
| 5432 | int w = ddsHeader->dwWidth; | - | ||||||||||||||||||
| 5433 | int h = ddsHeader->dwHeight; | - | ||||||||||||||||||
| 5434 | - | |||||||||||||||||||
| 5435 | // load mip-maps | - | ||||||||||||||||||
| 5436 | for(int i = 0; i < (int) ddsHeader->dwMipMapCount; ++i) {
| 0 | ||||||||||||||||||
| 5437 | if (w == 0) w = 1; never executed: w = 1;
| 0 | ||||||||||||||||||
| 5438 | if (h == 0) h = 1; never executed: h = 1;
| 0 | ||||||||||||||||||
| 5439 | - | |||||||||||||||||||
| 5440 | size = ((w+3)/4) * ((h+3)/4) * blockSize; | - | ||||||||||||||||||
| 5441 | if (size > available)
| 0 | ||||||||||||||||||
| 5442 | break; never executed: break; | 0 | ||||||||||||||||||
| 5443 | qgl_extensions()->glCompressedTexImage2D(GL_TEXTURE_2D, i, format, w, h, 0, | - | ||||||||||||||||||
| 5444 | size, pixels + offset); | - | ||||||||||||||||||
| 5445 | offset += size; | - | ||||||||||||||||||
| 5446 | available -= size; | - | ||||||||||||||||||
| 5447 | - | |||||||||||||||||||
| 5448 | // half size for each mip-map level | - | ||||||||||||||||||
| 5449 | w = w/2; | - | ||||||||||||||||||
| 5450 | h = h/2; | - | ||||||||||||||||||
| 5451 | } never executed: end of block | 0 | ||||||||||||||||||
| 5452 | - | |||||||||||||||||||
| 5453 | // DDS images are not inverted. | - | ||||||||||||||||||
| 5454 | options &= ~QGLContext::InvertedYBindOption; | - | ||||||||||||||||||
| 5455 | - | |||||||||||||||||||
| 5456 | return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); never executed: return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); | 0 | ||||||||||||||||||
| 5457 | } | - | ||||||||||||||||||
| 5458 | - | |||||||||||||||||||
| 5459 | QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len) | - | ||||||||||||||||||
| 5460 | { | - | ||||||||||||||||||
| 5461 | // We only support 2D texture loading at present. Cube maps later. | - | ||||||||||||||||||
| 5462 | if (target != GL_TEXTURE_2D)
| 0 | ||||||||||||||||||
| 5463 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5464 | - | |||||||||||||||||||
| 5465 | // Determine which texture format we will be loading. | - | ||||||||||||||||||
| 5466 | const PvrHeader *pvrHeader = reinterpret_cast<const PvrHeader *>(buf); | - | ||||||||||||||||||
| 5467 | GLenum textureFormat; | - | ||||||||||||||||||
| 5468 | quint32 minWidth, minHeight; | - | ||||||||||||||||||
| 5469 | switch (pvrHeader->flags & PVR_FORMAT_MASK) { | - | ||||||||||||||||||
| 5470 | case PVR_FORMAT_PVRTC2: never executed: case 0x00000018: | 0 | ||||||||||||||||||
| 5471 | if (pvrHeader->alphaMask)
| 0 | ||||||||||||||||||
| 5472 | textureFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; never executed: textureFormat = 0x8C03; | 0 | ||||||||||||||||||
| 5473 | else | - | ||||||||||||||||||
| 5474 | textureFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; never executed: textureFormat = 0x8C01; | 0 | ||||||||||||||||||
| 5475 | minWidth = 16; | - | ||||||||||||||||||
| 5476 | minHeight = 8; | - | ||||||||||||||||||
| 5477 | break; never executed: break; | 0 | ||||||||||||||||||
| 5478 | - | |||||||||||||||||||
| 5479 | case PVR_FORMAT_PVRTC4: never executed: case 0x00000019: | 0 | ||||||||||||||||||
| 5480 | if (pvrHeader->alphaMask)
| 0 | ||||||||||||||||||
| 5481 | textureFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; never executed: textureFormat = 0x8C02; | 0 | ||||||||||||||||||
| 5482 | else | - | ||||||||||||||||||
| 5483 | textureFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; never executed: textureFormat = 0x8C00; | 0 | ||||||||||||||||||
| 5484 | minWidth = 8; | - | ||||||||||||||||||
| 5485 | minHeight = 8; | - | ||||||||||||||||||
| 5486 | break; never executed: break; | 0 | ||||||||||||||||||
| 5487 | - | |||||||||||||||||||
| 5488 | case PVR_FORMAT_ETC1: never executed: case 0x00000036: | 0 | ||||||||||||||||||
| 5489 | textureFormat = GL_ETC1_RGB8_OES; | - | ||||||||||||||||||
| 5490 | minWidth = 4; | - | ||||||||||||||||||
| 5491 | minHeight = 4; | - | ||||||||||||||||||
| 5492 | break; never executed: break; | 0 | ||||||||||||||||||
| 5493 | - | |||||||||||||||||||
| 5494 | default: never executed: default: | 0 | ||||||||||||||||||
| 5495 | qWarning("QGLContext::bindTexture(): PVR image format 0x%x not supported.", int(pvrHeader->flags & PVR_FORMAT_MASK)); | - | ||||||||||||||||||
| 5496 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5497 | } | - | ||||||||||||||||||
| 5498 | - | |||||||||||||||||||
| 5499 | // Bail out if the necessary extension is not present. | - | ||||||||||||||||||
| 5500 | if (textureFormat == GL_ETC1_RGB8_OES) {
| 0 | ||||||||||||||||||
| 5501 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::ETC1TextureCompression)) {
| 0 | ||||||||||||||||||
| 5502 | qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); | - | ||||||||||||||||||
| 5503 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5504 | } | - | ||||||||||||||||||
| 5505 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 5506 | if (!qgl_extensions()->hasOpenGLExtension(QOpenGLExtensions::PVRTCTextureCompression)) {
| 0 | ||||||||||||||||||
| 5507 | qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported."); | - | ||||||||||||||||||
| 5508 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5509 | } | - | ||||||||||||||||||
| 5510 | } never executed: end of block | 0 | ||||||||||||||||||
| 5511 | - | |||||||||||||||||||
| 5512 | // Boundary check on the buffer size. | - | ||||||||||||||||||
| 5513 | quint32 bufferSize = pvrHeader->headerSize + pvrHeader->dataSize; | - | ||||||||||||||||||
| 5514 | if (bufferSize > quint32(len)) {
| 0 | ||||||||||||||||||
| 5515 | qWarning("QGLContext::bindTexture(): PVR image size is not valid."); | - | ||||||||||||||||||
| 5516 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 5517 | } | - | ||||||||||||||||||
| 5518 | - | |||||||||||||||||||
| 5519 | // Create the texture. | - | ||||||||||||||||||
| 5520 | QOpenGLFunctions *funcs = qgl_functions(); | - | ||||||||||||||||||
| 5521 | funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | - | ||||||||||||||||||
| 5522 | funcs->glGenTextures(1, &id); | - | ||||||||||||||||||
| 5523 | funcs->glBindTexture(GL_TEXTURE_2D, id); | - | ||||||||||||||||||
| 5524 | if (pvrHeader->mipMapCount) {
| 0 | ||||||||||||||||||
| 5525 | if ((options & QGLContext::LinearFilteringBindOption) != 0) {
| 0 | ||||||||||||||||||
| 5526 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
| 5527 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); | - | ||||||||||||||||||
| 5528 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 5529 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 5530 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); | - | ||||||||||||||||||
| 5531 | } never executed: end of block | 0 | ||||||||||||||||||
| 5532 | } else if ((options & QGLContext::LinearFilteringBindOption) != 0) {
| 0 | ||||||||||||||||||
| 5533 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||
| 5534 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||
| 5535 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 5536 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 5537 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 5538 | } never executed: end of block | 0 | ||||||||||||||||||
| 5539 | - | |||||||||||||||||||
| 5540 | // Load the compressed mipmap levels. | - | ||||||||||||||||||
| 5541 | const GLubyte *buffer = | - | ||||||||||||||||||
| 5542 | reinterpret_cast<const GLubyte *>(buf + pvrHeader->headerSize); | - | ||||||||||||||||||
| 5543 | bufferSize = pvrHeader->dataSize; | - | ||||||||||||||||||
| 5544 | quint32 level = 0; | - | ||||||||||||||||||
| 5545 | quint32 width = pvrHeader->width; | - | ||||||||||||||||||
| 5546 | quint32 height = pvrHeader->height; | - | ||||||||||||||||||
| 5547 | while (bufferSize > 0 && level <= pvrHeader->mipMapCount) {
| 0 | ||||||||||||||||||
| 5548 | quint32 size = | - | ||||||||||||||||||
| 5549 | (qMax(width, minWidth) * qMax(height, minHeight) * | - | ||||||||||||||||||
| 5550 | pvrHeader->bitsPerPixel) / 8; | - | ||||||||||||||||||
| 5551 | if (size > bufferSize)
| 0 | ||||||||||||||||||
| 5552 | break; never executed: break; | 0 | ||||||||||||||||||
| 5553 | qgl_extensions()->glCompressedTexImage2D(GL_TEXTURE_2D, GLint(level), textureFormat, | - | ||||||||||||||||||
| 5554 | GLsizei(width), GLsizei(height), 0, | - | ||||||||||||||||||
| 5555 | GLsizei(size), buffer); | - | ||||||||||||||||||
| 5556 | width /= 2; | - | ||||||||||||||||||
| 5557 | height /= 2; | - | ||||||||||||||||||
| 5558 | buffer += size; | - | ||||||||||||||||||
| 5559 | ++level; | - | ||||||||||||||||||
| 5560 | } never executed: end of block | 0 | ||||||||||||||||||
| 5561 | - | |||||||||||||||||||
| 5562 | // Restore the default pixel alignment for later texture uploads. | - | ||||||||||||||||||
| 5563 | funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 4); | - | ||||||||||||||||||
| 5564 | - | |||||||||||||||||||
| 5565 | // Set the invert flag for the texture. The "vertical flip" | - | ||||||||||||||||||
| 5566 | // flag in PVR is the opposite sense to our sense of inversion. | - | ||||||||||||||||||
| 5567 | options.setFlag(QGLContext::InvertedYBindOption, !(pvrHeader->flags & PVR_VERTICAL_FLIP)); | - | ||||||||||||||||||
| 5568 | - | |||||||||||||||||||
| 5569 | return QSize(pvrHeader->width, pvrHeader->height); never executed: return QSize(pvrHeader->width, pvrHeader->height); | 0 | ||||||||||||||||||
| 5570 | } | - | ||||||||||||||||||
| 5571 | - | |||||||||||||||||||
| 5572 | #undef ctx | - | ||||||||||||||||||
| 5573 | - | |||||||||||||||||||
| 5574 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |