24
24
COMPIZ_PLUGIN_20090315 (firepaint, FirePluginVTable);
26
26
/* 3 vertices per triangle, 2 triangles per particle */
27
const unsigned short CACHESIZE_FACTOR = 3 * 2;
27
const unsigned short CACHESIZE_FACTOR = 3 * 2;
29
28
/* 2 coordinates, x and y */
30
const unsigned short COORD_COMPONENTS = CACHESIZE_FACTOR * 2;
29
const unsigned short COORD_COMPONENTS = CACHESIZE_FACTOR * 2;
32
30
/* each vertex is stored as 3 GLfloats */
33
31
const unsigned short VERTEX_COMPONENTS = CACHESIZE_FACTOR * 3;
35
32
/* 4 colors, RGBA */
36
const unsigned short COLOR_COMPONENTS = CACHESIZE_FACTOR * 4;
33
const unsigned short COLOR_COMPONENTS = CACHESIZE_FACTOR * 4;
38
35
Particle::Particle () :
134
134
i = j = k = l = 0;
137
GLfloat xMinusW, xPlusW, yMinusH, yPlusH;
138
GLushort r, g, b, a, dark_a;
136
140
/* for each particle, use two triangles to display it */
137
141
foreach (Particle &part, particles)
139
143
if (part.life > 0.0f)
141
float w = part.width / 2;
142
float h = part.height / 2;
144
GLushort r, g, b, a, dark_a;
145
w = part.width / 2.0f;
146
h = part.height / 2.0f;
146
148
r = part.r * 65535.0f;
147
149
g = part.g * 65535.0f;
148
150
b = part.b * 65535.0f;
149
a = part.life * part.a * 65535.0f;
150
dark_a = part.life * part.a * darken * 65535.0f;
152
w += (w * part.w_mod) * part.life;
153
h += (h * part.h_mod) * part.life;
151
a = part.life * part.a * 65535.0f;
152
dark_a = part.life * part.a * 65535.0f * darken;
154
w += w * part.w_mod * part.life;
155
h += h * part.h_mod * part.life;
157
xMinusW = part.x - w;
160
yMinusH = part.y - h;
156
vertices_cache[i + 0] = part.x - w;
157
vertices_cache[i + 1] = part.y - h;
164
vertices_cache[i + 0] = xMinusW;
165
vertices_cache[i + 1] = yMinusH;
158
166
vertices_cache[i + 2] = part.z;
160
vertices_cache[i + 3] = part.x - w;
161
vertices_cache[i + 4] = part.y + h;
168
vertices_cache[i + 3] = xMinusW;
169
vertices_cache[i + 4] = yPlusH;
162
170
vertices_cache[i + 5] = part.z;
164
vertices_cache[i + 6] = part.x + w;
165
vertices_cache[i + 7] = part.y + h;
172
vertices_cache[i + 6] = xPlusW;
173
vertices_cache[i + 7] = yPlusH;
166
174
vertices_cache[i + 8] = part.z;
168
176
//second triangle
169
vertices_cache[i + 9] = part.x + w;
170
vertices_cache[i + 10] = part.y + h;
177
vertices_cache[i + 9] = xPlusW;
178
vertices_cache[i + 10] = yPlusH;
171
179
vertices_cache[i + 11] = part.z;
173
vertices_cache[i + 12] = part.x + w;
174
vertices_cache[i + 13] = part.y - h;
181
vertices_cache[i + 12] = xPlusW;
182
vertices_cache[i + 13] = yMinusH;
175
183
vertices_cache[i + 14] = part.z;
177
vertices_cache[i + 15] = part.x - w;
178
vertices_cache[i + 16] = part.y - h;
185
vertices_cache[i + 15] = xMinusW;
186
vertices_cache[i + 16] = yMinusH;
179
187
vertices_cache[i + 17] = part.z;
246
254
dcolors_cache[l + 6] = b;
247
255
dcolors_cache[l + 7] = dark_a;
249
dcolors_cache[l + 8] = r;
250
dcolors_cache[l + 9] = g;
257
dcolors_cache[l + 8] = r;
258
dcolors_cache[l + 9] = g;
251
259
dcolors_cache[l + 10] = b;
252
260
dcolors_cache[l + 11] = dark_a;
300
308
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
301
309
glDisable (GL_TEXTURE_2D);
302
glDisable (GL_BLEND);
311
/* only disable blending if it was disabled before */
313
glDisable (GL_BLEND);
306
ParticleSystem::updateParticles (float time)
317
ParticleSystem::updateParticles (float time)
308
float speed = (time / 50.0);
309
float f_slowdown = slowdown * (1 - MAX (0.99, time / 1000.0) ) * 1000;
319
float speed = (time / 50.0);
320
float f_slowdown = slowdown * (1 - MAX (0.99, time / 1000.0)) * 1000;
376
384
CompAction::State state,
377
385
CompOption::Vector options)
381
x = CompOption::getFloatOptionNamed (options, "x", 0);
382
y = CompOption::getFloatOptionNamed (options, "y", 0);
387
float x = CompOption::getFloatOptionNamed (options, "x", 0);
388
float y = CompOption::getFloatOptionNamed (options, "y", 0);
384
390
fireAddPoint (x, y, false);
394
400
CompOption::Vector options)
396
402
if (screen->otherGrabExist (NULL))
400
grabIndex = screen->pushGrab (None, "firepaint");
406
grabIndex = screen->pushGrab (None, "firepaint");
402
408
if (state & CompAction::StateInitButton)
403
action->setState (action->state () | CompAction::StateTermButton);
409
action->setState (action->state () | CompAction::StateTermButton);
405
411
if (state & CompAction::StateInitKey)
406
action->setState (action->state () | CompAction::StateTermKey);
412
action->setState (action->state () | CompAction::StateTermKey);
408
414
fireAddPoint (pointerX, pointerY, true);
469
472
if (!points.empty ())
471
float max_new = MIN ((int) ps.particles.size (), (int) points.size () * 2) *
472
((float) time / 50.0) *
473
(1.05 - optionGetFireLife());
474
475
float rVal, size = 4;
476
float fireLife = optionGetFireLife ();
477
float fireWidth = optionGetFireSize ();
478
float fireHeight = fireWidth * 1.5f;
479
bool mystFire = optionGetFireMystical ();
480
float max_new = MIN ((int) ps.particles.size (), (int) points.size () * 2) *
481
((float) time / 50.0f) * (1.05f - fireLife);
477
for (unsigned int i = 0;
478
i < ps.particles.size () && max_new > 0; i++)
483
for (unsigned int i = 0; i < ps.particles.size () && max_new > 0; ++i)
480
485
Particle &part = ps.particles.at (i);
481
487
if (part.life <= 0.0f)
483
489
/* give gt new life */
484
490
rVal = (float) (random () & 0xff) / 255.0;
485
491
part.life = 1.0f;
486
492
/* Random Fade Value */
487
part.fade = (rVal * (1 - optionGetFireLife ()) +
488
(0.2f * (1.01 - optionGetFireLife ())));
493
part.fade = (rVal * (1 - fireLife) +
494
(0.2f * (1.01 - fireLife)));
491
part.width = optionGetFireSize ();
492
part.height = optionGetFireSize () * 1.5;
497
part.width = fireWidth;
498
part.height = fireHeight;
493
499
rVal = (float) (random () & 0xff) / 255.0;
494
500
part.w_mod = size * rVal;
495
501
part.h_mod = size * rVal;
526
part.r = (float) optionGetFireColorRed () / 0xffff -
528
(float) optionGetFireColorRed () / 0xffff);
529
part.g = (float) optionGetFireColorGreen () / 0xffff -
531
(float) optionGetFireColorGreen () / 0xffff);
532
part.b = (float) optionGetFireColorBlue () / 0xffff -
534
(float) optionGetFireColorBlue () / 0xffff);
532
part.r = optionGetFireColorRed () / 0xffff -
533
(rVal / 1.7 * optionGetFireColorRed () / 0xffff);
534
part.g = optionGetFireColorGreen () / 0xffff -
535
(rVal / 1.7 * optionGetFireColorGreen () / 0xffff);
536
part.b = optionGetFireColorBlue () / 0xffff -
537
(rVal / 1.7 * optionGetFireColorBlue () / 0xffff);
537
540
/* set transparency */
582
581
FireScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
583
const GLMatrix &transform,
584
const CompRegion ®ion,
582
const GLMatrix &transform,
583
const CompRegion ®ion,
590
status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
592
if ( (!init && ps.active) || brightness < 1.0)
587
bool status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
589
if ((!init && ps.active) || brightness < 1.0)
594
591
GLMatrix sTransform = transform;
636
632
colors[i*4+3] = (1.0 - brightness) * 65535.0f;
639
GLVertexBuffer *stream = GLVertexBuffer::streamingBuffer ();
635
GLVertexBuffer *stream = GLVertexBuffer::streamingBuffer ();
636
GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
641
641
stream->begin (GL_TRIANGLES);
642
642
stream->addVertices (6, vertices);
643
643
stream->addColors (6, colors);