~compiz-team/compiz/compiz.packaging.gles2

« back to all changes in this revision

Viewing changes to plugins/ezoom/src/ezoom.cpp

  • Committer: Sam Spilsbury
  • Date: 2012-07-11 01:34:55 UTC
  • mfrom: (3273.1.2 compiz.packaging.gles)
  • Revision ID: sam.spilsbury@canonical.com-20120711013455-489y3e43oldfe395
[ Sam Spilsbury ]
Update patches for GLES2 support

Show diffs side-by-side

added added

removed removed

Lines of Context:
378
378
/* Draws a box from the screen coordinates inx1,iny1 to inx2,iny2 */
379
379
void
380
380
EZoomScreen::drawBox (const GLMatrix &transform,
381
 
                     CompOutput          *output,
382
 
                     CompRect             box)
 
381
                      CompOutput     *output,
 
382
                      CompRect        box)
383
383
{
384
 
    GLMatrix zTransform = transform;
385
 
    int           x1,x2,y1,y2;
386
 
    int           inx1, inx2, iny1, iny2;
387
 
    int           out = output->id ();
 
384
    GLMatrix zTransform (transform);
 
385
    int      x1, x2, y1, y2;
 
386
    int      inx1, inx2, iny1, iny2;
 
387
    int      out = output->id ();
 
388
    GLushort colorData[4];
 
389
    GLfloat  vertexData[12];
 
390
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
388
391
 
389
392
    zTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
390
393
    convertToZoomed (out, box.x1 (), box.y1 (), &inx1, &iny1);
394
397
    y1 = MIN (iny1, iny2);
395
398
    x2 = MAX (inx1, inx2);
396
399
    y2 = MAX (iny1, iny2);
397
 
    glPushMatrix ();
398
 
    glLoadMatrixf (zTransform.getMatrix ());
399
 
    glDisableClientState (GL_TEXTURE_COORD_ARRAY);
400
 
    glEnable (GL_BLEND);
401
 
    glColor4us (0x2fff, 0x2fff, 0x4fff, 0x4fff);
402
 
    glRecti (x1,y2,x2,y1);
403
 
    glColor4us (0x2fff, 0x2fff, 0x4fff, 0x9fff);
404
 
    glBegin (GL_LINE_LOOP);
405
 
    glVertex2i (x1, y1);
406
 
    glVertex2i (x2, y1);
407
 
    glVertex2i (x2, y2);
408
 
    glVertex2i (x1, y2);
409
 
    glEnd ();
410
 
    glColor4usv (defaultColor);
411
 
    glDisable (GL_BLEND);
412
 
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);
413
 
    glPopMatrix ();
 
400
 
 
401
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
402
 
 
403
    colorData[0] = 0x2fff;
 
404
    colorData[1] = 0x2fff;
 
405
    colorData[2] = 0x2fff;
 
406
    colorData[3] = 0x4fff;
 
407
 
 
408
    streamingBuffer->addColors (1, colorData);
 
409
 
 
410
    vertexData[0]  = x1;
 
411
    vertexData[1]  = y1;
 
412
    vertexData[2]  = 0.0f;
 
413
    vertexData[3]  = x1;
 
414
    vertexData[4]  = y2;
 
415
    vertexData[5]  = 0.0f;
 
416
    vertexData[6]  = x2;
 
417
    vertexData[7]  = y1;
 
418
    vertexData[8]  = 0.0f;
 
419
    vertexData[9]  = x2;
 
420
    vertexData[10] = y2;
 
421
    vertexData[11] = 0.0f;
 
422
 
 
423
    streamingBuffer->addVertices (4, vertexData);
 
424
 
 
425
    streamingBuffer->end ();
 
426
    streamingBuffer->render (zTransform);
 
427
 
 
428
 
 
429
    streamingBuffer->begin (GL_LINE_LOOP);
 
430
 
 
431
    colorData[0] = 0x2fff;
 
432
    colorData[1] = 0x2fff;
 
433
    colorData[2] = 0x4fff;
 
434
    colorData[3] = 0x9fff;
 
435
 
 
436
    streamingBuffer->addColors (1, colorData);
 
437
 
 
438
    vertexData[0]  = x1;
 
