Changeset 651 for trunk/src/opengl


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:
68 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/gl2paintengineex/qgl2pexvertexarray.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)
  • trunk/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h

    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)
  • trunk/src/opengl/gl2paintengineex/qglcustomshaderstage.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)
  • trunk/src/opengl/gl2paintengineex/qglcustomshaderstage_p.h

    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)
  • trunk/src/opengl/gl2paintengineex/qglengineshadermanager.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)
     
    185185    simpleShaderProg->addShader(fragShader);
    186186    simpleShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
     187    simpleShaderProg->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
     188    simpleShaderProg->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
     189    simpleShaderProg->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR);
    187190    simpleShaderProg->link();
    188191    if (!simpleShaderProg->isLinked()) {
     
    217220    }
    218221
     222}
     223
     224QGLEngineSharedShaders::~QGLEngineSharedShaders()
     225{
     226    QList<QGLEngineShaderProg*>::iterator itr;
     227    for (itr = cachedPrograms.begin(); itr != cachedPrograms.end(); ++itr)
     228        delete *itr;
     229
     230    if (blitShaderProg) {
     231        delete blitShaderProg;
     232        blitShaderProg = 0;
     233    }
     234
     235    if (simpleShaderProg) {
     236        delete simpleShaderProg;
     237        simpleShaderProg = 0;
     238    }
    219239}
    220240
     
    308328        if (newProg->useOpacityAttribute)
    309329            newProg->program->bindAttributeLocation("opacityArray", QT_OPACITY_ATTR);
     330        if (newProg->usePmvMatrix) {
     331            newProg->program->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
     332            newProg->program->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
     333            newProg->program->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR);
     334        }
    310335
    311336        newProg->program->link();
     
    394419}
    395420
    396 GLuint QGLEngineShaderManager::getUniformLocation(const Uniform id)
     421GLuint QGLEngineShaderManager::getUniformLocation(Uniform id)
    397422{
    398423    if (!currentShaderProg)
     
    408433        "globalOpacity",
    409434        "depth",
    410         "pmvMatrix",
    411435        "maskTexture",
    412436        "fragmentColor",
     
    429453
    430454
    431 void QGLEngineShaderManager::optimiseForBrushTransform(const QTransform::TransformationType transformType)
     455void QGLEngineShaderManager::optimiseForBrushTransform(QTransform::TransformationType transformType)
    432456{
    433457    Q_UNUSED(transformType); // Currently ignored
     
    506530        return currentShaderProg->program;
    507531    else
    508         return simpleProgram();
     532        return sharedShaders->simpleProgram();
     533}
     534
     535void QGLEngineShaderManager::useSimpleProgram()
     536{
     537    sharedShaders->simpleProgram()->bind();
     538    QGLContextPrivate* ctx_d = ctx->d_func();
     539    ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
     540    ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false);
     541    ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false);
     542    shaderProgNeedsChanging = true;
     543}
     544
     545void QGLEngineShaderManager::useBlitProgram()
     546{
     547    sharedShaders->blitProgram()->bind();
     548    QGLContextPrivate* ctx_d = ctx->d_func();
     549    ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
     550    ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, true);
     551    ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false);
     552    shaderProgNeedsChanging = true;
    509553}
    510554
     
    707751    requiredProgram.useTextureCoords = texCoords;
    708752    requiredProgram.useOpacityAttribute = (opacityMode == AttributeOpacity);
     753    requiredProgram.usePmvMatrix = true;
    709754
    710755    // At this point, requiredProgram is fully populated so try to find the program in the cache
     
    717762    }
    718763
     764    // Make sure all the vertex attribute arrays the program uses are enabled (and the ones it
     765    // doesn't use are disabled)
     766    QGLContextPrivate* ctx_d = ctx->d_func();
     767    ctx_d->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, true);
     768    ctx_d->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, currentShaderProg->useTextureCoords);
     769    ctx_d->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, currentShaderProg->useOpacityAttribute);
     770
    719771    shaderProgNeedsChanging = false;
    720772    return true;
  • trunk/src/opengl/gl2paintengineex/qglengineshadermanager_p.h

    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)
     
    254254static const GLuint QT_TEXTURE_COORDS_ATTR = 1;
    255255static const GLuint QT_OPACITY_ATTR = 2;
     256static const GLuint QT_PMV_MATRIX_1_ATTR = 3;
     257static const GLuint QT_PMV_MATRIX_2_ATTR = 4;
     258static const GLuint QT_PMV_MATRIX_3_ATTR = 5;
    256259
    257260class QGLEngineShaderProg;
     
    345348
    346349    QGLEngineSharedShaders(const QGLContext *context);
     350    ~QGLEngineSharedShaders();
    347351
    348352    QGLShaderProgram *simpleProgram() { return simpleShaderProg; }
     
    397401    bool                useTextureCoords;
    398402    bool                useOpacityAttribute;
     403    bool                usePmvMatrix;
    399404
    400405    bool operator==(const QGLEngineShaderProg& other) {
     
    431436        GlobalOpacity,
    432437        Depth,
    433         PmvMatrix,
    434438        MaskTexture,
    435439        FragmentColor,
     
    455459    //    1) May not have to apply perspective-correction
    456460    //    2) Can use lower precision for matrix
    457     void optimiseForBrushTransform(const QTransform::TransformationType transformType);
     461    void optimiseForBrushTransform(QTransform::TransformationType transformType);
    458462    void setSrcPixelType(Qt::BrushStyle);
    459463    void setSrcPixelType(PixelSrcType); // For non-brush sources, like pixmaps & images
     
    464468    void removeCustomStage();
    465469
    466     GLuint getUniformLocation(const Uniform id);
     470    GLuint getUniformLocation(Uniform id);
    467471
    468472    void setDirty(); // someone has manually changed the current shader program
    469473    bool useCorrectShaderProg(); // returns true if the shader program needed to be changed
     474
     475    void useSimpleProgram();
     476    void useBlitProgram();
    470477
    471478    QGLShaderProgram* currentProgram(); // Returns pointer to the shader the manager has chosen
  • trunk/src/opengl/gl2paintengineex/qglengineshadersource_p.h

    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)
     
    6464
    6565
    66 static const char* const qglslMainVertexShader = "\
    67     uniform   highp float   depth;\
    68     void setPosition();\
    69     void main(void)\
    70     {\
    71             setPosition();\
    72             gl_Position.z = depth * gl_Position.w;\
    73     }";
    74 
    75 static const char* const qglslMainWithTexCoordsVertexShader = "\
    76     attribute highp  vec2 textureCoordArray; \
    77     varying   highp  vec2 textureCoords; \
    78     uniform   highp float   depth;\
    79     void setPosition();\
    80     void main(void) \
    81     {\
    82             setPosition();\
    83             gl_Position.z = depth * gl_Position.w;\
    84             textureCoords = textureCoordArray; \
    85     }";
    86 
    87 static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\
    88     attribute highp vec2  textureCoordArray; \
    89     attribute lowp  float opacityArray; \
    90     varying   highp vec2  textureCoords; \
    91     varying   lowp  float opacity; \
    92     uniform   highp float depth; \
    93     void setPosition(); \
    94     void main(void) \
    95     { \
    96             setPosition(); \
    97             gl_Position.z = depth * gl_Position.w; \
    98             textureCoords = textureCoordArray; \
    99             opacity = opacityArray; \
    100     }";
     66static const char* const qglslMainVertexShader = "\n\
     67    void setPosition(); \n\
     68    void main(void) \n\
     69    { \n\
     70        setPosition(); \n\
     71    }\n";
     72
     73static const char* const qglslMainWithTexCoordsVertexShader = "\n\
     74    attribute highp   vec2      textureCoordArray; \n\
     75    varying   highp   vec2      textureCoords; \n\
     76    void setPosition(); \n\
     77    void main(void) \n\
     78    { \n\
     79        setPosition(); \n\
     80        textureCoords = textureCoordArray; \n\
     81    }\n";
     82
     83static const char* const qglslMainWithTexCoordsAndOpacityVertexShader = "\n\
     84    attribute highp   vec2      textureCoordArray; \n\
     85    attribute lowp    float     opacityArray; \n\
     86    varying   highp   vec2      textureCoords; \n\
     87    varying   lowp    float     opacity; \n\
     88    void setPosition(); \n\
     89    void main(void) \n\
     90    { \n\
     91        setPosition(); \n\
     92        textureCoords = textureCoordArray; \n\
     93        opacity = opacityArray; \n\
     94    }\n";
    10195
    10296// NOTE: We let GL do the perspective correction so texture lookups in the fragment
    10397//       shader are also perspective corrected.
    104 static const char* const qglslPositionOnlyVertexShader = "\
    105     attribute highp vec2    vertexCoordsArray;\
    106     uniform   highp mat3    pmvMatrix;\
    107     void setPosition(void)\
    108     {\
    109         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    110         gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \
    111     }";
    112 
    113 static const char* const qglslUntransformedPositionVertexShader = "\
    114     attribute highp vec4    vertexCoordsArray;\
    115     void setPosition(void)\
    116     {\
    117             gl_Position = vertexCoordsArray;\
    118     }";
     98static const char* const qglslPositionOnlyVertexShader = "\n\
     99    attribute highp   vec2      vertexCoordsArray; \n\
     100    attribute highp   vec3      pmvMatrix1; \n\
     101    attribute highp   vec3      pmvMatrix2; \n\
     102    attribute highp   vec3      pmvMatrix3; \n\
     103    void setPosition(void) \n\
     104    { \n\
     105        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     106        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     107        gl_Position = vec4(transformedPos.xy, 0.0, transformedPos.z); \n\
     108    }\n";
     109
     110static const char* const qglslUntransformedPositionVertexShader = "\n\
     111    attribute highp   vec4      vertexCoordsArray; \n\
     112    void setPosition(void) \n\
     113    { \n\
     114        gl_Position = vertexCoordsArray; \n\
     115    }\n";
    119116
    120117// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
    121 static const char* const qglslPositionWithPatternBrushVertexShader = "\
    122     attribute highp   vec2  vertexCoordsArray; \
    123     uniform   highp   mat3  pmvMatrix; \
    124     uniform   mediump vec2  halfViewportSize; \
    125     uniform   highp   vec2  invertedTextureSize; \
    126     uniform   highp   mat3  brushTransform; \
    127     varying   highp   vec2  patternTexCoords; \
    128     void setPosition(void) { \
    129             vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    130             gl_Position.xy = transformedPos.xy / transformedPos.z; \
    131             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
    132             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \
    133             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
    134             gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
    135             patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
    136     }";
     118static const char* const qglslPositionWithPatternBrushVertexShader = "\n\
     119    attribute highp   vec2      vertexCoordsArray; \n\
     120    attribute highp   vec3      pmvMatrix1; \n\
     121    attribute highp   vec3      pmvMatrix2; \n\
     122    attribute highp   vec3      pmvMatrix3; \n\
     123    uniform   mediump vec2      halfViewportSize; \n\
     124    uniform   highp   vec2      invertedTextureSize; \n\
     125    uniform   highp   mat3      brushTransform; \n\
     126    varying   highp   vec2      patternTexCoords; \n\
     127    void setPosition(void) \n\
     128    { \n\
     129        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     130        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     131        gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
     132        mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
     133        mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1.0); \n\
     134        mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
     135        gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
     136        patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \n\
     137    }\n";
    137138
    138139static const char* const qglslAffinePositionWithPatternBrushVertexShader
    139140                 = qglslPositionWithPatternBrushVertexShader;
    140141
    141 static const char* const qglslPatternBrushSrcFragmentShader = "\
    142     uniform lowp    sampler2D brushTexture;\
    143     uniform lowp    vec4      patternColor; \
    144     varying highp   vec2      patternTexCoords;\
    145     lowp vec4 srcPixel() { \
    146         return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \
     142static const char* const qglslPatternBrushSrcFragmentShader = "\n\
     143    uniform   lowp    sampler2D brushTexture; \n\
     144    uniform   lowp    vec4      patternColor; \n\
     145    varying   highp   vec2      patternTexCoords;\n\
     146    lowp vec4 srcPixel() \n\
     147    { \n\
     148        return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \n\
    147149    }\n";
    148150
    149151
    150152// Linear Gradient Brush
    151 static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
    152     attribute highp   vec2  vertexCoordsArray; \
    153     uniform   highp   mat3  pmvMatrix; \
    154     uniform   mediump vec2  halfViewportSize; \
    155     uniform   highp   vec3  linearData; \
    156     uniform   highp   mat3  brushTransform; \
    157     varying   mediump float index; \
    158     void setPosition() { \
    159         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    160         gl_Position.xy = transformedPos.xy / transformedPos.z; \
    161         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
    162         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
    163         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
    164         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
    165         index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
    166     }";
     153static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\n\
     154    attribute highp   vec2      vertexCoordsArray; \n\
     155    attribute highp   vec3      pmvMatrix1; \n\
     156    attribute highp   vec3      pmvMatrix2; \n\
     157    attribute highp   vec3      pmvMatrix3; \n\
     158    uniform   mediump vec2      halfViewportSize; \n\
     159    uniform   highp   vec3      linearData; \n\
     160    uniform   highp   mat3      brushTransform; \n\
     161    varying   mediump float     index; \n\
     162    void setPosition() \n\
     163    { \n\
     164        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     165        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     166        gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
     167        mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
     168        mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
     169        mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
     170        gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
     171        index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \n\
     172    }\n";
    167173
    168174static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
    169175                 = qglslPositionWithLinearGradientBrushVertexShader;
    170176
    171 static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
    172     uniform lowp    sampler2D   brushTexture; \
    173     varying mediump float       index; \
    174     lowp vec4 srcPixel() { \
    175         mediump vec2 val = vec2(index, 0.5); \
    176         return texture2D(brushTexture, val); \
     177static const char* const qglslLinearGradientBrushSrcFragmentShader = "\n\
     178    uniform   lowp    sampler2D brushTexture; \n\
     179    varying   mediump float     index; \n\
     180    lowp vec4 srcPixel() \n\
     181    { \n\
     182        mediump vec2 val = vec2(index, 0.5); \n\
     183        return texture2D(brushTexture, val); \n\
    177184    }\n";
    178185
    179186
    180187// Conical Gradient Brush
    181 static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
    182     attribute highp   vec2  vertexCoordsArray;\
    183     uniform   highp   mat3  pmvMatrix;\
    184     uniform   mediump vec2  halfViewportSize; \
    185     uniform   highp   mat3  brushTransform; \
    186     varying   highp   vec2  A; \
    187     void setPosition(void)\
    188     {\
    189         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    190         gl_Position.xy = transformedPos.xy / transformedPos.z; \
    191         mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
    192         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
    193         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
    194         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
    195         A = hTexCoords.xy * invertedHTexCoordsZ; \
    196     }";
     188static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\n\
     189    attribute highp   vec2      vertexCoordsArray; \n\
     190    attribute highp   vec3      pmvMatrix1; \n\
     191    attribute highp   vec3      pmvMatrix2; \n\
     192    attribute highp   vec3      pmvMatrix3; \n\
     193    uniform   mediump vec2      halfViewportSize; \n\
     194    uniform   highp   mat3      brushTransform; \n\
     195    varying   highp   vec2      A; \n\
     196    void setPosition(void) \n\
     197    { \n\
     198        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     199        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     200        gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
     201        mediump vec2  viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
     202        mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
     203        mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
     204        gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
     205        A = hTexCoords.xy * invertedHTexCoordsZ; \n\
     206    }\n";
    197207
    198208static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
     
    201211static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
    202212    #define INVERSE_2PI 0.1591549430918953358 \n\
    203     uniform lowp    sampler2D   brushTexture; \n\
    204     uniform mediump float       angle; \
    205     varying highp   vec2        A; \
    206     lowp vec4 srcPixel() { \
    207         highp float t; \
    208         if (abs(A.y) == abs(A.x)) \
    209             t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \
    210         else \
    211             t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \
    212         return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
    213     }";
     213    uniform   lowp    sampler2D brushTexture; \n\
     214    uniform   mediump float     angle; \n\
     215    varying   highp   vec2      A; \n\
     216    lowp vec4 srcPixel() \n\
     217    { \n\
     218        highp float t; \n\
     219        if (abs(A.y) == abs(A.x)) \n\
     220            t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \n\
     221        else \n\
     222            t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \n\
     223        return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \n\
     224    }\n";
    214225
    215226
    216227// Radial Gradient Brush
    217 static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
    218     attribute highp   vec2 vertexCoordsArray;\
    219     uniform   highp   mat3 pmvMatrix;\
    220     uniform   mediump vec2 halfViewportSize; \
    221     uniform   highp   mat3 brushTransform; \
    222     uniform   highp   vec2 fmp; \
    223     varying   highp   float b; \
    224     varying   highp   vec2  A; \
    225     void setPosition(void) \
    226     {\
    227         vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    228         gl_Position.xy = transformedPos.xy / transformedPos.z; \
    229         mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
    230         mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
    231         mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
    232         gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
    233         A = hTexCoords.xy * invertedHTexCoordsZ; \
    234         b = 2.0 * dot(A, fmp); \
    235     }";
     228static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\n\
     229    attribute highp   vec2      vertexCoordsArray;\n\
     230    attribute highp   vec3      pmvMatrix1; \n\
     231    attribute highp   vec3      pmvMatrix2; \n\
     232    attribute highp   vec3      pmvMatrix3; \n\
     233    uniform   mediump vec2      halfViewportSize; \n\
     234    uniform   highp   mat3      brushTransform; \n\
     235    uniform   highp   vec2      fmp; \n\
     236    varying   highp   float     b; \n\
     237    varying   highp   vec2      A; \n\
     238    void setPosition(void) \n\
     239    {\n\
     240        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     241        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     242        gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
     243        mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
     244        mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
     245        mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
     246        gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
     247        A = hTexCoords.xy * invertedHTexCoordsZ; \n\
     248        b = 2.0 * dot(A, fmp); \n\
     249    }\n";
    236250
    237251static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
    238252                 = qglslPositionWithRadialGradientBrushVertexShader;
    239253
    240 static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
    241     uniform lowp    sampler2D   brushTexture; \
    242     uniform highp   float       fmp2_m_radius2; \
    243     uniform highp   float       inverse_2_fmp2_m_radius2; \
    244     varying highp   float       b; \
    245     varying highp   vec2        A; \
    246     lowp vec4 srcPixel() { \
    247         highp float c = -dot(A, A); \
    248         highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
    249         return texture2D(brushTexture, val); \
    250     }";
     254static const char* const qglslRadialGradientBrushSrcFragmentShader = "\n\
     255    uniform   lowp    sampler2D brushTexture; \n\
     256    uniform   highp   float     fmp2_m_radius2; \n\
     257    uniform   highp   float     inverse_2_fmp2_m_radius2; \n\
     258    varying   highp   float     b; \n\
     259    varying   highp   vec2      A; \n\
     260    lowp vec4 srcPixel() \n\
     261    { \n\
     262        highp float c = -dot(A, A); \n\
     263        highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \n\
     264        return texture2D(brushTexture, val); \n\
     265    }\n";
    251266
    252267
    253268// Texture Brush
    254 static const char* const qglslPositionWithTextureBrushVertexShader = "\
    255     attribute highp   vec2 vertexCoordsArray; \
    256     uniform   highp   mat3  pmvMatrix; \
    257     uniform   mediump vec2  halfViewportSize; \
    258     uniform   highp   vec2  invertedTextureSize; \
    259     uniform   highp   mat3  brushTransform; \
    260     varying   highp   vec2  textureCoords; \
    261     void setPosition(void) { \
    262             vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \
    263             gl_Position.xy = transformedPos.xy / transformedPos.z; \
    264             mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
    265             mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
    266             mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
    267             gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \
    268             textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
    269     }";
     269static const char* const qglslPositionWithTextureBrushVertexShader = "\n\
     270    attribute highp   vec2      vertexCoordsArray; \n\
     271    attribute highp   vec3      pmvMatrix1; \n\
     272    attribute highp   vec3      pmvMatrix2; \n\
     273    attribute highp   vec3      pmvMatrix3; \n\
     274    uniform   mediump vec2      halfViewportSize; \n\
     275    uniform   highp   vec2      invertedTextureSize; \n\
     276    uniform   highp   mat3      brushTransform; \n\
     277    varying   highp   vec2      textureCoords; \n\
     278    void setPosition(void) \n\
     279    { \n\
     280        highp mat3 pmvMatrix = mat3(pmvMatrix1, pmvMatrix2, pmvMatrix3); \n\
     281        vec3 transformedPos = pmvMatrix * vec3(vertexCoordsArray.xy, 1.0); \n\
     282        gl_Position.xy = transformedPos.xy / transformedPos.z; \n\
     283        mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \n\
     284        mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \n\
     285        mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \n\
     286        gl_Position = vec4(gl_Position.xy * invertedHTexCoordsZ, 0.0, invertedHTexCoordsZ); \n\
     287        textureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \n\
     288    }\n";
    270289
    271290static const char* const qglslAffinePositionWithTextureBrushVertexShader
     
    276295// we emulate GL_REPEAT by only taking the fractional part of the texture coords.
    277296// TODO: Special case POT textures which don't need this emulation
    278 static const char* const qglslTextureBrushSrcFragmentShader = "\
    279     varying highp   vec2      textureCoords; \
    280     uniform lowp    sampler2D brushTexture; \
    281     lowp vec4 srcPixel() { \
    282         return texture2D(brushTexture, fract(textureCoords)); \
    283     }";
     297static const char* const qglslTextureBrushSrcFragmentShader = "\n\
     298    varying highp   vec2      textureCoords; \n\
     299    uniform lowp    sampler2D brushTexture; \n\
     300    lowp vec4 srcPixel() { \n\
     301        return texture2D(brushTexture, fract(textureCoords)); \n\
     302    }\n";
    284303#else
    285 static const char* const qglslTextureBrushSrcFragmentShader = "\
    286     varying highp   vec2      textureCoords; \
    287     uniform lowp    sampler2D brushTexture; \
    288     lowp vec4 srcPixel() { \
    289         return texture2D(brushTexture, textureCoords); \
    290     }";
     304static const char* const qglslTextureBrushSrcFragmentShader = "\n\
     305    varying   highp   vec2      textureCoords; \n\
     306    uniform   lowp    sampler2D brushTexture; \n\
     307    lowp vec4 srcPixel() \n\
     308    { \n\
     309        return texture2D(brushTexture, textureCoords); \n\
     310    }\n";
    291311#endif
    292312
    293 static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\
    294     varying highp   vec2      textureCoords; \
    295     uniform lowp    vec4      patternColor; \
    296     uniform lowp    sampler2D brushTexture; \
    297     lowp vec4 srcPixel() { \
    298         return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \
    299     }";
     313static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\n\
     314    varying   highp   vec2      textureCoords; \n\
     315    uniform   lowp    vec4      patternColor; \n\
     316    uniform   lowp    sampler2D brushTexture; \n\
     317    lowp vec4 srcPixel() \n\
     318    { \n\
     319        return patternColor * (1.0 - texture2D(brushTexture, textureCoords).r); \n\
     320    }\n";
    300321
    301322// Solid Fill Brush
    302 static const char* const qglslSolidBrushSrcFragmentShader = "\
    303     uniform lowp vec4 fragmentColor; \
    304     lowp vec4 srcPixel() { \
    305         return fragmentColor; \
    306     }";
    307 
    308 static const char* const qglslImageSrcFragmentShader = "\
    309     varying highp   vec2    textureCoords; \
    310     uniform lowp  sampler2D imageTexture; \
    311     lowp vec4 srcPixel() { \
    312         return texture2D(imageTexture, textureCoords); \
    313     }";
    314 
    315 static const char* const qglslCustomSrcFragmentShader = "\
    316     varying highp vec2      textureCoords; \
    317     uniform lowp  sampler2D imageTexture; \
    318     lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \
    319     lowp vec4 srcPixel() { \
    320         return customShader(imageTexture, textureCoords); \
    321     }";
    322 
    323 static const char* const qglslImageSrcWithPatternFragmentShader = "\
    324     varying highp vec2      textureCoords; \
    325     uniform lowp  vec4      patternColor; \
    326     uniform lowp  sampler2D imageTexture; \
    327     lowp vec4 srcPixel() { \
    328         return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \
    329     }\n";
    330 
    331 static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
    332     varying highp vec2      textureCoords; \
    333     uniform lowp  sampler2D imageTexture; \
    334     lowp vec4 srcPixel() { \
    335         lowp vec4 sample = texture2D(imageTexture, textureCoords); \
    336         sample.rgb = sample.rgb * sample.a; \
    337         return sample; \
    338     }";
    339 
    340 static const char* const qglslShockingPinkSrcFragmentShader = "\
    341     lowp vec4 srcPixel() { \
    342         return vec4(0.98, 0.06, 0.75, 1.0); \
    343     }";
    344 
    345 static const char* const qglslMainFragmentShader_ImageArrays = "\
    346     varying lowp float opacity; \
    347     lowp vec4 srcPixel(); \
    348     void main() { \
    349         gl_FragColor = srcPixel() * opacity; \
    350     }";
    351 
    352 static const char* const qglslMainFragmentShader_CMO = "\
    353     uniform lowp float globalOpacity; \
    354     lowp vec4 srcPixel(); \
    355     lowp vec4 applyMask(lowp vec4); \
    356     lowp vec4 compose(lowp vec4); \
    357     void main() { \
    358         gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \
    359     }";
    360 
    361 static const char* const qglslMainFragmentShader_CM = "\
    362     lowp vec4 srcPixel(); \
    363     lowp vec4 applyMask(lowp vec4); \
    364     lowp vec4 compose(lowp vec4); \
    365     void main() { \
    366         gl_FragColor = applyMask(compose(srcPixel())); \
    367     }";
    368 
    369 static const char* const qglslMainFragmentShader_MO = "\
    370     uniform lowp float globalOpacity; \
    371     lowp vec4 srcPixel(); \
    372     lowp vec4 applyMask(lowp vec4); \
    373     void main() { \
    374         gl_FragColor = applyMask(srcPixel()*globalOpacity); \
    375     }";
    376 
    377 static const char* const qglslMainFragmentShader_M = "\
    378     lowp vec4 srcPixel(); \
    379     lowp vec4 applyMask(lowp vec4); \
    380     void main() { \
    381         gl_FragColor = applyMask(srcPixel()); \
    382     }";
    383 
    384 static const char* const qglslMainFragmentShader_CO = "\
    385     uniform lowp float globalOpacity; \
    386     lowp vec4 srcPixel(); \
    387     lowp vec4 compose(lowp vec4); \
    388     void main() { \
    389         gl_FragColor = compose(srcPixel()*globalOpacity); \
    390     }";
    391 
    392 static const char* const qglslMainFragmentShader_C = "\
    393     lowp vec4 srcPixel(); \
    394     lowp vec4 compose(lowp vec4); \
    395     void main() { \
    396         gl_FragColor = compose(srcPixel()); \
    397     }";
    398 
    399 static const char* const qglslMainFragmentShader_O = "\
    400     uniform lowp float globalOpacity; \
    401     lowp vec4 srcPixel(); \
    402     void main() { \
    403         gl_FragColor = srcPixel()*globalOpacity; \
    404     }";
    405 
    406 static const char* const qglslMainFragmentShader = "\
    407     lowp vec4 srcPixel(); \
    408     void main() { \
    409         gl_FragColor = srcPixel(); \
    410     }";
    411 
    412 static const char* const qglslMaskFragmentShader = "\
    413     varying highp   vec2      textureCoords;\
    414     uniform lowp    sampler2D maskTexture;\
    415     lowp vec4 applyMask(lowp vec4 src) \
    416     {\
    417         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
    418         return src * mask.a; \
    419     }";
     323static const char* const qglslSolidBrushSrcFragmentShader = "\n\
     324    uniform   lowp    vec4      fragmentColor; \n\
     325    lowp vec4 srcPixel() \n\
     326    { \n\
     327        return fragmentColor; \n\
     328    }\n";
     329
     330static const char* const qglslImageSrcFragmentShader = "\n\
     331    varying   highp   vec2      textureCoords; \n\
     332    uniform   lowp    sampler2D imageTexture; \n\
     333    lowp vec4 srcPixel() \n\
     334    { \n\
     335        return texture2D(imageTexture, textureCoords); \n\
     336    }\n";
     337
     338static const char* const qglslCustomSrcFragmentShader = "\n\
     339    varying   highp   vec2      textureCoords; \n\
     340    uniform   lowp    sampler2D imageTexture; \n\
     341    lowp vec4 customShader(lowp sampler2D texture, highp vec2 coords); \n\
     342    lowp vec4 srcPixel() \n\
     343    { \n\
     344        return customShader(imageTexture, textureCoords); \n\
     345    }\n";
     346
     347static const char* const qglslImageSrcWithPatternFragmentShader = "\n\
     348    varying   highp   vec2      textureCoords; \n\
     349    uniform   lowp    vec4      patternColor; \n\
     350    uniform   lowp    sampler2D imageTexture; \n\
     351    lowp vec4 srcPixel() \n\
     352    { \n\
     353        return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \n\
     354    }\n";
     355
     356static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\n\
     357    varying   highp   vec2      textureCoords; \n\
     358    uniform   lowp    sampler2D imageTexture; \n\
     359    lowp vec4 srcPixel() \n\
     360    { \n\
     361        lowp vec4 sample = texture2D(imageTexture, textureCoords); \n\
     362        sample.rgb = sample.rgb * sample.a; \n\
     363        return sample; \n\
     364    }\n";
     365
     366static const char* const qglslShockingPinkSrcFragmentShader = "\n\
     367    lowp vec4 srcPixel() \n\
     368    { \n\
     369        return vec4(0.98, 0.06, 0.75, 1.0); \n\
     370    }\n";
     371
     372static const char* const qglslMainFragmentShader_ImageArrays = "\n\
     373    varying   lowp    float     opacity; \n\
     374    lowp vec4 srcPixel(); \n\
     375    void main() \n\
     376    { \n\
     377        gl_FragColor = srcPixel() * opacity; \n\
     378    }\n";
     379
     380static const char* const qglslMainFragmentShader_CMO = "\n\
     381    uniform   lowp    float     globalOpacity; \n\
     382    lowp vec4 srcPixel(); \n\
     383    lowp vec4 applyMask(lowp vec4); \n\
     384    lowp vec4 compose(lowp vec4); \n\
     385    void main() \n\
     386    { \n\
     387        gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \n\
     388    }\n";
     389
     390static const char* const qglslMainFragmentShader_CM = "\n\
     391    lowp vec4 srcPixel(); \n\
     392    lowp vec4 applyMask(lowp vec4); \n\
     393    lowp vec4 compose(lowp vec4); \n\
     394    void main() \n\
     395    { \n\
     396        gl_FragColor = applyMask(compose(srcPixel())); \n\
     397    }\n";
     398
     399static const char* const qglslMainFragmentShader_MO = "\n\
     400    uniform   lowp    float     globalOpacity; \n\
     401    lowp vec4 srcPixel(); \n\
     402    lowp vec4 applyMask(lowp vec4); \n\
     403    void main() \n\
     404    { \n\
     405        gl_FragColor = applyMask(srcPixel()*globalOpacity); \n\
     406    }\n";
     407
     408static const char* const qglslMainFragmentShader_M = "\n\
     409    lowp vec4 srcPixel(); \n\
     410    lowp vec4 applyMask(lowp vec4); \n\
     411    void main() \n\
     412    { \n\
     413        gl_FragColor = applyMask(srcPixel()); \n\
     414    }\n";
     415
     416static const char* const qglslMainFragmentShader_CO = "\n\
     417    uniform   lowp    float     globalOpacity; \n\
     418    lowp vec4 srcPixel(); \n\
     419    lowp vec4 compose(lowp vec4); \n\
     420    void main() \n\
     421    { \n\
     422        gl_FragColor = compose(srcPixel()*globalOpacity); \n\
     423    }\n";
     424
     425static const char* const qglslMainFragmentShader_C = "\n\
     426    lowp vec4 srcPixel(); \n\
     427    lowp vec4 compose(lowp vec4); \n\
     428    void main() \n\
     429    { \n\
     430        gl_FragColor = compose(srcPixel()); \n\
     431    }\n";
     432
     433static const char* const qglslMainFragmentShader_O = "\n\
     434    uniform   lowp    float     globalOpacity; \n\
     435    lowp vec4 srcPixel(); \n\
     436    void main() \n\
     437    { \n\
     438        gl_FragColor = srcPixel()*globalOpacity; \n\
     439    }\n";
     440
     441static const char* const qglslMainFragmentShader = "\n\
     442    lowp vec4 srcPixel(); \n\
     443    void main() \n\
     444    { \n\
     445        gl_FragColor = srcPixel(); \n\
     446    }\n";
     447
     448static const char* const qglslMaskFragmentShader = "\n\
     449    varying   highp   vec2      textureCoords;\n\
     450    uniform   lowp    sampler2D maskTexture;\n\
     451    lowp vec4 applyMask(lowp vec4 src) \n\
     452    {\n\
     453        lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
     454        return src * mask.a; \n\
     455    }\n";
    420456
    421457// For source over with subpixel antialiasing, the final color is calculated per component as follows
     
    434470//
    435471
    436 static const char* const qglslRgbMaskFragmentShaderPass1 = "\
    437     varying highp   vec2      textureCoords;\
    438     uniform lowp    sampler2D maskTexture;\
    439     lowp vec4 applyMask(lowp vec4 src) \
    440     {\
    441         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
    442         return src.a * mask; \
    443     }";
    444 
    445 static const char* const qglslRgbMaskFragmentShaderPass2 = "\
    446     varying highp   vec2      textureCoords;\
    447     uniform lowp    sampler2D maskTexture;\
    448     lowp vec4 applyMask(lowp vec4 src) \
    449     {\
    450         lowp vec4 mask = texture2D(maskTexture, textureCoords); \
    451         return src * mask; \
    452     }";
     472static const char* const qglslRgbMaskFragmentShaderPass1 = "\n\
     473    varying   highp   vec2      textureCoords;\n\
     474    uniform   lowp    sampler2D maskTexture;\n\
     475    lowp vec4 applyMask(lowp vec4 src) \n\
     476    { \n\
     477        lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
     478        return src.a * mask; \n\
     479    }\n";
     480
     481static const char* const qglslRgbMaskFragmentShaderPass2 = "\n\
     482    varying   highp   vec2      textureCoords;\n\
     483    uniform   lowp    sampler2D maskTexture;\n\
     484    lowp vec4 applyMask(lowp vec4 src) \n\
     485    { \n\
     486        lowp vec4 mask = texture2D(maskTexture, textureCoords); \n\
     487        return src * mask; \n\
     488    }\n";
    453489
    454490/*
  • trunk/src/opengl/gl2paintengineex/qglgradientcache.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)
  • trunk/src/opengl/gl2paintengineex/qglgradientcache_p.h

    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)
  • trunk/src/opengl/gl2paintengineex/qpaintengineex_opengl2.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)
     
    7676#include <private/qpainter_p.h>
    7777#include <private/qfontengine_p.h>
    78 #include <private/qtextureglyphcache_p.h>
    7978#include <private/qpixmapdata_gl_p.h>
    8079#include <private/qdatabuffer_p.h>
     
    8382#include "qglengineshadermanager_p.h"
    8483#include "qgl2pexvertexarray_p.h"
    85 
    8684#include "qtriangulatingstroker_p.h"
     85#include "qtextureglyphcache_gl_p.h"
    8786
    8887#include <QDebug>
     
    9190
    9291//#define QT_GL_NO_SCISSOR_TEST
    93 
    94 static const GLuint GL_STENCIL_HIGH_BIT         = 0x80;
    95 static const GLuint QT_BRUSH_TEXTURE_UNIT       = 0;
    96 static const GLuint QT_IMAGE_TEXTURE_UNIT       = 0; //Can be the same as brush texture unit
    97 static const GLuint QT_MASK_TEXTURE_UNIT        = 1;
    98 static const GLuint QT_BACKGROUND_TEXTURE_UNIT  = 2;
    99 
    100 #ifdef Q_WS_WIN
    101 extern Q_GUI_EXPORT bool qt_cleartype_enabled;
    102 #endif
    103 
    104 class QGLTextureGlyphCache : public QObject, public QTextureGlyphCache
    105 {
    106     Q_OBJECT
    107 public:
    108     QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix);
    109     ~QGLTextureGlyphCache();
    110 
    111     virtual void createTextureData(int width, int height);
    112     virtual void resizeTextureData(int width, int height);
    113     virtual void fillTexture(const Coord &c, glyph_t glyph);
    114     virtual int glyphMargin() const;
    115 
    116     inline GLuint texture() const { return m_texture; }
    117 
    118     inline int width() const { return m_width; }
    119     inline int height() const { return m_height; }
    120 
    121     inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; }
    122 
    123 
    124 public Q_SLOTS:
    125     void contextDestroyed(const QGLContext *context) {
    126         if (context == ctx) {
    127             QList<const QGLContext *> shares = qgl_share_reg()->shares(ctx);
    128             if (shares.isEmpty()) {
    129                 glDeleteFramebuffers(1, &m_fbo);
    130                 if (m_width || m_height)
    131                     glDeleteTextures(1, &m_texture);
    132                 ctx = 0;
    133             } else {
    134                 // since the context holding the texture is shared, and
    135                 // about to be destroyed, we have to transfer ownership
    136                 // of the texture to one of the share contexts
    137                 ctx = const_cast<QGLContext *>((ctx == shares.at(0)) ? shares.at(1) : shares.at(0));
    138             }
    139         }
    140     }
    141 
    142 private:
    143     QGLContext *ctx;
    144 
    145     QGL2PaintEngineExPrivate *pex;
    146 
    147     GLuint m_texture;
    148     GLuint m_fbo;
    149 
    150     int m_width;
    151     int m_height;
    152 
    153     QGLShaderProgram *m_program;
    154 };
    155 
    156 QGLTextureGlyphCache::QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix)
    157     : QTextureGlyphCache(type, matrix)
    158     , ctx(context)
    159     , m_width(0)
    160     , m_height(0)
    161 {
    162     glGenFramebuffers(1, &m_fbo);
    163     connect(QGLSignalProxy::instance(), SIGNAL(aboutToDestroyContext(const QGLContext*)),
    164             SLOT(contextDestroyed(const QGLContext*)));
    165 }
    166 
    167 QGLTextureGlyphCache::~QGLTextureGlyphCache()
    168 {
    169     if (ctx) {
    170         QGLShareContextScope scope(ctx);
    171         glDeleteFramebuffers(1, &m_fbo);
    172 
    173         if (m_width || m_height)
    174             glDeleteTextures(1, &m_texture);
    175     }
    176 }
    177 
    178 void QGLTextureGlyphCache::createTextureData(int width, int height)
    179 {
    180     glGenTextures(1, &m_texture);
    181     glBindTexture(GL_TEXTURE_2D, m_texture);
    182 
    183     m_width = width;
    184     m_height = height;
    185 
    186     QVarLengthArray<uchar> data(width * height);
    187     for (int i = 0; i < data.size(); ++i)
    188         data[i] = 0;
    189 
    190     if (m_type == QFontEngineGlyphCache::Raster_RGBMask)
    191         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]);
    192     else
    193         glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]);
    194 
    195     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    196     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    197 }
    198 
    199 void QGLTextureGlyphCache::resizeTextureData(int width, int height)
    200 {
    201     // ### the QTextureGlyphCache API needs to be reworked to allow
    202     // ### resizeTextureData to fail
    203 
    204     int oldWidth = m_width;
    205     int oldHeight = m_height;
    206 
    207     GLuint oldTexture = m_texture;
    208     createTextureData(width, height);
    209 
    210     glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
    211 
    212     GLuint tmp_texture;
    213     glGenTextures(1, &tmp_texture);
    214     glBindTexture(GL_TEXTURE_2D, tmp_texture);
    215     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0,
    216                  GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    217     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    218     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    219     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    220     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    221     glBindTexture(GL_TEXTURE_2D, 0);
    222     glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    223                            GL_TEXTURE_2D, tmp_texture, 0);
    224 
    225     glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
    226     glBindTexture(GL_TEXTURE_2D, oldTexture);
    227 
    228     pex->transferMode(BrushDrawingMode);
    229 
    230     glDisable(GL_STENCIL_TEST);
    231     glDisable(GL_DEPTH_TEST);
    232     glDisable(GL_SCISSOR_TEST);
    233     glDisable(GL_BLEND);
    234 
    235     glViewport(0, 0, oldWidth, oldHeight);
    236 
    237     float vertexCoordinateArray[] = { -1, -1, 1, -1, 1, 1, -1, 1 };
    238     float textureCoordinateArray[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
    239 
    240     glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    241     glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    242 
    243     glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray);
    244     glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray);
    245 
    246     pex->shaderManager->blitProgram()->bind();
    247     pex->shaderManager->blitProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT);
    248     pex->shaderManager->setDirty();
    249 
    250     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    251 
    252     glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    253     glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    254 
    255     glBindTexture(GL_TEXTURE_2D, m_texture);
    256 
    257 #ifdef QT_OPENGL_ES_2
    258     QDataBuffer<uchar> buffer(4*oldWidth*oldHeight);
    259     buffer.resize(4*oldWidth*oldHeight);
    260     glReadPixels(0, 0, oldWidth, oldHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer.data());
    261 
    262     // do an in-place conversion from GL_RGBA to GL_ALPHA
    263     for (int i=0; i<oldWidth*oldHeight; ++i)
    264         buffer.data()[i] = buffer.at(4*i + 3);
    265 
    266     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, oldWidth, oldHeight,
    267                     GL_ALPHA, GL_UNSIGNED_BYTE, buffer.data());
    268 #else
    269     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight);
    270 #endif
    271 
    272     glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    273                               GL_RENDERBUFFER_EXT, 0);
    274     glDeleteTextures(1, &tmp_texture);
    275     glDeleteTextures(1, &oldTexture);
    276 
    277     glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
    278 
    279     glViewport(0, 0, pex->width, pex->height);
    280     pex->updateClipScissorTest();
    281 }
    282 
    283 void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph)
    284 {
    285     QImage mask = textureMapForGlyph(glyph);
    286     const int maskWidth = mask.width();
    287     const int maskHeight = mask.height();
    288 
    289     if (mask.format() == QImage::Format_Mono) {
    290         mask = mask.convertToFormat(QImage::Format_Indexed8);
    291         for (int y = 0; y < maskHeight; ++y) {
    292             uchar *src = (uchar *) mask.scanLine(y);
    293             for (int x = 0; x < maskWidth; ++x)
    294                 src[x] = -src[x]; // convert 0 and 1 into 0 and 255
    295         }
    296      }
    297 
    298 
    299     glBindTexture(GL_TEXTURE_2D, m_texture);
    300     if (mask.format() == QImage::Format_RGB32) {
    301         glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits());
    302     } else {
    303 #ifdef QT_OPENGL_ES2
    304         glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits());
    305 #else
    306         // glTexSubImage2D() might cause some garbage to appear in the texture if the mask width is
    307         // not a multiple of four bytes. The bug appeared on a computer with 32-bit Windows Vista
    308         // and nVidia GeForce 8500GT. GL_UNPACK_ALIGNMENT is set to four bytes, 'mask' has a
    309         // multiple of four bytes per line, and most of the glyph shows up correctly in the
    310         // texture, which makes me think that this is a driver bug.
    311         // One workaround is to make sure the mask width is a multiple of four bytes, for instance
    312         // by converting it to a format with four bytes per pixel. Another is to copy one line at a
    313         // time.
    314 
    315         for (int i = 0; i < maskHeight; ++i)
    316             glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, maskWidth, 1, GL_ALPHA, GL_UNSIGNED_BYTE, mask.scanLine(i));
    317 #endif
    318     }
    319 }
    320 
    321 int QGLTextureGlyphCache::glyphMargin() const
    322 {
    323 #if defined(Q_WS_MAC)
    324     return 2;
    325 #elif defined (Q_WS_X11)
    326     return 0;
    327 #else
    328     return m_type == QFontEngineGlyphCache::Raster_RGBMask ? 2 : 0;
    329 #endif
    330 }
    33192
    33293extern QImage qt_imageForBrush(int brushStyle, bool invert);
     
    404165void QGL2PaintEngineExPrivate::useSimpleShader()
    405166{
    406     shaderManager->simpleProgram()->bind();
    407     shaderManager->setDirty();
     167    shaderManager->useSimpleProgram();
    408168
    409169    if (matrixDirty)
    410170        updateMatrix();
    411 
    412     if (simpleShaderMatrixUniformDirty) {
    413         const GLuint location = shaderManager->simpleProgram()->uniformLocation("pmvMatrix");
    414         glUniformMatrix3fv(location, 1, GL_FALSE, (GLfloat*)pmvMatrix);
    415         simpleShaderMatrixUniformDirty = false;
    416     }
    417171}
    418172
     
    633387    matrixDirty = false;
    634388
    635     // The actual data has been updated so both shader program's uniforms need updating
    636     simpleShaderMatrixUniformDirty = true;
    637     shaderMatrixUniformDirty = true;
     389    // Set the PMV matrix attribute. As we use an attributes rather than uniforms, we only
     390    // need to do this once for every matrix change and persists across all shader programs.
     391    glVertexAttrib3fv(QT_PMV_MATRIX_1_ATTR, pmvMatrix[0]);
     392    glVertexAttrib3fv(QT_PMV_MATRIX_2_ATTR, pmvMatrix[1]);
     393    glVertexAttrib3fv(QT_PMV_MATRIX_3_ATTR, pmvMatrix[2]);
    638394
    639395    dasher.setInvScale(inverseScale);
     
    751507    glUseProgram(0);
    752508
     509    // Disable all the vertex attribute arrays:
     510    for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
     511        glDisableVertexAttribArray(i);
     512
    753513#ifndef QT_OPENGL_ES_2
    754514    // be nice to people who mix OpenGL 1.x code with QPainter commands
     
    796556    glDepthFunc(GL_LESS);
    797557    glClearDepth(1);
     558    glStencilMask(0xff);
     559    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
     560    glStencilFunc(GL_ALWAYS, 0, 0xff);
     561    glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
     562    glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
     563    glDisableVertexAttribArray(QT_OPACITY_ATTR);
     564#ifndef QT_OPENGL_ES_2
     565    glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // color may have been changed by glVertexAttrib()
     566#endif
    798567}
    799568
     
    810579
    811580    if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) {
    812         glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    813         glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    814         glDisableVertexAttribArray(QT_OPACITY_ATTR);
    815 
    816581        lastTextureUsed = GLuint(-1);
    817582    }
    818583
    819584    if (newMode == TextDrawingMode) {
    820         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    821         glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    822 
    823         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data());
    824         glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data());
     585        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
     586        setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
    825587    }
    826588
    827589    if (newMode == ImageDrawingMode) {
    828         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    829         glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    830 
    831         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticVertexCoordinateArray);
    832         glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticTextureCoordinateArray);
     590        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
     591        setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray);
    833592    }
    834593
    835594    if (newMode == ImageArrayDrawingMode) {
    836         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    837         glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
    838         glEnableVertexAttribArray(QT_OPACITY_ATTR);
    839 
    840         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data());
    841         glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data());
    842         glVertexAttribPointer(QT_OPACITY_ATTR, 1, GL_FLOAT, GL_FALSE, 0, opacityArray.data());
     595        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
     596        setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
     597        setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data());
    843598    }
    844599
     
    953708
    954709            prepareForDraw(currentBrush.isOpaque());
    955             glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    956710#ifdef QT_OPENGL_CACHE_AS_VBOS
    957711            glBindBuffer(GL_ARRAY_BUFFER, cache->vbo);
    958             glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, false, 0, 0);
     712            setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0);
    959713#else
    960             glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, false, 0, cache->vertices);
     714            setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices);
    961715#endif
    962716            glDrawArrays(cache->primitiveType, 0, cache->vertexCount);
     
    1078832#if 0
    1079833        glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit
    1080         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1081         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, data);
     834        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
    1082835        glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
    1083         glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1084836#else
    1085837
     
    1091843            glStencilFunc(GL_ALWAYS, GL_STENCIL_HIGH_BIT, 0xff);
    1092844        }
    1093         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1094         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, data);
     845        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data);
    1095846        glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
    1096         glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1097847#endif
    1098848    }
     
    1185935        // The shader program has changed so mark all uniforms as dirty:
    1186936        brushUniformsDirty = true;
    1187         shaderMatrixUniformDirty = true;
    1188937        opacityUniformDirty = true;
    1189938    }
     
    1191940    if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
    1192941        updateBrushUniforms();
    1193 
    1194     if (shaderMatrixUniformDirty) {
    1195         glUniformMatrix3fv(location(QGLEngineShaderManager::PmvMatrix), 1, GL_FALSE, (GLfloat*)pmvMatrix);
    1196         shaderMatrixUniformDirty = false;
    1197     }
    1198942
    1199943    if (opacityMode == QGLEngineShaderManager::UniformOpacity && opacityUniformDirty) {
     
    1207951void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect)
    1208952{
    1209     // Setup a vertex array for the bounding rect:
    1210     GLfloat rectVerts[] = {
    1211         boundingRect.left, boundingRect.top,
    1212         boundingRect.left, boundingRect.bottom,
    1213         boundingRect.right, boundingRect.bottom,
    1214         boundingRect.right, boundingRect.top
    1215     };
    1216 
    1217     glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1218     glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, rectVerts);
    1219 
     953    setCoords(staticVertexCoordinateArray, boundingRect);
     954    setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray);
    1220955    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    1221 
    1222     glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1223956}
    1224957
     
    1228961{
    1229962    // Now setup the pointer to the vertex array:
    1230     glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1231     glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, data);
     963    setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)data);
    1232964
    1233965    int previousStop = 0;
     
    1242974        previousStop = stop;
    1243975    }
    1244     glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1245976}
    1246977
     
    13291060    if (opaque) {
    13301061        prepareForDraw(opaque);
    1331         glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    1332         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, false, 0, stroker.vertices());
     1062        setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices());
    13331063        glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2);
    13341064
     
    13371067//         d->prepareForDraw(true);
    13381068//         glDrawArrays(GL_LINE_STRIP, 0, d->stroker.vertexCount() / 2);
    1339 
    1340         glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
    13411069
    13421070    } else {
     
    15531281    GLfloat dy = 1.0 / cache->height();
    15541282
    1555     QGLPoint *oldVertexCoordinateDataPtr = vertexCoordinateArray.data();
    1556     QGLPoint *oldTextureCoordinateDataPtr = textureCoordinateArray.data();
    1557 
    15581283    vertexCoordinateArray.clear();
    15591284    textureCoordinateArray.clear();
     
    15681293    }
    15691294
    1570     if (vertexCoordinateArray.data() != oldVertexCoordinateDataPtr)
    1571         glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data());
    1572     if (textureCoordinateArray.data() != oldTextureCoordinateDataPtr)
    1573         glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data());
     1295    setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
     1296    setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
    15741297
    15751298    if (addOffset) {
     
    18331556#if !defined(QT_OPENGL_ES_2)
    18341557#if defined(Q_WS_WIN)
     1558    extern Q_GUI_EXPORT bool qt_cleartype_enabled;
    18351559    if (qt_cleartype_enabled)
    18361560#endif
     
    19001624        d->needsSync = false;
    19011625        d->shaderManager->setDirty();
     1626        d->ctx->d_func()->syncGlState();
     1627        for (int i = 0; i < 3; ++i)
     1628            d->vertexAttribPointers[i] = (GLfloat*)-1; // Assume the pointers are clobbered
    19021629        setState(state());
    19031630    }
     
    22251952        renderHintsChanged();
    22261953
    2227     if (old_state == s || old_state->matrixChanged) {
     1954    if (old_state == s || old_state->matrixChanged)
    22281955        d->matrixDirty = true;
    2229         d->simpleShaderMatrixUniformDirty = true;
    2230         d->shaderMatrixUniformDirty = true;
    2231     }
    22321956
    22331957    if (old_state == s || old_state->compositionModeChanged)
     
    22912015
    22922016QT_END_NAMESPACE
    2293 
    2294 #include "qpaintengineex_opengl2.moc"
  • trunk/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h

    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)
     
    7474QT_BEGIN_NAMESPACE
    7575
     76#define GL_STENCIL_HIGH_BIT         GLuint(0x80)
     77#define QT_BRUSH_TEXTURE_UNIT       GLuint(0)
     78#define QT_IMAGE_TEXTURE_UNIT       GLuint(0) //Can be the same as brush texture unit
     79#define QT_MASK_TEXTURE_UNIT        GLuint(1)
     80#define QT_BACKGROUND_TEXTURE_UNIT  GLuint(2)
     81
    7682class QGL2PaintEngineExPrivate;
    7783
     
    191197    void drawCachedGlyphs(const QPointF &p, QFontEngineGlyphCache::Type glyphType, const QTextItemInt &ti);
    192198
     199    // Calls glVertexAttributePointer if the pointer has changed
     200    inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer);
     201
    193202    // draws whatever is in the vertex array:
    194203    void drawVertexArrays(const float *data, int *stops, int stopCount, GLenum primitive);
     
    224233    void regenerateClip();
    225234    void systemStateChanged();
     235
    226236
    227237    static QGLEngineShaderManager* shaderManagerForEngine(QGL2PaintEngineEx *engine) { return engine->d_func()->shaderManager; }
     
    243253    bool brushTextureDirty;
    244254    bool brushUniformsDirty;
    245     bool simpleShaderMatrixUniformDirty;
    246     bool shaderMatrixUniformDirty;
    247255    bool opacityUniformDirty;
    248256
     
    286294    QSet<QVectorPath::CacheEntry *> pathCaches;
    287295    QVector<GLuint> unusedVBOSToClean;
     296
     297    const GLfloat *vertexAttribPointers[3];
    288298};
    289299
     300
     301void QGL2PaintEngineExPrivate::setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer)
     302{
     303    Q_ASSERT(arrayIndex < 3);
     304    if (pointer == vertexAttribPointers[arrayIndex])
     305        return;
     306
     307    vertexAttribPointers[arrayIndex] = pointer;
     308    if (arrayIndex == QT_OPACITY_ATTR)
     309        glVertexAttribPointer(arrayIndex, 1, GL_FLOAT, GL_FALSE, 0, pointer);
     310    else
     311        glVertexAttribPointer(arrayIndex, 2, GL_FLOAT, GL_FALSE, 0, pointer);
     312}
     313
    290314QT_END_NAMESPACE
    291315
  • trunk/src/opengl/gl2paintengineex/qtriangulatingstroker.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)
  • trunk/src/opengl/gl2paintengineex/qtriangulatingstroker_p.h

    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)
  • trunk/src/opengl/opengl.pro

    r561 r651  
    5555                gl2paintengineex/qglengineshadersource_p.h \
    5656                gl2paintengineex/qglcustomshaderstage_p.h \
    57                 gl2paintengineex/qtriangulatingstroker_p.h
     57                gl2paintengineex/qtriangulatingstroker_p.h \
     58                gl2paintengineex/qtextureglyphcache_gl_p.h
    5859
    5960    SOURCES +=  qglshaderprogram.cpp \
     
    6869                gl2paintengineex/qpaintengineex_opengl2.cpp \
    6970                gl2paintengineex/qglcustomshaderstage.cpp \
    70                 gl2paintengineex/qtriangulatingstroker.cpp
     71                gl2paintengineex/qtriangulatingstroker.cpp \
     72                gl2paintengineex/qtextureglyphcache_gl.cpp
    7173
    7274}
  • 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.");
  • trunk/src/opengl/qgl.h

    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)
     
    394394    friend class QGL2PaintEngineEx;
    395395    friend class QGL2PaintEngineExPrivate;
     396    friend class QGLEngineShaderManager;
    396397    friend class QGLWindowSurface;
    397398    friend class QGLPixmapData;
    398399    friend class QGLPixmapFilterBase;
    399400    friend class QGLTextureGlyphCache;
    400     friend class QGLShareRegister;
     401    friend class QGLContextGroup;
    401402    friend class QGLSharedResourceGuard;
    402403    friend class QGLPixmapBlurFilter;
     404    friend class QGLExtensions;
    403405    friend QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags();
    404406#ifdef Q_WS_MAC
  • trunk/src/opengl/qgl_cl_p.h

    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)
  • trunk/src/opengl/qgl_egl.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)
     
    153153    d->transpColor = QColor();
    154154    d->initDone = false;
    155     qgl_share_reg()->removeShare(this);
     155    QGLContextGroup::removeShare(this);
    156156}
    157157
  • trunk/src/opengl/qgl_egl_p.h

    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)
  • trunk/src/opengl/qgl_mac.mm

    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)
     
    116116extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp
    117117extern void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1);  //qglobal.cpp
     118
     119/*
     120    QGLTemporaryContext implementation
     121*/
     122
     123class QGLTemporaryContextPrivate
     124{
     125public:
     126#ifndef QT_MAC_USE_COCOA
     127    AGLContext ctx;
     128#else
     129    NSOpenGLContext *ctx;
     130#endif
     131};
     132
     133QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     134    : d(new QGLTemporaryContextPrivate)
     135{
     136    d->ctx = 0;
     137#ifndef QT_MAC_USE_COCOA
     138    GLint attribs[] = {AGL_RGBA, AGL_NONE};
     139    AGLPixelFormat fmt = aglChoosePixelFormat(0, 0, attribs);
     140    if (!fmt) {
     141        qDebug("QGLTemporaryContext: Couldn't find any RGB visuals");
     142        return;
     143    }
     144    d->ctx = aglCreateContext(fmt, 0);
     145    if (!d->ctx)
     146        qDebug("QGLTemporaryContext: Unable to create context");
     147    else
     148        aglSetCurrentContext(d->ctx);
     149    aglDestroyPixelFormat(fmt);
     150#else
     151    QMacCocoaAutoReleasePool pool;
     152    NSOpenGLPixelFormatAttribute attribs[] = { 0 };
     153    NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
     154    if (!fmt) {
     155        qWarning("QGLTemporaryContext: Cannot find any visuals");
     156        return;
     157    }
     158
     159    d->ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:0];
     160    if (!d->ctx)
     161        qWarning("QGLTemporaryContext: Cannot create context");
     162    else
     163        [d->ctx makeCurrentContext];
     164    [fmt release];
     165#endif
     166}
     167
     168QGLTemporaryContext::~QGLTemporaryContext()
     169{
     170    if (d->ctx) {
     171#ifndef QT_MAC_USE_COCOA
     172        aglSetCurrentContext(0);
     173        aglDestroyContext(d->ctx);
     174#else
     175        [NSOpenGLContext clearCurrentContext];
     176        [d->ctx release];
     177#endif
     178    }
     179}
    118180
    119181bool QGLFormat::hasOpenGL()
     
    477539    d->transpColor = QColor();
    478540    d->initDone = false;
    479     qgl_share_reg()->removeShare(this);
     541    QGLContextGroup::removeShare(this);
    480542}
    481543
     
    607669        }
    608670    } else if (d->paintDevice->devType() == QInternal::Pixmap) {
    609         QPixmap *pm = (QPixmap *)d->paintDevice;
    610         PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle());
    611         aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(),
    612                 GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm));
     671        QPixmap *pm = reinterpret_cast<QPixmap *>(d->paintDevice);
     672
     673        unsigned long qdformat = k32ARGBPixelFormat;
     674        if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
     675            qdformat = k32BGRAPixelFormat;
     676        Rect rect;
     677        SetRect(&rect, 0, 0, pm->width(), pm->height());
     678
     679        GWorldPtr gworld;
     680        NewGWorldFromPtr(&gworld, qdformat, &rect, 0, 0, 0,
     681                         reinterpret_cast<char *>(qt_mac_pixmap_get_base(pm)),
     682                         qt_mac_pixmap_get_bytes_per_line(pm));
     683
     684        PixMapHandle pixmapHandle = GetGWorldPixMap(gworld);
     685        aglSetOffScreen(reinterpret_cast<AGLContext>(d->cx), pm->width(), pm->height(),
     686                        GetPixRowBytes(pixmapHandle), GetPixBaseAddr(pixmapHandle));
    613687    } else {
    614688        qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
     
    907981}
    908982
    909 
    910 void QGLExtensions::init()
    911 {
    912     static bool init_done = false;
    913 
    914     if (init_done)
    915         return;
    916     init_done = true;
    917 
    918 #ifndef QT_MAC_USE_COCOA
    919     GLint attribs[] = { AGL_RGBA, AGL_NONE };
    920     AGLPixelFormat fmt = aglChoosePixelFormat(0, 0, attribs);
    921     if (!fmt) {
    922         qDebug("QGLExtensions: Couldn't find any RGB visuals");
    923         return;
    924     }
    925     AGLContext ctx = aglCreateContext(fmt, 0);
    926     if (!ctx) {
    927         qDebug("QGLExtensions: Unable to create context");
    928     } else {
    929         aglSetCurrentContext(ctx);
    930         init_extensions();
    931         aglSetCurrentContext(0);
    932         aglDestroyContext(ctx);
    933     }
    934     aglDestroyPixelFormat(fmt);
    935 #else
    936     QMacCocoaAutoReleasePool pool;
    937     NSOpenGLPixelFormatAttribute attribs[] = { 0 };
    938     NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
    939     if (!fmt) {
    940         qWarning("QGLExtensions: Cannot find any visuals");
    941         return;
    942     }
    943 
    944     NSOpenGLContext *ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:0];
    945     if (!ctx) {
    946         qWarning("QGLExtensions: Cannot create context");
    947     } else {
    948         [ctx makeCurrentContext];
    949         init_extensions();
    950         [NSOpenGLContext clearCurrentContext];
    951         [ctx release];
    952     }
    953     [fmt release];
    954 #endif
    955 }
    956 
    957983#endif
    958984
  • trunk/src/opengl/qgl_p.h

    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)
     
    223223
    224224// QGLContextPrivate has the responsibility of creating context groups.
    225 // QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy
     225// QGLContextPrivate maintains the reference counter and destroys
    226226// context groups when needed.
    227 // QGLShareRegister has the responsibility of keeping the context pointer up to date.
    228227class QGLContextGroup
    229228{
     
    234233    const QGLContext *context() const {return m_context;}
    235234    bool isSharing() const { return m_shares.size() >= 2; }
     235    QList<const QGLContext *> shares() const { return m_shares; }
    236236
    237237    void addGuard(QGLSharedResourceGuard *guard);
    238238    void removeGuard(QGLSharedResourceGuard *guard);
     239
     240    static void addShare(const QGLContext *context, const QGLContext *share);
     241    static void removeShare(const QGLContext *context);
    239242private:
    240243    QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
     
    250253    void cleanupResources(const QGLContext *ctx);
    251254
    252     friend class QGLShareRegister;
    253255    friend class QGLContext;
    254256    friend class QGLContextPrivate;
     
    256258};
    257259
    258 class QGLTexture;
    259 
    260 class QGLContextPrivate
    261 {
    262     Q_DECLARE_PUBLIC(QGLContext)
    263 public:
    264     explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
    265     ~QGLContextPrivate();
    266     QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
    267                             QGLContext::BindOptions options);
    268     QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key,
    269                             QGLContext::BindOptions options);
    270     QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
    271                             QGLContext::BindOptions options);
    272     QGLTexture *textureCacheLookup(const qint64 key, GLenum target);
    273     void init(QPaintDevice *dev, const QGLFormat &format);
    274     QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format);
    275     int maxTextureSize();
    276 
    277     void cleanup();
    278 
    279 #if defined(Q_WS_WIN)
    280     HGLRC rc;
    281     HDC dc;
    282     WId        win;
    283     int pixelFormatId;
    284     QGLCmap* cmap;
    285     HBITMAP hbitmap;
    286     HDC hbitmap_hdc;
    287 #endif
    288 #if defined(QT_OPENGL_ES)
    289     QEglContext *eglContext;
    290     EGLSurface eglSurface;
    291     void destroyEglSurfaceForDevice();
    292 #elif defined(Q_WS_X11) || defined(Q_WS_MAC)
    293     void* cx;
    294 #endif
    295 #if defined(Q_WS_X11) || defined(Q_WS_MAC)
    296     void* vi;
    297 #endif
    298 #if defined(Q_WS_X11)
    299     void* pbuf;
    300     quint32 gpm;
    301     int screen;
    302     QHash<QPixmapData*, QPixmap> boundPixmaps;
    303     QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
    304                                             QGLContext::BindOptions options);
    305     static void destroyGlSurfaceForPixmap(QPixmapData*);
    306     static void unbindPixmapFromTexture(QPixmapData*);
    307 #endif
    308 #if defined(Q_WS_MAC)
    309     bool update;
    310     void *tryFormat(const QGLFormat &format);
    311     void clearDrawable();
    312 #endif
    313     QGLFormat glFormat;
    314     QGLFormat reqFormat;
    315     GLuint fbo;
    316 
    317     uint valid : 1;
    318     uint sharing : 1;
    319     uint initDone : 1;
    320     uint crWin : 1;
    321     uint internal_context : 1;
    322     uint version_flags_cached : 1;
    323     QPaintDevice *paintDevice;
    324     QColor transpColor;
    325     QGLContext *q_ptr;
    326     QGLFormat::OpenGLVersionFlags version_flags;
    327 
    328     QGLContextGroup *group;
    329     GLint max_texture_size;
    330 
    331     GLuint current_fbo;
    332     GLuint default_fbo;
    333     QPaintEngine *active_engine;
    334 
    335     static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
    336 
    337 #ifdef Q_WS_WIN
    338     static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
    339 #endif
    340 
    341 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
    342     static QGLExtensionFuncs qt_extensionFuncs;
    343     static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
    344 #endif
    345 
    346     static void setCurrentContext(QGLContext *context);
    347 };
    348 
    349 // ### make QGLContext a QObject in 5.0 and remove the proxy stuff
    350 class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
    351 {
    352     Q_OBJECT
    353 public:
    354     QGLSignalProxy() : QObject() {}
    355     void emitAboutToDestroyContext(const QGLContext *context) {
    356         emit aboutToDestroyContext(context);
    357     }
    358     static QGLSignalProxy *instance();
    359 Q_SIGNALS:
    360     void aboutToDestroyContext(const QGLContext *context);
    361 };
     260// Get the context that resources for "ctx" will transfer to once
     261// "ctx" is destroyed.  Returns null if nothing is sharing with ctx.
     262Q_OPENGL_EXPORT const QGLContext *qt_gl_transfer_context(const QGLContext *);
    362263
    363264// GL extension definitions
     
    387288    Q_DECLARE_FLAGS(Extensions, Extension)
    388289
    389     static Extensions glExtensions;
    390     static bool nvidiaFboNeedsFinish;
    391     static void init(); // sys dependent
    392     static void init_extensions(); // general: called by init()
     290    static Extensions glExtensions();
     291
     292private:
     293    static Extensions currentContextExtensions();
     294};
     295
     296/*
     297    QGLTemporaryContext - the main objective of this class is to have a way of
     298    creating a GL context and making it current, without going via QGLWidget
     299    and friends. At certain points during GL initialization we need a current
     300    context in order decide what GL features are available, and to resolve GL
     301    extensions. Having a light-weight way of creating such a context saves
     302    initial application startup time, and it doesn't wind up creating recursive
     303    conflicts.
     304    The class currently uses a private d pointer to hide the platform specific
     305    types. This could possibly been done inline with #ifdef'ery, but it causes
     306    major headaches on e.g. X11 due to namespace pollution.
     307*/
     308class QGLTemporaryContextPrivate;
     309class QGLTemporaryContext {
     310public:
     311    QGLTemporaryContext(bool directRendering = true, QWidget *parent = 0);
     312    ~QGLTemporaryContext();
     313
     314private:
     315    QScopedPointer<QGLTemporaryContextPrivate> d;
     316};
     317
     318class QGLTexture;
     319
     320// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's
     321// all the GL2 engine uses:
     322#define QT_GL_VERTEX_ARRAY_TRACKED_COUNT 3
     323
     324class QGLContextPrivate
     325{
     326    Q_DECLARE_PUBLIC(QGLContext)
     327public:
     328    explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
     329    ~QGLContextPrivate();
     330    QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
     331                            QGLContext::BindOptions options);
     332    QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, const qint64 key,
     333                            QGLContext::BindOptions options);
     334    QGLTexture *bindTexture(const QPixmap &pixmap, GLenum target, GLint format,
     335                            QGLContext::BindOptions options);
     336    QGLTexture *textureCacheLookup(const qint64 key, GLenum target);
     337    void init(QPaintDevice *dev, const QGLFormat &format);
     338    QImage convertToGLFormat(const QImage &image, bool force_premul, GLenum texture_format);
     339    int maxTextureSize();
     340
     341    void cleanup();
     342
     343    void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
     344    void syncGlState(); // Makes sure the GL context's state is what we think it is
     345
     346#if defined(Q_WS_WIN)
     347    HGLRC rc;
     348    HDC dc;
     349    WId        win;
     350    int pixelFormatId;
     351    QGLCmap* cmap;
     352    HBITMAP hbitmap;
     353    HDC hbitmap_hdc;
     354#endif
     355#if defined(QT_OPENGL_ES)
     356    QEglContext *eglContext;
     357    EGLSurface eglSurface;
     358    void destroyEglSurfaceForDevice();
     359#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
     360    void* cx;
     361#endif
     362#if defined(Q_WS_X11) || defined(Q_WS_MAC)
     363    void* vi;
     364#endif
     365#if defined(Q_WS_X11)
     366    void* pbuf;
     367    quint32 gpm;
     368    int screen;
     369    QHash<QPixmapData*, QPixmap> boundPixmaps;
     370    QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
     371                                            QGLContext::BindOptions options);
     372    static void destroyGlSurfaceForPixmap(QPixmapData*);
     373    static void unbindPixmapFromTexture(QPixmapData*);
     374#endif
     375#if defined(Q_WS_MAC)
     376    bool update;
     377    void *tryFormat(const QGLFormat &format);
     378    void clearDrawable();
     379#endif
     380    QGLFormat glFormat;
     381    QGLFormat reqFormat;
     382    GLuint fbo;
     383
     384    uint valid : 1;
     385    uint sharing : 1;
     386    uint initDone : 1;
     387    uint crWin : 1;
     388    uint internal_context : 1;
     389    uint version_flags_cached : 1;
     390    uint extension_flags_cached : 1;
     391    QPaintDevice *paintDevice;
     392    QColor transpColor;
     393    QGLContext *q_ptr;
     394    QGLFormat::OpenGLVersionFlags version_flags;
     395    QGLExtensions::Extensions extension_flags;
     396
     397    QGLContextGroup *group;
     398    GLint max_texture_size;
     399
     400    GLuint current_fbo;
     401    GLuint default_fbo;
     402    QPaintEngine *active_engine;
     403
     404    bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT];
     405
     406    static inline QGLContextGroup *contextGroup(const QGLContext *ctx) { return ctx->d_ptr->group; }
     407
     408#ifdef Q_WS_WIN
     409    static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *ctx) { return ctx->d_ptr->group->extensionFuncs(); }
     410#endif
     411
     412#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
     413    static QGLExtensionFuncs qt_extensionFuncs;
     414    static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
     415#endif
     416
     417    static void setCurrentContext(QGLContext *context);
     418};
     419
     420// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
     421class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
     422{
     423    Q_OBJECT
     424public:
     425    QGLSignalProxy() : QObject() {}
     426    void emitAboutToDestroyContext(const QGLContext *context) {
     427        emit aboutToDestroyContext(context);
     428    }
     429    static QGLSignalProxy *instance();
     430Q_SIGNALS:
     431    void aboutToDestroyContext(const QGLContext *context);
    393432};
    394433
    395434Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
    396 
    397 
    398 class Q_OPENGL_EXPORT QGLShareRegister
    399 {
    400 public:
    401     QGLShareRegister() {}
    402     ~QGLShareRegister() {}
    403 
    404     void addShare(const QGLContext *context, const QGLContext *share);
    405     QList<const QGLContext *> shares(const QGLContext *context);
    406     void removeShare(const QGLContext *context);
    407 };
    408 
    409 extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();
    410435
    411436// Temporarily make a context current if not already current or
     
    498523};
    499524
    500 class QGLTextureCache {
     525class Q_AUTOTEST_EXPORT QGLTextureCache {
    501526public:
    502527    QGLTextureCache();
     
    515540    static void deleteIfEmpty();
    516541    static void imageCleanupHook(qint64 cacheKey);
    517     static void cleanupTextures(QPixmap* pixmap);
    518 #ifdef Q_WS_X11
    519     // X11 needs to catch pixmap data destruction to delete EGL/GLX pixmap surfaces
    520     static void cleanupPixmapSurfaces(QPixmap* pixmap);
    521 #endif
     542    static void cleanupTextures(QPixmapData* pixmap);
     543    static void cleanupBeforePixmapDestruction(QPixmapData* pixmap);
    522544
    523545private:
     
    532554inline GLenum qt_gl_preferredTextureFormat()
    533555{
    534     return (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian
     556    return (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian
    535557        ? GL_BGRA : GL_RGBA;
    536558}
     
    541563    return GL_TEXTURE_2D;
    542564#else
    543     return (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
     565    return (QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle)
    544566           && !qt_gl_preferGL2Engine()
    545567           ? GL_TEXTURE_RECTANGLE_NV
     
    613635
    614636
    615 // This class can be used to match GL extensions with doing any mallocs. The
     637// This class can be used to match GL extensions without doing any mallocs. The
    616638// class assumes that the GL extension string ends with a space character,
    617639// which it should do on all conformant platforms. Create the object and pass
  • trunk/src/opengl/qgl_qws.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)
     
    8282    else
    8383        return 0;
     84}
     85
     86/*
     87    QGLTemporaryContext implementation
     88*/
     89
     90class QGLTemporaryContextPrivate
     91{
     92public:
     93    QGLWidget *widget;
     94};
     95
     96QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     97    : d(new QGLTemporaryContextPrivate)
     98{
     99    d->widget = new QGLWidget;
     100    d->widget->makeCurrent();
     101}
     102
     103QGLTemporaryContext::~QGLTemporaryContext()
     104{
     105    delete d->widget;
    84106}
    85107
     
    312334}
    313335
    314 void QGLExtensions::init()
    315 {
    316     static bool init_done = false;
    317 
    318     if (init_done)
    319         return;
    320     init_done = true;
    321 
    322     // We need a context current to initialize the extensions,
    323     // but getting a valid EGLNativeWindowType this early can be
    324     // problematic under QWS.  So use a pbuffer instead.
    325     //
    326     // Unfortunately OpenGL/ES 2.0 systems don't normally
    327     // support pbuffers, so we have no choice but to try
    328     // our luck with a window on those systems.
    329 #if defined(QT_OPENGL_ES_2)
    330     QGLWidget tmpWidget;
    331     tmpWidget.makeCurrent();
    332 
    333     init_extensions();
    334 
    335     tmpWidget.doneCurrent();
    336 #else
    337     QGLPixelBuffer pbuffer(16, 16);
    338     pbuffer.makeCurrent();
    339 
    340     init_extensions();
    341 
    342     pbuffer.doneCurrent();
    343 #endif
    344 }
    345 
    346336QT_END_NAMESPACE
  • trunk/src/opengl/qgl_win.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)
     
    552552    QVarLengthArray<int> iValues(40);
    553553    int i = 0;
    554     bool has_sample_buffers = QGLExtensions::glExtensions & QGLExtensions::SampleBuffers;
     554    bool has_sample_buffers = QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers;
    555555
    556556    iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB; // 0
     
    629629
    630630/*
    631    Creates a temporary GL context and makes it current
    632    - cleans up when the object is destructed.
     631    QGLTemporaryContext implementation
    633632*/
    634633
    635634Q_GUI_EXPORT const QString qt_getRegisteredWndClass();
    636635
    637 class QGLTempContext
     636class QGLTemporaryContextPrivate
    638637{
    639638public:
    640     QGLTempContext(bool directRendering, QWidget *parent = 0)
    641     {
    642         QString windowClassName = qt_getRegisteredWndClass();
    643         if (parent && !parent->internalWinId())
    644             parent = parent->nativeParentWidget();
    645 
    646         dmy_id = CreateWindow((const wchar_t *)windowClassName.utf16(),
    647                               0, 0, 0, 0, 1, 1,
    648                               parent ? parent->winId() : 0, 0, qWinAppInst(), 0);
    649 
    650         dmy_pdc = GetDC(dmy_id);
    651         PIXELFORMATDESCRIPTOR dmy_pfd;
    652         memset(&dmy_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
    653         dmy_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    654         dmy_pfd.nVersion = 1;
    655         dmy_pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
    656         dmy_pfd.iPixelType = PFD_TYPE_RGBA;
    657         if (!directRendering)
    658             dmy_pfd.dwFlags |= PFD_GENERIC_FORMAT;
    659 
    660         int dmy_pf = ChoosePixelFormat(dmy_pdc, &dmy_pfd);
    661         SetPixelFormat(dmy_pdc, dmy_pf, &dmy_pfd);
    662         dmy_rc = wglCreateContext(dmy_pdc);
    663         old_dc = wglGetCurrentDC();
    664         old_context = wglGetCurrentContext();
    665         wglMakeCurrent(dmy_pdc, dmy_rc);
    666     }
    667 
    668     ~QGLTempContext() {
    669         wglMakeCurrent(dmy_pdc, 0);
    670         wglDeleteContext(dmy_rc);
    671         ReleaseDC(dmy_id, dmy_pdc);
    672         DestroyWindow(dmy_id);
    673         if (old_dc && old_context)
    674             wglMakeCurrent(old_dc, old_context);
    675     }
    676 
    677639    HDC dmy_pdc;
    678640    HGLRC dmy_rc;
     
    681643    WId dmy_id;
    682644};
     645
     646QGLTemporaryContext::QGLTemporaryContext(bool directRendering, QWidget *parent)
     647    : d(new QGLTemporaryContextPrivate)
     648{
     649    QString windowClassName = qt_getRegisteredWndClass();
     650    if (parent && !parent->internalWinId())
     651        parent = parent->nativeParentWidget();
     652
     653    d->dmy_id = CreateWindow((const wchar_t *)windowClassName.utf16(),
     654                             0, 0, 0, 0, 1, 1,
     655                             parent ? parent->winId() : 0, 0, qWinAppInst(), 0);
     656
     657    d->dmy_pdc = GetDC(d->dmy_id);
     658    PIXELFORMATDESCRIPTOR dmy_pfd;
     659    memset(&dmy_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
     660    dmy_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
     661    dmy_pfd.nVersion = 1;
     662    dmy_pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
     663    dmy_pfd.iPixelType = PFD_TYPE_RGBA;
     664    if (!directRendering)
     665        dmy_pfd.dwFlags |= PFD_GENERIC_FORMAT;
     666
     667    int dmy_pf = ChoosePixelFormat(d->dmy_pdc, &dmy_pfd);
     668    SetPixelFormat(d->dmy_pdc, dmy_pf, &dmy_pfd);
     669    d->dmy_rc = wglCreateContext(d->dmy_pdc);
     670    d->old_dc = wglGetCurrentDC();
     671    d->old_context = wglGetCurrentContext();
     672    wglMakeCurrent(d->dmy_pdc, d->dmy_rc);
     673}
     674
     675QGLTemporaryContext::~QGLTemporaryContext()
     676{
     677    wglMakeCurrent(d->dmy_pdc, 0);
     678    wglDeleteContext(d->dmy_rc);
     679    ReleaseDC(d->dmy_id, d->dmy_pdc);
     680    DestroyWindow(d->dmy_id);
     681    if (d->old_dc && d->old_context)
     682        wglMakeCurrent(d->old_dc, d->old_context);
     683}
    683684
    684685bool QGLContext::chooseContext(const QGLContext* shareContext)
     
    722723    }
    723724
    724     // NB! the QGLTempContext object is needed for the
     725    // NB! the QGLTemporaryContext object is needed for the
    725726    // wglGetProcAddress() calls to succeed and are absolutely
    726727    // necessary - don't remove!
    727     QGLTempContext tmp_ctx(d->glFormat.directRendering(), widget);
     728    QGLTemporaryContext tmp_ctx(d->glFormat.directRendering(), widget);
    728729
    729730    if (!myDc) {
     
    966967        }
    967968        int si = 0;
    968         bool trySampleBuffers = QGLExtensions::glExtensions & QGLExtensions::SampleBuffers;
     969        bool trySampleBuffers = QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers;
    969970        if (trySampleBuffers && d->glFormat.sampleBuffers()) {
    970971            iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB;
     
    11461147    d->cmap = 0;
    11471148    d->initDone = false;
    1148     qgl_share_reg()->removeShare(this);
     1149    QGLContextGroup::removeShare(this);
    11491150}
    11501151
     
    14721473}
    14731474
    1474 void QGLExtensions::init()
    1475 {
    1476     static bool init_done = false;
    1477 
    1478     if (init_done)
    1479         return;
    1480     init_done = true;
    1481     QGLTempContext temp_ctx(QGLFormat::defaultFormat().directRendering());
    1482     init_extensions();
    1483 }
    1484 
    14851475QT_END_NAMESPACE
  • trunk/src/opengl/qgl_wince.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)
     
    9696#include <qcolor.h>
    9797
    98 
    99 
     98/*
     99    QGLTemporaryContext implementation
     100*/
     101
     102class QGLTemporaryContextPrivate
     103{
     104public:
     105    QGLWidget *widget;
     106};
     107
     108QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     109    : d(new QGLTemporaryContextPrivate)
     110{
     111    d->widget = new QGLWidget;
     112    d->widget->makeCurrent();
     113}
     114
     115QGLTemporaryContext::~QGLTemporaryContext()
     116{
     117    delete d->widget;
     118}
    100119
    101120/*****************************************************************************
     
    628647}
    629648
    630 void QGLExtensions::init()
    631 {
    632     static bool init_done = false;
    633 
    634     if (init_done)
    635         return;
    636     init_done = true;
    637 
    638     // We need a context current to initialize the extensions.
    639     QGLWidget tmpWidget;
    640     tmpWidget.makeCurrent();
    641 
    642     init_extensions();
    643 
    644     tmpWidget.doneCurrent();
    645 }
    646 
    647649QT_END_NAMESPACE
  • trunk/src/opengl/qgl_x11.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)
     
    550550    bool triedSample = false;
    551551    if (fmt.sampleBuffers())
    552         fmt.setSampleBuffers(QGLExtensions::glExtensions & QGLExtensions::SampleBuffers);
     552        fmt.setSampleBuffers(QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers);
    553553    while(!fail && !(vis = tryVisual(fmt, bufDepths[i]))) {
    554554        if (!fmt.rgba() && bufDepths[i] > 1) {
     
    826826    d->transpColor = QColor();
    827827    d->initDone = false;
    828     qgl_share_reg()->removeShare(this);
     828    QGLContextGroup::removeShare(this);
    829829}
    830830
     
    11331133}
    11341134
     1135/*
     1136    QGLTemporaryContext implementation
     1137*/
     1138
     1139class QGLTemporaryContextPrivate {
     1140public:
     1141    bool initialized;
     1142    Window drawable;
     1143    GLXContext context;
     1144    GLXDrawable oldDrawable;
     1145    GLXContext oldContext;
     1146};
     1147
     1148QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     1149    : d(new QGLTemporaryContextPrivate)
     1150{
     1151    d->initialized = false;
     1152    d->oldDrawable = 0;
     1153    d->oldContext = 0;
     1154    int screen = 0;
     1155
     1156    int attribs[] = {GLX_RGBA, XNone};
     1157    XVisualInfo *vi = glXChooseVisual(X11->display, screen, attribs);
     1158    if (!vi) {
     1159        qWarning("QGLTempContext: No GL capable X visuals available.");
     1160        return;
     1161    }
     1162
     1163    int useGL;
     1164    glXGetConfig(X11->display, vi, GLX_USE_GL, &useGL);
     1165    if (!useGL) {
     1166        XFree(vi);
     1167        return;
     1168    }
     1169
     1170    d->oldDrawable = glXGetCurrentDrawable();
     1171    d->oldContext = glXGetCurrentContext();
     1172
     1173    XSetWindowAttributes a;
     1174    a.colormap = qt_gl_choose_cmap(X11->display, vi);
     1175    d->drawable = XCreateWindow(X11->display, RootWindow(X11->display, screen),
     1176                                0, 0, 1, 1, 0,
     1177                                vi->depth, InputOutput, vi->visual,
     1178                                CWColormap, &a);
     1179    d->context = glXCreateContext(X11->display, vi, 0, True);
     1180    if (d->context && glXMakeCurrent(X11->display, d->drawable, d->context)) {
     1181        d->initialized = true;
     1182    } else {
     1183        qWarning("QGLTempContext: Unable to create GL context.");
     1184        XDestroyWindow(X11->display, d->drawable);
     1185    }
     1186    XFree(vi);
     1187}
     1188
     1189QGLTemporaryContext::~QGLTemporaryContext()
     1190{
     1191    if (d->initialized) {
     1192        glXMakeCurrent(X11->display, 0, 0);
     1193        glXDestroyContext(X11->display, d->context);
     1194        XDestroyWindow(X11->display, d->drawable);
     1195    }
     1196    if (d->oldDrawable && d->oldContext)
     1197        glXMakeCurrent(X11->display, d->oldDrawable, d->oldContext);
     1198}
     1199
    11351200/*****************************************************************************
    11361201  QGLOverlayWidget (Internal overlay class for X11)
     
    15671632}
    15681633
    1569 void QGLExtensions::init()
    1570 {
    1571     static bool init_done = false;
    1572 
    1573     if (init_done)
    1574         return;
    1575     init_done = true;
    1576 
    1577     QGLWidget dmy;
    1578     dmy.makeCurrent();
    1579     init_extensions();
    1580 
    1581     // nvidia 9x.xx unix drivers contain a bug which requires us to call glFinish before releasing an fbo
    1582     // to avoid painting artifacts
    1583     const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
    1584     const int pos = versionString.indexOf("NVIDIA");
    1585     if (pos >= 0) {
    1586         const float nvidiaDriverVersion = versionString.mid(pos + strlen("NVIDIA")).toFloat();
    1587         nvidiaFboNeedsFinish = nvidiaDriverVersion >= 90.0 && nvidiaDriverVersion < 100.0;
    1588     }
    1589 }
    1590 
    15911634// Solaris defines glXBindTexImageEXT as part of the GL library
    15921635#if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
     
    16041647
    16051648        // Check to see if we have NPOT texture support
    1606         if ( !(QGLExtensions::glExtensions & QGLExtensions::NPOTTextures) &&
     1649        if ( !(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) &&
    16071650             !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0))
    16081651        {
    16091652            return false; // Can't use TFP without NPOT
    16101653        }
     1654
    16111655        const QX11Info *xinfo = qt_x11Info(paintDevice);
    1612         QGLExtensionMatcher extensions(glXQueryExtensionsString(xinfo->display(), xinfo->screen()));
     1656        Display *display = xinfo ? xinfo->display() : X11->display;
     1657        int screen = xinfo ? xinfo->screen() : X11->defaultScreen;
     1658
     1659        QGLExtensionMatcher extensions(glXQueryExtensionsString(display, screen));
    16131660        if (extensions.match("GLX_EXT_texture_from_pixmap")) {
    16141661            glXBindTexImageEXT = (qt_glXBindTexImageEXT) qglx_getProcAddress("glXBindTexImageEXT");
  • trunk/src/opengl/qgl_x11egl.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)
     
    5353QT_BEGIN_NAMESPACE
    5454
     55
     56bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config,
     57                             const QX11Info &x11Info, bool useArgbVisual);
     58
     59/*
     60    QGLTemporaryContext implementation
     61*/
     62
     63class QGLTemporaryContextPrivate
     64{
     65public:
     66    bool initialized;
     67    Window window;
     68    EGLContext context;
     69    EGLSurface surface;
     70    EGLDisplay display;
     71};
     72
     73QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     74    : d(new QGLTemporaryContextPrivate)
     75{
     76    d->initialized = false;
     77    d->window = 0;
     78    d->context = 0;
     79    d->surface = 0;
     80    int screen = 0;
     81
     82    d->display = eglGetDisplay(EGLNativeDisplayType(X11->display));
     83
     84    if (!eglInitialize(d->display, NULL, NULL)) {
     85        qWarning("QGLTemporaryContext: Unable to initialize EGL display.");
     86        return;
     87    }
     88
     89    EGLConfig config;
     90    int numConfigs = 0;
     91    EGLint attribs[] = {
     92        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
     93#ifdef QT_OPENGL_ES_2
     94        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
     95#endif
     96        EGL_NONE
     97    };
     98
     99    eglChooseConfig(d->display, attribs, &config, 1, &numConfigs);
     100    if (!numConfigs) {
     101        qWarning("QGLTemporaryContext: No EGL configurations available.");
     102        return;
     103    }
     104
     105    XVisualInfo visualInfo;
     106    XVisualInfo *vi;
     107    int numVisuals;
     108    EGLint id = 0;
     109
     110    eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id);
     111    if (id == 0) {
     112        // EGL_NATIVE_VISUAL_ID is optional and might not be supported
     113        // on some implementations - we'll have to do it the hard way
     114        QX11Info xinfo;
     115        qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false);
     116    } else {
     117        visualInfo.visualid = id;
     118    }
     119    vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals);
     120    if (!vi || numVisuals < 1) {
     121        qWarning("QGLTemporaryContext: Unable to get X11 visual info id.");
     122        return;
     123    }
     124
     125    d->window = XCreateWindow(X11->display, RootWindow(X11->display, screen),
     126                              0, 0, 1, 1, 0,
     127                              vi->depth, InputOutput, vi->visual,
     128                              0, 0);
     129
     130    d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL);
     131
     132    if (d->surface == EGL_NO_SURFACE) {
     133        qWarning("QGLTemporaryContext: Error creating EGL surface.");
     134        XFree(vi);
     135        XDestroyWindow(X11->display, d->window);
     136        return;
     137    }
     138
     139    EGLint contextAttribs[] = {
     140#ifdef QT_OPENGL_ES_2
     141        EGL_CONTEXT_CLIENT_VERSION, 2,
     142#endif
     143        EGL_NONE
     144    };
     145    d->context = eglCreateContext(d->display, config, 0, contextAttribs);
     146    if (d->context != EGL_NO_CONTEXT
     147        && eglMakeCurrent(d->display, d->surface, d->surface, d->context))
     148    {
     149        d->initialized = true;
     150    } else {
     151        qWarning("QGLTemporaryContext: Error creating EGL context.");
     152        eglDestroySurface(d->display, d->surface);
     153        XDestroyWindow(X11->display, d->window);
     154    }
     155    XFree(vi);
     156}
     157
     158QGLTemporaryContext::~QGLTemporaryContext()
     159{
     160    if (d->initialized) {
     161        eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     162        eglDestroyContext(d->display, d->context);
     163        eglDestroySurface(d->display, d->surface);
     164        XDestroyWindow(X11->display, d->window);
     165    }
     166}
     167
    55168bool QGLFormat::hasOpenGLOverlays()
    56169{
     
    240353    // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first
    241354    // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo
    242          
     355
    243356#if !defined(QT_NO_XRENDER)
    244357    if (vi.visualid == 0 && useArgbVisual) {
     
    438551}
    439552
    440 void QGLExtensions::init()
    441 {
    442     static bool init_done = false;
    443 
    444     if (init_done)
    445         return;
    446     init_done = true;
    447 
    448     // We need a context current to initialize the extensions.
    449     QGLWidget tmpWidget;
    450     tmpWidget.makeCurrent();
    451 
    452     init_extensions();
    453 
    454     tmpWidget.doneCurrent();
    455 }
    456 
    457553// Re-creates the EGL surface if the window ID has changed or if force is true
    458554void QGLWidgetPrivate::recreateEglSurface(bool force)
  • trunk/src/opengl/qglcolormap.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)
  • trunk/src/opengl/qglcolormap.h

    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)
  • trunk/src/opengl/qglextensions.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)
  • trunk/src/opengl/qglextensions_p.h

    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)
  • trunk/src/opengl/qglframebufferobject.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)
     
    397397    fbo_guard.setContext(ctx);
    398398
    399     bool ext_detected = (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject);
     399    bool ext_detected = (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject);
    400400    if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(ctx)))
    401401        return;
     
    467467
    468468    if (attachment == QGLFramebufferObject::CombinedDepthStencil
    469         && (QGLExtensions::glExtensions & QGLExtensions::PackedDepthStencil)) {
     469        && (QGLExtensions::glExtensions() & QGLExtensions::PackedDepthStencil)) {
    470470        // depth and stencil buffer needs another extension
    471471        glGenRenderbuffers(1, &depth_stencil_buffer);
     
    10291029bool QGLFramebufferObject::hasOpenGLFramebufferObjects()
    10301030{
    1031     QGLExtensions::init();
    1032     return (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject);
     1031    return (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject);
    10331032}
    10341033
     
    11891188bool QGLFramebufferObject::hasOpenGLFramebufferBlit()
    11901189{
    1191     QGLExtensions::init();
    1192     return (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit);
     1190    return (QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit);
    11931191}
    11941192
     
    12301228                                           GLenum filter)
    12311229{
    1232     if (!(QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit))
     1230    if (!(QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit))
    12331231        return;
    12341232
  • trunk/src/opengl/qglframebufferobject.h

    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)
  • trunk/src/opengl/qglframebufferobject_p.h

    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)
  • trunk/src/opengl/qglpaintdevice.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)
  • trunk/src/opengl/qglpaintdevice_p.h

    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)
  • trunk/src/opengl/qglpixelbuffer.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)
     
    128128        qctx->d_func()->sharing = (shareWidget != 0);
    129129        if (shareWidget != 0 && shareWidget->d_func()->glcx) {
    130             qgl_share_reg()->addShare(qctx, shareWidget->d_func()->glcx);
     130            QGLContextGroup::addShare(qctx, shareWidget->d_func()->glcx);
    131131            shareWidget->d_func()->glcx->d_func()->sharing = true;
    132132        }
  • trunk/src/opengl/qglpixelbuffer.h

    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)
  • trunk/src/opengl/qglpixelbuffer_egl.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)
  • trunk/src/opengl/qglpixelbuffer_mac.mm

    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)
     
    9393    GLenum target = GL_TEXTURE_2D;
    9494
    95     if ((QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
     95    if ((QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle)
    9696        && (size.width() != nearest_gl_texture_size(size.width())
    9797            || size.height() != nearest_gl_texture_size(size.height())))
     
    224224    GLenum target = GL_TEXTURE_2D;
    225225
    226     if ((QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
     226    if ((QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle)
    227227        && (size.width() != nearest_gl_texture_size(size.width())
    228228            || size.height() != nearest_gl_texture_size(size.height())))
  • trunk/src/opengl/qglpixelbuffer_p.h

    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)
     
    155155    QGLPixelBufferPrivate(QGLPixelBuffer *q) : q_ptr(q), invalid(true), qctx(0), pbuf(0), ctx(0)
    156156    {
    157         QGLExtensions::init();
    158157#ifdef Q_WS_WIN
    159158        dc = 0;
  • trunk/src/opengl/qglpixelbuffer_win.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)
     
    222222    if ((f.redBufferSize() > 8 || f.greenBufferSize() > 8
    223223         || f.blueBufferSize() > 8 || f.alphaBufferSize() > 8)
    224         && (QGLExtensions::glExtensions & QGLExtensions::NVFloatBuffer))
     224        && (QGLExtensions::glExtensions() & QGLExtensions::NVFloatBuffer))
    225225    {
    226226        attribs[i++] = WGL_FLOAT_COMPONENTS_NV;
     
    369369{
    370370    bool ret = false;
    371     QGLWidget *dmy = 0;
    372     if (!QGLContext::currentContext()) {
    373         dmy = new QGLWidget;
    374         dmy->makeCurrent();
    375     }
     371    QGLTemporaryContext *tmpContext = 0;
     372    if (!QGLContext::currentContext())
     373        tmpContext = new QGLTemporaryContext;
    376374    PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB =
    377375        (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
     
    383381        }
    384382    }
    385     if (dmy)
    386         delete dmy;
     383    if (tmpContext)
     384        delete tmpContext;
    387385    return ret;
    388386}
  • trunk/src/opengl/qglpixelbuffer_x11.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)
  • trunk/src/opengl/qglpixmapfilter.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)
     
    320320
    321321    QGLBlurTextureInfo *takeBlurTextureInfo(const QPixmap &pixmap);
    322     bool hasBlurTextureInfo(const QPixmap &pixmap) const;
     322    bool hasBlurTextureInfo(quint64 cacheKey) const;
    323323    void insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info);
    324     void clearBlurTextureInfo(const QPixmap &pixmap);
     324    void clearBlurTextureInfo(quint64 cacheKey);
    325325
    326326    void timerEvent(QTimerEvent *event);
    327327
    328328private:
    329     static void pixmapDestroyed(QPixmap *pixmap);
     329    static void pixmapDestroyed(QPixmapData *pixmap);
    330330
    331331    QCache<quint64, QGLBlurTextureInfo > cache;
     
    380380}
    381381
    382 void QGLBlurTextureCache::clearBlurTextureInfo(const QPixmap &pixmap)
    383 {
    384     cache.remove(pixmap.cacheKey());
    385 }
    386 
    387 bool QGLBlurTextureCache::hasBlurTextureInfo(const QPixmap &pixmap) const
    388 {
    389     return cache.contains(pixmap.cacheKey());
     382void QGLBlurTextureCache::clearBlurTextureInfo(quint64 cacheKey)
     383{
     384    cache.remove(cacheKey);
     385}
     386
     387bool QGLBlurTextureCache::hasBlurTextureInfo(quint64 cacheKey) const
     388{
     389    return cache.contains(cacheKey);
    390390}
    391391
     
    394394    static bool hookAdded = false;
    395395    if (!hookAdded) {
    396         QImagePixmapCleanupHooks::instance()->addPixmapDestructionHook(pixmapDestroyed);
     396        QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(pixmapDestroyed);
    397397        hookAdded = true;
    398398    }
     
    407407}
    408408
    409 void QGLBlurTextureCache::pixmapDestroyed(QPixmap *pixmap)
     409void QGLBlurTextureCache::pixmapDestroyed(QPixmapData *pmd)
    410410{
    411411    foreach (QGLBlurTextureCache *cache, blurTextureCaches) {
    412         if (cache->hasBlurTextureInfo(*pixmap))
    413             cache->clearBlurTextureInfo(*pixmap);
     412        if (cache->hasBlurTextureInfo(pmd->cacheKey()))
     413            cache->clearBlurTextureInfo(pmd->cacheKey());
    414414    }
    415415}
  • trunk/src/opengl/qglpixmapfilter_p.h

    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)
  • trunk/src/opengl/qglscreen_qws.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)
  • trunk/src/opengl/qglscreen_qws.h

    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)
  • trunk/src/opengl/qglshaderprogram.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)
     
    106106
    107107    \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 2
     108
     109    \section1 Binary shaders and programs
     110
     111    Binary shaders may be specified using \c{glShaderBinary()} on
     112    the return value from QGLShader::shaderId().  The QGLShader instance
     113    containing the binary can then be added to the shader program with
     114    addShader() and linked in the usual fashion with link().
     115
     116    Binary programs may be specified using \c{glProgramBinaryOES()}
     117    on the return value from programId().  Then the application should
     118    call link(), which will notice that the program has already been
     119    specified and linked, allowing other operations to be performed
     120    on the shader program.
    108121
    109122    \sa QGLShader
     
    633646            return false;
    634647        }
    635         if (!shader->d_func()->compiled)
    636             return false;
    637648        if (!shader->d_func()->shaderGuard.id())
    638649            return false;
     
    821832    if (!program)
    822833        return false;
     834    GLint value;
     835    if (d->shaders.isEmpty()) {
     836        // If there are no explicit shaders, then it is possible that the
     837        // application added a program binary with glProgramBinaryOES(),
     838        // or otherwise populated the shaders itself.  Check to see if the
     839        // program is already linked and bail out if so.
     840        value = 0;
     841        glGetProgramiv(program, GL_LINK_STATUS, &value);
     842        d->linked = (value != 0);
     843        if (d->linked)
     844            return true;
     845    }
    823846    glLinkProgram(program);
    824     GLint value = 0;
     847    value = 0;
    825848    glGetProgramiv(program, GL_LINK_STATUS, &value);
    826849    d->linked = (value != 0);
     
    929952{
    930953    Q_D(const QGLShaderProgram);
     954    GLuint id = d->programGuard.id();
     955    if (id)
     956        return id;
     957
     958    // Create the identifier if we don't have one yet.  This is for
     959    // applications that want to create the attached shader configuration
     960    // themselves, particularly those using program binaries.
     961    if (!const_cast<QGLShaderProgram *>(this)->init())
     962        return 0;
    931963    return d->programGuard.id();
    932964}
  • trunk/src/opengl/qglshaderprogram.h

    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)
  • trunk/src/opengl/qglwindowsurface_qws.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)
  • trunk/src/opengl/qglwindowsurface_qws_p.h

    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)
  • trunk/src/opengl/qgraphicsshadereffect.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)
  • trunk/src/opengl/qgraphicsshadereffect_p.h

    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)
  • trunk/src/opengl/qgraphicssystem_gl.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)
  • trunk/src/opengl/qgraphicssystem_gl_p.h

    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)
  • trunk/src/opengl/qpaintengine_opengl.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)
     
    109109#endif
    110110
     111#ifdef Q_WS_X11
     112static bool qt_nvidiaFboNeedsFinish = false;
     113#endif
     114
    111115static inline void qt_glColor4ubv(unsigned char *col)
    112116{
     
    424428#ifdef Q_WS_X11
    425429    // workaround for bug in nvidia driver versions 9x.xx
    426     if (QGLExtensions::nvidiaFboNeedsFinish)
     430    if (qt_nvidiaFboNeedsFinish)
    427431        glFinish();
    428432#endif
     
    478482bool QGLOffscreen::isSupported()
    479483{
    480     return (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject); // for fbo
     484    return (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject); // for fbo
    481485}
    482486
     
    12671271            d->mv_matrix[i][j] = (i == j ? qreal(1) : qreal(0));
    12681272
    1269     bool has_frag_program = (QGLExtensions::glExtensions & QGLExtensions::FragmentProgram)
     1273    bool has_frag_program = (QGLExtensions::glExtensions() & QGLExtensions::FragmentProgram)
    12701274                            && (pdev->devType() != QInternal::Pixmap);
    12711275
     
    12801284
    12811285    d->use_stencil_method = d->device->format().stencil()
    1282                             && (QGLExtensions::glExtensions & QGLExtensions::StencilWrap);
     1286                            && (QGLExtensions::glExtensions() & QGLExtensions::StencilWrap);
    12831287    if (d->device->format().directRendering()
    1284         && (d->use_stencil_method && QGLExtensions::glExtensions & QGLExtensions::StencilTwoSide))
     1288        && (d->use_stencil_method && QGLExtensions::glExtensions() & QGLExtensions::StencilTwoSide))
    12851289        d->has_stencil_face_ext = qt_resolve_stencil_face_extension(ctx);
     1290
     1291#ifdef Q_WS_X11
     1292    static bool nvidia_workaround_needs_init = true;
     1293    if (nvidia_workaround_needs_init) {
     1294        // nvidia 9x.xx unix drivers contain a bug which requires us to
     1295        // call glFinish before releasing an fbo to avoid painting
     1296        // artifacts
     1297        const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
     1298        const int pos = versionString.indexOf("NVIDIA");
     1299        if (pos >= 0) {
     1300            const float nvidiaDriverVersion = versionString.mid(pos + strlen("NVIDIA")).toFloat();
     1301            qt_nvidiaFboNeedsFinish = nvidiaDriverVersion >= 90.0 && nvidiaDriverVersion < 100.0;
     1302        }
     1303        nvidia_workaround_needs_init = false;
     1304    }
     1305#endif
    12861306
    12871307#ifndef QT_OPENGL_ES
     
    13341354        glDisableClientState(GL_VERTEX_ARRAY);
    13351355
    1336         if (QGLExtensions::glExtensions & QGLExtensions::SampleBuffers)
     1356        if (QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers)
    13371357            glDisable(GL_MULTISAMPLE);
    13381358        glDisable(GL_TEXTURE_2D);
    1339         if (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
     1359        if (QGLExtensions::glExtensions() & QGLExtensions::TextureRectangle)
    13401360            glDisable(GL_TEXTURE_RECTANGLE_NV);
    13411361        glDisable(GL_STENCIL_TEST);
     
    15351555    Q_UNUSED(brush);
    15361556#else
    1537     bool has_mirrored_repeat = QGLExtensions::glExtensions & QGLExtensions::MirroredRepeat;
     1557    bool has_mirrored_repeat = QGLExtensions::glExtensions() & QGLExtensions::MirroredRepeat;
    15381558    Qt::BrushStyle style = brush.style();
    15391559
     
    20992119    return !(style == Qt::SolidPattern
    21002120             || (style == Qt::LinearGradientPattern
    2101                  && (QGLExtensions::glExtensions & QGLExtensions::MirroredRepeat)));
     2121                 && (QGLExtensions::glExtensions() & QGLExtensions::MirroredRepeat)));
    21022122}
    21032123
     
    24212441        } else {
    24222442            d->high_quality_antialiasing = false;
    2423             if (QGLExtensions::glExtensions & QGLExtensions::SampleBuffers)
     2443            if (QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers)
    24242444                glEnable(GL_MULTISAMPLE);
    24252445        }
    24262446    } else {
    24272447        d->high_quality_antialiasing = false;
    2428         if (QGLExtensions::glExtensions & QGLExtensions::SampleBuffers)
     2448        if (QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers)
    24292449            glDisable(GL_MULTISAMPLE);
    24302450    }
     
    24362456            DEBUG_ONCE_STR("Unable to initialize offscreen, disabling high quality antialiasing");
    24372457            d->high_quality_antialiasing = false;
    2438             if (QGLExtensions::glExtensions & QGLExtensions::SampleBuffers)
     2458            if (QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers)
    24392459                glEnable(GL_MULTISAMPLE);
    24402460        }
     
    24432463    d->has_antialiasing = d->high_quality_antialiasing
    24442464                          || ((hints & QPainter::Antialiasing)
    2445                               && (QGLExtensions::glExtensions & QGLExtensions::SampleBuffers));
     2465                              && (QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers));
    24462466}
    24472467
     
    49324952    glEnableClientState(GL_VERTEX_ARRAY);
    49334953    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    4934     bool antialias = !(ti.fontEngine->fontDef.styleStrategy & QFont::NoAntialias);
     4954    bool antialias = !(ti.fontEngine->fontDef.styleStrategy & QFont::NoAntialias)
     4955                   && (d->matrix.type() > QTransform::TxTranslate);
    49354956    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
    49364957    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, antialias ? GL_LINEAR : GL_NEAREST);
  • trunk/src/opengl/qpaintengine_opengl_p.h

    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)
  • trunk/src/opengl/qpixmapdata_gl.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)
     
    342342    if (!m_source.isNull()) {
    343343        if (external_format == GL_RGB) {
    344             const QImage tx = m_source.convertToFormat(QImage::Format_RGB888);
     344            const QImage tx = m_source.convertToFormat(QImage::Format_RGB888).mirrored(false, true);
    345345
    346346            glBindTexture(target, m_texture.id);
  • trunk/src/opengl/qpixmapdata_gl_p.h

    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)
  • trunk/src/opengl/qpixmapdata_x11gl_egl.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)
     
    4040****************************************************************************/
    4141
     42#include <QDebug>
     43
    4244#include <private/qgl_p.h>
    4345#include <private/qegl_p.h>
    4446#include <private/qeglproperties_p.h>
     47
     48#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
    4549#include <private/qpaintengineex_opengl2_p.h>
     50#endif
     51
     52#ifndef QT_OPENGL_ES_2
     53#include <private/qpaintengine_opengl_p.h>
     54#endif
    4655
    4756#include "qpixmapdata_x11gl_p.h"
     
    188197}
    189198
    190 static QGL2PaintEngineEx* qt_gl2_engine_for_pixmaps = 0;
     199#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
     200Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_pixmap_2_engine)
     201#endif
     202
     203#ifndef QT_OPENGL_ES_2
     204Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_pixmap_engine)
     205#endif
     206
    191207
    192208QPaintEngine* QX11GLPixmapData::paintEngine() const
     
    203219    }
    204220
    205     if (!qt_gl2_engine_for_pixmaps)
    206         qt_gl2_engine_for_pixmaps = new QGL2PaintEngineEx();
     221    QPaintEngine* engine;
     222
     223#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
     224    engine = qt_gl_pixmap_engine();
     225#elif defined(QT_OPENGL_ES_2)
     226    engine = qt_gl_pixmap_2_engine();
     227#else
     228    if (qt_gl_preferGL2Engine())
     229        engine = qt_gl_pixmap_2_engine();
     230    else
     231        engine = qt_gl_pixmap_engine();
     232#endif
     233
     234
    207235
    208236    // Support multiple painters on multiple pixmaps simultaniously
    209     if (qt_gl2_engine_for_pixmaps->isActive()) {
     237    if (engine->isActive()) {
    210238        qWarning("Pixmap paint engine already active");
    211         QPaintEngine* engine = new QGL2PaintEngineEx();
     239
     240#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
     241        engine = new QOpenGLPaintEngine;
     242#elif defined(QT_OPENGL_ES_2)
     243        engine = new QGL2PaintEngineEx;
     244#else
     245        if (qt_gl_preferGL2Engine())
     246            engine = new QGL2PaintEngineEx;
     247        else
     248            engine = new QOpenGLPaintEngine;
     249#endif
     250
    212251        engine->setAutoDestruct(true);
    213252        return engine;
    214253    }
    215254
    216     return qt_gl2_engine_for_pixmaps;
     255    return engine;
    217256}
    218257
  • trunk/src/opengl/qpixmapdata_x11gl_p.h

    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)
  • trunk/src/opengl/qwindowsurface_gl.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)
     
    296296{
    297297    Q_ASSERT(window->isTopLevel());
    298     QGLExtensions::init();
    299298    d_ptr->pb = 0;
    300299    d_ptr->fbo = 0;
     
    521520    glDisable(GL_SCISSOR_TEST);
    522521
    523     if (d_ptr->fbo && (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit)) {
     522    if (d_ptr->fbo && (QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit)) {
    524523        const int h = d_ptr->fbo->height();
    525524
     
    699698
    700699    if (d_ptr->destructive_swap_buffers
    701         && (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject)
     700        && (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject)
    702701        && (d_ptr->fbo || !d_ptr->tried_fbo)
    703702        && qt_gl_preferGL2Engine())
     
    713712        format.setTextureTarget(target);
    714713
    715         if (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit)
     714        if (QGLExtensions::glExtensions() & QGLExtensions::FramebufferBlit)
    716715            format.setSamples(8);
    717716
  • trunk/src/opengl/qwindowsurface_gl_p.h

    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)
  • trunk/src/opengl/qwindowsurface_x11gl.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)
  • trunk/src/opengl/qwindowsurface_x11gl_p.h

    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)
  • trunk/src/opengl/util/fragmentprograms_p.h

    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)
  • trunk/src/opengl/util/generator.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)
     
    288288    out << "/****************************************************************************\n"
    289289           "**\n"
    290            "** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n"
     290           "** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).\n"
    291291           "** All rights reserved.\n"
    292292           "** Contact: Nokia Corporation (qt-info@nokia.com)\n"
  • trunk/src/opengl/util/glsl_to_include.sh

    r561 r651  
    22#############################################################################
    33##
    4 ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     4## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    55## All rights reserved.
    66## Contact: Nokia Corporation (qt-info@nokia.com)
Note: See TracChangeset for help on using the changeset viewer.