Merge lp:~mc-return/compiz/compiz.merge-cubeaddon-improvements into lp:compiz/0.9.11

Proposed by MC Return
Status: Work in progress
Proposed branch: lp:~mc-return/compiz/compiz.merge-cubeaddon-improvements
Merge into: lp:compiz/0.9.11
Diff against target: 1515 lines (+403/-315)
2 files modified
plugins/cubeaddon/src/cubeaddon.cpp (+311/-252)
plugins/cubeaddon/src/cubeaddon.h (+92/-63)
To merge this branch: bzr merge lp:~mc-return/compiz/compiz.merge-cubeaddon-improvements
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+176726@code.launchpad.net

Commit message

Cubeaddon, cleanup:

Declaration of variables outside of loops.
Declaration and assignment of local variables in one line.
Merged if condition checks.
Use pre- instead of postfix increments.
Removed redundant brackets.
Added and removed newlines.
Fixed indentation.
float rS = cDist2 + 0.5; is needed in both if-else branches.

Cubeaddon, speedup:

Calculation of static values outside of loops, no need to
recalculate those multiple times (float premultColors[],
float normalizedOpacity).
Just call optionGetGroundSize () once, save the value in
the float groundSize and use this in following calculations.
Introduced
GLfloat cubeDistance = cubeScreen->distance ();,
GLfloat cubeDistanceSquared = cubeDistance * cubeDistance;,
float tsSize = 360.0f / static_cast <float> (size);,
float aScale = 1.0 / scale;,
float outputWidth = static_cast <float> (output->width ());,
float outputHeight = static_cast <float> (output->height ());,
int jPlus1 = j + 1;,
float halfW = w / 2.0f;,
float xSq = x * x;,
float cDistW = cDist * w;,
float rMinusXSq = r - xSq;,
int iCapElem = i * (CAP_ELEMENTS + 1);,
float halfAngle = angle / 2.0f;,
float degToRad = M_PI / 180.0f; and
GLfloat gsf = -0.5f + static_cast <GLfloat> (((1 - v) *
optionGetGroundSize ()) + v);
and used those variables in the following calculations.
Do not call screen->width (); twice in a row (several times).
Do not calculate
mCapFill[1] - 0.5,
sqrt (0.5 + cDist2) - 0.5; and
point[1] - 0.5 twice in a row.
Introduced GLfloat gSY = static_cast <GLfloat>(groundSize - 0.5f); and
used this variable in the assignment of the ground2Vertices[] array.
Introduced GLfloat halfV = v / 2.0f; and used this variable in the
assignment of the GLfloat vertices[] array.

Just enable GL_BLEND if it is disabled and just disable
it afterwards, if it was disabled before.

Description of the change

Still WIP.

To post a comment you must log in.

Unmerged revisions

3757. By MC Return

Merged latest lp:compiz

3756. By MC Return

Added missing whitespace
Renamed csDistance and csDistanceSquared to cubeDistance and
cubeDistanceSquared
NULL-initialized the GLVertexBuffer *streamingBuffer pointer
Renamed oWidth and oHeight to outputWidth and outputHeight

3755. By MC Return

Introduced GLfloat gSY = static_cast <GLfloat>(groundSize - 0.5f); and
used this variable in the assignment of the ground2Vertices[] array
Introduced GLfloat halfV = v / 2.0f; and used this variable in the
assignment of the GLfloat vertices[] array
Added missing whitespace
Reverted alignment in the ctor

3754. By MC Return

