Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5050#define INT32 dummy_INT32
    5151#define INT8 dummy_INT8
    52 #if !defined(QT_OPENGL_ES)
     52#ifdef QT_NO_EGL
    5353# include <GL/glx.h>
    5454#endif
     
    6868#include "qgl_p.h"
    6969
    70 #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
     70#if !defined(QT_OPENGL_ES_1)
    7171#include "gl2paintengineex/qpaintengineex_opengl2_p.h"
    7272#endif
     
    9292#include "qfile.h"
    9393#include "qlibrary.h"
     94#include <qmutex.h>
    9495
    9596
    9697QT_BEGIN_NAMESPACE
    9798
    98 #ifdef QT_OPENGL_ES_1_CL
    99 #include "qgl_cl_p.h"
    100 #endif
    101 
    102 
    103 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
     99#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
    104100QGLExtensionFuncs QGLContextPrivate::qt_extensionFuncs;
    105101#endif
     
    132128QGLSignalProxy *QGLSignalProxy::instance()
    133129{
    134     return theSignalProxy();
     130    QGLSignalProxy *proxy = theSignalProxy();
     131    if (proxy && proxy->thread() != qApp->thread()) {
     132        if (proxy->thread() == QThread::currentThread())
     133            proxy->moveToThread(qApp->thread());
     134    }
     135    return proxy;
    135136}
    136137
     
    227228    \value HasOverlay        Enables the use of an overlay.
    228229    \value SampleBuffers     Enables the use of sample buffers.
     230    \value DeprecatedFunctions      Enables the use of deprecated functionality for OpenGL 3.x
     231                                    contexts. A context with deprecated functionality enabled is
     232                                    called a full context in the OpenGL specification.
    229233    \value SingleBuffer      Specifies the use of a single buffer, as opposed to double buffers.
    230234    \value NoDepthBuffer     Disables the use of a depth buffer.
     
    237241    \value NoOverlay         Disables the use of an overlay.
    238242    \value NoSampleBuffers   Disables the use of sample buffers.
     243    \value NoDeprecatedFunctions    Disables the use of deprecated functionality for OpenGL 3.x
     244                                    contexts. A context with deprecated functionality disabled is
     245                                    called a forward compatible context in the OpenGL specification.
    239246
    240247    \sa {Sample Buffers Example}
     
    508515    flicker-free drawing and often better performance.
    509516
     517    Note that single buffered contexts are currently not supported
     518    with EGL.
     519
    510520    \sa doubleBuffer(), QGLContext::swapBuffers(),
    511521    QGLWidget::swapBuffers()
     
    766776    }
    767777    d->numSamples = numSamples;
     778    setSampleBuffers(numSamples > 0);
    768779}
    769780
     
    904915    }
    905916    d->depthSize = size;
     917    setDepth(size > 0);
    906918}
    907919
     
    10171029    }
    10181030    d->alphaSize = size;
    1019     setOption(QGL::AlphaChannel);
     1031    setAlpha(size > 0);
    10201032}
    10211033
     
    10441056    }
    10451057    d->accumSize = size;
     1058    setAccum(size > 0);
    10461059}
    10471060
     
    10691082    }
    10701083    d->stencilSize = size;
     1084    setStencil(size > 0);
    10711085}
    10721086
     
    10801094   return d->stencilSize;
    10811095}
     1096
     1097/*!
     1098    \since 4.7
     1099
     1100    Set the OpenGL version to the \a major and \a minor numbers. If a
     1101    context compatible with the requested OpenGL version cannot be
     1102    created, a context compatible with version 1.x is created instead.
     1103
     1104    \sa majorVersion(), minorVersion()
     1105*/
     1106void QGLFormat::setVersion(int major, int minor)
     1107{
     1108    if (major < 1 || minor < 0) {
     1109        qWarning("QGLFormat::setVersion: Cannot set zero or negative version number %d.%d", major, minor);
     1110        return;
     1111    }
     1112    detach();
     1113    d->majorVersion = major;
     1114    d->minorVersion = minor;
     1115}
     1116
     1117/*!
     1118    \since 4.7
     1119
     1120    Returns the OpenGL major version.
     1121
     1122    \sa setVersion(), minorVersion()
     1123*/
     1124int QGLFormat::majorVersion() const
     1125{
     1126    return d->majorVersion;
     1127}
     1128
     1129/*!
     1130    \since 4.7
     1131
     1132    Returns the OpenGL minor version.
     1133
     1134    \sa setVersion(), majorVersion()
     1135*/
     1136int QGLFormat::minorVersion() const
     1137{
     1138    return d->minorVersion;
     1139}
     1140
     1141/*!
     1142    \enum QGLFormat::OpenGLContextProfile
     1143    \since 4.7
     1144
     1145    This enum describes the OpenGL context profiles that can be
     1146    specified for contexts implementing OpenGL version 3.2 or
     1147    higher. These profiles are different from OpenGL ES profiles.
     1148
     1149    \value NoProfile            OpenGL version is lower than 3.2.
     1150    \value CoreProfile          Functionality deprecated in OpenGL version 3.0 is not available.
     1151    \value CompatibilityProfile Functionality from earlier OpenGL versions is available.
     1152*/
     1153
     1154/*!
     1155    \since 4.7
     1156
     1157    Set the OpenGL context profile to \a profile. The \a profile is
     1158    ignored if the requested OpenGL version is less than 3.2.
     1159
     1160    \sa profile()
     1161*/
     1162void QGLFormat::setProfile(OpenGLContextProfile profile)
     1163{
     1164    detach();
     1165    d->profile = profile;
     1166}
     1167
     1168/*!
     1169    \since 4.7
     1170
     1171    Returns the OpenGL context profile.
     1172
     1173    \sa setProfile()
     1174*/
     1175QGLFormat::OpenGLContextProfile QGLFormat::profile() const
     1176{
     1177    return d->profile;
     1178}
     1179
    10821180
    10831181/*!
     
    11171215                        versionFlags |= QGLFormat::OpenGL_ES_Common_Version_1_1 |
    11181216                                        QGLFormat::OpenGL_ES_CommonLite_Version_1_1;
    1119                 }
    1120                 else {
     1217                } else {
    11211218                    // Not -CM, must be CL, CommonLite
    11221219                    versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_0;
     
    11241221                        versionFlags |= QGLFormat::OpenGL_ES_CommonLite_Version_1_1;
    11251222                }
    1126             }
    1127             else {
     1223            } else {
    11281224                // OpenGL ES version 2.0 or higher
    11291225                versionFlags |= QGLFormat::OpenGL_ES_Version_2_0;
    11301226            }
    1131         }
    1132         else {
     1227        } else {
    11331228            // if < 3 parts to the name, it is an unrecognised OpenGL ES
    11341229            qWarning("Unrecognised OpenGL ES version");
    11351230        }
    1136     }
    1137     else {
     1231    } else {
    11381232        // not ES, regular OpenGL, the version numbers are first in the string
    11391233        if (versionString.startsWith(QLatin1String("1."))) {
     
    11521246                break;
    11531247            }
    1154         }
    1155         else if (versionString.startsWith(QLatin1String("2."))) {
     1248        } else if (versionString.startsWith(QLatin1String("2."))) {
    11561249            versionFlags |= QGLFormat::OpenGL_Version_1_1 |
    11571250                            QGLFormat::OpenGL_Version_1_2 |
     
    11601253                            QGLFormat::OpenGL_Version_1_5 |
    11611254                            QGLFormat::OpenGL_Version_2_0;
    1162             QString minorVersion = versionString.section(QLatin1Char(' '), 0, 0).section(QLatin1Char('.'), 1, 1);
    1163             if (minorVersion == QChar(QLatin1Char('1')))
     1255            if (versionString[2].toAscii() == '1')
    11641256                versionFlags |= QGLFormat::OpenGL_Version_2_1;
     1257        } else if (versionString.startsWith(QLatin1String("3."))) {
     1258            versionFlags |= QGLFormat::OpenGL_Version_1_1 |
     1259                            QGLFormat::OpenGL_Version_1_2 |
     1260                            QGLFormat::OpenGL_Version_1_3 |
     1261                            QGLFormat::OpenGL_Version_1_4 |
     1262                            QGLFormat::OpenGL_Version_1_5 |
     1263                            QGLFormat::OpenGL_Version_2_0 |
     1264                            QGLFormat::OpenGL_Version_2_1 |
     1265                            QGLFormat::OpenGL_Version_3_0;
     1266            switch (versionString[2].toAscii()) {
     1267            case '3':
     1268                versionFlags |= QGLFormat::OpenGL_Version_3_3;
     1269            case '2':
     1270                versionFlags |= QGLFormat::OpenGL_Version_3_2;
     1271            case '1':
     1272                versionFlags |= QGLFormat::OpenGL_Version_3_1;
     1273            case '0':
     1274                break;
     1275            default:
     1276                versionFlags |= QGLFormat::OpenGL_Version_3_1 |
     1277                                QGLFormat::OpenGL_Version_3_2 |
     1278                                QGLFormat::OpenGL_Version_3_3;
     1279                break;
     1280            }
     1281        } else if (versionString.startsWith(QLatin1String("4."))) {
     1282            versionFlags |= QGLFormat::OpenGL_Version_1_1 |
     1283                            QGLFormat::OpenGL_Version_1_2 |
     1284                            QGLFormat::OpenGL_Version_1_3 |
     1285                            QGLFormat::OpenGL_Version_1_4 |
     1286                            QGLFormat::OpenGL_Version_1_5 |
     1287                            QGLFormat::OpenGL_Version_2_0 |
     1288                            QGLFormat::OpenGL_Version_2_1 |
     1289                            QGLFormat::OpenGL_Version_3_0 |
     1290                            QGLFormat::OpenGL_Version_3_1 |
     1291                            QGLFormat::OpenGL_Version_3_2 |
     1292                            QGLFormat::OpenGL_Version_3_3 |
     1293                            QGLFormat::OpenGL_Version_4_0;
     1294        } else {
     1295            versionFlags |= QGLFormat::OpenGL_Version_1_1 |
     1296                            QGLFormat::OpenGL_Version_1_2 |
     1297                            QGLFormat::OpenGL_Version_1_3 |
     1298                            QGLFormat::OpenGL_Version_1_4 |
     1299                            QGLFormat::OpenGL_Version_1_5 |
     1300                            QGLFormat::OpenGL_Version_2_0 |
     1301                            QGLFormat::OpenGL_Version_2_1 |
     1302                            QGLFormat::OpenGL_Version_3_0 |
     1303                            QGLFormat::OpenGL_Version_3_1 |
     1304                            QGLFormat::OpenGL_Version_3_2 |
     1305                            QGLFormat::OpenGL_Version_3_3 |
     1306                            QGLFormat::OpenGL_Version_4_0;
    11651307        }
    1166         else if (versionString.startsWith(QLatin1String("3."))) {
    1167          versionFlags |= QGLFormat::OpenGL_Version_1_1 |
    1168                          QGLFormat::OpenGL_Version_1_2 |
    1169                          QGLFormat::OpenGL_Version_1_3 |
    1170                          QGLFormat::OpenGL_Version_1_4 |
    1171                          QGLFormat::OpenGL_Version_1_5 |
    1172                          QGLFormat::OpenGL_Version_2_0 |
    1173                          QGLFormat::OpenGL_Version_2_1 |
    1174                          QGLFormat::OpenGL_Version_3_0;
    1175         }
    1176         else
    1177             qWarning("Unrecognised OpenGL version");
    11781308    }
    11791309    return versionFlags;
     
    12061336
    12071337    \value OpenGL_Version_3_0  OpenGL version 3.0 or higher is present.
     1338
     1339    \value OpenGL_Version_3_1  OpenGL version 3.1 or higher is present.
     1340    Note that OpenGL version 3.1 or higher does not necessarily support all the features of
     1341    version 3.0 and lower.
     1342
     1343    \value OpenGL_Version_3_2  OpenGL version 3.2 or higher is present.
     1344
     1345    \value OpenGL_Version_3_3  OpenGL version 3.3 or higher is present.
     1346
     1347    \value OpenGL_Version_4_0  OpenGL version 4.0 or higher is present.
    12081348
    12091349    \value OpenGL_ES_CommonLite_Version_1_0  OpenGL ES version 1.0 Common Lite or higher is present.
     
    13781518bool operator==(const QGLFormat& a, const QGLFormat& b)
    13791519{
    1380     return (int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize
    1381         && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize
     1520    return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
     1521        && a.d->pln == b.d->pln
     1522        && a.d->alphaSize == b.d->alphaSize
     1523        && a.d->accumSize == b.d->accumSize
     1524        && a.d->stencilSize == b.d->stencilSize
    13821525        && a.d->depthSize == b.d->depthSize
    13831526        && a.d->redSize == b.d->redSize
     
    13851528        && a.d->blueSize == b.d->blueSize
    13861529        && a.d->numSamples == b.d->numSamples
    1387         && a.d->swapInterval == b.d->swapInterval;
    1388 }
     1530        && a.d->swapInterval == b.d->swapInterval
     1531        && a.d->majorVersion == b.d->majorVersion
     1532        && a.d->minorVersion == b.d->minorVersion
     1533        && a.d->profile == b.d->profile);
     1534}
     1535
     1536#ifndef QT_NO_DEBUG_STREAM
     1537QDebug operator<<(QDebug dbg, const QGLFormat &f)
     1538{
     1539    const QGLFormatPrivate * const d = f.d;
     1540
     1541    dbg.nospace() << "QGLFormat("
     1542                  << "options " << d->opts
     1543                  << ", plane " << d->pln
     1544                  << ", depthBufferSize " << d->depthSize
     1545                  << ", accumBufferSize " << d->accumSize
     1546                  << ", stencilBufferSize " << d->stencilSize
     1547                  << ", redBufferSize " << d->redSize
     1548                  << ", greenBufferSize " << d->greenSize
     1549                  << ", blueBufferSize " << d->blueSize
     1550                  << ", alphaBufferSize " << d->alphaSize
     1551                  << ", samples " << d->numSamples
     1552                  << ", swapInterval " << d->swapInterval
     1553                  << ", majorVersion " << d->majorVersion
     1554                  << ", minorVersion " << d->minorVersion
     1555                  << ", profile " << d->profile
     1556                  << ')';
     1557
     1558    return dbg.space();
     1559}
     1560#endif
    13891561
    13901562
     
    14001572    return !(a == b);
    14011573}
     1574
     1575struct QGLContextGroupList {
     1576    void append(QGLContextGroup *group) {
     1577        QMutexLocker locker(&m_mutex);
     1578        m_list.append(group);
     1579    }
     1580
     1581    void remove(QGLContextGroup *group) {
     1582        QMutexLocker locker(&m_mutex);
     1583        m_list.removeOne(group);
     1584    }
     1585
     1586    QList<QGLContextGroup *> m_list;
     1587    QMutex m_mutex;
     1588};
     1589
     1590Q_GLOBAL_STATIC(QGLContextGroupList, qt_context_groups)
    14021591
    14031592/*****************************************************************************
    14041593  QGLContext implementation
    14051594 *****************************************************************************/
     1595
     1596QGLContextGroup::QGLContextGroup(const QGLContext *context)
     1597    : m_context(context), m_guards(0), m_refs(1)
     1598{
     1599    qt_context_groups()->append(this);
     1600}
    14061601
    14071602QGLContextGroup::~QGLContextGroup()
     
    14141609        guard = guard->m_next;
    14151610    }
     1611    qt_context_groups()->remove(this);
    14161612}
    14171613
     
    14471643}
    14481644
     1645QGLContextPrivate::QGLContextPrivate(QGLContext *context)
     1646    : internal_context(false)
     1647    , q_ptr(context)
     1648{
     1649    group = new QGLContextGroup(context);
     1650    texture_destroyer = new QGLTextureDestroyer;
     1651    texture_destroyer->moveToThread(qApp->thread());
     1652}
     1653
    14491654QGLContextPrivate::~QGLContextPrivate()
    14501655{
     
    14531658        delete group;
    14541659    }
     1660
     1661    delete texture_destroyer;
    14551662}
    14561663
     
    14811688    vi = 0;
    14821689#endif
    1483 #if defined(QT_OPENGL_ES)
     1690#ifndef QT_NO_EGL
     1691    ownsEglContext = false;
    14841692    eglContext = 0;
    14851693    eglSurface = EGL_NO_SURFACE;
     
    14971705    default_fbo = 0;
    14981706    active_engine = 0;
     1707    workaround_needsFullClearOnEveryFrame = false;
     1708    workaround_brokenFBOReadBack = false;
     1709    workaround_brokenTexSubImage = false;
     1710    workaroundsCached = false;
     1711
     1712    workaround_brokenTextureFromPixmap = false;
     1713    workaround_brokenTextureFromPixmap_init = false;
     1714
    14991715    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
    15001716        vertexAttributeArraysEnabledState[i] = false;
     
    15671783    int w = size.width();
    15681784    int h = size.height();
    1569 #if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
     1785#if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_ES_1)
    15701786    //### glGetTexImage not in GL ES 2.0, need to do something else here!
    15711787    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
     
    15951811extern Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64;
    15961812
    1597 static QGLTextureCache *qt_gl_texture_cache = 0;
     1813
     1814Q_GLOBAL_STATIC(QGLTextureCache, qt_gl_texture_cache)
    15981815
    15991816QGLTextureCache::QGLTextureCache()
    16001817    : m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though
    16011818{
    1602     Q_ASSERT(qt_gl_texture_cache == 0);
    1603     qt_gl_texture_cache = this;
    1604 
    16051819    QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTexturesForPixampData);
    16061820    QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction);
     
    16101824QGLTextureCache::~QGLTextureCache()
    16111825{
    1612     qt_gl_texture_cache = 0;
    1613 
    16141826    QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTexturesForPixampData);
    16151827    QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction);
     
    16191831void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost)
    16201832{
     1833    QWriteLocker locker(&m_lock);
    16211834    if (m_cache.totalCost() + cost > m_cache.maxCost()) {
    16221835        // the cache is full - make an attempt to remove something
    1623         const QList<qint64> keys = m_cache.keys();
     1836        const QList<QGLTextureCacheKey> keys = m_cache.keys();
    16241837        int i = 0;
    16251838        while (i < m_cache.count()
     
    16311844        }
    16321845    }
    1633     m_cache.insert(key, texture, cost);
     1846    const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)};
     1847    m_cache.insert(cacheKey, texture, cost);
     1848}
     1849
     1850void QGLTextureCache::remove(qint64 key)
     1851{
     1852    QWriteLocker locker(&m_lock);
     1853    QMutexLocker groupLocker(&qt_context_groups()->m_mutex);
     1854    QList<QGLContextGroup *>::const_iterator it = qt_context_groups()->m_list.constBegin();
     1855    while (it != qt_context_groups()->m_list.constEnd()) {
     1856        const QGLTextureCacheKey cacheKey = {key, *it};
     1857        m_cache.remove(cacheKey);
     1858        ++it;
     1859    }
    16341860}
    16351861
    16361862bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId)
    16371863{
    1638     QList<qint64> keys = m_cache.keys();
     1864    QWriteLocker locker(&m_lock);
     1865    QList<QGLTextureCacheKey> keys = m_cache.keys();
    16391866    for (int i = 0; i < keys.size(); ++i) {
    16401867        QGLTexture *tex = m_cache.object(keys.at(i));
     
    16501877void QGLTextureCache::removeContextTextures(QGLContext* ctx)
    16511878{
    1652     QList<qint64> keys = m_cache.keys();
     1879    QWriteLocker locker(&m_lock);
     1880    QList<QGLTextureCacheKey> keys = m_cache.keys();
    16531881    for (int i = 0; i < keys.size(); ++i) {
    1654         const qint64 &key = keys.at(i);
     1882        const QGLTextureCacheKey &key = keys.at(i);
    16551883        if (m_cache.object(key)->context == ctx)
    16561884            m_cache.remove(key);
    16571885    }
    1658 }
    1659 
    1660 QGLTextureCache* QGLTextureCache::instance()
    1661 {
    1662     if (!qt_gl_texture_cache)
    1663         qt_gl_texture_cache = new QGLTextureCache;
    1664 
    1665     return qt_gl_texture_cache;
    16661886}
    16671887
     
    16721892void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey)
    16731893{
    1674     // ### remove when the GL texture cache becomes thread-safe
    1675     if (qApp->thread() == QThread::currentThread()) {
    1676         instance()->remove(cacheKey);
    1677         Q_ASSERT(instance()->getTexture(cacheKey) == 0);
    1678     }
     1894    qt_gl_texture_cache()->remove(cacheKey);
    16791895}
    16801896
     
    16981914}
    16991915
    1700 void QGLTextureCache::deleteIfEmpty()
    1701 {
    1702     if (instance()->size() == 0)
    1703         delete instance();
     1916QGLTextureCache *QGLTextureCache::instance()
     1917{
     1918    return qt_gl_texture_cache();
    17041919}
    17051920
     
    18012016
    18022017    \omitvalue CanFlipNativePixmapBindOption Used by x11 from pixmap to choose
    1803     wether or not it can bind the pixmap upside down or not.
     2018    whether or not it can bind the pixmap upside down or not.
    18042019
    18052020    \omitvalue MemoryManagedBindOption Used by paint engines to
     
    18672082    // remove any textures cached in this context
    18682083    QGLTextureCache::instance()->removeContextTextures(this);
    1869     QGLTextureCache::deleteIfEmpty(); // ### thread safety
    18702084
    18712085    d_ptr->group->cleanupResources(this);
     
    18832097{
    18842098    Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT);
     2099#ifdef glEnableVertexAttribArray
    18852100    Q_ASSERT(glEnableVertexAttribArray);
     2101#endif
    18862102
    18872103    if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
     
    18962112void QGLContextPrivate::syncGlState()
    18972113{
     2114#ifdef glEnableVertexAttribArray
    18982115    Q_ASSERT(glEnableVertexAttribArray);
     2116#endif
    18992117    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
    19002118        if (vertexAttributeArraysEnabledState[i])
     
    19072125#undef ctx
    19082126
     2127#ifdef QT_NO_EGL
     2128void QGLContextPrivate::swapRegion(const QRegion &)
     2129{
     2130    Q_Q(QGLContext);
     2131    q->swapBuffers();
     2132}
     2133#endif
    19092134
    19102135/*!
     
    20612286}
    20622287
     2288#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
     2289QGLExtensionFuncs& QGLContextPrivate::extensionFuncs(const QGLContext *)
     2290{
     2291    return qt_extensionFuncs;
     2292}
     2293#endif
     2294
    20632295QImage QGLContextPrivate::convertToGLFormat(const QImage &image, bool force_premul,
    20642296                                            GLenum texture_format)
     
    20772309                                           QGLContext::BindOptions options)
    20782310{
     2311    Q_Q(QGLContext);
     2312
    20792313    const qint64 key = image.cacheKey();
    20802314    QGLTexture *texture = textureCacheLookup(key, target);
    20812315    if (texture) {
    2082         glBindTexture(target, texture->id);
    2083         return texture;
     2316        if (image.paintingActive()) {
     2317            // A QPainter is active on the image - take the safe route and replace the texture.
     2318            q->deleteTexture(texture->id);
     2319            texture = 0;
     2320        } else {
     2321            glBindTexture(target, texture->id);
     2322            return texture;
     2323        }
    20842324    }
    20852325
     
    21272367
    21282368#ifdef QGL_BIND_TEXTURE_DEBUG
    2129     printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x\n",
    2130            image.width(), image.height(), internalFormat, int(options));
     2369    printf("QGLContextPrivate::bindTexture(), imageSize=(%d,%d), internalFormat =0x%x, options=%x, key=%llx\n",
     2370           image.width(), image.height(), internalFormat, int(options), key);
    21312371    QTime time;
    21322372    time.start();
     
    21722412        && (options & QGLContext::MipmapBindOption))
    21732413    {
    2174 #ifdef QGL_BIND_TEXTURE_DEBUG
    2175         printf(" - generating mipmaps (%d ms)\n", time.elapsed());
    2176 #endif
    21772414#if !defined(QT_OPENGL_ES_2)
    21782415        glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
     
    21882425        glTexParameterf(target, GL_TEXTURE_MIN_FILTER, options & QGLContext::LinearFilteringBindOption
    21892426                        ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST);
     2427#ifdef QGL_BIND_TEXTURE_DEBUG
     2428        printf(" - generating mipmaps (%d ms)\n", time.elapsed());
     2429#endif
    21902430    } else {
    21912431        glTexParameterf(target, GL_TEXTURE_MIN_FILTER, filtering);
     
    22122452            img = img.convertToFormat(target_format = QImage::Format_ARGB32_Premultiplied);
    22132453#ifdef QGL_BIND_TEXTURE_DEBUG
    2214             printf(" - converting ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed());
     2454            printf(" - converted ARGB32 -> ARGB32_Premultiplied (%d ms) \n", time.elapsed());
    22152455#endif
    22162456        }
     
    22202460            img = img.convertToFormat(target_format = QImage::Format_ARGB32);
    22212461#ifdef QGL_BIND_TEXTURE_DEBUG
    2222             printf(" - converting ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed());
     2462            printf(" - converted ARGB32_Premultiplied -> ARGB32 (%d ms)\n", time.elapsed());
    22232463#endif
    22242464        }
     
    22372477                                      : QImage::Format_ARGB32);
    22382478#ifdef QGL_BIND_TEXTURE_DEBUG
    2239             printf(" - converting to 32-bit alpha format (%d ms)\n", time.elapsed());
     2479            printf(" - converted to 32-bit alpha format (%d ms)\n", time.elapsed());
    22402480#endif
    22412481        } else {
    22422482            img = img.convertToFormat(QImage::Format_RGB32);
    22432483#ifdef QGL_BIND_TEXTURE_DEBUG
    2244             printf(" - converting to 32-bit (%d ms)\n", time.elapsed());
     2484            printf(" - converted to 32-bit (%d ms)\n", time.elapsed());
    22452485#endif
    22462486        }
     
    22482488
    22492489    if (options & QGLContext::InvertedYBindOption) {
    2250 #ifdef QGL_BIND_TEXTURE_DEBUG
    2251             printf(" - flipping bits over y (%d ms)\n", time.elapsed());
    2252 #endif
    22532490        if (img.isDetached()) {
    22542491            int ipl = img.bytesPerLine() / 4;
     
    22672504            img = img.mirrored();
    22682505        }
     2506#ifdef QGL_BIND_TEXTURE_DEBUG
     2507            printf(" - flipped bits over y (%d ms)\n", time.elapsed());
     2508#endif
    22692509    }
    22702510
    22712511    if (externalFormat == GL_RGBA) {
    2272 #ifdef QGL_BIND_TEXTURE_DEBUG
    2273             printf(" - doing byte swapping (%d ms)\n", time.elapsed());
    2274 #endif
    22752512        // The only case where we end up with a depth different from
    22762513        // 32 in the switch above is for the RGB16 case, where we set
     
    22782515        Q_ASSERT(img.depth() == 32);
    22792516        qgl_byteSwapImage(img, pixel_type);
     2517#ifdef QGL_BIND_TEXTURE_DEBUG
     2518            printf(" - did byte swapping (%d ms)\n", time.elapsed());
     2519#endif
    22802520    }
    22812521#ifdef QT_OPENGL_ES
     
    22992539    GLenum error = glGetError();
    23002540    if (error != GL_NO_ERROR) {
    2301         qWarning(" - texture upload failed, error code 0x%x\n", error);
     2541        qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target);
    23022542    }
    23032543#endif
     
    23062546    static int totalUploadTime = 0;
    23072547    totalUploadTime += time.elapsed();
    2308     printf(" - upload done in (%d ms) time=%d\n", time.elapsed(), totalUploadTime);
     2548    printf(" - upload done in %d ms, (accumulated: %d ms)\n", time.elapsed(), totalUploadTime);
    23092549#endif
    23102550
     
    23212561{
    23222562    Q_Q(QGLContext);
    2323     QGLTexture *texture = QGLTextureCache::instance()->getTexture(key);
     2563    QGLTexture *texture = QGLTextureCache::instance()->getTexture(q, key);
    23242564    if (texture && texture->target == target
    23252565        && (texture->context == q || QGLContext::areSharing(q, texture->context)))
     
    23362576    Q_Q(QGLContext);
    23372577    QPixmapData *pd = pixmap.pixmapData();
    2338 #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
     2578#if !defined(QT_OPENGL_ES_1)
    23392579    if (target == GL_TEXTURE_2D && pd->classId() == QPixmapData::OpenGLClass) {
    23402580        const QGLPixmapData *data = static_cast<const QGLPixmapData *>(pd);
     
    23472587#else
    23482588    Q_UNUSED(pd);
    2349     Q_UNUSED(q);
    23502589#endif
    23512590
     
    23532592    QGLTexture *texture = textureCacheLookup(key, target);
    23542593    if (texture) {
    2355         glBindTexture(target, texture->id);
    2356         return texture;
     2594        if (pixmap.paintingActive()) {
     2595            // A QPainter is active on the pixmap - take the safe route and replace the texture.
     2596            q->deleteTexture(texture->id);
     2597            texture = 0;
     2598        } else {
     2599            glBindTexture(target, texture->id);
     2600            return texture;
     2601        }
    23572602    }
    23582603
     
    23612606    const QX11Info *xinfo = qt_x11Info(paintDevice);
    23622607    if (pd->classId() == QPixmapData::X11Class && pd->pixelType() == QPixmapData::PixmapType
    2363         && xinfo && xinfo->screen() == pixmap.x11Info().screen())
     2608        && xinfo && xinfo->screen() == pixmap.x11Info().screen()
     2609        && target == GL_TEXTURE_2D)
    23642610    {
    2365         texture = bindTextureFromNativePixmap(pd, key, options);
    2366         if (texture) {
    2367             texture->options |= QGLContext::MemoryManagedBindOption;
    2368             texture->boundPixmap = pd;
    2369             boundPixmaps.insert(pd, QPixmap(pixmap));
     2611        if (!workaround_brokenTextureFromPixmap_init) {
     2612            workaround_brokenTextureFromPixmap_init = true;
     2613
     2614            const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
     2615            const int pos = versionString.indexOf("NVIDIA ");
     2616
     2617            if (pos >= 0) {
     2618                const QByteArray nvidiaVersionString = versionString.mid(pos + strlen("NVIDIA "));
     2619
     2620                if (nvidiaVersionString.startsWith("195") || nvidiaVersionString.startsWith("256"))
     2621                    workaround_brokenTextureFromPixmap = true;
     2622            }
    23702623        }
    2371     }
    2372 #endif
    2373 
    2374     if (!texture)
    2375         texture = bindTexture(pixmap.toImage(), target, format, key, options);
     2624
     2625        if (!workaround_brokenTextureFromPixmap) {
     2626            texture = bindTextureFromNativePixmap(const_cast<QPixmap*>(&pixmap), key, options);
     2627            if (texture) {
     2628                texture->options |= QGLContext::MemoryManagedBindOption;
     2629                texture->boundPixmap = pd;
     2630                boundPixmaps.insert(pd, QPixmap(pixmap));
     2631            }
     2632        }
     2633    }
     2634#endif
     2635
     2636    if (!texture) {
     2637        QImage image = pixmap.toImage();
     2638        // If the system depth is 16 and the pixmap doesn't have an alpha channel
     2639        // then we convert it to RGB16 in the hope that it gets uploaded as a 16
     2640        // bit texture which is much faster to access than a 32-bit one.
     2641        if (pixmap.depth() == 16 && !image.hasAlphaChannel() )
     2642            image = image.convertToFormat(QImage::Format_RGB16);
     2643        texture = bindTexture(image, target, format, key, options);
     2644    }
    23762645    // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null
    23772646    Q_ASSERT(texture);
     
    24662735
    24672736    Q_D(QGLContext);
    2468     QGLTexture *texture = d->bindTexture(image, target, format, false, options);
     2737    QGLTexture *texture = d->bindTexture(image, target, format, options);
    24692738    return texture->id;
    24702739}
     
    24782747
    24792748    Q_D(QGLContext);
    2480     QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), false, DefaultBindOption);
     2749    QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), DefaultBindOption);
    24812750    return texture->id;
    24822751}
     
    24902759
    24912760    Q_D(QGLContext);
    2492     QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), false, options);
     2761    QGLTexture *texture = d->bindTexture(image, GLenum(target), GLint(format), options);
    24932762    return texture->id;
    24942763}
     
    25882857#endif
    25892858
    2590 void qt_add_rect_to_array(const QRectF &r, q_vertexType *array)
     2859void qt_add_rect_to_array(const QRectF &r, GLfloat *array)
    25912860{
    25922861    qreal left = r.left();
     
    25952864    qreal bottom = r.bottom();
    25962865
    2597     array[0] = f2vt(left);
    2598     array[1] = f2vt(top);
    2599     array[2] = f2vt(right);
    2600     array[3] = f2vt(top);
    2601     array[4] = f2vt(right);
    2602     array[5] = f2vt(bottom);
    2603     array[6] = f2vt(left);
    2604     array[7] = f2vt(bottom);
    2605 }
    2606 
    2607 void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array)
    2608 {
    2609     array[0] = f2vt(x1);
    2610     array[1] = f2vt(y1);
    2611     array[2] = f2vt(x2);
    2612     array[3] = f2vt(y1);
    2613     array[4] = f2vt(x2);
    2614     array[5] = f2vt(y2);
    2615     array[6] = f2vt(x1);
    2616     array[7] = f2vt(y2);
     2866    array[0] = left;
     2867    array[1] = top;
     2868    array[2] = right;
     2869    array[3] = top;
     2870    array[4] = right;
     2871    array[5] = bottom;
     2872    array[6] = left;
     2873    array[7] = bottom;
     2874}
     2875
     2876void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, GLfloat *array)
     2877{
     2878    array[0] = x1;
     2879    array[1] = y1;
     2880    array[2] = x2;
     2881    array[3] = y1;
     2882    array[4] = x2;
     2883    array[5] = y2;
     2884    array[6] = x1;
     2885    array[7] = y2;
    26172886}
    26182887
     
    26212890static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget)
    26222891{
    2623     q_vertexType tx = f2vt(1);
    2624     q_vertexType ty = f2vt(1);
     2892    GLfloat tx = 1.0f;
     2893    GLfloat ty = 1.0f;
    26252894
    26262895#ifdef QT_OPENGL_ES
     
    26352904        }
    26362905
    2637         tx = f2vt(textureWidth);
    2638         ty = f2vt(textureHeight);
    2639     }
    2640 #endif
    2641 
    2642     q_vertexType texCoordArray[4*2] = {
     2906        tx = GLfloat(textureWidth);
     2907        ty = GLfloat(textureHeight);
     2908    }
     2909#endif
     2910
     2911    GLfloat texCoordArray[4*2] = {
    26432912        0, ty, tx, ty, tx, 0, 0, 0
    26442913    };
    26452914
    2646     q_vertexType vertexArray[4*2];
     2915    GLfloat vertexArray[4*2];
    26472916    qt_add_rect_to_array(target, vertexArray);
    26482917
    2649     glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);
    2650     glTexCoordPointer(2, q_vertexTypeEnum, 0, texCoordArray);
     2918    glVertexPointer(2, GL_FLOAT, 0, vertexArray);
     2919    glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray);
    26512920
    26522921    glEnableClientState(GL_VERTEX_ARRAY);
     
    26632932    \since 4.4
    26642933
    2665     Draws the given texture, \a textureId, to the given target rectangle,
    2666     \a target, in OpenGL model space. The \a textureTarget should be a 2D
    2667     texture target.
    2668 
    2669     \note This function is not supported under OpenGL/ES 2.0.
     2934    This function supports the following use cases:
     2935
     2936    \list
     2937    \i On OpenGL and OpenGL ES 1.x it draws the given texture, \a textureId,
     2938    to the given target rectangle, \a target, in OpenGL model space. The
     2939    \a textureTarget should be a 2D texture target.
     2940    \i On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a
     2941    beginNativePainting / endNativePainting block, and uses the
     2942    engine with type QPaintEngine::OpenGL2, the function will draw the given
     2943    texture, \a textureId, to the given target rectangle, \a target,
     2944    respecting the current painter state. This will let you draw a texture
     2945    with the clip, transform, render hints, and composition mode set by the
     2946    painter. Note that the texture target needs to be GL_TEXTURE_2D for this
     2947    use case, and that this is the only supported use case under OpenGL ES 2.x.
     2948    \endlist
     2949
    26702950*/
    26712951void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget)
    26722952{
     2953#if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2)
     2954     if (d_ptr->active_engine &&
     2955         d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
     2956         QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine);
     2957         if (!eng->isNativePaintingActive()) {
     2958            QRectF src(0, 0, target.width(), target.height());
     2959            QSize size(target.width(), target.height());
     2960            if (eng->drawTexture(target, textureId, size, src))
     2961                return;
     2962        }
     2963     }
     2964#endif
     2965
    26732966#ifndef QT_OPENGL_ES_2
    26742967#ifdef QT_OPENGL_ES
     
    26992992    Q_UNUSED(textureId);
    27002993    Q_UNUSED(textureTarget);
    2701     qWarning("drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES/2.0");
     2994    qWarning("drawTexture() with OpenGL ES 2.0 requires an active OpenGL2 paint engine");
    27022995#endif
    27032996}
     
    27143007    \since 4.4
    27153008
    2716     Draws the given texture at the given \a point in OpenGL model
    2717     space. The \a textureTarget should be a 2D texture target.
    2718 
    2719     \note This function is not supported under OpenGL/ES.
     3009    This function supports the following use cases:
     3010
     3011    \list
     3012    \i By default it draws the given texture, \a textureId,
     3013    at the given \a point in OpenGL model space. The
     3014    \a textureTarget should be a 2D texture target.
     3015    \i If a painter is active, not inside a
     3016    beginNativePainting / endNativePainting block, and uses the
     3017    engine with type QPaintEngine::OpenGL2, the function will draw the given
     3018    texture, \a textureId, at the given \a point,
     3019    respecting the current painter state. This will let you draw a texture
     3020    with the clip, transform, render hints, and composition mode set by the
     3021    painter. Note that the texture target needs to be GL_TEXTURE_2D for this
     3022    use case.
     3023    \endlist
     3024
     3025    \note This function is not supported under any version of OpenGL ES.
    27203026*/
    27213027void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget)
    27223028{
    2723     // this would be ok on OpenGL ES 2.0, but currently we don't have a define for that
    27243029#ifdef QT_OPENGL_ES
    27253030    Q_UNUSED(point);
     
    27283033    qWarning("drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) not supported with OpenGL ES, use rect version instead");
    27293034#else
     3035
    27303036    const bool wasEnabled = glIsEnabled(GL_TEXTURE_2D);
    27313037    GLint oldTexture;
     
    27403046    glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth);
    27413047    glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight);
     3048
     3049    if (d_ptr->active_engine &&
     3050        d_ptr->active_engine->type() == QPaintEngine::OpenGL2) {
     3051        QGL2PaintEngineEx *eng = static_cast<QGL2PaintEngineEx*>(d_ptr->active_engine);
     3052        if (!eng->isNativePaintingActive()) {
     3053            QRectF dest(point, QSizeF(textureWidth, textureHeight));
     3054            QRectF src(0, 0, textureWidth, textureHeight);
     3055            QSize size(textureWidth, textureHeight);
     3056            if (eng->drawTexture(dest, textureId, size, src))
     3057                return;
     3058        }
     3059    }
    27423060
    27433061    qDrawTextureRect(QRectF(point, QSizeF(textureWidth, textureHeight)), textureWidth, textureHeight, textureTarget);
     
    31993517    \sa QGLWidget::renderText()
    32003518*/
     3519
    32013520
    32023521
     
    33213640    \l{Overpainting Example}{Overpainting} example.
    33223641
     3642    \section1 Threading
     3643
     3644    It is possible to render into a QGLWidget from another thread, but it
     3645    requires that all access to the GL context is safe guarded. The Qt GUI
     3646    thread will try to use the context in resizeEvent and paintEvent, so in
     3647    order for threaded rendering using a GL widget to work, these functions
     3648    need to be intercepted in the GUI thread and handled accordingly in the
     3649    application.
     3650
    33233651    \e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other
    33243652    countries.}
     
    34483776#endif
    34493777    delete d->glcx;
    3450 #if defined(Q_WGL)
     3778    d->glcx = 0;
     3779#if defined(Q_WS_WIN)
    34513780    delete d->olcx;
     3781    d->olcx = 0;
    34523782#endif
    34533783#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)
     
    38514181    }
    38524182
    3853 #if defined(QT_OPENGL_ES)
     4183#ifndef QT_NO_EGL
    38544184    // A re-parent is likely to destroy the X11 window and re-create it. It is important
    38554185    // that we free the EGL surface _before_ the winID changes - otherwise we can leak.
     
    38604190        // The window may have been re-created during re-parent or state change - if so, the EGL
    38614191        // surface will need to be re-created.
    3862         d->recreateEglSurface(false);
     4192        d->recreateEglSurface();
    38634193    }
    38644194#endif
     
    39024232#  endif
    39034233    }
     4234#elif defined(Q_OS_SYMBIAN)
     4235    // prevents errors on some systems, where we get a flush to a
     4236    // hidden widget
     4237    if (e->type() == QEvent::Hide) {
     4238        makeCurrent();
     4239        glFinish();
     4240        doneCurrent();
     4241    } else if (e->type() == QEvent::ParentChange) {
     4242        // if we've reparented a window that has the current context
     4243        // bound, we need to rebind that context to the new window id
     4244        if (d->glcx == QGLContext::currentContext())
     4245            makeCurrent();
     4246
     4247        if (testAttribute(Qt::WA_TranslucentBackground))
     4248            setContext(new QGLContext(d->glcx->requestedFormat(), this));
     4249    }
     4250
     4251    // A re-parent is likely to destroy the Symbian window and re-create it. It is important
     4252    // that we free the EGL surface _before_ the winID changes - otherwise we can leak.
     4253    if (e->type() == QEvent::ParentAboutToChange)
     4254        d->glcx->d_func()->destroyEglSurfaceForDevice();
     4255
     4256    if ((e->type() == QEvent::ParentChange) || (e->type() == QEvent::WindowStateChange)) {
     4257        // The window may have been re-created during re-parent or state change - if so, the EGL
     4258        // surface will need to be re-created.
     4259        d->recreateEglSurface();
     4260    }
     4261
    39044262#endif
    39054263
     
    41094467    if (!isValid())
    41104468        return;
     4469#ifdef Q_OS_SYMBIAN
     4470    // Crashes on Symbian if trying to render to invisible surfaces
     4471    if (!isVisible() && d->glcx->device()->devType() == QInternal::Widget)
     4472        return;
     4473#endif
    41114474    makeCurrent();
    41124475#ifndef QT_OPENGL_ES
     
    47665129    \since 4.4
    47675130
    4768     Draws the given texture, \a textureId to the given target rectangle,
    4769     \a target, in OpenGL model space. The \a textureTarget should be a 2D
    4770     texture target.
    4771 
    4772     Equivalent to the corresponding QGLContext::drawTexture().
     5131    Calls the corresponding QGLContext::drawTexture() with
     5132    \a target, \a textureId, and \a textureTarget for this
     5133    widget's context.
    47735134*/
    47745135void QGLWidget::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget)
     
    47905151    \since 4.4
    47915152
    4792     Draws the given texture, \a textureId, at the given \a point in OpenGL
    4793     model space. The \a textureTarget should be a 2D texture target.
    4794 
    4795     Equivalent to the corresponding QGLContext::drawTexture().
     5153    Calls the corresponding QGLContext::drawTexture() with
     5154    \a point, \a textureId, and \a textureTarget for this
     5155    widget's context.
    47965156*/
    47975157void QGLWidget::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget)
     
    48105170#endif
    48115171
    4812 #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
     5172#ifndef QT_OPENGL_ES_1
    48135173Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_2_engine)
    48145174#endif
     
    48205180Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine()
    48215181{
    4822 #if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
     5182#if defined(QT_OPENGL_ES_1)
    48235183    return qt_gl_engine();
    48245184#elif defined(QT_OPENGL_ES_2)
     
    49245284    if (extensions.match("GL_ARB_fragment_shader"))
    49255285        glExtensions |= FragmentShader;
     5286    if (extensions.match("GL_ARB_shader_objects"))
     5287        glExtensions |= FragmentShader;
    49265288    if (extensions.match("GL_ARB_texture_mirrored_repeat"))
    49275289        glExtensions |= MirroredRepeat;
     
    49385300    if (extensions.match("GL_ARB_pixel_buffer_object"))
    49395301        glExtensions |= PixelBufferObject;
     5302    if (extensions.match("GL_IMG_texture_format_BGRA8888"))
     5303        glExtensions |= BGRATextureFormat;
    49405304#if defined(QT_OPENGL_ES_2)
    49415305    glExtensions |= FramebufferObject;
     
    49435307    glExtensions |= FragmentShader;
    49445308#endif
    4945 #if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
     5309#if defined(QT_OPENGL_ES_1)
    49465310    if (extensions.match("GL_OES_framebuffer_object"))
    49475311        glExtensions |= FramebufferObject;
     
    49505314    if (extensions.match("GL_OES_packed_depth_stencil"))
    49515315        glExtensions |= PackedDepthStencil;
     5316    if (extensions.match("GL_OES_element_index_uint"))
     5317        glExtensions |= ElementIndexUint;
     5318    if (extensions.match("GL_OES_depth24"))
     5319        glExtensions |= Depth24;
     5320#else
     5321    glExtensions |= ElementIndexUint;
    49525322#endif
    49535323    if (extensions.match("GL_ARB_framebuffer_object")) {
     
    49695339}
    49705340
     5341
     5342class QGLDefaultExtensions
     5343{
     5344public:
     5345    QGLDefaultExtensions() {
     5346        QGLTemporaryContext tempContext;
     5347        extensions = QGLExtensions::currentContextExtensions();
     5348    }
     5349
     5350    QGLExtensions::Extensions extensions;
     5351};
     5352
     5353Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions)
     5354
    49715355/*
    49725356    Returns the GL extensions for the current QGLContext. If there is no
     
    49765360QGLExtensions::Extensions QGLExtensions::glExtensions()
    49775361{
    4978     QGLTemporaryContext *tmpContext = 0;
    4979     static bool cachedDefault = false;
    4980     static Extensions defaultExtensions = 0;
     5362    Extensions extensionFlags = 0;
    49815363    QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext());
    49825364
     
    49855367
    49865368    if (!currentCtx) {
    4987         if (cachedDefault) {
    4988             return defaultExtensions;
    4989         } else {
    4990             tmpContext = new QGLTemporaryContext;
    4991             cachedDefault = true;
    4992         }
    4993     }
    4994 
    4995     Extensions extensionFlags = currentContextExtensions();
    4996     if (currentCtx) {
     5369        extensionFlags = qtDefaultExtensions()->extensions;
     5370    } else {
     5371        extensionFlags = currentContextExtensions();
    49975372        currentCtx->d_func()->extension_flags_cached = true;
    49985373        currentCtx->d_func()->extension_flags = extensionFlags;
    4999     } else {
    5000         defaultExtensions = extensionFlags;
    5001     }
    5002 
    5003     if (tmpContext)
    5004         delete tmpContext;
    5005 
     5374    }
    50065375    return extensionFlags;
    50075376}
     
    50385407{
    50395408    if (qt_gl_lib_name()->isNull()) {
    5040 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
     5409#ifdef Q_WS_MAC
     5410        return QLatin1String("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib");
     5411#else
     5412# if defined(QT_OPENGL_ES_1)
     5413        return QLatin1String("GLES_CM");
     5414# elif defined(QT_OPENGL_ES_2)
     5415        return QLatin1String("GLESv2");
     5416# else
    50415417        return QLatin1String("GL");
    5042 #else // Q_WS_MAC
    5043         return QLatin1String("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib");
    5044 #endif
     5418# endif
     5419#endif // defined Q_WS_MAC
    50455420    }
    50465421    return *qt_gl_lib_name();
Note: See TracChangeset for help on using the changeset viewer.