~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
ImportĀ upstreamĀ versionĀ 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
void
45
45
CubeaddonScreen::CubeCap::load (bool scale, bool aspect, bool clamp)
46
46
{
 
47
    /* we need to clear the texture, if no texture files are specified */
47
48
    if (mFiles.empty ())
 
49
    {
 
50
        mTexture.clear ();
 
51
        mLoaded = false;
 
52
        mCurrent = 0;
 
53
 
48
54
        return;
 
55
    }
49
56
 
50
57
    CompSize tSize;
51
58
    float    xScale, yScale;
56
63
 
57
64
    mLoaded = false;
58
65
 
59
 
    mCurrent = mCurrent % mFiles.size ();
60
 
 
61
 
 
62
66
    CompString imgName = mFiles[mCurrent].s ();
63
67
    CompString pname = "cubeaddon";
64
68
    mTexture = GLTexture::readImageToTexture (imgName, pname, tSize);
143
147
CubeaddonScreen::changeCap (bool top, int change)
144
148
{
145
149
    CubeCap *cap = (top)? &mTopCap : &mBottomCap;
146
 
    if (cap->mFiles.size ())
147
 
    {
148
 
        int count = cap->mFiles.size ();
 
150
 
 
151
    int count = cap->mFiles.size ();
 
152
 
 
153
    /* mCurrent just changes in this case */
 
154
    if (count && change)
149
155
        cap->mCurrent = (cap->mCurrent + change + count) % count;
150
 
        if (top)
151
 
        {
152
 
            cap->load (optionGetTopScale (), optionGetTopAspect (),
153
 
                       optionGetTopClamp ());
154
 
        }
155
 
        else
156
 
        {
157
 
            cap->load (optionGetBottomScale (), optionGetBottomAspect (),
158
 
                       optionGetBottomClamp ());
159
 
            cap->mTexMat.scale (1.0, -1.0, 1.0);
160
 
        }
161
 
        cScreen->damageScreen ();
162
 
    }
 
156
 
 
157
    if (top)
 
158
    {
 
159
        cap->load (optionGetTopScale (), optionGetTopAspect (),
 
160
                   optionGetTopClamp ());
 
161
    }
 
162
    else
 
163
    {
 
164
        cap->load (optionGetBottomScale (), optionGetBottomAspect (),
 
165
                   optionGetBottomClamp ());
 
166
        cap->mTexMat.scale (1.0, -1.0, 1.0);
 
167
    }
 
168
    cScreen->damageScreen ();
163
169
 
164
170
    return false;
165
171
}
167
173
bool
168
174
CubeaddonScreen::setOption (const CompString &name, CompOption::Value &value)
169
175
{
170
 
 
171
176
    unsigned int index;
172
177
 
173
178
    bool rv = CubeaddonOptions::setOption (name, value);
206
211
void
207
212
CubeaddonScreen::drawBasicGround ()
208
213
{
209
 
    float i;
210
 
 
211
214
    glEnable (GL_BLEND);
212
215
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
213
 
    i = optionGetIntensity () * 2;
 
216
    float i = optionGetIntensity () * 2;
214
217
 
215
218
    GLMatrix transform;
216
219
    transform.translate (0.0f, 0.0f, -DEFAULT_Z_CAMERA);
272
275
                                       CompOutput                *output,
273
276
                                       std::vector<GLVector>     &points)
274
277
{
275
 
    bool status;
276
 
 
277
 
    status = cubeScreen->cubeCheckOrientation (sAttrib, transform,
278
 
                                               output, points);
 
278
    bool status = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
279
                                                    output, points);
279
280
 
280
281
    if (mReflection)
281
282
        return !status;
311
312
        glCullFace (GL_FRONT);
312
313
}
313
314
 
314
 
bool 
 
315
bool
315
316
CubeaddonScreen::cubeShouldPaintViewport (const GLScreenPaintAttrib &sAttrib,
316
317
                                          const GLMatrix            &transform,
317
318
                                          CompOutput                *output,
318
319
                                          PaintOrder                order)
319
320
{
320
321
    bool rv = cubeScreen->cubeShouldPaintViewport (sAttrib, transform,
321
 
                                              output, order);
 
322
                                                   output, order);
322
323
 
323
324
    if (rv || cubeScreen->unfolded ())
324
325
        return rv;
326
327
    if (mDeform > 0.0 && optionGetDeformation () == DeformationCylinder)
327
328
    {
328
329
        float z[3];
329
 
        bool  ftb1, ftb2, ftb3;
330
330
 
331
331
        z[0] = cubeScreen->invert () * cubeScreen->distance ();
332
332
        z[1] = z[0] + (0.25 / cubeScreen->distance ());
333
 
        z[2] = cubeScreen->invert () * 
 
333
        z[2] = cubeScreen->invert () *
334
334
               sqrtf (0.25 + (cubeScreen->distance () * cubeScreen->distance ()));
335
335
 
336
336
        std::vector<GLVector> vPoints[3];
337
 
        
 
337
 
338
338
        vPoints[0].push_back (GLVector (-0.5,  0.0, z[0], 1.0));
339
339
        vPoints[0].push_back (GLVector ( 0.0,  0.5, z[1], 1.0));
340
340
        vPoints[0].push_back (GLVector ( 0.0,  0.0, z[1], 1.0));
345
345
        vPoints[2].push_back (GLVector ( 0.0,  0.5, z[2], 1.0));
346
346
        vPoints[2].push_back (GLVector ( 0.0,  0.0, z[2], 1.0));
347
347
 
348
 
        ftb1 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
349
 
                                                 output, vPoints[0]);
350
 
        ftb2 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
351
 
                                                 output, vPoints[1]);
