~mc-return/compiz/compiz.merge-src-header-files-cleanup

« back to all changes in this revision

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

Cube code cleanup:

Replaced 0xffff with GLfloat MaxUShortFloat = static_cast <GLfloat>
(std::numeric_limits <unsigned short>::max ());.
Use prefix instead of postfix de- and increments.
Declaration and assignment of variables in one line.
Declare variables shortly before you need them.
Merged if condition checks.
Added missing breaks (just a style issue).
Added and removed brackets.
Added and removed newlines.
Fixed indentation.

Approved by PS Jenkins bot, Sam Spilsbury.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
COMPIZ_PLUGIN_20090315 (cube, CubePluginVTable)
45
45
 
46
46
void
47
 
CubeScreenInterface::cubeGetRotation (float &x, float &v, float &progress)
 
47
CubeScreenInterface::cubeGetRotation (float &x,
 
48
                                      float &v,
 
49
                                      float &progress)
48
50
    WRAPABLE_DEF (cubeGetRotation, x, v, progress);
49
51
 
50
52
void
51
 
CubeScreenInterface::cubeClearTargetOutput (float xRotate, float vRotate)
 
53
CubeScreenInterface::cubeClearTargetOutput (float xRotate,
 
54
                                            float vRotate)
52
55
    WRAPABLE_DEF (cubeClearTargetOutput, xRotate, vRotate);
53
56
 
54
57
void
55
58
CubeScreenInterface::cubePaintTop (const GLScreenPaintAttrib &sAttrib,
56
 
                                   const GLMatrix            &transform,
57
 
                                   CompOutput                *output,
 
59
                                   const GLMatrix            &transform,
 
60
                                   CompOutput                *output,
58
61
                                   int                       size,
59
62
                                   const GLVector            &normal)
60
63
    WRAPABLE_DEF (cubePaintTop, sAttrib, transform, output, size, normal)
61
 
    
 
64
 
62
65
void
63
66
CubeScreenInterface::cubePaintBottom (const GLScreenPaintAttrib &sAttrib,
64
67
                                      const GLMatrix            &transform,
96
99
                                              CompOutput                *output,
97
100
                                              PaintOrder                order)
98
101
    WRAPABLE_DEF (cubeShouldPaintViewport, sAttrib, transform, output, order)
99
 
    
 
102
 
100
103
bool
101
104
CubeScreenInterface::cubeShouldPaintAllViewports ()
102
105
    WRAPABLE_DEF (cubeShouldPaintAllViewports);
192
195
    {
193
196
        case CubeOptions::MultioutputModeOneBigCube:
194
197
            return OneBigCube;
 
198
            break;
 
199
 
195
200
        case CubeOptions::MultioutputModeMultipleCubes:
196
201
            return MultipleCubes;
 
202
            break;
 
203
 
197
204
        default:
198
205
            break;
199
206
    }
217
224
CubeScreen::cubeShouldPaintAllViewports ()
218
225
{
219
226
    WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintAllViewports);
220
 
    
 
227
 
221
228
    return priv->mPaintAllViewports;
222
229
}
223
230
 
228
235
}
229
236
 
230
237
bool
231
 
PrivateCubeScreen::updateGeometry (int sides, int invert)
 
238
PrivateCubeScreen::updateGeometry (int sides,
 
239
                                   int invert)