439
    vertexData[1]  = y1;
 
440
    vertexData[2]  = 0.0f;
 
441
    vertexData[3]  = x2;
 
442
    vertexData[4]  = y1;
 
443
    vertexData[5]  = 0.0f;
 
444
    vertexData[6]  = x2;
 
445
    vertexData[7]  = y2;
 
446
    vertexData[8]  = 0.0f;
 
447
    vertexData[9]  = x1;
 
448
    vertexData[10] = y2;
 
449
    vertexData[11] = 0.0f;
 
450
 
 
451
    streamingBuffer->addVertices (4, vertexData);
 
452
 
 
453
    streamingBuffer->end ();
 
454
    streamingBuffer->render (zTransform);
414
455
}
415
456
/* Apply the zoom if we are grabbed.
416
457
 * Make sure to use the correct filter.
1050
1091
 
1051
1092
/* Translate into place and draw the scaled cursor.  */
1052
1093
void
1053
 
EZoomScreen::drawCursor (CompOutput          *output,
1054
 
                        const GLMatrix      &transform)
 
1094
EZoomScreen::drawCursor (CompOutput     *output,
 
1095
                         const GLMatrix &transform)
1055
1096
{
1056
 
    int         out = output->id ();
 
1097
    int out = output->id ();
1057
1098
 
1058
1099
    if (cursor.isSet)
1059
1100
    {
1060
 
        GLMatrix      sTransform = transform;
1061
 
        float         scaleFactor;
1062
 
        int           ax, ay, x, y;
 
1101
        GLMatrix        sTransform (transform);
 
1102
        float           scaleFactor;
 
1103
        int             ax, ay, x, y;
 
1104
        GLfloat         textureData[8];
 
1105
        GLfloat         vertexData[12];
 
1106
        GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
1063
1107
 
1064
1108
        /*
1065
1109
         * XXX: expo knows how to handle mouse when zoomed, so we back off
1066
1110
         * when expo is active.
1067
1111
         */
1068
 
        if (screen->grabExist ( "expo"))
 
1112
        if (screen->grabExist ("expo"))
1069
1113
        {
1070
1114
            cursorZoomInactive ();
1071
1115
            return;
1073
1117
 
1074
1118
        sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
1075
1119
        convertToZoomed (out, mouse.x (), mouse.y (), &ax, &ay);
1076
 
        glPushMatrix ();
1077
 
        glLoadMatrixf (sTransform.getMatrix ());
1078
 
        glTranslatef ((float) ax, (float) ay, 0.0f);
 
1120
        sTransform.translate ((float) ax, (float) ay, 0.0f);
 
1121
 
1079
1122
        if (optionGetScaleMouseDynamic ())
1080
1123
            scaleFactor = 1.0f / zooms.at (out).currentZoom;
1081
1124
        else
1082
1125
            scaleFactor = 1.0f / optionGetScaleMouseStatic ();
1083
 
        glScalef (scaleFactor,
1084
 
                  scaleFactor,
1085
 
                  1.0f);
 
1126
 
 
1127
        sTransform.scale (scaleFactor, scaleFactor, 1.0f);
1086
1128
        x = -cursor.hotX;
1087
1129
        y = -cursor.hotY;
1088
1130
 
1089
 
        glEnable (GL_BLEND);
1090
 
        glBindTexture (GL_TEXTURE_RECTANGLE_ARB, cursor.texture);
1091
 
        glEnable (GL_TEXTURE_RECTANGLE_ARB);
1092
 
 
1093
 
        glBegin (GL_QUADS);
1094
 
        glTexCoord2d (0, 0);
1095
 
        glVertex2f (x, y);
1096
 
        glTexCoord2d (0, cursor.height);
1097
 
        glVertex2f (x, y + cursor.height);
1098
 
        glTexCoord2d (cursor.width, cursor.height);
1099
 
        glVertex2f (x + cursor.width, y + cursor.height);
1100
 
        glTexCoord2d (cursor.width, 0);
1101
 
        glVertex2f (x + cursor.width, y);
1102
 
        glEnd ();
1103
 
        glDisable (GL_BLEND);
1104
 
        glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
1105
 
        glDisable (GL_TEXTURE_RECTANGLE_ARB);
1106
 
        glPopMatrix ();
 
1131
        glBindTexture (GL_TEXTURE_2D, cursor.texture);
 
1132
 
 
1133
        streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1134
 
 
1135
        vertexData[0]  = x;
 
1136
        vertexData[1]  = y;
 
1137
        vertexData[2]  = 0.0f;
 
1138
        vertexData[3]  = x;
 
1139
        vertexData[4]  = y + cursor.height;
 
1140
        vertexData[5]  = 0.0f;
 
1141
        vertexData[6]  = x + cursor.width;
 
1142
        vertexData[7]  = y;
 
1143
        vertexData[8]  = 0.0f;
 
1144
        vertexData[9]  = x + cursor.width;
 
1145
        vertexData[10] = y + cursor.height;
 
1146
        vertexData[11] = 0.0f;
 
1147
 
 
1148
        streamingBuffer->addVertices (4, vertexData);
 
1149
 
 
1150
        textureData[0] = 0;
 
1151
        textureData[1] = 0;
 
1152
        textureData[2] = 0;
 
1153
        textureData[3] = cursor.height;
 
1154
        textureData[4] = cursor.width;
 
1155
        textureData[5] = 0;
 
1156
        textureData[6] = cursor.width;
 
1157
        textureData[7] = cursor.height;
 
1158
 
 
1159
        streamingBuffer->addTexCoords (1, 4, textureData);
 
1160
 
 
1161
        streamingBuffer->end ();
 
1162
        streamingBuffer->render (sTransform);
 
1163
 
 
1164
        glBindTexture (GL_TEXTURE_2D, 0);
1107
1165
    }
1108
1166
}
1109
1167
 
1110
1168
/* Create (if necessary) a texture to store the cursor,
1111
1169
 * fetch the cursor with XFixes. Store it.  */
1112
1170
void
1113
 
EZoomScreen::updateCursor (CursorTexture * cursor)
 
1171
EZoomScreen::updateCursor (CursorTexture *cursor)
1114
1172
{
1115
1173
    unsigned char *pixels;
1116
 
    int           i;
 
1174
    int            i;
1117
1175
    Display       *dpy = screen->dpy ();
1118
1176
 
1119
1177
    if (!cursor->isSet)
1120
1178
    {
1121
1179
        cursor->isSet = true;
1122
1180
        cursor->screen = screen;
1123
 
        glEnable (GL_TEXTURE_RECTANGLE_ARB);
 
1181
 
 
1182
        glEnable (GL_TEXTURE_2D);
1124
1183
        glGenTextures (1, &cursor->texture);
1125
 
        glBindTexture (GL_TEXTURE_RECTANGLE_ARB, cursor->texture);
 
1184
        glBindTexture (GL_TEXTURE_2D, cursor->texture);
1126
1185
 
1127
 
        glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
1128
 
                         GL_TEXTURE_WRAP_S, GL_CLAMP);
1129
 
        glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
1130
 
                         GL_TEXTURE_WRAP_T, GL_CLAMP);
1131
 
    } else {
1132
 
        glEnable (GL_TEXTURE_RECTANGLE_ARB);
 
1186
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 
1187
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
1188
    }
 
1189
    else {
 
1190
        glEnable (GL_TEXTURE_2D);
1133
1191
    }
1134
1192
 
1135
1193
    XFixesCursorImage *ci = XFixesGetCursorImage (dpy);
1185
1243
        compLogMessage ("ezoom", CompLogLevelWarn, "unable to get system cursor image!");
1186
1244
    }
1187
1245
 
1188
 
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, cursor->texture);
1189
 
    glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, cursor->width,
 
1246
    glBindTexture (GL_TEXTURE_2D, cursor->texture);
 
1247
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, cursor->width,
1190
1248
                  cursor->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
1191
 
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
1192
 
    glDisable (GL_TEXTURE_RECTANGLE_ARB);
 
1249
    glBindTexture (GL_TEXTURE_2D, 0);
 
1250
    glDisable (GL_TEXTURE_2D);
1193
1251
        
1194
1252
    free (pixels);
1195
1253
}