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_win.cpp

    r651 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)
     
    123123#endif
    124124
     125#ifndef WGL_ARB_create_context
     126#define WGL_CONTEXT_MAJOR_VERSION_ARB               0x2091
     127#define WGL_CONTEXT_MINOR_VERSION_ARB               0x2092
     128#define WGL_CONTEXT_LAYER_PLANE_ARB                 0x2093
     129#define WGL_CONTEXT_FLAGS_ARB                       0x2094
     130#define WGL_CONTEXT_PROFILE_MASK_ARB                0x9126
     131#define WGL_CONTEXT_DEBUG_BIT_ARB                   0x0001
     132#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB      0x0002
     133#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB            0x0001
     134#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB   0x0002
     135// Error codes returned by GetLastError().
     136#define ERROR_INVALID_VERSION_ARB                   0x2095
     137#define ERROR_INVALID_PROFILE_ARB                   0x2096
     138#endif
     139
     140#ifndef GL_VERSION_3_2
     141#define GL_CONTEXT_PROFILE_MASK                     0x9126
     142#define GL_MAJOR_VERSION                            0x821B
     143#define GL_MINOR_VERSION                            0x821C
     144#define GL_NUM_EXTENSIONS                           0x821D
     145#define GL_CONTEXT_FLAGS                            0x821E
     146#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT      0x0001
     147#endif
     148
    125149QT_BEGIN_NAMESPACE
    126150
     
    683707}
    684708
     709static bool qgl_create_context(HDC hdc, QGLContextPrivate *d, QGLContextPrivate *shareContext)
     710{
     711    d->rc = 0;
     712
     713    typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTATTRIBSARB)(HDC, HGLRC, const int *);
     714    PFNWGLCREATECONTEXTATTRIBSARB wglCreateContextAttribsARB =
     715        (PFNWGLCREATECONTEXTATTRIBSARB) wglGetProcAddress("wglCreateContextAttribsARB");
     716    if (wglCreateContextAttribsARB) {
     717        int attributes[11];
     718        int attribIndex = 0;
     719        const int major = d->reqFormat.majorVersion();
     720        const int minor = d->reqFormat.minorVersion();
     721        attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
     722        attributes[attribIndex++] = major;
     723        attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB;
     724        attributes[attribIndex++] = minor;
     725
     726        if (major >= 3 && !d->reqFormat.testOption(QGL::DeprecatedFunctions)) {
     727            attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB;
     728            attributes[attribIndex++] = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
     729        }
     730
     731        if ((major == 3 && minor >= 2) || major > 3) {
     732            switch (d->reqFormat.profile()) {
     733            case QGLFormat::NoProfile:
     734                break;
     735            case QGLFormat::CoreProfile:
     736                attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
     737                attributes[attribIndex++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
     738                break;
     739            case QGLFormat::CompatibilityProfile:
     740                attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB;
     741                attributes[attribIndex++] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
     742                break;
     743            default:
     744                qWarning("QGLContext::chooseContext(): Context profile not supported.");
     745                return false;
     746            }
     747        }
     748
     749        if (d->reqFormat.plane() != 0) {
     750            attributes[attribIndex++] = WGL_CONTEXT_LAYER_PLANE_ARB;
     751            attributes[attribIndex++] = d->reqFormat.plane();
     752        }
     753
     754        attributes[attribIndex++] = 0; // Terminate list.
     755        d->rc = wglCreateContextAttribsARB(hdc, shareContext && shareContext->valid
     756                                           ? shareContext->rc : 0, attributes);
     757        if (d->rc) {
     758            if (shareContext)
     759                shareContext->sharing = d->sharing = true;
     760            return true;
     761        }
     762    }
     763
     764    d->rc = wglCreateLayerContext(hdc, d->reqFormat.plane());
     765    if (d->rc && shareContext && shareContext->valid)
     766        shareContext->sharing = d->sharing = wglShareLists(shareContext->rc, d->rc);
     767    return d->rc != 0;
     768}
     769
     770void QGLContextPrivate::updateFormatVersion()
     771{
     772    const GLubyte *s = glGetString(GL_VERSION);
     773
     774    if (!(s && s[0] >= '0' && s[0] <= '9' && s[1] == '.' && s[2] >= '0' && s[2] <= '9')) {
     775        if (!s)
     776            qWarning("QGLContext::chooseContext(): OpenGL version string is null.");
     777        else
     778            qWarning("QGLContext::chooseContext(): Unexpected OpenGL version string format.");
     779        glFormat.setVersion(0, 0);
     780        glFormat.setProfile(QGLFormat::NoProfile);
     781        glFormat.setOption(QGL::DeprecatedFunctions);
     782        return;
     783    }
     784
     785    int major = s[0] - '0';
     786    int minor = s[2] - '0';
     787    glFormat.setVersion(major, minor);
     788
     789    if (major < 3) {
     790        glFormat.setProfile(QGLFormat::NoProfile);
     791        glFormat.setOption(QGL::DeprecatedFunctions);
     792    } else {
     793        GLint value = 0;
     794        if (major > 3 || minor >= 2)
     795            glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value);
     796
     797        switch (value) {
     798        case WGL_CONTEXT_CORE_PROFILE_BIT_ARB:
     799            glFormat.setProfile(QGLFormat::CoreProfile);
     800            break;
     801        case WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
     802            glFormat.setProfile(QGLFormat::CompatibilityProfile);
     803            break;
     804        default:
     805            glFormat.setProfile(QGLFormat::NoProfile);
     806            break;
     807        }
     808
     809        glGetIntegerv(GL_CONTEXT_FLAGS, &value);
     810        if (value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
     811            glFormat.setOption(QGL::NoDeprecatedFunctions);
     812        else
     813            glFormat.setOption(QGL::DeprecatedFunctions);
     814    }
     815}
     816
    685817bool QGLContext::chooseContext(const QGLContext* shareContext)
    686818{
     819    QGLContextPrivate *share = shareContext ? const_cast<QGLContext *>(shareContext)->d_func() : 0;
     820
    687821    Q_D(QGLContext);
    688822    // workaround for matrox driver:
     
    742876        }
    743877
    744         d->rc = wglCreateLayerContext(myDc, d->glFormat.plane());
    745         if (!d->rc) {
     878        if (!qgl_create_context(myDc, d, share)) {
    746879            qwglError("QGLContext::chooseContext()", "CreateLayerContext");
    747880            result = false;
     
    793926            d->cmap->setEntry(lpfd.crTransparent, qRgb(1, 2, 3));//, QGLCmap::Reserved);
    794927        }
    795 
    796         if (shareContext && shareContext->isValid()) {
    797             QGLContext *share = const_cast<QGLContext *>(shareContext);
    798             d->sharing = (wglShareLists(shareContext->d_func()->rc, d->rc) != 0);
    799             share->d_func()->sharing = d->sharing;
    800         }
    801 
    802         goto end;
    803     }
    804     {
     928    } else {
    805929        PIXELFORMATDESCRIPTOR pfd;
    806930        PIXELFORMATDESCRIPTOR realPfd;
     
    841965        }
    842966
    843         if (!(d->rc = wglCreateLayerContext(myDc, 0))) {
     967        if (!qgl_create_context(myDc, d, share)) {
    844968            qwglError("QGLContext::chooseContext()", "wglCreateContext");
    845969            result = false;
    846970            goto end;
    847         }
    848 
    849         if (shareContext && shareContext->isValid()) {
    850             d->sharing = (wglShareLists(shareContext->d_func()->rc, d->rc) != 0);
    851             const_cast<QGLContext *>(shareContext)->d_func()->sharing = d->sharing;
    852971        }
    853972
     
    866985    // vblanking
    867986    wglMakeCurrent(myDc, d->rc);
     987    if (d->rc)
     988        d->updateFormatVersion();
     989
    868990    typedef BOOL (APIENTRYP PFNWGLSWAPINTERVALEXT) (int interval);
    869991    typedef int (APIENTRYP PFNWGLGETSWAPINTERVALEXT) (void);
     
    9211043        iAttributes[i++] = TRUE;
    9221044        iAttributes[i++] = WGL_COLOR_BITS_ARB;
    923         iAttributes[i++] = 32;
     1045        iAttributes[i++] = 24;
    9241046        iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB;
    9251047        iAttributes[i++] = d->glFormat.doubleBuffer();
     
    11591281{
    11601282    Q_D(QGLContext);
    1161     if (d->rc == wglGetCurrentContext() || !d->valid)        // already current
     1283    if (d->rc == wglGetCurrentContext() || !d->valid)       // already current
    11621284        return;
     1285
    11631286    if (d->win) {
    11641287        d->dc = GetDC(d->win);
Note: See TracChangeset for help on using the changeset viewer.