232
240
{
233
 
    GLfloat radius, distance;
234
241
    GLfloat *v;
235
 
    int     i, n;
 
242
    int     i;
236
243
 
237
244
    sides *= mNOutput;
238
245
 
239
 
    distance = 0.5f / tanf (M_PI / sides);
240
 
    radius   = 0.5f / sinf (M_PI / sides);
 
246
    GLfloat distance = 0.5f / tanf (M_PI / sides);
 
247
    GLfloat radius   = 0.5f / sinf (M_PI / sides);
241
248
 
242
 
    n = (sides + 2) * 2;
 
249
    int n = (sides + 2) * 2;
243
250
 
244
251
    if (mNVertices != n)
245
252
    {
257
264
    *v++ = 0.5 * invert;
258
265
    *v++ = 0.0f;
259
266
 
260
 
    for (i = 0; i <= sides; i++)
 
267
    for (i = 0; i <= sides; ++i)
261
268
    {
262
269
        *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
263
270
        *v++ = 0.5 * invert;
268
275
    *v++ = -0.5 * invert;
269
276
    *v++ = 0.0f;
270
277
 
271
 
    for (i = sides; i >= 0; i--)
 
278
    for (i = sides; i >= 0; --i)
272
279
    {
273
280
        *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
274
281
        *v++ = -0.5 * invert;
284
291
void
285
292
PrivateCubeScreen::updateOutputs ()
286
293
{
287
 
    CompOutput *pBox0, *pBox1;
 
294
    CompOutput   *pBox0, *pBox1;
288
295
    unsigned int i, j;
289
 
    int    k, x;
290
 
 
291
 
    k = 0;
 
296
    int          k = 0;
292
297
 
293
298
    mFullscreenOutput = true;
294
299
 
295
 
    for (i = 0; i < screen->outputDevs ().size (); i++)
 
300
    for (i = 0; i < screen->outputDevs ().size (); ++i)
296
301
    {
297
302
        mOutputMask[i] = -1;
298
303
 
308
313
        if (pBox0->y1 () != pBox1->y1 () || pBox0->y2 () != pBox1->y2 ())
309
314
            continue;
310
315
 
311
 
        k++;
 
316
        ++k;
312
317
 
313
 
        for (j = 0; j < screen->outputDevs ().size (); j++)
 
318
        for (j = 0; j < screen->outputDevs ().size (); ++j)
314
319
        {
315
320
            pBox0 = &screen->outputDevs ()[j];
316
321
 
317
322
            /* must not intersect other output region */
318
323
            if (i != j && pBox0->x2 () > pBox1->x1 () && pBox0->x1 () < pBox1->x2 ())
319
324
            {
320
 
                k--;
 
325
                --k;
321
326
                break;
322
327
            }
323
328
        }
345
350
    }
346
351
 
347
352
    /* add output indices from left to right */
 
353
    int x;
348
354
    j = 0;
 
355
 
349
356
    for (;;)
350
357
    {
351
358
        x = MAXSHORT;
352
359
        k = -1;
353
360
 
354
 
        for (i = 0; i < screen->outputDevs ().size (); i++)
 
361
        for (i = 0; i < screen->outputDevs ().size (); ++i)
355
362
        {
356
363
            if (mOutputMask[i] != -1)
357
364
                continue;
369
376
        mOutputMask[k] = j;
370
377
        mOutput[j]     = k;
371
378
 
372
 
        j++;
 
379
        ++j;
373
380
    }
374
381
 
375
382
    mNOutput = j;
391
398
        return;
392
399
 
393
400
    CompString imgName = optionGetSkydomeImage ();
394
 
    CompString pname = "cube";
 
401
    CompString pname   = "cube";
395
402
 
396
403
    if (optionGetSkydomeImage ().empty () ||
397
404
        (mSky = GLTexture::readImageToTexture (imgName, pname, mSkySize)).empty ())
398
405
    {
 
406
        GLfloat MaxUShortFloat = static_cast <GLfloat>
 
407
                                 (std::numeric_limits <unsigned short>::max ());
399
408
        GLfloat aaafTextureData[128][128][3];
400
 
        GLfloat fRStart = (GLfloat) optionGetSkydomeGradientStartColorRed () / 0xffff;
401
 
        GLfloat fGStart = (GLfloat) optionGetSkydomeGradientStartColorGreen () / 0xffff;
402
 
        GLfloat fBStart = (GLfloat) optionGetSkydomeGradientStartColorBlue () / 0xffff;
403
 
        GLfloat fREnd = (GLfloat) optionGetSkydomeGradientEndColorRed () / 0xffff;
404
 
        GLfloat fGEnd = (GLfloat) optionGetSkydomeGradientEndColorGreen () / 0xffff;
405
 
        GLfloat fBEnd = (GLfloat) optionGetSkydomeGradientEndColorBlue () / 0xffff;
406
 
        GLfloat fRStep = (fREnd - fRStart) / 128.0f;
407
 
        GLfloat fGStep = (fGEnd - fGStart) / 128.0f;
408
 
        GLfloat fBStep = (fBStart - fBEnd) / 128.0f;
409
 
        GLfloat fR = fRStart;
410
 
        GLfloat fG = fGStart;
411
 
        GLfloat fB = fBStart;
412
 
 
413
 
        int     iX, iY;
414
 
 
415
 
        for (iX = 127; iX >= 0; iX--)
 
409
 
 
410
        GLfloat fRStart = optionGetSkydomeGradientStartColorRed () / MaxUShortFloat;
 
411
        GLfloat fGStart = optionGetSkydomeGradientStartColorGreen () / MaxUShortFloat;
 
412
        GLfloat fBStart = optionGetSkydomeGradientStartColorBlue () / MaxUShortFloat;
 
413
 
 
414
        GLfloat fREnd   = optionGetSkydomeGradientEndColorRed () / MaxUShortFloat;
 
415
        GLfloat fGEnd   = optionGetSkydomeGradientEndColorGreen () / MaxUShortFloat;
 
416
        GLfloat fBEnd   = optionGetSkydomeGradientEndColorBlue () / MaxUShortFloat;
 
417
 
 
418
        GLfloat fRStep  = (fREnd - fRStart) / 128.0f;
 
419
        GLfloat fGStep  = (fGEnd - fGStart) / 128.0f;
 
420
        GLfloat fBStep  = (fBStart - fBEnd) / 128.0f;
 
421
 
 
422
        GLfloat fR      = fRStart;
 
423
        GLfloat fG      = fGStart;
 
424
        GLfloat fB      = fBStart;
 
425
 
 
426
        for (int iX = 127; iX >= 0; --iX)
416
427
        {
417
428
            fR += fRStep;
418
429
            fG += fGStep;
419
430
            fB -= fBStep;
420
431
 
421
 
            for (iY = 0; iY < 128; iY++)
 
432
            for (int iY = 0; iY < 128; ++iY)
422
433
            {
423
434
                aaafTextureData[iX][iY][0] = fR;
424
435
                aaafTextureData[iX][iY][1] = fG;
443
454
                 const int n)
444
455
{
445
456
    const GLfloat angle = 2 * M_PI / (GLfloat) ((n == 0) ? 1 : n);
446
 
    const int     size = abs (n);
 
457
    const int     size  = abs (n);
447
458
 
448
459
    *ppSint = (GLfloat *) calloc (sizeof (GLfloat), size + 1);
449
460
    *ppCost = (GLfloat *) calloc (sizeof (GLfloat), size + 1);
459
470
    (*ppSint)[0] = 0.0;
460
471
    (*ppCost)[0] = 1.0;
461
472
 
462
 
    for (int i = 1; i < size; i++)
 
473
    for (int i = 1; i < size; ++i)
463
474
    {
464
475
        (*ppSint)[i] = sin (angle * i);
465
476
        (*ppCost)[i] = cos (angle * i);
488
499
    GLfloat x;
489
500
    GLfloat y;
490
501
    GLfloat z;
491
 
    int     iStacksStart;
492
 
    int     iStacksEnd;
493
 
    int     iSlicesStart;
494
 
    int     iSlicesEnd;
495
 
    GLfloat fStepX;
496
 
    GLfloat fStepY;
 
502
    int     iStacksStart;
 
503
    int     iStacksEnd;
 
504
    int     iSlicesStart;
 
505
    int     iSlicesEnd;
497
506
 
498
507
    if (optionGetSkydomeAnimated ())
499
508
    {
500
 
        iStacksStart = 11; /* min.   0 */
501
 
        iStacksEnd = 53;   /* max.  64 */
502
 
        iSlicesStart = 0;  /* min.   0 */
503
 
        iSlicesEnd = 128;  /* max. 128 */
 
509
        iStacksStart = 11;  /* min.   0 */
 
510
        iStacksEnd   = 53;  /* max.  64 */
 
511
        iSlicesStart = 0;   /* min.   0 */
 
512
        iSlicesEnd   = 128; /* max. 128 */
504
513
    }
505
514
    else
506
515
    {
507
 
        iStacksStart = 21; /* min.   0 */
508
 
        iStacksEnd = 43;   /* max.  64 */
509
 
        iSlicesStart = 21; /* min.   0 */
510
 
        iSlicesEnd = 44;   /* max. 128 */
 
516
        iStacksStart = 21;  /* min.   0 */
 
517
        iStacksEnd   = 43;  /* max.  64 */
 
518
        iSlicesStart = 21;  /* min.   0 */
 
519
        iSlicesEnd   = 44;  /* max. 128 */
511
520
    }
512
521
 
513
 
    fStepX = 1.0 / (GLfloat) (iSlicesEnd - iSlicesStart);
514
 
    fStepY = 1.0 / (GLfloat) (iStacksEnd - iStacksStart);
 
522
    GLfloat fStepX = 1.0 / (GLfloat) (iSlicesEnd - iSlicesStart);
 
523
    GLfloat fStepY = 1.0 / (GLfloat) (iStacksEnd - iStacksStart);
515
524
 
516
525
    if (!mSky.size ())
517
526
        return;
535
544
    afTexCoordX[3] = 1.0f;
536
545
    afTexCoordY[3] = 1.0f;
537
546
 
538
 
 
539
547
    if (!mSkyListId)
540
548
        mSkyListId = glGenLists (1);
541
549
 
545
553
 
546
554
    glBegin (GL_QUADS);
547
555
 
548
 
    for (int i = iStacksStart; i < iStacksEnd; i++)
 
556
    for (int i = iStacksStart; i < iStacksEnd; ++i)
549
557
    {
550
558
        afTexCoordX[0] = 1.0f;
551
559
        afTexCoordX[1] = 1.0f - fStepX;
552
560
        afTexCoordX[2] = 1.0f - fStepX;
553
561
        afTexCoordX[3] = 1.0f;
554
562
 
555
 
        for (int j = iSlicesStart; j < iSlicesEnd; j++)
 
563
        for (int j = iSlicesStart; j < iSlicesEnd; ++j)
556
564
        {
557
565
            /* bottom-right */
558
566
            z = cost2[i];
625
633
}
626
634
 
627
635
bool
628
 
PrivateCubeScreen::setOption (const CompString &name, CompOption::Value &value)
 
636
PrivateCubeScreen::setOption (const CompString  &name,
 
637
                              CompOption::Value &value)
629
638
{
630
 
 
631
639
    unsigned int index;
632
 
 
633
 
    bool rv = CubeOptions::setOption (name, value);
 
640
    bool         rv = CubeOptions::setOption (name, value);
634
641
 
635
642
    if (!rv || !CompOption::findOption (getOptions (), name, &index))
636
643
        return false;
637
644
 
638
 
    switch (index) {
 
645
    switch (index)
 
646
    {
639
647
        case CubeOptions::In:
640
648
            rv = updateGeometry (screen->vpSize ().width (), value.b () ? -1 : 1);
641
649
            break;
 
650
 
642
651
        case CubeOptions::Skydome:
643
652
        case CubeOptions::SkydomeImage:
644
653
        case CubeOptions::SkydomeAnimated:
648
657
            updateSkydomeList (1.0f);
649
658
            cScreen->damageScreen ();
650
659
            break;
 
660
 
651
661
        case CubeOptions::MultioutputMode:
652
662
            updateOutputs ();
653
663
            updateGeometry (screen->vpSize ().width (), mInvert);
654
664
            cScreen->damageScreen ();
655
665
            break;
 
666
 
656
667
        default:
657
668
            break;
658
669
    }
663
674
bool
664
675
PrivateCubeScreen::adjustVelocity ()
665
676
{
666
 
    float unfold, adjust, amount;
 
677
    float unfold;
667
678
 
668
679
    if (mUnfolded)
669
680
        unfold = 1.0f - mUnfold;
670
681
    else
671
682
        unfold = 0.0f - mUnfold;
672
683
 
673
 
    adjust = unfold * 0.02f * optionGetAcceleration ();
674
 
    amount = fabs (unfold);
 
684
    float adjust = unfold * 0.02f * optionGetAcceleration ();
 
685
    float amount = fabs (unfold);
 
686
 
675
687
    if (amount < 1.0f)
676
688
        amount = 1.0f;
677
689
    else if (amount > 3.0f)
678
690
        amount = 3.0f;
679
691
 
680
 
    mUnfoldVelocity = (amount * mUnfoldVelocity + adjust) /
681
 
        (amount + 2.0f);
 
692
    mUnfoldVelocity = (amount * mUnfoldVelocity + adjust) / (amount + 2.0f);
682
693
 
683
694
    return (fabs (unfold) < 0.002f && fabs (mUnfoldVelocity) < 0.01f);
684
695
}
692
703
 
693
704
    if (mGrabIndex)
694
705
    {
695
 
        int   steps;
696
 
        float amount, chunk;
697
 
 
698
 
        amount = msSinceLastPaint * 0.2f *
699
 
            optionGetSpeed ();
700
 
        steps  = amount / (0.5f * optionGetTimestep ());
701
 
        if (!steps) steps = 1;
702
 
        chunk  = amount / (float) steps;
 
706
        float amount = msSinceLastPaint * 0.2f * optionGetSpeed ();
 
707
        int   steps  = amount / (0.5f * optionGetTimestep ());
 
708
 
 
709
        if (!steps)
 
710
            steps = 1;
 
711
 
 
712
        float chunk  = amount / (float) steps;
703
713
 
704
714
        while (steps--)
705
715
        {
706
716
            mUnfold += mUnfoldVelocity * chunk;
 
717
 
707
718
            if (mUnfold > 1.0f)
708
719
                mUnfold = 1.0f;
709
720
 
731
742
    if (mRotationState == CubeScreen::RotationManual ||
732
743
        (mRotationState == CubeScreen::RotationChange &&
733
744
         !optionGetTransparentManualOnly ()))
734
 
    {
735
745
        opt = mLastOpacityIndex = CubeOptions::ActiveOpacity;
736
 
    }
737
746
    else if (mRotationState == CubeScreen::RotationChange)
738
 
    {
739
747
        opt = mLastOpacityIndex = CubeOptions::InactiveOpacity;
740
 
    }
741
748
    else
742
 
    {
743
749
        opt = CubeOptions::InactiveOpacity;
744
 
    }
745
750
 
746
751
    mToOpacity = (mOptions[opt].value ().f () / 100.0f) * OPAQUE;
747
752
 
758
763
 
759
764
    }
760
765
 
761
 
    topColor    = optionGetTopColor ();
762
 
    bottomColor = optionGetBottomColor ();
 
766
    topColor    = optionGetTopColor ();
 
767
    bottomColor = optionGetBottomColor ();
763
768
 
764
769
    mPaintAllViewports = (mDesktopOpacity != OPAQUE ||
765
770
                          topColor[3] != OPAQUE ||
769
774
}
770
775
 
771
776
void
772
 
PrivateCubeScreen::paint (CompOutput::ptrList &outputs, unsigned int mask)
 
777
PrivateCubeScreen::paint (CompOutput::ptrList &outputs,
 
778
                          unsigned int        mask)
773
779
{
774
780
    float x, progress;
775
781
 
776
782
    cubeScreen->cubeGetRotation (x, x, progress);
777
783
 
778
 
    if (optionGetMultioutputMode () == MultioutputModeOneBigCube && 
 
784
    if (optionGetMultioutputMode () == MultioutputModeOneBigCube &&
779
785
        screen->outputDevs ().size () &&
780
 
        (progress > 0.0f || mDesktopOpacity != OPAQUE))
 
786
        (progress > 0.0f || mDesktopOpacity != OPAQUE))
781
787
    {
782
788
        outputs.clear ();
783
789
        outputs.push_back (&screen->fullscreenOutput ());
800
806
    }
801
807
 
802
808
    mSrcOutput = ((unsigned int) output->id () != (unsigned int) ~0) ?
803
 
                                                              output->id () : 0;
 
809
                     output->id () : 0;
804
810
    /* Always use BTF painting on non-transformed screen */
805
811
    mPaintOrder = BTF;
806
812
 
823
829
                                  std::vector<GLVector>     &points)
824
830
{
825
831
    WRAPABLE_HND_FUNCTN_RETURN (bool, cubeCheckOrientation, sAttrib, transform, output, points)
 
832
 
 
833
    GLMatrix pm (priv->gScreen->projectionMatrix ()->getMatrix ());
826
834
    GLMatrix sTransform = transform;
827
 
    GLMatrix mvp, pm (priv->gScreen->projectionMatrix ()->getMatrix ());
828
 
    GLVector pntA, pntB, pntC;
829
 
    GLVector vecA, vecB, ortho;
830
 
    bool     rv = false;
 
835
    bool     rv         = false;
831
836
 
832
837
    priv->gScreen->glApplyTransform (sAttrib, output, &sTransform);
833
838
    sTransform.translate (priv->mOutputXOffset, -priv->mOutputYOffset, 0.0f);
834
839
    sTransform.scale (priv->mOutputXScale, priv->mOutputYScale, 1.0f);
835
840
 
836
 
    mvp = pm * sTransform;
 
841
    GLMatrix mvp = pm * sTransform;
837
842
 
838
 
    pntA = mvp * points[0];
 
843
    GLVector pntA = mvp * points[0];
839
844
 
840
845
    if (pntA[3] < 0.0f)
841
846
        rv = !rv;
842
847
 
843
848
    pntA.homogenize ();
844
849
 
845
 
    pntB = mvp * points[1];
 
850
    GLVector pntB = mvp * points[1];
846
851
 
847
852
    if (pntB[3] < 0.0f)
848
853
        rv = !rv;
849
854
 
850
855
    pntB.homogenize ();
851
856
 
852
 
    pntC = mvp * points[2];
 
857
    GLVector pntC = mvp * points[2];
853
858
    pntC.homogenize ();
854
859
 
855
 
    vecA = pntC - pntA;
856
 
    vecB = pntC - pntB;
 
860
    GLVector vecA = pntC - pntA;
 
861
    GLVector vecB = pntC - pntB;
857
862
 
858
 
    ortho = vecA ^ vecB;
 
863
    GLVector ortho = vecA ^ vecB;
859
864
 
860
865
    if (ortho[2] > 0.0f)
861
866
        rv = !rv;
871
876
{
872
877
    WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintViewport, sAttrib, transform, output, order)
873
878
 
874
 
    bool  ftb;
875
 
    float pointZ;
876
 
 
877
 
    pointZ = priv->mInvert * priv->mDistance;
 
879
    float pointZ = priv->mInvert * priv->mDistance;
878
880
    std::vector<GLVector> vPoints;
879
881
    vPoints.push_back (GLVector (-0.5, 0.0, pointZ, 1.0));
880
882
    vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
881
883
    vPoints.push_back (GLVector (0.0, 0.0, pointZ, 1.0));
882
884
 
883
 
    ftb = cubeCheckOrientation (sAttrib, transform, output, vPoints);
 
885
    bool ftb = cubeCheckOrientation (sAttrib, transform, output, vPoints);
884
886
 
885
887
    return (order == FTB && ftb) || (order == BTF && !ftb);
886
888
}
893
895
                                         PaintOrder                paintOrder,
894
896
                                         int                       dx)
895
897
{
896
 
    if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr, 
 
898
    if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr,
897
899
                                              paintOrder))
898
900
        return;
899
901
 
900
 
    int output = ((unsigned int) outputPtr->id () != (unsigned int) ~0)
901
 
                                                         ? outputPtr->id () : 0;
 
902
    int output = ((unsigned int) outputPtr->id () != (unsigned int) ~0) ?
 
903
                     outputPtr->id () : 0;
902
904
 
903
905
    mPaintOrder = paintOrder;
904
906
 
905
907
    if (mNOutput > 1)
906
908
    {
907
 
        int cubeOutput, dView;
908
 
 
909
909
        /* translate to cube output */
910
 
        cubeOutput = mOutputMask[output];
 
910
        int cubeOutput = mOutputMask[output];
911
911
 
912
912
        /* convert from window movement to viewport movement */
913
 
        dView = -dx;
 
913
        int dView = -dx;
914
914
 
915
915
        cubeOutput += dView;
916
916
 
920
920
        if (cubeOutput < 0)
921
921
        {
922
922
            cubeOutput += mNOutput;
923
 
            dView--;
 
923
            --dView;
924
924
        }
925
925
 
926
926
        /* translate back to compiz output */
963
963
{
964
964
    GLScreenPaintAttrib sa = sAttrib;
965
965
 
966
 
    int xMoveAdd;
967
 
    int origXMoveAdd = 0; /* dx for the viewport we start
968
 
                             painting with (back-most). */
 
966
    int origXMoveAdd = 0; // dx for the viewport we start painting with (back-most).
969
967
    int iFirstSign;       /* 1 if we do xMove += i first and
970
 
                             -1 if we do xMove -= i first. */
 
968
                            -1 if we do xMove -= i first. */
971
969
 
972
970
    if (mInvert == 1)
973
971
    {
997
995
            iFirstSign = 1;
998
996
    }
999
997
 
1000
 
    for (int i = 0; i <= hsize / 2; i++)
 
998
    int xMoveAdd;
 
999
 
 
1000
    for (int i = 0; i <= hsize / 2; ++i)
1001
1001
    {
1002
1002
        /* move to the correct viewport (back to front). */
1003
1003
        xMoveAdd = origXMoveAdd;        /* move to farthest viewport. */
1049
1049
}
1050
1050
 
1051
1051
void
1052
 
CubeScreen::cubeGetRotation (float &x, float &v, float &progress)
 
1052
CubeScreen::cubeGetRotation (float &x,
 
1053
                             float &v,
 
1054
                             float &progress)
1053
1055
{
1054
1056
    WRAPABLE_HND_FUNCTN (cubeGetRotation, x, v, progress)
1055
1057
 
1059
1061
}
1060
1062
 
1061
1063
void
1062
 
CubeScreen::cubeClearTargetOutput (float xRotate, float vRotate)
 
1064
CubeScreen::cubeClearTargetOutput (float xRotate,
 
1065
                                   float vRotate)
1063
1066
{
1064
1067
    WRAPABLE_HND_FUNCTN (cubeClearTargetOutput, xRotate, vRotate)
1065
1068
 
1076
1079
            glRotatef (xRotate, 0.0f, 0.0f, -1.0f);
1077
1080
        }
1078
1081
        else
1079
 
        {
1080
1082
            glRotatef (90.0f, 1.0f, 0.0f, 0.0f);
1081
 
        }
1082
1083
 
1083
1084
        glCallList (priv->mSkyListId);
1084
1085
        glPopMatrix ();
1085
1086
#endif
1086
1087
    }
1087
1088
    else
1088
 
    {
1089
1089
        priv->gScreen->clearTargetOutput (GL_COLOR_BUFFER_BIT);
1090
 
    }
1091
1090
}
1092
1091
 
1093
1092
void 
1099
1098
{
1100
1099
    WRAPABLE_HND_FUNCTN (cubePaintTop, sAttrib, transform, output, size, normal)
1101
1100
 
1102
 
    GLScreenPaintAttrib sa = sAttrib;
 
1101
    GLScreenPaintAttrib sa         = sAttrib;
1103
1102
    GLMatrix            sTransform = transform;
1104
1103
 
1105
 
    unsigned short*     color;
1106
 
    int                 opacity;
1107
 
 
1108
1104
    priv->gScreen->setLighting (true);
1109
1105
 
1110
 
    color = priv->optionGetTopColor ();
1111
 
    opacity = priv->mDesktopOpacity * color[3] / 0xffff;
 
1106
    unsigned short *color  = priv->optionGetTopColor ();
 
1107
    int            opacity = priv->mDesktopOpacity * color[3] / 0xffff;
1112
1108
 
1113
 
    GLVertexBuffer        *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
1109
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
1114
1110
    std::vector <GLushort> colorData;
1115
1111
 
1116
1112
    colorData.push_back (color[0] * opacity / 0xffff);
1167
1163
{
1168
1164
    WRAPABLE_HND_FUNCTN (cubePaintBottom, sAttrib, transform, output, size, normal)
1169
1165
 
1170
 
    GLScreenPaintAttrib sa = sAttrib;
 
1166
    GLScreenPaintAttrib sa         = sAttrib;
1171
1167
    GLMatrix            sTransform = transform;
1172
1168
 
1173
 
    unsigned short*     color;
1174
 
    int                 opacity;
1175
 
 
1176
1169
    priv->gScreen->setLighting (true);
1177
1170
 
1178
 
    color   = priv->optionGetBottomColor ();
1179
 
    opacity = priv->mDesktopOpacity * color[3] / 0xffff;
 
1171
    unsigned short *color  = priv->optionGetBottomColor ();
 
1172
    int            opacity = priv->mDesktopOpacity * color[3] / 0xffff;
1180
1173
 
1181
 
    GLVertexBuffer        *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
1174
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
1182
1175
    std::vector <GLushort> colorData;
1183
1176
 
1184
1177
    colorData.push_back (color[0] * opacity / 0xffff);
1228
1221
}
1229
1222
 
1230
1223
void 
1231
 
PrivateCubeScreen::glEnableOutputClipping (const GLMatrix &transform, 
 
1224
PrivateCubeScreen::glEnableOutputClipping (const GLMatrix   &transform,
1232
1225
                                           const CompRegion &region,
1233
 
                                           CompOutput *output)
 
1226
                                           CompOutput       *output)
1234
1227
{
1235
1228
    if (mRotationState != CubeScreen::RotationNone)
1236
1229
    {
1296
1289
                                             CompOutput                *outputPtr, 
1297
1290
                                             unsigned int              mask)
1298
1291
{
1299
 
    GLScreenPaintAttrib sa = sAttrib;
1300
 
    float               xRotate, vRotate, progress;
1301
 
    int                 hsize;
1302
 
    float               size;
1303
 
    GLenum              filter = gScreen->textureFilter ();
1304
 
    PaintOrder          paintOrder;
1305
 
    bool                wasCulled = false;
1306
 
    bool                paintCaps;
1307
 
    int                 cullNorm, cullInv;
1308
 
    int                 output = 0;
1309
 
 
1310
 
    output = ((unsigned int) outputPtr->id () != (unsigned int) ~0) ?
1311
 
                                                           outputPtr->id () : 0;
 
1292
    int output = ((unsigned int) outputPtr->id () != (unsigned int) ~0) ?
 
1293
                     outputPtr->id () : 0;
1312
1294
 
1313
1295
    mReversedWindowList = cScreen->getWindowPaintList ();
1314
1296
    mReversedWindowList.reverse ();
1322
1304
        updateGeometry (screen->vpSize ().width (), mInvert);
1323
1305
    }
1324
1306
 
1325
 
    hsize = screen->vpSize ().width () * mNOutput;
1326
 
    size  = hsize;
1327
 
 
 
1307
    int cullNorm;
1328
1308
    glGetIntegerv (GL_CULL_FACE_MODE, &cullNorm);
1329
 
    cullInv   = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
1330
 
    wasCulled = glIsEnabled (GL_CULL_FACE);
 
1309
 
 
1310
    bool cullInv   = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
 
1311
    bool wasCulled = glIsEnabled (GL_CULL_FACE);
1331
1312
 
1332
1313
    if (!mFullscreenOutput)
1333
1314
    {
1334
1315
        mOutputXScale = (float) screen->width () / outputPtr->width ();
1335
1316
        mOutputYScale = (float) screen->height () / outputPtr->height ();
1336
1317
 
1337
 
        mOutputXOffset =
1338
 
            (screen->width () / 2.0f -
1339
 
             (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) /
1340
 
            (float) outputPtr->width ();
 
1318
        mOutputXOffset = (screen->width () / 2.0f -
 
1319
                          (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) /
 
1320
                         (float) outputPtr->width ();
1341
1321
 
1342
 
        mOutputYOffset =
1343
 
            (screen->height () / 2.0f -
1344
 
             (outputPtr->y1 () +
1345
 
              outputPtr->y2 ()) / 2.0f) /
1346
 
            (float) outputPtr->height ();
 
1322
        mOutputYOffset = (screen->height () / 2.0f -
 
1323
                          (outputPtr->y1 () +
 
1324
                           outputPtr->y2 ()) / 2.0f) /
 
1325
                         (float) outputPtr->height ();
1347
1326
    }
1348
1327
    else
1349
1328
    {
1353
1332
        mOutputYOffset = 0.0f;
1354
1333
    }
1355
1334
 
 
1335
    float xRotate, vRotate, progress;
1356
1336
    cubeScreen->cubeGetRotation (xRotate, vRotate, progress);
1357
1337
 
 
1338
    GLScreenPaintAttrib sa = sAttrib;
1358
1339
    sa.xRotate += xRotate;
1359
1340
    sa.vRotate += vRotate;
1360
1341
 
1361
1342
    if (!mCleared[output])
1362
1343
    {
1363
 
        float rRotate;
1364
 
 
1365
 
        rRotate = xRotate - ((screen->vp ().x () *360.0f) / screen->vpSize ().width ());
 
1344
        float rRotate = xRotate - ((screen->vp ().x () *360.0f) /
 
1345
                                   screen->vpSize ().width ());
1366
1346
 
1367
1347
        cubeScreen->cubeClearTargetOutput (rRotate, vRotate);
1368
1348
        mCleared[output] = true;
1370
1350
 
1371
1351
    mask &= ~PAINT_SCREEN_CLEAR_MASK;
1372
1352
 
 
1353
    int   hsize = screen->vpSize ().width () * mNOutput;
 
1354
    float size  = hsize;
 
1355
 
1373
1356
    if (mGrabIndex)
1374
1357
    {
1375
1358
        sa.vRotate = 0.0f;
1409
1392
    if (mGrabIndex && optionGetMipmap ())
1410
1393
        gScreen->setTextureFilter (GL_LINEAR_MIPMAP_LINEAR);
1411
1394
 
 
1395
    PaintOrder paintOrder;
 
1396
 
1412
1397
    if (mInvert == 1)
1413
1398
    {
1414
1399
        /* Outside cube - start with FTB faces */
1416
1401
        glCullFace (cullInv);
1417
1402
    }
1418
1403
    else
1419
 
    {
1420
1404
        /* Inside cube - start with BTF faces */
1421
1405
        paintOrder = BTF;
1422
 
    }
1423
1406
 
1424
1407
    if (mInvert == -1 || cubeScreen->cubeShouldPaintAllViewports ())
1425
1408
        paintAllViewports (sa, transform, region, outputPtr,
1430
1413
    if (wasCulled && cubeScreen->cubeShouldPaintAllViewports ())
1431
1414
        glDisable (GL_CULL_FACE);
1432
1415
 
1433
 
    paintCaps = !mGrabIndex && (hsize > 2) && !mCapsPainted[output] &&
1434
 
                (mInvert != 1 || mDesktopOpacity != OPAQUE ||
1435
 
                 cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
1436
 
                 sa.yTranslate != 0.0f);
 
1416
    bool paintCaps = !mGrabIndex && (hsize > 2) && !mCapsPainted[output] &&
 
1417
                     (mInvert != 1 || mDesktopOpacity != OPAQUE ||
 
1418
                     cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
 
1419
                     sa.yTranslate != 0.0f);
1437
1420
 
1438
1421
    if (paintCaps)
1439
1422
    {
1440
 
        Bool topDir, bottomDir, allCaps;
1441
 
 
1442
1423
        std::vector<GLVector> top;
1443
1424
        top.push_back (GLVector (0.5, 0.5,  0.0, 1.0));
1444
1425
        top.push_back (GLVector (0.0, 0.5, -0.5, 1.0));
1449
1430
        bottom.push_back (GLVector (0.0, -0.5, -0.5, 1.0));
1450
1431
        bottom.push_back (GLVector (0.0, -0.5,  0.0, 1.0));
1451
1432
 
1452
 
        topDir    = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
1453
 
        bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
 
1433
        Bool topDir    = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
 
1434
        Bool bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
1454
1435
 
1455
1436
        mCapsPainted[output] = TRUE;
1456
1437
 
1457
 
        allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
 
1438
        Bool allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
1458
1439
 
1459
1440
        if (topDir && bottomDir)
1460
1441
        {
1463
1444
                cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1464
1445
                cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
1465
1446
            }
 
1447
 
1466
1448
            cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1467
1449
        }
1468
1450
        else if (!topDir && !bottomDir)
1472
1454
                cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
1473
1455
                cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
1474
1456
            }
 
1457
 
1475
1458
            cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1476
1459
        }
1477
1460
        else if (allCaps)
1486
1469
        glEnable (GL_CULL_FACE);
1487
1470
 
1488
1471
    if (mInvert == 1)
1489
 
    {
1490
1472
        /* Outside cube - continue with BTF faces */
1491
1473
        paintOrder = BTF;
1492
 
    }
1493
1474
    else
1494
1475
    {
1495
1476
        /* Inside cube - continue with FTB faces */
1503
1484
 
1504
1485
    glCullFace (cullNorm);
1505
1486
 
 
1487
    GLenum filter = gScreen->textureFilter ();
1506
1488
    gScreen->setTextureFilter (filter);
1507
1489
}
1508
1490
 
1533
1515
    if (mPaintOrder == FTB)
1534
1516
        return mReversedWindowList;
1535
1517
    else
1536
 
        return cScreen->getWindowPaintList ();
 
1518
        return cScreen->getWindowPaintList ();
1537
1519
}
1538
1520
 
1539
1521
void 
1555
1537
                           CompAction::State  state,
1556
1538
                           CompOption::Vector &options)
1557
1539
{
1558
 
    Window     xid;
1559
 
 
1560
 
    xid = CompOption::getIntOptionNamed (options, "root");
 
1540
    Window xid = CompOption::getIntOptionNamed (options, "root");
1561
1541
 
1562
1542
    if (::screen->root () == xid)
1563
1543
    {
1564
1544
        CUBE_SCREEN (screen);
1565
1545
 
1566
 
        if (screen->vpSize ().width () * cs->priv->mNOutput < 4)
1567
 
            return false;
1568
 
 
1569
 
        if (screen->otherGrabExist ("rotate", "switcher", "cube", NULL))
 
1546
        if (screen->vpSize ().width () * cs->priv->mNOutput < 4 ||
 
1547
            screen->otherGrabExist ("rotate", "switcher", "cube", NULL))
1570
1548
            return false;
1571
1549
 
1572
1550
        if (!cs->priv->mGrabIndex)
1593
1571
                         CompAction::State  state,
1594
1572
                         CompOption::Vector &options)
1595
1573
{
1596
 
    Window     xid;
1597
 
    xid = CompOption::getIntOptionNamed (options, "root");
 
1574
    Window xid = CompOption::getIntOptionNamed (options, "root");
1598
1575
 
1599
1576
    if (!xid || ::screen->root () == xid)
1600
1577
    {
1622
1599
}
1623
1600
 
1624
1601
bool 
1625
 
PrivateCubeScreen::setOptionForPlugin (const char *plugin,
1626
 
                                       const char *name,
 
1602
PrivateCubeScreen::setOptionForPlugin (const char        *plugin,
 
1603
                                       const char        *name,
1627
1604
                                       CompOption::Value &v)
1628
1605
{
1629
 
    bool status;
1630
 
 
1631
 
    status = screen->setOptionForPlugin (plugin, name, v);
1632
 
 
1633
 
    if (status)
1634
 
    {
1635
 
        if (strcmp (plugin, "core") == 0 && strcmp (name, "hsize") == 0)
1636
 
            updateGeometry (screen->vpSize ().width (), mInvert);
1637
 
    }
 
1606
    bool status = screen->setOptionForPlugin (plugin, name, v);
 
1607
 
 
1608
    if (status                          &&
 
1609
        strcmp (plugin, "core") == 0    &&
 
1610
        strcmp (name, "hsize")  == 0)
 
1611
        updateGeometry (screen->vpSize ().width (), mInvert);
1638
1612
 
1639
1613
    return status;
1640
1614
}
1644
1618
    gScreen (GLScreen::get (s)),
1645
1619
    cubeScreen (CubeScreen::get (s))
1646
1620
{
1647
 
 
1648
1621
    mPw = 0;
1649
1622
    mPh = 0;
1650
1623
 
1651
1624
    mInvert = 1;
1652
1625
 
1653
 
    for (int i = 0; i < 8; i++)
 
1626
    for (int i = 0; i < 8; ++i)
1654
1627
        mTc[i] = 0.0f;
1655
1628
 
1656
1629
    mNVertices = 0;