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:
14 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)
Note: See TracChangeset for help on using the changeset viewer.