Cubeaddon, multiple improvements
(please see main commit message for details)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/cubeaddon/src/cubeaddon.cpp'
2--- plugins/cubeaddon/src/cubeaddon.cpp 2013-05-09 13:43:07 +0000
3+++ plugins/cubeaddon/src/cubeaddon.cpp 2013-07-24 16:09:50 +0000
4@@ -34,21 +34,23 @@
5 */
6 CubeaddonScreen::CubeCap::CubeCap ()
7 {
8- mCurrent = 0;
9- mLoaded = false;
10+ mCurrent = 0;
11+ mLoaded = false;
12 }
13
14 /*
15 * Attempt to load current cap image (if any)
16 */
17 void
18-CubeaddonScreen::CubeCap::load (bool scale, bool aspect, bool clamp)
19+CubeaddonScreen::CubeCap::load (bool scale,
20+ bool aspect,
21+ bool clamp)
22 {
23 /* we need to clear the texture, if no texture files are specified */
24 if (mFiles.empty ())
25 {
26 mTexture.clear ();
27- mLoaded = false;
28+ mLoaded = false;
29 mCurrent = 0;
30
31 return;
32@@ -64,7 +66,7 @@
33 mLoaded = false;
34
35 CompString imgName = mFiles[mCurrent].s ();
36- CompString pname = "cubeaddon";
37+ CompString pname = "cubeaddon";
38 mTexture = GLTexture::readImageToTexture (imgName, pname, tSize);
39
40 if (mTexture.empty ())
41@@ -78,10 +80,10 @@
42 mLoaded = true;
43 mTexMat.reset ();
44
45- mTexMat[0] = mTexture[0]->matrix ().xx;
46- mTexMat[1] = mTexture[0]->matrix ().yx;
47- mTexMat[4] = mTexture[0]->matrix ().xy;
48- mTexMat[5] = mTexture[0]->matrix ().yy;
49+ mTexMat[0] = mTexture[0]->matrix ().xx;
50+ mTexMat[1] = mTexture[0]->matrix ().yx;
51+ mTexMat[4] = mTexture[0]->matrix ().xy;
52+ mTexMat[5] = mTexture[0]->matrix ().yy;
53 mTexMat[12] = mTexture[0]->matrix ().x0;
54 mTexMat[13] = mTexture[0]->matrix ().y0;
55
56@@ -135,6 +137,7 @@
57 glTexParameteri (mTexture[0]->target (), GL_TEXTURE_WRAP_S, GL_REPEAT);
58 glTexParameteri (mTexture[0]->target (), GL_TEXTURE_WRAP_T, GL_REPEAT);
59 }
60+
61 mTexture[0]->disable ();
62 }
63
64@@ -144,63 +147,68 @@
65 * Switch cap, load it and damage screen if possible
66 */
67 bool
68-CubeaddonScreen::changeCap (bool top, int change)
69+CubeaddonScreen::changeCap (bool top,
70+ int change)
71 {
72- CubeCap *cap = (top)? &mTopCap : &mBottomCap;
73-
74- int count = cap->mFiles.size ();
75+ CubeCap *cap = (top) ? &mTopCap : &mBottomCap;
76+ int count = cap->mFiles.size ();
77
78 /* mCurrent just changes in this case */
79 if (count && change)
80 cap->mCurrent = (cap->mCurrent + change + count) % count;
81
82 if (top)
83- {
84 cap->load (optionGetTopScale (), optionGetTopAspect (),
85 optionGetTopClamp ());
86- }
87 else
88 {
89 cap->load (optionGetBottomScale (), optionGetBottomAspect (),
90 optionGetBottomClamp ());
91 cap->mTexMat.scale (1.0, -1.0, 1.0);
92 }
93+
94 cScreen->damageScreen ();
95
96 return false;
97 }
98
99 bool
100-CubeaddonScreen::setOption (const CompString &name, CompOption::Value &value)
101+CubeaddonScreen::setOption (const CompString &name,
102+ CompOption::Value &value)
103 {
104 unsigned int index;
105
106 bool rv = CubeaddonOptions::setOption (name, value);
107
108 if (!rv || !CompOption::findOption (getOptions (), name, &index))
109- return false;
110+ return false;
111
112- switch (index) {
113+ switch (index)
114+ {
115 case CubeaddonOptions::TopImages :
116 mTopCap.mFiles = optionGetTopImages ();
117- mTopCap.mCurrent = 0;
118- changeCap (true, 0);
119+ mTopCap.mCurrent = 0;
120+ changeCap (true, 0);
121 break;
122+
123 case CubeaddonOptions::BottomImages :
124 mBottomCap.mFiles = optionGetBottomImages ();
125- mBottomCap.mCurrent = 0;
126- changeCap (false, 0);
127+ mBottomCap.mCurrent = 0;
128+ changeCap (false, 0);
129 break;
130+
131 case CubeaddonOptions::TopScale :
132 case CubeaddonOptions::TopAspect :
133 case CubeaddonOptions::TopClamp :
134- changeCap (true, 0);
135+ changeCap (true, 0);
136 break;
137+
138 case CubeaddonOptions::BottomScale :
139 case CubeaddonOptions::BottomAspect :
140 case CubeaddonOptions::BottomClamp :
141- changeCap (false, 0);
142+ changeCap (false, 0);
143 break;
144+
145 default:
146 break;
147 }
148@@ -211,7 +219,11 @@
149 void
150 CubeaddonScreen::drawBasicGround ()
151 {
152- glEnable (GL_BLEND);
153+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
154+
155+ if (!glBlendEnabled)
156+ glEnable (GL_BLEND);
157+
158 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
159 float i = optionGetIntensity () * 2;
160
161@@ -221,9 +233,9 @@
162 GLfloat ground1Vertices[] =
163 {
164 -0.5, -0.5, 0.0,
165- 0.5, -0.5, 0.0,
166- -0.5, 0.0, 0.0,
167- 0.5, 0.0, 0.0
168+ 0.5, -0.5, 0.0,
169+ -0.5, 0.0, 0.0,
170+ 0.5, 0.0, 0.0
171 };
172
173 unsigned short maxG1Color = MAX (0.0f, 1.0f - i) * 65535;
174@@ -242,17 +254,22 @@
175
176 streamingBuffer->addVertices (4, ground1Vertices);
177 streamingBuffer->addColors (4, ground1Colors);
178+
179 if (streamingBuffer->end ())
180 streamingBuffer->render (transform);
181
182- if (optionGetGroundSize () > 0.0)
183+ float groundSize = optionGetGroundSize ();
184+
185+ if (groundSize)
186 {
187+ GLfloat gSY = static_cast <GLfloat>(groundSize - 0.5f);
188+
189 GLfloat ground2Vertices[] =
190 {
191 -0.5, -0.5, 0.0,
192- 0.5, -0.5, 0.0,
193- -0.5, static_cast <GLfloat> (-0.5 + optionGetGroundSize ()), 0.0,
194- 0.5, static_cast <GLfloat> (-0.5 + optionGetGroundSize ()), 0.0
195+ 0.5, -0.5, 0.0,
196+ -0.5, gSY, 0.0,
197+ 0.5, gSY, 0.0
198 };
199
200 streamingBuffer->begin (GL_TRIANGLE_STRIP);
201@@ -261,12 +278,15 @@
202 streamingBuffer->addColors (1, optionGetGroundColor2 ());
203 streamingBuffer->addColors (1, optionGetGroundColor2 ());
204 streamingBuffer->addVertices (4, ground2Vertices);
205+
206 if (streamingBuffer->end ())
207 streamingBuffer->render (transform);
208 }
209
210 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
211- glDisable (GL_BLEND);
212+
213+ if (!glBlendEnabled)
214+ glDisable (GL_BLEND);
215 }
216
217 bool
218@@ -285,24 +305,25 @@
219 }
220
221 void
222-CubeaddonScreen::cubeGetRotation (float &x, float &v, float &progress)
223+CubeaddonScreen::cubeGetRotation (float &x,
224+ float &v,
225+ float &progress)
226 {
227-
228 cubeScreen->cubeGetRotation (x, v, progress);
229
230 if (optionGetMode () == ModeAbove && v > 0.0 && mReflection)
231 {
232 mVRot = v;
233- v = 0.0;
234+ v = 0.0;
235 }
236 else
237 mVRot = 0.0;
238 }
239
240 void
241-CubeaddonScreen::cubeClearTargetOutput (float xRotate, float vRotate)
242+CubeaddonScreen::cubeClearTargetOutput (float xRotate,
243+ float vRotate)
244 {
245-
246 if (mReflection)
247 glCullFace (GL_BACK);
248
249@@ -324,14 +345,17 @@
250 if (rv || cubeScreen->unfolded ())
251 return rv;
252
253+ GLfloat cubeDistance = cubeScreen->distance ();
254+ GLfloat cubeDistanceSquared = cubeDistance * cubeDistance;
255+
256 if (mDeform > 0.0 && optionGetDeformation () == DeformationCylinder)
257 {
258 float z[3];
259
260- z[0] = cubeScreen->invert () * cubeScreen->distance ();
261- z[1] = z[0] + (0.25 / cubeScreen->distance ());
262+ z[0] = cubeScreen->invert () * cubeDistance;
263+ z[1] = z[0] + (0.25 / cubeDistance);
264 z[2] = cubeScreen->invert () *
265- sqrtf (0.25 + (cubeScreen->distance () * cubeScreen->distance ()));
266+ sqrtf (0.25 + cubeDistanceSquared);
267
268 std::vector<GLVector> vPoints[3];
269
270@@ -352,16 +376,16 @@
271 bool ftb3 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
272 output, vPoints[2]);
273
274- rv = (order == FTB && (ftb1 || ftb2 || ftb3)) ||
275+ rv = (order == FTB && ( ftb1 || ftb2 || ftb3)) ||
276 (order == BTF && (!ftb1 || !ftb2 || !ftb3));
277 }
278 else if (mDeform > 0.0 && optionGetDeformation () == DeformationSphere)
279 {
280 float z[4];
281
282- z[0] = sqrtf (0.5 + (cubeScreen->distance () * cubeScreen->distance ()));
283- z[1] = z[0] + (0.25 / cubeScreen->distance ());
284- z[2] = sqrtf (0.25 + (cubeScreen->distance () * cubeScreen->distance ()));
285+ z[0] = sqrtf (0.5 + cubeDistanceSquared);
286+ z[1] = z[0] + (0.25 / cubeDistance);
287+ z[2] = sqrtf (0.25 + cubeDistanceSquared);
288 z[3] = z[2] + 0.5;
289
290 std::vector<GLVector> vPoints[4];
291@@ -388,7 +412,7 @@
292 bool ftb4 = cubeScreen->cubeCheckOrientation (sAttrib, transform,
293 output, vPoints[3]);
294
295- rv = (order == FTB && (ftb1 || ftb2 || ftb3 || ftb4)) ||
296+ rv = (order == FTB && (ftb1 || ftb2 || ftb3 || ftb4)) ||
297 (order == BTF && (!ftb1 || !ftb2 || !ftb3 || !ftb4));
298 }
299
300@@ -405,12 +429,14 @@
301 {
302 GLScreenPaintAttrib sa;
303 GLMatrix sTransform;
304+ GLVertexBuffer *streamingBuffer = NULL;
305 int cullNorm, cullInv;
306 bool wasCulled = glIsEnabled (GL_CULL_FACE);
307 float cInv = (top) ? 1.0: -1.0;
308+ float tsSize = 360.0f / static_cast <float> (size);
309 CubeCap *cap;
310 bool cAspect;
311- unsigned short *color;
312+ unsigned short *color;
313
314 glGetIntegerv (GL_CULL_FACE_MODE, &cullNorm);
315 cullInv = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
316@@ -422,7 +448,10 @@
317
318 int opacity = cubeScreen->desktopOpacity () * color[3] / 0xffff;
319
320- glEnable (GL_BLEND);
321+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
322+
323+ if (!glBlendEnabled)
324+ glEnable (GL_BLEND);
325
326 if (top)
327 {
328@@ -437,21 +466,28 @@
329
330 glEnable(GL_CULL_FACE);
331
332- for (int l = 0; l < ((cubeScreen->invert () == 1) ? 2 : 1); l++)
333+ unsigned int vertexIndex;
334+ float normalizedOpacity = opacity / static_cast <float> (OPAQUE);
335+ float premultColors[] =
336+ {
337+ (color[0] / OPAQUE) * normalizedOpacity,
338+ (color[1] / OPAQUE) * normalizedOpacity,
339+ (color[2] / OPAQUE) * normalizedOpacity
340+ };
341+
342+ for (int l = 0; l < ((cubeScreen->invert () == 1) ? 2 : 1); ++l)
343 {
344 glCullFace(((l == 1) ^ top) ? cullInv : cullNorm);
345
346- for (int i = 0; i < size; i++)
347+ for (int i = 0; i < size; ++i)
348 {
349- GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
350+ streamingBuffer = GLVertexBuffer::streamingBuffer ();
351
352 streamingBuffer->begin (GL_TRIANGLE_FAN);
353
354 if (optionGetDeformation () == DeformationSphere &&
355 optionGetDeformCaps ())
356- {
357 streamingBuffer->addNormals (CAP_NVERTEX / 3, (l == 0) ? mCapFill : mCapFillNorm);
358- }
359 else
360 {
361 GLfloat nonDeformNormals[] = { 0.0f, (l == 0) ? 1.0f : -1.0f, 0.0f };
362@@ -460,20 +496,24 @@
363
364 sa = sAttrib;
365 sTransform = transform;
366+
367 if (cubeScreen->invert () == 1)
368 {
369- sa.yRotate += (360.0f / size) * cubeScreen->xRotations ();
370+ sa.yRotate += tsSize * cubeScreen->xRotations ();
371+
372 if (!adjust)
373- sa.yRotate -= (360.0f / size) * screen->vp ().x ();
374+ sa.yRotate -= tsSize * screen->vp ().x ();
375 }
376 else
377 {
378 sa.yRotate += 180.0f;
379- sa.yRotate -= (360.0f / size) * cubeScreen->xRotations ();
380+ sa.yRotate -= tsSize * cubeScreen->xRotations ();
381+
382 if (!adjust)
383- sa.yRotate += (360.0f / size) * screen->vp ().x ();
384+ sa.yRotate += tsSize * screen->vp ().x ();
385 }
386- sa.yRotate += (360.0f / size) * i;
387+
388+ sa.yRotate += tsSize * i;
389
390 gScreen->glApplyTransform (sa, output, &sTransform);
391
392@@ -482,25 +522,18 @@
393 cTransform.scale (cubeScreen->outputXScale (), cubeScreen->outputYScale (), 1.0f);
394 cTransform.scale (1.0, cInv, 1.0);
395
396- float normalizedOpacity = opacity / static_cast <float> (OPAQUE);
397- float premultColors[] =
398- {
399- (color[0] / OPAQUE) * normalizedOpacity,
400- (color[1] / OPAQUE) * normalizedOpacity,
401- (color[2] / OPAQUE) * normalizedOpacity
402- };
403-
404 streamingBuffer->color4f (premultColors[0],
405 premultColors[1],
406 premultColors[2],
407 normalizedOpacity);
408
409 streamingBuffer->addVertices (CAP_ELEMENTS + 2, mCapFill);
410+
411 if (streamingBuffer->end ())
412 streamingBuffer->render (cTransform);
413
414 if (optionGetDeformation () == DeformationSphere &&
415- optionGetDeformCaps ())
416+ optionGetDeformCaps ())
417 {
418 #ifndef USE_GLES
419 streamingBuffer->begin (GL_QUADS);
420@@ -516,7 +549,7 @@
421
422 for (unsigned int i = 0; i < CAP_NIDX; ++i)
423 {
424- unsigned int vertexIndex = idx[i] * 3;
425+ vertexIndex = idx[i] * 3;
426
427 *(capVerticesPtr++) = (mCapFill[vertexIndex]);
428 *(capVerticesPtr++) = (mCapFill[vertexIndex + 1]);
429@@ -533,7 +566,7 @@
430 if (cap->mLoaded)
431 {
432 GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
433- GLMatrix texMat = cap->mTexMat;
434+ GLMatrix texMat = cap->mTexMat;
435
436 if (cubeScreen->invert () != 1)
437 texMat.scale (-1.0, 1.0, 1.0);
438@@ -547,17 +580,18 @@
439 normalizedOpacity,
440 normalizedOpacity);
441
442- cap->mTexture[0]->enable (GLTexture::Good);
443+ cap->mTexture[0]->enable (GLTexture::Good);
444
445 if (cAspect)
446 {
447- float scale, xScale = 1.0, yScale = 1.0;
448- scale = (float)output->width () / (float)output->height ();
449+ float xScale = 1.0, yScale = 1.0;
450+ float scale = (float)output->width () / (float)output->height ();
451+ float aScale = 1.0 / scale;
452
453 if (output->width () > output->height ())
454 {
455 xScale = 1.0;
456- yScale = 1.0 / scale;
457+ yScale = aScale;
458 }
459 else
460 {
461@@ -567,32 +601,34 @@
462
463 if (optionGetTopScale ())
464 {
465- scale = xScale;
466+ scale = xScale;
467 xScale = 1.0 / yScale;
468- yScale = 1.0 / scale;
469+ yScale = aScale;
470 }
471
472 texMat.scale (xScale, yScale, 1.0);
473 }
474
475- texMat.rotate (-(360.0f / size) * i, 0.0, 0.0, 1.0);
476+ texMat.rotate (-tsSize * i, 0.0, 0.0, 1.0);
477
478 GLVector sGen (texMat[0], texMat[8], texMat[4], texMat[12]);
479 GLVector tGen (texMat[1], texMat[9], texMat[5], texMat[13]);
480
481 /* Generate texCoords for the top section of the
482 * cap */
483- GLfloat texCoords[(CAP_ELEMENTS + 2) * 2];
484- GLfloat *texCoordsPtr = texCoords;
485+ GLfloat texCoords[(CAP_ELEMENTS + 2) * 2];
486+ GLfloat *texCoordsPtr = texCoords;
487+ float s, t;
488
489- for (unsigned int i = 0; i < CAP_ELEMENTS + 2; i++)
490+ for (unsigned int i = 0; i < CAP_ELEMENTS + 2; ++i)
491 {
492 GLVector v (mCapFill[i * 3],
493 mCapFill[i * 3 + 1],
494 mCapFill[i * 3 + 2],
495 1.0f);
496- float s = v * sGen;
497- float t = v * tGen;
498+
499+ s = v * sGen;
500+ t = v * tGen;
501
502 *(texCoordsPtr++) = s;
503 *(texCoordsPtr++) = t;
504@@ -601,11 +637,12 @@
505 streamingBuffer->addTexCoords (0, CAP_NVERTEX / 3, &texCoords[0]);
506 streamingBuffer->addVertices (CAP_NVERTEX / 3, mCapFill);
507 streamingBuffer->setMaxVertices (CAP_ELEMENTS + 2);
508+
509 if (streamingBuffer->end ())
510 streamingBuffer->render (cTransform);
511
512 if (optionGetDeformation () == DeformationSphere &&
513- optionGetDeformCaps ())
514+ optionGetDeformCaps ())
515 {
516 #ifndef USE_GLES
517 streamingBuffer->begin (GL_QUADS);
518@@ -632,13 +669,14 @@
519 GLushort *idx = mCapFillIdx;
520 GLfloat capVertices[CAP_NIDX * 3];
521 GLfloat texCoords[CAP_NIDX * 2];
522+ GLfloat *capVerticesPtr = capVertices;
523+ GLfloat *texCoordsPtr = texCoords;
524
525- GLfloat *capVerticesPtr = capVertices;
526- GLfloat *texCoordsPtr = texCoords;
527+ unsigned int vertexIndex;
528
529 for (unsigned int i = 0; i < CAP_NIDX; ++i)
530 {
531- unsigned int vertexIndex = idx[i] * 3;
532+ vertexIndex = idx[i] * 3;
533
534 GLVector v (mCapFill[vertexIndex],
535 mCapFill[vertexIndex + 1],
536@@ -653,8 +691,8 @@
537 * texCoord.s = dot (vec4 (obj, 1.0), sGenPlane)
538 * texCoord.t = dot (vec4 (obj, 1.0), tGenPlane)
539 */
540- float s = v * sGen;
541- float t = v * tGen;
542+ s = v * sGen;
543+ t = v * tGen;
544
545 *(texCoordsPtr++) = s;
546 *(texCoordsPtr++) = t;
547@@ -673,9 +711,11 @@
548 }
549 }
550
551- glDisable (GL_BLEND);
552+ if (!glBlendEnabled)
553+ glDisable (GL_BLEND);
554
555 glCullFace (cullNorm);
556+
557 if (!wasCulled)
558 glDisable (GL_CULL_FACE);
559 }
560@@ -719,7 +759,7 @@
561 cubeScreen->cubePaintBottom (sAttrib, transform, output, size, normal);
562 else
563 paintCap (sAttrib, transform, output, size,
564- false, optionGetAdjustBottom ());
565+ false, optionGetAdjustBottom ());
566 }
567
568 void
569@@ -731,57 +771,50 @@
570 {
571 if (caScreen->mDeform > 0.0)
572 {
573- GLVertexBuffer *vb = gWindow->vertexBuffer ();
574- int i, oldVCount = vb->countVertices ();
575- GLfloat *v;
576- int offX = 0, offY = 0;
577- int sx1, sx2, sw, sy1, sy2, sh;
578- float radSquare, last[2][4];
579- float inv = (cubeScreen->invert () == 1) ? 1.0 : -1.0;
580-
581- float ang, sx1g, sx2g, sy1g, sy2g;
582-
583- CubeScreen::MultioutputMode cMOM = cubeScreen->multioutputMode ();
584- int caD = caScreen->optionGetDeformation ();
585- float cDist = cubeScreen->distance ();
586-
587+ CubeScreen::MultioutputMode cMOM = cubeScreen->multioutputMode ();
588+ int caD = caScreen->optionGetDeformation ();
589+ float cDist = cubeScreen->distance ();
590+ float radSquare;
591
592 if (caD == CubeaddonScreen::DeformationCylinder || cubeScreen->unfolded ())
593- {
594- radSquare = (cDist * cDist) + 0.25;
595- }
596+ radSquare = cDist * cDist + 0.25;
597 else
598 {
599 maxGridHeight = MIN (CUBEADDON_GRID_SIZE, maxGridHeight);
600- radSquare = (cDist * cDist) + 0.5;
601+ radSquare = cDist * cDist + 0.5;
602 }
603
604 gWindow->glAddGeometry (matrix, region, clip,
605 MIN (CUBEADDON_GRID_SIZE, maxGridWidth),
606 maxGridHeight);
607
608- vb = gWindow->vertexBuffer ();
609+ GLVertexBuffer *vb = gWindow->vertexBuffer ();
610+ int oldVCount = vb->countVertices ();
611
612- v = vb->getVertices ();
613- v += vb->getVertexStride () - 3;
614- v += vb->getVertexStride () * oldVCount;
615+ GLfloat *v = vb->getVertices ();
616+ v += vb->getVertexStride () - 3;
617+ v += vb->getVertexStride () * oldVCount;
618+
619+ int offX = 0, offY = 0;
620
621 if (!window->onAllViewports ())
622 {
623 CompPoint offset = caScreen->cScreen->windowPaintOffset ();
624- offset = window->getMovementForOffset (offset);
625- offX = offset.x ();
626- offY = offset.y ();
627+ offset = window->getMovementForOffset (offset);
628+ offX = offset.x ();
629+ offY = offset.y ();
630 }
631-
632+
633+ int sx1, sx2, sw, sy1, sy2, sh;
634+
635 if (cMOM == CubeScreen::OneBigCube)
636 {
637 sx1 = 0;
638 sx2 = screen->width ();
639- sw = screen->width ();
640+ sw = sx2;
641 sy1 = 0;
642 sy2 = screen->height ();
643- sh = screen->height ();
644+ sh = sy2;
645 }
646 else if (cMOM == CubeScreen::MultipleCubes)
647 {
648@@ -798,10 +831,10 @@
649 {
650 sx1 = 0;
651 sx2 = screen->width ();
652- sw = screen->width ();
653+ sw = sx2;
654 sy1 = 0;
655 sy2 = screen->height ();
656- sh = screen->height ();
657+ sh = sy2;
658 }
659 else
660 {
661@@ -814,26 +847,29 @@
662 }
663 }
664
665- sx1g = sx1 - CUBEADDON_GRID_SIZE;
666- sx2g = sx2 + CUBEADDON_GRID_SIZE;
667- sy1g = sy1 - CUBEADDON_GRID_SIZE;
668- sy2g = sy2 + CUBEADDON_GRID_SIZE;
669+ float sx1g = sx1 - CUBEADDON_GRID_SIZE;
670+ float sx2g = sx2 + CUBEADDON_GRID_SIZE;
671+ float sy1g = sy1 - CUBEADDON_GRID_SIZE;
672+ float sy2g = sy2 + CUBEADDON_GRID_SIZE;
673+ float inv = (cubeScreen->invert () == 1) ? 1.0 : -1.0;
674+ float last[2][4];
675+ float ang;
676+ int i;
677
678 if (caD == CubeaddonScreen::DeformationCylinder || cubeScreen->unfolded ())
679 {
680 float lastX = std::numeric_limits <float>::min (), lastZ = 0.0;
681
682- for (i = oldVCount; i < vb->countVertices (); i++)
683+ for (i = oldVCount; i < vb->countVertices (); ++i)
684 {
685 if (v[0] == lastX)
686- {
687 v[2] = lastZ;
688- }
689 else if (v[0] + offX >= sx1g &&
690 v[0] + offY < sx2g)
691 {
692 ang = (((v[0] + offX - sx1) / (float)sw) - 0.5);
693 ang *= ang;
694+
695 if (ang < radSquare)
696 {
697 v[2] = sqrtf (radSquare - ang) - cDist;
698@@ -849,12 +885,13 @@
699 }
700 else
701 {
702-
703 last[0][0] = -1000000000.0;
704 last[1][0] = -1000000000.0;
705
706- int cLast = 0;
707- for (i = oldVCount; i < vb->countVertices (); i++)
708+ int cLast = 0;
709+ float vpx, vpy;
710+
711+ for (i = oldVCount; i < vb->countVertices (); ++i)
712 {
713 if (last[0][0] == v[0] && last[0][1] == v[1])
714 {
715@@ -871,8 +908,8 @@
716 continue;
717 }
718
719- float vpx = v[0] + offX;
720- float vpy = v[1] + offY;
721+ vpx = v[0] + offX;
722+ vpy = v[1] + offY;
723
724 if (vpx >= sx1g && vpx < sx2g &&
725 vpy >= sy1g && vpy < sy2g)
726@@ -883,8 +920,8 @@
727 float a2 = (((vpy - sy1) / (float)sh) - 0.5);
728 a2 *= a2;
729
730- ang = atanf (a1 / cDist);
731- a2 = sqrtf (radSquare - a2);
732+ ang = atanf (a1 / cDist);
733+ a2 = sqrtf (radSquare - a2);
734 int iang = (((int)(ang * RAD2I1024)) + 1024) & 0x3ff;
735
736 v[2] += ((caScreen->mCosT [iang] * a2) - cDist) * caScreen->mDeform * inv;
737@@ -898,9 +935,7 @@
738 }
739 }
740 else
741- {
742 gWindow->glAddGeometry (matrix, region, clip, maxGridWidth, maxGridHeight);
743- }
744 }
745
746 bool
747@@ -921,9 +956,9 @@
748
749 int x1 = window->x () - window->output ().left + offset.x ();
750 int x2 = window->x () + window->width () + window->output ().right + offset.x ();
751- if (x1 < 0 && x2 < 0)
752- return false;
753- if (x1 > screen->width () && x2 > screen->width ())
754+
755+ if ((x1 < 0 && x2 < 0) ||
756+ (x1 > screen->width () && x2 > screen->width ()))
757 return false;
758 }
759
760@@ -944,8 +979,8 @@
761 float x, y;
762 GLfloat *v, *n;
763
764- GLVertexBuffer *vb = gWindow->vertexBuffer ();
765- CubeScreen::MultioutputMode cMOM = cubeScreen->multioutputMode ();
766+ GLVertexBuffer *vb = gWindow->vertexBuffer ();
767+ CubeScreen::MultioutputMode cMOM = cubeScreen->multioutputMode ();
768 float cDist = cubeScreen->distance ();
769
770 float inv = (cubeScreen->invert () == 1) ? 1.0: -1.0;
771@@ -956,14 +991,14 @@
772 if ((int) caScreen->mWinNormSize < vertexCount * 3)
773 {
774 delete [] caScreen->mWinNormals;
775- caScreen->mWinNormals = new GLfloat[vertexCount * 3];
776+ caScreen->mWinNormals = new GLfloat[vertexCount * 3];
777 caScreen->mWinNormSize = vertexCount * 3;
778 }
779
780 if (!window->onAllViewports ())
781 {
782 CompPoint offset = caScreen->cScreen->windowPaintOffset ();
783- offset = window->getMovementForOffset (offset);
784+ offset = window->getMovementForOffset (offset);
785 offX = offset.x ();
786 offY = offset.y ();
787 }
788@@ -972,10 +1007,10 @@
789 {
790 sx1 = 0;
791 sx2 = screen->width ();
792- sw = screen->width ();
793+ sw = sx2;
794 sy1 = 0;
795 sy2 = screen->height ();
796- sh = screen->height ();
797+ sh = sy2;
798 }
799 else if (cMOM == CubeScreen::MultipleCubes)
800 {
801@@ -1013,7 +1048,7 @@
802
803 if (cubeScreen->paintOrder () == FTB)
804 {
805- for (i = 0; i < vertexCount; i++)
806+ for (i = 0; i < vertexCount; ++i)
807 {
808 x = (((v[0] + offX - sx1) / (float)sw) - 0.5);
809 y = (((v[1] + offY - sy1) / (float)sh) - 0.5);
810@@ -1027,7 +1062,7 @@
811 }
812 else
813 {
814- for (i = 0; i < vertexCount; i++)
815+ for (i = 0; i < vertexCount; ++i)
816 {
817 x = (((v[0] + offX - sx1) / (float)sw) - 0.5);
818 y = (((v[1] + offY - sy1) / (float)sh) - 0.5);
819@@ -1054,9 +1089,10 @@
820 CubeaddonScreen::cubeShouldPaintAllViewports ()
821 {
822 bool status = cubeScreen->cubeShouldPaintAllViewports ();
823- return (!optionGetDrawTop () ||
824+
825+ return (!optionGetDrawTop () ||
826 !optionGetDrawBottom () ||
827- (mDeform > 0.0) ||
828+ (mDeform > 0.0) ||
829 status);
830 }
831
832@@ -1067,16 +1103,16 @@
833 CompOutput *output,
834 unsigned int mask)
835 {
836- GLMatrix sTransform = transform;
837- float cDist = cubeScreen->distance ();
838- float cDist2 = cubeScreen->distance () * cubeScreen->distance ();
839+ GLMatrix sTransform = transform;
840+ float cDist = cubeScreen->distance ();
841+ float cDist2 = cDist * cDist;
842
843- if (optionGetDeformation () != DeformationNone &&
844- screen->vpSize ().width () * cubeScreen->nOutput () > 2 &&
845- screen->desktopWindowCount () &&
846+ if (optionGetDeformation () != DeformationNone &&
847+ screen->vpSize ().width () * cubeScreen->nOutput () > 2 &&
848+ screen->desktopWindowCount () &&
849 (cubeScreen->rotationState () == CubeScreen::RotationManual ||
850 (cubeScreen->rotationState () == CubeScreen::RotationChange &&
851- !optionGetCylinderManualOnly ()) || mWasDeformed) &&
852+ !optionGetCylinderManualOnly ()) || mWasDeformed) &&
853 (!cubeScreen->unfolded () || optionGetUnfoldDeformation ()))
854 {
855 float x, progress;
856@@ -1087,26 +1123,26 @@
857 if (optionGetSphereAspect () > 0.0 && cubeScreen->invert () == 1 &&
858 optionGetDeformation () == DeformationSphere)
859 {
860- float scale, val = optionGetSphereAspect () * mDeform;
861+ float scale, val = optionGetSphereAspect () * mDeform;
862+ float outputWidth = static_cast <float> (output->width ());
863+ float outputHeight = static_cast <float> (output->height ());
864
865- if (output->width () > output->height ())
866+ if (outputWidth > outputHeight)
867 {
868- scale = (float)output->height () / (float)output->width ();
869+ scale = outputHeight / outputWidth;
870 scale = (scale * val) + 1.0 - val;
871 sTransform.scale (scale, 1.0, 1.0);
872 }
873 else
874 {
875- scale = (float)output->width () / (float)output->height ();
876+ scale = outputWidth / outputHeight;
877 scale = (scale * val) + 1.0 - val;
878 sTransform.scale (1.0, scale, 1.0);
879 }
880 }
881 }
882 else
883- {
884 mDeform = 0.0;
885- }
886
887 cubeScreen->cubeShouldPaintAllViewportsSetEnabled (this, true);
888
889@@ -1116,40 +1152,42 @@
890 changeCap (false, 0);
891 }
892
893- if (mDeform != mCapDeform || mCapDistance != cDist ||
894- mCapDeformType != optionGetDeformation ())
895+ if (mDeform != mCapDeform ||
896+ mCapDistance != cDist ||
897+ mCapDeformType != optionGetDeformation ())
898 {
899- float *quad;
900- int j;
901- float rS, r, x, y, z;
902+ float *quad;
903+ int j, jPlus1;
904+ float rS = cDist2 + 0.5;
905+ float r, x, y, z;
906+
907 if (optionGetDeformation () != DeformationSphere ||
908 !optionGetDeformCaps ())
909 {
910- rS = cDist2 + 0.5;
911-
912 mCapFill[0] = 0.0;
913 mCapFill[1] = 0.5;
914 mCapFill[2] = 0.0;
915- mCapFillNorm[0] = 0.0;
916+ mCapFillNorm[0] = 0.0;
917 mCapFillNorm[1] = -1.0;
918- mCapFillNorm[2] = 0.0;
919+ mCapFillNorm[2] = 0.0;
920
921+ y = 0.5;
922 z = cDist;
923 r = 0.25 + cDist2;
924
925- for (j = 0; j <= CAP_ELEMENTS; j++)
926+ for (j = 0; j <= CAP_ELEMENTS; ++j)
927 {
928- x = -0.5 + ((float)j / (float)CAP_ELEMENTS);
929- z = ((sqrtf(r - (x * x)) - cDist) * mDeform) + cDist;
930- y = 0.5;
931+ x = -0.5 + ((float)j / (float)CAP_ELEMENTS);
932+ z = ((sqrtf(r - (x * x)) - cDist) * mDeform) + cDist;
933+ jPlus1 = j + 1;
934
935- quad = &mCapFill[(1 + j) * 3];
936+ quad = &mCapFill[jPlus1 * 3];
937
938 quad[0] = x;
939 quad[1] = y;
940 quad[2] = z;
941
942- quad = &mCapFillNorm[(1 + j) * 3];
943+ quad = &mCapFillNorm[jPlus1 * 3];
944
945 quad[0] = -x;
946 quad[1] = -y;
947@@ -1158,35 +1196,40 @@
948 }
949 else
950 {
951- float w;
952- rS = cDist2 + 0.5;
953+ float w, halfW, xSq, cDistW, rMinusXSq;
954+ int iCapElem;
955
956 mCapFill[0] = 0.0;
957 mCapFill[1] = ((sqrtf (rS) - 0.5) * mDeform) + 0.5;
958 mCapFill[2] = 0.0;
959- mCapFillNorm[0] = 0.0;
960+ mCapFillNorm[0] = 0.0;
961 mCapFillNorm[1] = -1.0;
962- mCapFillNorm[2] = 0.0;
963+ mCapFillNorm[2] = 0.0;
964
965- for (int i = 0; i < CAP_ELEMENTS; i++)
966+ for (int i = 0; i < CAP_ELEMENTS; ++i)
967 {
968- w = (float)(i + 1) / (float)CAP_ELEMENTS;
969-
970- r = (((w / 2.0) * (w / 2.0)) + (cDist2 * w * w));
971-
972- for (j = 0; j <= CAP_ELEMENTS; j++)
973+ w = (float)(i + 1) / (float)CAP_ELEMENTS;
974+ halfW = w / 2.0f;
975+ r = (halfW * halfW) + (cDist2 * w * w);
976+
977+ for (j = 0; j <= CAP_ELEMENTS; ++j)
978 {
979- x = - (w / 2.0) + ((float)j * w / (float)CAP_ELEMENTS);
980- z = ((sqrtf(r - (x * x)) - (cDist * w)) * mDeform) + (cDist * w);
981- y = ((sqrtf(rS - (x * x) - (r - (x * x))) - 0.5) * mDeform) + 0.5;
982+ x = -halfW + ((float)j * w / (float)CAP_ELEMENTS);
983+ xSq = x * x;
984+ cDistW = cDist * w;
985+ rMinusXSq = r - xSq;
986+ z = ((sqrtf(rMinusXSq) - cDistW) * mDeform) + cDistW;
987+ y = ((sqrtf(rS - xSq - rMinusXSq) - 0.5) * mDeform) + 0.5;
988+ iCapElem = i * (CAP_ELEMENTS + 1);
989+ jPlus1 = j + 1;
990
991- quad = &mCapFill[(1 + (i * (CAP_ELEMENTS + 1)) + j) * 3];
992+ quad = &mCapFill[(jPlus1 + iCapElem) * 3];
993
994 quad[0] = x;
995 quad[1] = y;
996 quad[2] = z;
997
998- quad = &mCapFillNorm[(1 + (i * (CAP_ELEMENTS + 1)) + j) * 3];
999+ quad = &mCapFillNorm[(jPlus1 + iCapElem) * 3];
1000
1001 quad[0] = -x;
1002 quad[1] = -y;
1003@@ -1202,7 +1245,7 @@
1004
1005 if (cubeScreen->invert () == 1 && mFirst && optionGetReflection ())
1006 {
1007- mFirst = false;
1008+ mFirst = false;
1009 mReflection = true;
1010
1011 if (screen->grabExist ("cube"))
1012@@ -1221,62 +1264,68 @@
1013 }
1014 else
1015 {
1016- GLMatrix rTransform = sTransform;
1017- GLMatrix pTransform;
1018- float angle = 360.0 / ((float) screen->vpSize ().width () *
1019- cubeScreen->nOutput ());
1020- float xRot, vRot, xRotate, xRotate2, vRotate, p;
1021- float rYTrans;
1022- GLVector point (-0.5, -0.5, cDist, 1.0);
1023- GLVector point2 (-0.5, 0.5, cDist, 1.0);
1024- float deform = 0.0f;
1025+ GLMatrix rTransform = sTransform;
1026
1027+ float xRot, vRot, p;
1028 cubeScreen->cubeGetRotation (xRot, vRot, p);
1029
1030 mBackVRotate = 0.0;
1031
1032- xRotate = xRot;
1033- xRotate2 = xRot;
1034- vRotate = vRot;
1035+ float xRotate = xRot;
1036+ float xRotate2 = xRot;
1037+ float vRotate = vRot;
1038
1039 if (vRotate < 0.0)
1040 xRotate += 180;
1041
1042- vRotate = fmod (fabs (vRotate), 180.0);
1043- xRotate = fmod (fabs (xRotate), angle);
1044- xRotate2 = fmod (fabs (xRotate2), angle);
1045+ float angle = 360.0 / ((float) screen->vpSize ().width () *
1046+ cubeScreen->nOutput ());
1047+ float halfAngle = angle / 2.0f;
1048+ float degToRad = M_PI / 180.0f;
1049+
1050+ vRotate = fmod (fabs (vRotate), 180.0);
1051+ xRotate = fmod (fabs (xRotate), angle);
1052+ xRotate2 = fmod (fabs (xRotate2), angle);
1053
1054 if (vRotate >= 90.0)
1055 vRotate = 180.0 - vRotate;
1056
1057- if (xRotate >= angle / 2.0)
1058+ if (xRotate >= halfAngle)
1059 xRotate = angle - xRotate;
1060
1061- if (xRotate2 >= angle / 2.0)
1062+ if (xRotate2 >= halfAngle)
1063 xRotate2 = angle - xRotate2;
1064
1065- xRotate = (mDeform * angle * 0.5) +
1066+ xRotate = (mDeform * halfAngle) +
1067 ((1.0 - mDeform) * xRotate);
1068- xRotate2 = (mDeform * angle * 0.5) +
1069+ xRotate2 = (mDeform * halfAngle) +
1070 ((1.0 - mDeform) * xRotate2);
1071
1072+ GLVector point (-0.5, -0.5, cDist, 1.0);
1073+ GLVector point2 (-0.5, 0.5, cDist, 1.0);
1074+ GLMatrix pTransform;
1075+
1076 pTransform.reset ();
1077 pTransform.rotate (xRotate, 0.0f, 1.0f, 0.0f);
1078- pTransform.rotate (vRotate, cosf (xRotate * (M_PI / 180.0f)),
1079- 0.0f, sinf (xRotate * (M_PI / 180.0f)));
1080+ pTransform.rotate (vRotate, cosf (xRotate * degToRad),
1081+ 0.0f, sinf (xRotate * degToRad));
1082
1083 point = pTransform * point;
1084
1085 pTransform.reset ();
1086 pTransform.rotate (xRotate2, 0.0f, 1.0f, 0.0f);
1087- pTransform.rotate (vRotate, cosf (xRotate2 * (M_PI / 180.0f)),
1088- 0.0f, sinf (xRotate2 * (M_PI / 180.0f)));
1089+ pTransform.rotate (vRotate, cosf (xRotate2 * degToRad),
1090+ 0.0f, sinf (xRotate2 * degToRad));
1091
1092 point2 = pTransform * point2;
1093
1094- switch (optionGetMode ()) {
1095+ float rYTrans;
1096+
1097+ switch (optionGetMode ())
1098+ {
1099 case ModeJumpyReflection:
1100 mYTrans = 0.0;
1101+
1102 if (optionGetDeformation () == DeformationSphere &&
1103 optionGetDeformCaps () && optionGetDrawBottom ())
1104 rYTrans = sqrt (0.5 + cDist2) * -2.0;
1105@@ -1295,19 +1344,20 @@
1106 optionGetDeformCaps () && optionGetDrawBottom ())
1107 {
1108 mYTrans = mCapFill[1] - 0.5;
1109- rYTrans = -mCapFill[1] - 0.5;
1110+ rYTrans = -mYTrans;
1111 }
1112 else if (optionGetDeformation () == DeformationSphere &&
1113- vRotate > atan (cDist * 2) / (M_PI / 180.0f))
1114+ vRotate > atan (cDist * 2) / degToRad)
1115 {
1116- mYTrans = sqrt (0.5 + cDist2) - 0.5;
1117- rYTrans = -sqrt (0.5 + cDist2) - 0.5;
1118+ mYTrans = sqrt (0.5 + cDist2) - 0.5;
1119+ rYTrans = -mYTrans;
1120 }
1121 else
1122 {
1123 mYTrans = -point[1] - 0.5;
1124- rYTrans = point[1] - 0.5;
1125+ rYTrans = -mYTrans;
1126 }
1127+
1128 break;
1129 }
1130
1131@@ -1321,17 +1371,20 @@
1132 if (optionGetMode () == ModeAbove)
1133 mZTrans = 0.0;
1134
1135+ float deform = 0.0f;
1136+
1137 if (optionGetDeformation () == DeformationCylinder)
1138 deform = (sqrt (0.25 + cDist2) - cDist) * -mDeform;
1139 else if (optionGetDeformation () == DeformationSphere)
1140- deform = (sqrt (0.5 + cDist2) - cDist) * -mDeform;
1141+ deform = (sqrt (0.5 + cDist2) - cDist) * -mDeform;
1142
1143 if (mDeform > 0.0)
1144- mZTrans = deform;
1145+ mZTrans = deform;
1146
1147 if (optionGetMode () == ModeAbove && mVRot > 0.0)
1148 {
1149 mBackVRotate = mVRot;
1150+
1151 if (optionGetDeformation () == DeformationSphere &&
1152 optionGetDeformCaps () && optionGetDrawBottom ())
1153 {
1154@@ -1340,7 +1393,7 @@
1155 }
1156 else
1157 {
1158- mYTrans = 0.0;
1159+ mYTrans = 0.0;
1160 rYTrans = -1.0;
1161 }
1162
1163@@ -1374,23 +1427,27 @@
1164 unsigned short col1[4], col2[4];
1165
1166 GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
1167-
1168- GLMatrix gTransform;
1169-
1170- glEnable (GL_BLEND);
1171+ GLMatrix gTransform;
1172+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
1173+
1174+ if (!glBlendEnabled)
1175+ glEnable (GL_BLEND);
1176+
1177 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1178
1179 gTransform.translate (0, 0, -DEFAULT_Z_CAMERA);
1180
1181- float i = optionGetIntensity () * 2;
1182 float c = optionGetIntensity ();
1183+ float i = c * 2;
1184+
1185+ GLfloat halfV = v / 2.0f;
1186
1187 GLfloat vertices[] =
1188 {
1189- 0.5f, v / 2.0f, 0.0f,
1190- -0.5f, v / 2.0f, 0.0f,
1191+ 0.5f, halfV, 0.0f,
1192+ -0.5f, halfV, 0.0f,
1193 -0.5f, -0.5f, 0.0f,
1194- 0.5f, -0.5f, 0.0f
1195+ 0.5f, -0.5f, 0.0f
1196 };
1197
1198 unsigned short cMax = MAX (0.0, 1.0 - i) + (v * c);
1199@@ -1407,10 +1464,11 @@
1200 streamingBuffer->begin (GL_TRIANGLE_STRIP);
1201 streamingBuffer->addColors (4, colors);
1202 streamingBuffer->addVertices (4, vertices);
1203+
1204 if (streamingBuffer->end ())
1205 streamingBuffer->render (gTransform);
1206
1207- for (int j = 0; j < 4; j++)
1208+ for (int j = 0; j < 4; ++j)
1209 {
1210 col1[j] = (1.0 - v) * optionGetGroundColor1 () [j] +
1211 (v * (optionGetGroundColor1 () [j] +
1212@@ -1422,14 +1480,14 @@
1213
1214 if (optionGetGroundSize () > 0.0)
1215 {
1216+ GLfloat gsf = -0.5f + static_cast <GLfloat> (((1 - v) *
1217+ optionGetGroundSize ()) + v);
1218 GLfloat vertices[] =
1219 {
1220 -0.5f, -0.5f, 0.0f,
1221- 0.5f, -0.5f, 0.0f,
1222- 0.5f, -0.5f +
1223- static_cast <GLfloat> (((1 - v) * optionGetGroundSize ()) + v),
1224- -0.5f, -0.5f +
1225- static_cast <GLfloat> (((1 - v) * optionGetGroundSize ()) + v)
1226+ 0.5f, -0.5f, 0.0f,
1227+ 0.5f, gsf,
1228+ -0.5f, gsf
1229 };
1230
1231 GLushort colors[] =
1232@@ -1449,7 +1507,9 @@
1233 }
1234
1235 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1236- glDisable (GL_BLEND);
1237+
1238+ if (!glBlendEnabled)
1239+ glDisable (GL_BLEND);
1240 }
1241 else
1242 drawBasicGround ();
1243@@ -1516,19 +1576,18 @@
1244 mReflection (false),
1245 mFirst (true),
1246 mLast (0),
1247- mYTrans (0.0),
1248- mZTrans (0.0),
1249- mDeform (0.0),
1250+ mYTrans (0.0f),
1251+ mZTrans (0.0f),
1252+ mDeform (0.0f),
1253 mWinNormals (0),
1254 mWinNormSize (0),
1255- mCapDeform (-1.0),
1256+ mCapDeform (-1.0f),
1257 mCapDistance (cubeScreen->distance ())
1258 {
1259- GLushort *idx;
1260+ GLushort *idx = mCapFillIdx;
1261
1262- idx = mCapFillIdx;
1263- for (int i = 0; i < CAP_ELEMENTS - 1; i++)
1264- for (int j = 0; j < CAP_ELEMENTS; j++)
1265+ for (int i = 0; i < CAP_ELEMENTS - 1; ++i)
1266+ for (int j = 0; j < CAP_ELEMENTS; ++j)
1267 {
1268 idx[0] = 1 + (i * (CAP_ELEMENTS + 1)) + j;
1269 idx[1] = 1 + ((i + 1) * (CAP_ELEMENTS + 1)) + j;
1270@@ -1537,13 +1596,13 @@
1271 idx += 4;
1272 }
1273
1274- mTopCap.mFiles = optionGetTopImages ();
1275+ mTopCap.mFiles = optionGetTopImages ();
1276 mBottomCap.mFiles = optionGetBottomImages ();
1277-
1278- for (int i = 0; i < 1024; i++)
1279+
1280+ for (int i = 0; i < 1024; ++i)
1281 {
1282- mSinT[i] = sinf(i / RAD2I1024);
1283- mCosT[i] = cosf(i / RAD2I1024);
1284+ mSinT[i] = sinf (i / RAD2I1024);
1285+ mCosT[i] = cosf (i / RAD2I1024);
1286 }
1287
1288 changeCap (true, 0);
1289
1290=== modified file 'plugins/cubeaddon/src/cubeaddon.h'
1291--- plugins/cubeaddon/src/cubeaddon.h 2013-01-04 05:52:46 +0000
1292+++ plugins/cubeaddon/src/cubeaddon.h 2013-07-24 16:09:50 +0000
1293@@ -40,14 +40,14 @@
1294 #include "cubeaddon_options.h"
1295
1296 const unsigned short CUBEADDON_GRID_SIZE = 100;
1297-const unsigned short CAP_ELEMENTS = 15;
1298-const unsigned int CAP_NVERTEX = (((CAP_ELEMENTS * (CAP_ELEMENTS + 1)) + 2) * 3);
1299-const unsigned int CAP_NIDX = (CAP_ELEMENTS * (CAP_ELEMENTS - 1) * 4);
1300-
1301-const unsigned int CAP_NIMGVERTEX = (((CAP_ELEMENTS + 1) * (CAP_ELEMENTS + 1)) * 5);
1302-const unsigned int CAP_NIMGIDX = (CAP_ELEMENTS * CAP_ELEMENTS * 4);
1303-
1304-const float RAD2I1024 = 162.9746617f;
1305+const unsigned short CAP_ELEMENTS = 15;
1306+const unsigned int CAP_NVERTEX = (((CAP_ELEMENTS * (CAP_ELEMENTS + 1)) + 2) * 3);
1307+const unsigned int CAP_NIDX = (CAP_ELEMENTS * (CAP_ELEMENTS - 1) * 4);
1308+
1309+const unsigned int CAP_NIMGVERTEX = (((CAP_ELEMENTS + 1) * (CAP_ELEMENTS + 1)) * 5);
1310+const unsigned int CAP_NIMGIDX = (CAP_ELEMENTS * CAP_ELEMENTS * 4);
1311+
1312+const float RAD2I1024 = 162.9746617f;
1313
1314 class CubeaddonScreen :
1315 public CompositeScreenInterface,
1316@@ -57,36 +57,51 @@
1317 public CubeaddonOptions
1318 {
1319 public:
1320+
1321 CubeaddonScreen (CompScreen *);
1322 ~CubeaddonScreen ();
1323
1324- bool setOption (const CompString &name, CompOption::Value &value);
1325+ bool setOption (const CompString &name,
1326+ CompOption::Value &value);
1327
1328 void donePaint ();
1329
1330- bool glPaintOutput (const GLScreenPaintAttrib&, const GLMatrix&,
1331- const CompRegion&, CompOutput *, unsigned int);
1332- void glPaintTransformedOutput (const GLScreenPaintAttrib&,
1333- const GLMatrix&, const CompRegion&,
1334- CompOutput *, unsigned int);
1335-
1336-
1337- void cubeGetRotation (float &x, float &v, float &progress);
1338- void cubeClearTargetOutput (float xRotate, float vRotate);
1339+ bool glPaintOutput (const GLScreenPaintAttrib &,
1340+ const GLMatrix &,
1341+ const CompRegion &,
1342+ CompOutput *,
1343+ unsigned int );
1344+
1345+ void glPaintTransformedOutput (const GLScreenPaintAttrib &,
1346+ const GLMatrix &,
1347+ const CompRegion &,
1348+ CompOutput *,
1349+ unsigned int );
1350+
1351+ void cubeGetRotation (float &x,
1352+ float &v,
1353+ float &progress);
1354+
1355+ void cubeClearTargetOutput (float xRotate,
1356+ float vRotate);
1357+
1358 void cubePaintTop (const GLScreenPaintAttrib &sAttrib,
1359 const GLMatrix &transform,
1360 CompOutput *output,
1361 int size,
1362 const GLVector &normal);
1363+
1364 void cubePaintBottom (const GLScreenPaintAttrib &sAttrib,
1365 const GLMatrix &transform,
1366 CompOutput *output,
1367 int size,
1368 const GLVector &normal);
1369+
1370 bool cubeCheckOrientation (const GLScreenPaintAttrib &sAttrib,
1371 const GLMatrix &transform,
1372 CompOutput *output,
1373 std::vector<GLVector> &points);
1374+
1375 bool cubeShouldPaintViewport (const GLScreenPaintAttrib &sAttrib,
1376 const GLMatrix &transform,
1377 CompOutput *output,
1378@@ -97,24 +112,31 @@
1379 class CubeCap
1380 {
1381 public:
1382+
1383 CubeCap ();
1384
1385- void load (bool scale, bool aspect, bool clamp);
1386+ void load (bool scale,
1387+ bool aspect,
1388+ bool clamp);
1389
1390- int mCurrent;
1391- CompOption::Value::Vector mFiles;
1392-
1393- bool mLoaded;
1394-
1395- GLTexture::List mTexture;
1396- GLMatrix mTexMat;
1397+ int mCurrent;
1398+ CompOption::Value::Vector mFiles;
1399+
1400+ bool mLoaded;
1401+
1402+ GLTexture::List mTexture;
1403+ GLMatrix mTexMat;
1404 };
1405
1406 friend class CubeaddonWindow;
1407
1408 private:
1409- bool changeCap (bool top, int change);
1410+
1411+ bool changeCap (bool top,
1412+ int change);
1413+
1414 void drawBasicGround ();
1415+
1416 void paintCap (const GLScreenPaintAttrib &sAttrib,
1417 const GLMatrix &transform,
1418 CompOutput *output,
1419@@ -129,35 +151,35 @@
1420 CubeScreen *cubeScreen;
1421
1422
1423- bool mReflection;
1424- bool mFirst;
1425-
1426- CompOutput *mLast;
1427-
1428- float mYTrans;
1429- float mZTrans;
1430-
1431- float mBackVRotate;
1432- float mVRot;
1433-
1434- float mDeform;
1435- bool mWasDeformed;
1436-
1437- GLfloat *mWinNormals;
1438- unsigned int mWinNormSize;
1439-
1440- GLfloat mCapFill[CAP_NVERTEX];
1441- GLfloat mCapFillNorm[CAP_NVERTEX];
1442- GLushort mCapFillIdx[CAP_NIDX];
1443- float mCapDeform;
1444- float mCapDistance;
1445- int mCapDeformType;
1446-
1447- CubeCap mTopCap;
1448- CubeCap mBottomCap;
1449+ bool mReflection;
1450+ bool mFirst;
1451+
1452+ CompOutput *mLast;
1453+
1454+ float mYTrans;
1455+ float mZTrans;
1456+
1457+ float mBackVRotate;
1458+ float mVRot;
1459+
1460+ float mDeform;
1461+ bool mWasDeformed;
1462+
1463+ GLfloat *mWinNormals;
1464+ unsigned int mWinNormSize;
1465+
1466+ GLfloat mCapFill[CAP_NVERTEX];
1467+ GLfloat mCapFillNorm[CAP_NVERTEX];
1468+ GLushort mCapFillIdx[CAP_NIDX];
1469+ float mCapDeform;
1470+ float mCapDistance;
1471+ int mCapDeformType;
1472+
1473+ CubeCap mTopCap;
1474+ CubeCap mBottomCap;
1475
1476- float mSinT[1024];
1477- float mCosT[1024];
1478+ float mSinT[1024];
1479+ float mCosT[1024];
1480 };
1481
1482 class CubeaddonWindow :
1483@@ -165,17 +187,24 @@
1484 public PluginClassHandler<CubeaddonWindow, CompWindow>
1485 {
1486 public:
1487+
1488 CubeaddonWindow (CompWindow *);
1489
1490- bool glDraw (const GLMatrix&, const GLWindowPaintAttrib&,
1491- const CompRegion&, unsigned int);
1492- void glAddGeometry (const GLTexture::MatrixList&,
1493- const CompRegion&, const CompRegion&,
1494- unsigned int, unsigned int);
1495- void glDrawTexture (GLTexture *,
1496- const GLMatrix &matrix,
1497+ bool glDraw (const GLMatrix &,
1498+ const GLWindowPaintAttrib &,
1499+ const CompRegion &,
1500+ unsigned int );
1501+
1502+ void glAddGeometry (const GLTexture::MatrixList &,
1503+ const CompRegion &,
1504+ const CompRegion &,
1505+ unsigned int ,
1506+ unsigned int );
1507+
1508+ void glDrawTexture (GLTexture *,
1509+ const GLMatrix &matrix,
1510 const GLWindowPaintAttrib& attrib,
1511- unsigned int);
1512+ unsigned int );
1513
1514 CompWindow *window;
1515 GLWindow *gWindow;

Subscribers

People subscribed via source and target branches

to all changes: