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) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5050#define INT32 dummy_INT32
    5151#define INT8 dummy_INT8
    52 #if !defined(QT_OPENGL_ES)
     52#if
    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
    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
     231
     232
    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
     244
     245
    239246
    240247    \sa {Sample Buffers Example}
     
    508515    flicker-free drawing and often better performance.
    509516
     517
     518
     519
    510520    \sa doubleBuffer(), QGLContext::swapBuffers(),
    511521    QGLWidget::swapBuffers()
     
    766776    }
    767777    d->numSamples = numSamples;
     778
    768779}
    769780
     
    904915    }
    905916    d->depthSize = size;
     917
    906918}
    907919
     
    10171029    }
    10181030    d->alphaSize = size;
    1019     setOption(QGL::AlphaChannel);
     1031    set);
    10201032}
    10211033
     
    10441056    }
    10451057    d->accumSize = size;
     1058
    10461059}
    10471060
     
    10691082    }
    10701083    d->stencilSize = size;
     1084
    10711085}
    10721086
     
    10801094   return d->stencilSize;
    10811095}
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
     1120
     1121
     1122
     1123
     1124
     1125
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
     1136
     1137
     1138
     1139
     1140
     1141
     1142
     1143
     1144
     1145
     1146
     1147
     1148
     1149
     1150
     1151
     1152
     1153
     1154
     1155
     1156
     1157
     1158
     1159
     1160
     1161
     1162
     1163
     1164
     1165
     1166
     1167
     1168
     1169
     1170
     1171
     1172
     1173
     1174
     1175
     1176
     1177
     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
     1258
     1259
     1260
     1261
     1262
     1263
     1264
     1265
     1266
     1267
     1268
     1269
     1270
     1271
     1272
     1273
     1274
     1275
     1276
     1277
     1278
     1279
     1280
     1281
     1282
     1283
     1284
     1285
     1286
     1287
     1288
     1289
     1290
     1291
     1292
     1293
     1294
     1295
     1296
     1297
     1298
     1299
     1300
     1301
     1302
     1303
     1304
     1305
     1306
    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
     1340
     1341
     1342
     1343
     1344
     1345
     1346
     1347
    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
     1575
     1576
     1577
     1578
     1579
     1580
     1581
     1582
     1583
     1584
     1585
     1586
     1587
     1588
     1589
     1590
    14021591
    14031592/*****************************************************************************
    14041593  QGLContext implementation
    14051594 *****************************************************************************/
     1595
     1596
     1597
     1598
     1599
     1600
    14061601
    14071602QGLContextGroup::~QGLContextGroup()
     
    14141609        guard = guard->m_next;
    14151610    }
     1611
    14161612}
    14171613
     
    14471643}
    14481644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
    14491654QGLContextPrivate::~QGLContextPrivate()
    14501655{
     
    14531658        delete group;
    14541659    }
     1660
     1661
    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
     1708
     1709
     1710
     1711
     1712
     1713
     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
    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<> 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 &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    wether 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
    18852100    Q_ASSERT(glEnableVertexAttribArray);
     2101
    18862102
    18872103    if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
     
    18962112void QGLContextPrivate::syncGlState()
    18972113{
     2114
    18982115    Q_ASSERT(glEnableVertexAttribArray);
     2116
    18992117    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
    19002118        if (vertexAttributeArraysEnabledState[i])
     
    19072125#undef ctx
    19082126
     2127
     2128
     2129
     2130
     2131
     2132
     2133
    19092134
    19102135/*!
     
    20612286}
    20622287
     2288
     2289
     2290
     2291
     2292
     2293
     2294
    20632295QImage QGLContextPrivate::convertToGLFormat(const QImage &image, bool force_premul,
    20642296                                            GLenum texture_format)
     
    20772309                                           QGLContext::BindOptions options)
    20782310{
     2311
     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\n",
     2370           image.width(), image.height(), internalFormat, int(options));
    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
     2428
     2429
    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(" - convert 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(" - convert 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(" - convert 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(" - convert 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
     2507
     2508
    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
     2518
     2519
    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);
    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 \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(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, *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] = ;
     2867    array[1] = ;
     2868    array[2] = ;
     2869    array[3] = ;
     2870    array[4] = ;
     2871    array[5] = ;
     2872    array[6] = ;
     2873    array[7] = ;
     2874}
     2875
     2876void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, *array)
     2877{
     2878    array[0] = ;
     2879    array[1] = ;
     2880    array[2] = ;
     2881    array[3] = ;
     2882    array[4] = ;
     2883    array[5] = ;
     2884    array[6] = ;
     2885    array[7] = ;
    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    ;
     2893    ;
    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 = t(textureWidth);
     2907        ty = t(textureHeight);
     2908    }
     2909#endif
     2910
     2911    texCoordArray[4*2] = {
    26432912        0, ty, tx, ty, tx, 0, 0, 0
    26442913    };
    26452914
    2646     q_vertexType vertexArray[4*2];
     2915    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, , 0, vertexArray);
     2919    glTexCoordPointer(2, , 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
     2954
     2955
     2956
     2957
     2958
     2959
     2960
     2961
     2962
     2963
     2964
     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(");
    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
     3050
     3051
     3052
     3053
     3054
     3055
     3056
     3057
     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
     3643
     3644
     3645
     3646
     3647
     3648
     3649
     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
    34523782#endif
    34533783#if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)
     
    38514181    }
    38524182
    3853 #if defined(QT_OPENGL_ES)
     4183#if
    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
     4235
     4236
     4237
     4238
     4239
     4240
     4241
     4242
     4243
     4244
     4245
     4246
     4247
     4248
     4249
     4250
     4251
     4252
     4253
     4254
     4255
     4256
     4257
     4258
     4259
     4260
     4261
    39044262#endif
    39054263
     
    41094467    if (!isValid())
    41104468        return;
     4469
     4470
     4471
     4472
     4473
    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#if
    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
     5287
    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
     5303
    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
     5317
     5318
     5319
     5320
     5321
    49525322#endif
    49535323    if (extensions.match("GL_ARB_framebuffer_object")) {
     
    49695339}
    49705340
     5341
     5342
     5343
     5344
     5345
     5346
     5347
     5348
     5349
     5350
     5351
     5352
     5353
     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.