352
 
        ftb3 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
353
 
                                                 output, vPoints[2]);
 
348
        bool ftb1 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
349
                                                      output, vPoints[0]);
 
350
        bool ftb2 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
351
                                                      output, vPoints[1]);
 
352
        bool ftb3 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
353
                                                      output, vPoints[2]);
354
354
 
355
355
        rv = (order == FTB && (ftb1 || ftb2 || ftb3)) ||
356
356
             (order == BTF && (!ftb1 || !ftb2 || !ftb3));
358
358
    else if (mDeform > 0.0 && optionGetDeformation () == DeformationSphere)
359
359
    {
360
360
        float z[4];
361
 
        bool  ftb1, ftb2, ftb3, ftb4;
362
361
 
363
362
        z[0] = sqrtf (0.5 + (cubeScreen->distance () * cubeScreen->distance ()));
364
363
        z[1] = z[0] + (0.25 / cubeScreen->distance ());
365
364
        z[2] = sqrtf (0.25 + (cubeScreen->distance () * cubeScreen->distance ()));
366
365
        z[3] = z[2] + 0.5;
367
 
        
 
366
 
368
367
        std::vector<GLVector> vPoints[4];
369
 
        
 
368
 
370
369
        vPoints[0].push_back (GLVector ( 0.0,  0.0, z[3], 1.0));
371
370
        vPoints[0].push_back (GLVector (-0.5,  0.5, z[2], 1.0));
372
371
        vPoints[0].push_back (GLVector ( 0.0,  0.5, z[2], 1.0));
380
379
        vPoints[3].push_back (GLVector ( 0.5,  0.5, z[0], 1.0));
381
380
        vPoints[3].push_back (GLVector ( 0.5,  0.0, z[0], 1.0));
382
381
 
383
 
        ftb1 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
384
 
                                                 output, vPoints[0]);
385
 
        ftb2 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
386
 
                                                 output, vPoints[1]);
387
 
        ftb3 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
388
 
                                                 output, vPoints[2]);
389
 
        ftb4 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
390
 
                                                 output, vPoints[3]);
 
382
        bool ftb1 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
383
                                                      output, vPoints[0]);
 
384
        bool ftb2 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
385
                                                      output, vPoints[1]);
 
386
        bool ftb3 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
387
                                                      output, vPoints[2]);
 
388
        bool ftb4 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
 
389
                                                      output, vPoints[3]);
391
390
 
392
391
        rv = (order == FTB && (ftb1 || ftb2 || ftb3 || ftb4)) ||
393
392
             (order == BTF && (!ftb1 || !ftb2 || !ftb3 || !ftb4));
