Ignore:
Timestamp:
Mar 8, 2010, 12:52:58 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.2 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    125125Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance)
    126126
    127 QGLExtensions::Extensions QGLExtensions::glExtensions = 0;
    128 bool QGLExtensions::nvidiaFboNeedsFinish = false;
    129 
    130127Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy)
    131128QGLSignalProxy *QGLSignalProxy::instance()
     
    155152        static bool mac_x1600_check_done = false;
    156153        if (!mac_x1600_check_done) {
    157             QGLWidget *tmp = 0;
    158             if (!QGLContext::currentContext()) {
    159                 tmp = new QGLWidget();
    160                 tmp->makeCurrent();
    161             }
     154            QGLTemporaryContext *tmp = 0;
     155            if (!QGLContext::currentContext())
     156                tmp = new QGLTemporaryContext();
    162157            if (strstr((char *) glGetString(GL_RENDERER), "X1600"))
    163158                engineType = QPaintEngine::OpenGL;
     
    179174            // use GL 2.0.
    180175            if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)
    181                 && (QGLExtensions::glExtensions & QGLExtensions::FragmentShader)
     176                && (QGLExtensions::glExtensions() & QGLExtensions::FragmentShader)
    182177                && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty())
    183178                engineType = QPaintEngine::OpenGL2;
     
    12511246    static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None;
    12521247    QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext());
    1253     QGLWidget *dummy = 0;
     1248    QGLTemporaryContext *tmpContext = 0;
    12541249
    12551250    if (currentCtx && currentCtx->d_func()->version_flags_cached)
     
    12621257            if (!hasOpenGL())
    12631258                return defaultVersionFlags;
    1264             dummy = new QGLWidget;
    1265             dummy->makeCurrent(); // glGetString() needs a current context
     1259            tmpContext = new QGLTemporaryContext;
    12661260            cachedDefault = true;
    12671261        }
     
    12741268        currentCtx->d_func()->version_flags = versionFlags;
    12751269    }
    1276     if (dummy) {
     1270    if (tmpContext) {
    12771271        defaultVersionFlags = versionFlags;
    1278         delete dummy;
     1272        delete tmpContext;
    12791273    }
    12801274
     
    14371431}
    14381432
     1433const QGLContext *qt_gl_transfer_context(const QGLContext *ctx)
     1434{
     1435    if (!ctx)
     1436        return 0;
     1437    QList<const QGLContext *> shares
     1438        (QGLContextPrivate::contextGroup(ctx)->shares());
     1439    if (shares.size() >= 2)
     1440        return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0);
     1441    else
     1442        return 0;
     1443}
     1444
    14391445QGLContextPrivate::~QGLContextPrivate()
    14401446{
     
    14821488    version_flags_cached = false;
    14831489    version_flags = QGLFormat::OpenGL_Version_None;
     1490    extension_flags_cached = false;
     1491    extension_flags = 0;
    14841492    current_fbo = 0;
    14851493    default_fbo = 0;
    14861494    active_engine = 0;
     1495    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
     1496        vertexAttributeArraysEnabledState[i] = false;
    14871497}
    14881498
     
    15421552QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha)
    15431553{
    1544     QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32);
     1554    QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32);
    15451555    int w = size.width();
    15461556    int h = size.height();
     
    15811591    qt_gl_texture_cache = this;
    15821592
    1583     QImagePixmapCleanupHooks::instance()->addPixmapModificationHook(cleanupTextures);
    1584 #ifdef Q_WS_X11
    1585     QImagePixmapCleanupHooks::instance()->addPixmapDestructionHook(cleanupPixmapSurfaces);
    1586 #endif
     1593    QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTextures);
     1594    QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction);
    15871595    QImagePixmapCleanupHooks::instance()->addImageHook(imageCleanupHook);
    15881596}
     
    15921600    qt_gl_texture_cache = 0;
    15931601
    1594     QImagePixmapCleanupHooks::instance()->removePixmapModificationHook(cleanupTextures);
    1595 #ifdef Q_WS_X11
    1596     QImagePixmapCleanupHooks::instance()->removePixmapDestructionHook(cleanupPixmapSurfaces);
    1597 #endif
     1602    QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTextures);
     1603    QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction);
    15981604    QImagePixmapCleanupHooks::instance()->removeImageHook(imageCleanupHook);
    15991605}
     
    16631669
    16641670
    1665 void QGLTextureCache::cleanupTextures(QPixmap* pixmap)
     1671void QGLTextureCache::cleanupTextures(QPixmapData* pmd)
    16661672{
    16671673    // ### remove when the GL texture cache becomes thread-safe
    16681674    if (qApp->thread() == QThread::currentThread()) {
    1669         const qint64 cacheKey = pixmap->cacheKey();
     1675        const qint64 cacheKey = pmd->cacheKey();
    16701676        QGLTexture *texture = instance()->getTexture(cacheKey);
    16711677        if (texture && texture->options & QGLContext::MemoryManagedBindOption)
     
    16741680}
    16751681
     1682void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd)
     1683{
     1684    // Remove any bound textures first:
     1685    cleanupTextures(pmd);
     1686    Q_ASSERT(instance()->getTexture(pmd->cacheKey()) == 0);
     1687
    16761688#if defined(Q_WS_X11)
    1677 void QGLTextureCache::cleanupPixmapSurfaces(QPixmap* pixmap)
    1678 {
    1679     // Remove any bound textures first:
    1680     cleanupTextures(pixmap);
    1681 
    1682     QPixmapData *pd = pixmap->data_ptr().data();
    1683     if (pd->classId() == QPixmapData::X11Class) {
    1684         Q_ASSERT(pd->ref == 1); // Make sure reference counting isn't broken
    1685         QGLContextPrivate::destroyGlSurfaceForPixmap(pd);
    1686     }
    1687 }
    1688 #endif
     1689    if (pmd->classId() == QPixmapData::X11Class) {
     1690        Q_ASSERT(pmd->ref == 0); // Make sure reference counting isn't broken
     1691        QGLContextPrivate::destroyGlSurfaceForPixmap(pmd);
     1692    }
     1693#endif
     1694}
    16891695
    16901696void QGLTextureCache::deleteIfEmpty()
     
    17301736#endif
    17311737
    1732 Q_GLOBAL_STATIC(QGLShareRegister, _qgl_share_reg)
    1733 Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg()
    1734 {
    1735     return _qgl_share_reg();
    1736 }
    1737 
    17381738/*!
    17391739    \class QGLContext
     
    18741874{
    18751875}
     1876
     1877#define ctx q_ptr
     1878void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled)
     1879{
     1880    Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT);
     1881    Q_ASSERT(glEnableVertexAttribArray);
     1882
     1883    if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
     1884        glDisableVertexAttribArray(arrayIndex);
     1885
     1886    if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled)
     1887        glEnableVertexAttribArray(arrayIndex);
     1888
     1889    vertexAttributeArraysEnabledState[arrayIndex] = enabled;
     1890}
     1891
     1892void QGLContextPrivate::syncGlState()
     1893{
     1894    Q_ASSERT(glEnableVertexAttribArray);
     1895    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) {
     1896        if (vertexAttributeArraysEnabledState[i])
     1897            glEnableVertexAttribArray(i);
     1898        else
     1899            glDisableVertexAttribArray(i);
     1900    }
     1901
     1902}
     1903#undef ctx
     1904
    18761905
    18771906/*!
     
    21112140
    21122141    QImage img = image;
    2113     if (!(QGLExtensions::glExtensions & QGLExtensions::NPOTTextures)
     2142    if (!(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures)
    21142143        && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0)
    21152144        && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height())))
     
    21332162#endif
    21342163    if (glFormat.directRendering()
    2135         && (QGLExtensions::glExtensions & QGLExtensions::GenerateMipmap)
     2164        && (QGLExtensions::glExtensions() & QGLExtensions::GenerateMipmap)
    21362165        && target == GL_TEXTURE_2D
    21372166        && (options & QGLContext::MipmapBindOption))
     
    21612190    GLenum externalFormat;
    21622191    GLuint pixel_type;
    2163     if (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) {
     2192    if (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) {
    21642193        externalFormat = GL_BGRA;
    2165         pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV;
     2194        if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2)
     2195            pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV;
     2196        else
     2197            pixel_type = GL_UNSIGNED_BYTE;
    21662198    } else {
    21672199        externalFormat = GL_RGBA;
     
    22422274    }
    22432275#ifdef QT_OPENGL_ES
    2244     // OpenGL/ES requires that the internal and external formats be identical.
    2245     // This is typically used to convert GL_RGBA into GL_BGRA.
    2246     // Also, we need to use GL_UNSIGNED_BYTE when the format is GL_BGRA.
     2276    // OpenGL/ES requires that the internal and external formats be
     2277    // identical.
    22472278    internalFormat = externalFormat;
    2248     if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV)
    2249         pixel_type = GL_UNSIGNED_BYTE;
    22502279#endif
    22512280#ifdef QGL_BIND_TEXTURE_DEBUG
     
    29552984    }
    29562985    if (d->sharing)  // ok, we managed to share
    2957         qgl_share_reg()->addShare(this, shareContext);
     2986        QGLContextGroup::addShare(this, shareContext);
    29582987    return d->valid;
    29592988}
     
    43614390   text is drawn.
    43624391
     4392   \note This function can only be used inside a
     4393   QPainter::beginNativePainting()/QPainter::endNativePainting() block
     4394   if the default OpenGL paint engine is QPaintEngine::OpenGL. To make
     4395   QPaintEngine::OpenGL the default GL engine, call
     4396   QGL::setPreferredPaintEngine(QPaintEngine::OpenGL) before the
     4397   QApplication constructor.
     4398
    43634399   \l{Overpainting Example}{Overpaint} with QPainter::drawText() instead.
    43644400*/
     
    48324868#endif // QT3_SUPPORT
    48334869
    4834 void QGLExtensions::init_extensions()
     4870/*
     4871    Returns the GL extensions for the current context.
     4872*/
     4873QGLExtensions::Extensions QGLExtensions::currentContextExtensions()
    48354874{
    48364875    QGLExtensionMatcher extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
     4876    Extensions glExtensions;
    48374877
    48384878    if (extensions.match("GL_ARB_texture_rectangle"))
     
    48954935    if (extensions.match("GL_EXT_bgra"))
    48964936        glExtensions |= BGRATextureFormat;
     4937
     4938    return glExtensions;
     4939}
     4940
     4941/*
     4942    Returns the GL extensions for the current QGLContext. If there is no
     4943    current QGLContext, a default context will be created and the extensions
     4944    for that context will be returned instead.
     4945*/
     4946QGLExtensions::Extensions QGLExtensions::glExtensions()
     4947{
     4948    QGLTemporaryContext *tmpContext = 0;
     4949    static bool cachedDefault = false;
     4950    static Extensions defaultExtensions = 0;
     4951    QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext());
     4952
     4953    if (currentCtx && currentCtx->d_func()->extension_flags_cached)
     4954        return currentCtx->d_func()->extension_flags;
     4955
     4956    if (!currentCtx) {
     4957        if (cachedDefault) {
     4958            return defaultExtensions;
     4959        } else {
     4960            tmpContext = new QGLTemporaryContext;
     4961            cachedDefault = true;
     4962        }
     4963    }
     4964
     4965    Extensions extensionFlags = currentContextExtensions();
     4966    if (currentCtx) {
     4967        currentCtx->d_func()->extension_flags_cached = true;
     4968        currentCtx->d_func()->extension_flags = extensionFlags;
     4969    } else {
     4970        defaultExtensions = extensionFlags;
     4971    }
     4972
     4973    if (tmpContext)
     4974        delete tmpContext;
     4975
     4976    return extensionFlags;
    48974977}
    48984978
     
    49064986    glDevice.setWidget(q);
    49074987
    4908     QGLExtensions::init();
    49094988    glcx = 0;
    49104989    autoSwap = true;
     
    49164995    if (!glcx)
    49174996        glcx = new QGLContext(QGLFormat::defaultFormat(), q);
    4918 
    4919     q->setAttribute(Qt::WA_NoSystemBackground);
    49204997}
    49214998
     
    49415018#endif
    49425019
    4943 void QGLShareRegister::addShare(const QGLContext *context, const QGLContext *share) {
     5020void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) {
    49445021    Q_ASSERT(context && share);
    49455022    if (context->d_ptr->group == share->d_ptr->group)
     
    49625039}
    49635040
    4964 QList<const QGLContext *> QGLShareRegister::shares(const QGLContext *context) {
    4965     return context->d_ptr->group->m_shares;
    4966 }
    4967 
    4968 void QGLShareRegister::removeShare(const QGLContext *context) {
     5041void QGLContextGroup::removeShare(const QGLContext *context) {
    49695042    // Remove the context from the group.
    49705043    QGLContextGroup *group = context->d_ptr->group;
     
    51615234#if !defined(QT_OPENGL_ES)
    51625235    if (!glCompressedTexImage2D) {
    5163         if (!(QGLExtensions::glExtensions & QGLExtensions::TextureCompression)) {
     5236        if (!(QGLExtensions::glExtensions() & QGLExtensions::TextureCompression)) {
    51645237            qWarning("QGLContext::bindTexture(): The GL implementation does "
    51655238                     "not support texture compression extensions.");
     
    52005273
    52015274    // Bail out if the necessary extension is not present.
    5202     if (!(QGLExtensions::glExtensions & QGLExtensions::DDSTextureCompression)) {
     5275    if (!(QGLExtensions::glExtensions() & QGLExtensions::DDSTextureCompression)) {
    52035276        qWarning("QGLContext::bindTexture(): DDS texture compression is not supported.");
    52045277        return QSize();
     
    53105383    // Bail out if the necessary extension is not present.
    53115384    if (textureFormat == GL_ETC1_RGB8_OES) {
    5312         if (!(QGLExtensions::glExtensions &
     5385        if (!(QGLExtensions::glExtensions() &
    53135386                    QGLExtensions::ETC1TextureCompression)) {
    53145387            qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported.");
     
    53165389        }
    53175390    } else {
    5318         if (!(QGLExtensions::glExtensions &
     5391        if (!(QGLExtensions::glExtensions() &
    53195392                    QGLExtensions::PVRTCTextureCompression)) {
    53205393            qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported.");
Note: See TracChangeset for help on using the changeset viewer.