406
405
{
407
406
    GLScreenPaintAttrib sa;
408
407
    GLMatrix            sTransform;
409
 
    int                 i, l, opacity;
410
408
    int                 cullNorm, cullInv;
411
409
    bool                wasCulled = glIsEnabled (GL_CULL_FACE);
412
410
    float               cInv = (top) ? 1.0: -1.0;
416
414
 
417
415
    glGetIntegerv (GL_CULL_FACE_MODE, &cullNorm);
418
416
    cullInv   = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
 
417
 
419
418
    if (top)
420
419
        color = cubeScreen->topColor ();
421
420
    else
422
421
        color = cubeScreen->bottomColor ();
423
422
 
424
 
    opacity = cubeScreen->desktopOpacity () * color[3] / 0xffff;
 
423
    int opacity = cubeScreen->desktopOpacity () * color[3] / 0xffff;
425
424
 
426
425
    glEnable (GL_BLEND);
427
426
 
438
437
 
439
438
    glEnable(GL_CULL_FACE);
440
439
 
441
 
    for (l = 0; l < ((cubeScreen->invert () == 1) ? 2 : 1); l++)
 
440
    for (int l = 0; l < ((cubeScreen->invert () == 1) ? 2 : 1); l++)
442
441
    {
443
442
        glCullFace(((l == 1) ^ top) ? cullInv : cullNorm);
444
443
 
445
 
        for (i = 0; i < size; i++)
 
444
        for (int i = 0; i < size; i++)
446
445
        {
447
446
            GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
448
447
 
688
687
                               int                       size,
689
688
                               const GLVector            &normal)
690
689
{
691
 
    if ((!optionGetDrawBottom () && cubeScreen->invert () == -1) ||
692
 
        (!optionGetDrawTop () && cubeScreen->invert () == 1))
693
 
    {
 
690
    /* we do not want to draw anything if this option is disabled */
 
691
    if (!optionGetDrawTop ())
 
692
        return;
 
693
 
 
694
    if (((!optionGetDrawBottom () && cubeScreen->invert () == -1) ||
 
695
         (!optionGetDrawTop () && cubeScreen->invert () == 1)) &&
 
696
        /* the original top cap will work for the non-deformed cube only */
 
697
        (optionGetDeformation () == DeformationNone))
694
698
        cubeScreen->cubePaintTop (sAttrib, transform, output, size, normal);
695
 
    }
696
 
 
697
 
    if (!optionGetDrawTop ())
698
 
        return;
699
 
 
700
 
    paintCap (sAttrib, transform, output, size,
701
 
              true, optionGetAdjustTop ());
 
699
    else
 
700
        paintCap (sAttrib, transform, output, size,
 
701
                  true, optionGetAdjustTop ());
702
702
}
703
703
 
704
704
void 
708
708
                                  int                       size,
709
709
                                  const GLVector            &normal)
710
710
{
711
 
    if ((!optionGetDrawBottom () && cubeScreen->invert () == 1) ||
712
 
        (!optionGetDrawTop () && cubeScreen->invert () == -1))
713
 
    {
 
711
    /* we do not want to draw anything if this option is disabled */
 
712
    if (!optionGetDrawBottom ())
 
713
        return;
 
714
 
 
715
    if (((!optionGetDrawBottom () && cubeScreen->invert () == 1) ||
 
716
         (!optionGetDrawTop () && cubeScreen->invert () == -1)) &&
 
717
        /* the original bottom cap will work for the non-deformed cube only */
 
718
        (optionGetDeformation () == DeformationNone))
714
719
        cubeScreen->cubePaintBottom (sAttrib, transform, output, size, normal);
715
 
    }
716
 
 
717
 
    if (!optionGetDrawBottom ())
718
 
        return;
719
 
 
720
 
    paintCap (sAttrib, transform, output, size,
 
720
    else
 
721
        paintCap (sAttrib, transform, output, size,
721
722
              false, optionGetAdjustBottom ());
722
723
}
723
724
 
911
912
    if (!(mask & PAINT_WINDOW_TRANSFORMED_MASK) && caScreen->mDeform)
912
913
    {
913
914
        CompPoint offset;
914
 
        int x1, x2;
915
915
 
916
916
        if (!window->onAllViewports ())
917
917
        {
919
919
            offset = window->getMovementForOffset (offset);
920
920
        }
921
921
        
922
 
        x1 = window->x () - window->output ().left + offset.x ();
923
 
        x2 = window->x () + window->width () + window->output ().right + offset.x ();
 
922
        int x1 = window->x () - window->output ().left + offset.x ();
 
923
        int x2 = window->x () + window->width () + window->output ().right + offset.x ();
924
924
        if (x1 < 0 && x2 < 0)
925
925
            return false;
926
926
        if (x1 > screen->width () && x2 > screen->width ())
941
941
        int       i;
942
942
        int       sx1, sx2, sw, sy1, sy2, sh;
943
943
        int       offX = 0, offY = 0;
944
 
        float     x, y, ym;
 
944
        float     x, y;
945
945
        GLfloat   *v, *n;
946
 
        float     inv;
947
946
        
948
947
        GLVertexBuffer               *vb = gWindow->vertexBuffer ();
949
948
        CubeScreen::MultioutputMode  cMOM = cubeScreen->multioutputMode ();
950
949
        float                        cDist = cubeScreen->distance ();
951
950
 
952
 
        inv = (cubeScreen->invert () == 1) ? 1.0: -1.0;
953
 
        ym  = (caScreen->optionGetDeformation () == CubeaddonScreen::DeformationCylinder) ? 0.0 : 1.0;
 
951
        float inv = (cubeScreen->invert () == 1) ? 1.0: -1.0;
 
952
        float ym  = (caScreen->optionGetDeformation () == CubeaddonScreen::DeformationCylinder) ? 0.0 : 1.0;
954
953
        
955
954
        int vertexCount = vb->countVertices ();
956
955
 
1159
1158
        }
1160
1159
        else
1161
1160
        {
1162
 
            int i;
1163
1161
            float w;
1164
1162
            rS = cDist2 + 0.5;
1165
1163
 
1170
1168
            mCapFillNorm[1] = -1.0;
1171
1169
            mCapFillNorm[2] = 0.0;
1172
1170
 
1173
 
            for (i = 0; i < CAP_ELEMENTS; i++)
 
1171
            for (int i = 0; i < CAP_ELEMENTS; i++)
1174
1172
            {
1175
1173
                w = (float)(i + 1) / (float)CAP_ELEMENTS;
1176
1174
 
1281
1279
                    mYTrans    = 0.0;
1282
1280
                    if (optionGetDeformation () == DeformationSphere &&
1283
1281
                        optionGetDeformCaps () && optionGetDrawBottom ())
1284
 
                    {
1285
1282
                        rYTrans = sqrt (0.5 + cDist2) * -2.0;
1286
 
                    }
1287
1283
                    else
1288
 
                    {
1289
1284
                        rYTrans = point[1] * 2.0;
1290
 
                    }
 
1285
 
1291
1286
                    break;
 
1287
 
1292
1288
                case ModeDistance:
1293
1289
                    mYTrans = 0.0;
1294
1290
                    rYTrans = sqrt (0.5 + cDist2) * -2.0;
1295
1291
                    break;
 
1292
 
1296
1293
                default:
1297
 
 
1298
1294
                    if (optionGetDeformation () == DeformationSphere &&
1299
1295
                        optionGetDeformCaps () && optionGetDrawBottom ())
1300
1296
                    {
1315
1311
                    break;
1316
1312
            }
1317
1313
 
1318
 
 
1319
1314
            if (!optionGetAutoZoom () ||
1320
1315
                ((cubeScreen->rotationState () != CubeScreen::RotationManual) &&
1321
1316
                 optionGetZoomManualOnly ()))
1322
 
            {
1323
1317
                mZTrans = 0.0;
1324
 
            }
1325
1318
            else
1326
1319
                mZTrans = -point2[2] + cDist;
1327
1320
 
1377
1370
 
1378
1371
            if (optionGetMode () == ModeAbove && mVRot > 0.0)
1379
1372
            {
1380
 
                int   j;
1381
 
                float i, c;
1382
1373
                float v = MIN (1.0, mVRot / 30.0);
1383
1374
                unsigned short col1[4], col2[4];
1384
1375
 
1391
1382
 
1392
1383
                gTransform.translate (0, 0, -DEFAULT_Z_CAMERA);
1393
1384
 
1394
 
                i = optionGetIntensity () * 2;
1395
 
                c = optionGetIntensity ();
 
1385
                float i = optionGetIntensity () * 2;
 
1386
                float c = optionGetIntensity ();
1396
1387
 
1397
1388
                GLfloat vertices[] =
1398
1389
                {
1419
1410
                if (streamingBuffer->end ())
1420
1411
                    streamingBuffer->render (gTransform);
1421
1412
 
1422
 
                for (j = 0; j < 4; j++)
 
1413
                for (int j = 0; j < 4; j++)
1423
1414
                {
1424
1415
                    col1[j] = (1.0 - v) * optionGetGroundColor1 () [j] +
1425
1416
                              (v * (optionGetGroundColor1 () [j] +
1516
1507
    cScreen->donePaint ();
1517
1508
}
1518
1509
 
1519
 
 
1520
1510
CubeaddonScreen::CubeaddonScreen (CompScreen *s) :
1521
1511
    PluginClassHandler<CubeaddonScreen, CompScreen> (s),
1522
1512
    CubeaddonOptions (),
1538
1528
 
1539
1529
    idx = mCapFillIdx;
1540
1530
    for (int i = 0; i < CAP_ELEMENTS - 1; i++)
1541
 
    {
1542
1531
        for (int j = 0; j < CAP_ELEMENTS; j++)
1543
1532
        {
1544
1533
            idx[0] = 1 + (i * (CAP_ELEMENTS + 1)) + j;
1547
1536
            idx[3] = 2 + (i * (CAP_ELEMENTS + 1)) + j;
1548
1537
            idx += 4;
1549
1538
        }
1550
 
    }
1551
1539
 
1552
1540
    mTopCap.mFiles = optionGetTopImages ();
1553
1541
    mBottomCap.mFiles = optionGetBottomImages ();
1600
1588
bool
1601
1589
CubeaddonPluginVTable::init ()
1602
1590
{
1603
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
1604
 
        !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) ||
1605
 
        !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI) ||
1606
 
        !CompPlugin::checkPluginABI ("cube", COMPIZ_CUBE_ABI))
1607
 
        return false;
 
1591
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
1592
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
1593
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI)        &&
 
1594
        CompPlugin::checkPluginABI ("cube", COMPIZ_CUBE_ABI))
 
1595
        return true;
1608
1596
 
1609
 
    return true;
 
1597
    return false;
1610
1598
}
1611