Merge lp:~smspillaz/compiz/compiz.revenge-of-the-blur-plugin into lp:compiz/0.9.12
- compiz.revenge-of-the-blur-plugin
- Merge into 0.9.12
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | 4020 |
Merged at revision: | 4020 |
Proposed branch: | lp:~smspillaz/compiz/compiz.revenge-of-the-blur-plugin |
Merge into: | lp:compiz/0.9.12 |
Diff against target: |
3208 lines (+1260/-1141) 16 files modified
debian/compiz-plugins.install (+2/-0) plugins/CMakeLists.txt (+0/-1) plugins/blur/CMakeLists.txt (+12/-12) plugins/blur/src/blur.cpp (+1086/-1077) plugins/blur/src/blur.h (+59/-38) plugins/opengl/DRIVERS (+10/-0) plugins/opengl/include/opengl/opengl.h (+14/-2) plugins/opengl/include/opengl/program.h (+1/-1) plugins/opengl/include/opengl/vertexbuffer.h (+1/-0) plugins/opengl/src/paint.cpp (+10/-0) plugins/opengl/src/privates.h (+3/-0) plugins/opengl/src/program.cpp (+2/-2) plugins/opengl/src/screen.cpp (+44/-4) plugins/opengl/src/shadercache.cpp (+5/-4) plugins/opengl/src/vertexbuffer.cpp (+5/-0) plugins/opengl/src/window.cpp (+6/-0) |
To merge this branch: | bzr merge lp:~smspillaz/compiz/compiz.revenge-of-the-blur-plugin |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+294604@code.launchpad.net |
Commit message
Blur: port the plugin to modern OpenGL
Description of the change
Port the blur plugin to modern OpenGL
Note: An ABI break was necessary to add glTransformatio
PS Jenkins bot (ps-jenkins) wrote : | # |
- 4019. By Sam Spilsbury <email address hidden>
-
debian: Install the blur plugin as part of compiz-plugins
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:4019
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 4020. By Sam Spilsbury <email address hidden>
-
opengl: Don't invalidate the scratch buffer frame age every time it is queried
We only want to do this when we query the scratch buffer age and then
use it - as it is only on use when the age resets back to an invalidated
state.Previously, the age would re-set every time it is queried, which would
cause it to appear invalidated the next time damageCutoff was reached.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:4020
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Nice cleanup, thanks a lot.
ABI changes are in fact not relevant for other parts.
Preview Diff
1 | === modified file 'debian/compiz-plugins.install' | |||
2 | --- debian/compiz-plugins.install 2015-07-24 16:28:37 +0000 | |||
3 | +++ debian/compiz-plugins.install 2016-05-14 02:33:05 +0000 | |||
4 | @@ -4,6 +4,8 @@ | |||
5 | 4 | usr/share/compiz/*annotate.* | 4 | usr/share/compiz/*annotate.* |
6 | 5 | usr/lib/*/compiz/*bench.* | 5 | usr/lib/*/compiz/*bench.* |
7 | 6 | usr/share/compiz/*bench.* | 6 | usr/share/compiz/*bench.* |
8 | 7 | usr/lib/*/compiz/*blur.* | ||
9 | 8 | usr/share/compiz/*blur.* | ||
10 | 7 | usr/lib/*/compiz/*clone.* | 9 | usr/lib/*/compiz/*clone.* |
11 | 8 | usr/share/compiz/*clone.* | 10 | usr/share/compiz/*clone.* |
12 | 9 | usr/lib/*/compiz/*crashhandler.* | 11 | usr/lib/*/compiz/*crashhandler.* |
13 | 10 | 12 | ||
14 | === modified file 'plugins/CMakeLists.txt' | |||
15 | --- plugins/CMakeLists.txt 2016-03-03 14:23:38 +0000 | |||
16 | +++ plugins/CMakeLists.txt 2016-05-14 02:33:05 +0000 | |||
17 | @@ -12,7 +12,6 @@ | |||
18 | 12 | # temporarily disable plugins that aren't ported yet | 12 | # temporarily disable plugins that aren't ported yet |
19 | 13 | set (COMPIZ_DISABLE_PLUGIN_ANIMATIONADDON ON) | 13 | set (COMPIZ_DISABLE_PLUGIN_ANIMATIONADDON ON) |
20 | 14 | set (COMPIZ_DISABLE_PLUGIN_BICUBIC ON) | 14 | set (COMPIZ_DISABLE_PLUGIN_BICUBIC ON) |
21 | 15 | set (COMPIZ_DISABLE_PLUGIN_BLUR ON) | ||
22 | 16 | set (COMPIZ_DISABLE_PLUGIN_COLORFILTER ON) | 15 | set (COMPIZ_DISABLE_PLUGIN_COLORFILTER ON) |
23 | 17 | set (COMPIZ_DISABLE_PLUGIN_GROUP ON) | 16 | set (COMPIZ_DISABLE_PLUGIN_GROUP ON) |
24 | 18 | set (COMPIZ_DISABLE_PLUGIN_LOGINOUT ON) | 17 | set (COMPIZ_DISABLE_PLUGIN_LOGINOUT ON) |
25 | 19 | 18 | ||
26 | === modified file 'plugins/blur/CMakeLists.txt' | |||
27 | --- plugins/blur/CMakeLists.txt 2012-05-17 10:41:21 +0000 | |||
28 | +++ plugins/blur/CMakeLists.txt 2016-05-14 02:33:05 +0000 | |||
29 | @@ -2,15 +2,15 @@ | |||
30 | 2 | 2 | ||
31 | 3 | include (CompizPlugin) | 3 | include (CompizPlugin) |
32 | 4 | 4 | ||
45 | 5 | #find_package (OpenGL) | 5 | find_package (OpenGL) |
46 | 6 | 6 | ||
47 | 7 | #if (OPENGL_GLU_FOUND) | 7 | if (OPENGL_GLU_FOUND) |
48 | 8 | # compiz_plugin(blur PLUGINDEPS composite opengl LIBRARIES decoration ${OPENGL_glu_LIBRARY} INCDIRS ${OPENGL_INCLUDE_DIR}) | 8 | compiz_plugin(blur PLUGINDEPS composite opengl LIBRARIES decoration ${OPENGL_glu_LIBRARY} INCDIRS ${OPENGL_INCLUDE_DIR}) |
49 | 9 | 9 | ||
50 | 10 | # if (COMPIZ_BUILD_WITH_RPATH AND NOT COMPIZ_DISABLE_PLUGIN_BLUR) | 10 | if (COMPIZ_BUILD_WITH_RPATH AND NOT COMPIZ_DISABLE_PLUGIN_BLUR) |
51 | 11 | # set_target_properties ( | 11 | set_target_properties ( |
52 | 12 | # blur PROPERTIES | 12 | blur PROPERTIES |
53 | 13 | # INSTALL_RPATH "${COMPIZ_LIBDIR}" | 13 | INSTALL_RPATH "${COMPIZ_LIBDIR}" |
54 | 14 | # ) | 14 | ) |
55 | 15 | # endif (COMPIZ_BUILD_WITH_RPATH AND NOT COMPIZ_DISABLE_PLUGIN_BLUR) | 15 | endif (COMPIZ_BUILD_WITH_RPATH AND NOT COMPIZ_DISABLE_PLUGIN_BLUR) |
56 | 16 | #endif () | 16 | endif () |
57 | 17 | 17 | ||
58 | === modified file 'plugins/blur/src/blur.cpp' | |||
59 | --- plugins/blur/src/blur.cpp 2013-05-09 13:43:07 +0000 | |||
60 | +++ plugins/blur/src/blur.cpp 2016-05-14 02:33:05 +0000 | |||
61 | @@ -22,19 +22,22 @@ | |||
62 | 22 | * | 22 | * |
63 | 23 | * Author: David Reveman <davidr@novell.com> | 23 | * Author: David Reveman <davidr@novell.com> |
64 | 24 | */ | 24 | */ |
65 | 25 | |||
66 | 26 | #include <blur.h> | 25 | #include <blur.h> |
67 | 26 | #include <sstream> | ||
68 | 27 | #include <opengl/framebufferobject.h> | ||
69 | 28 | |||
70 | 29 | /* Supporting independent texture fetch operations will require | ||
71 | 30 | * GLVertexBuffer to support per-plugin attributes as texture co-ordinates | ||
72 | 31 | * are two-component and not four-component | ||
73 | 32 | */ | ||
74 | 33 | #define INDEPENDENT_TEX_SUPPORTED 0 | ||
75 | 27 | 34 | ||
76 | 28 | COMPIZ_PLUGIN_20090315 (blur, BlurPluginVTable) | 35 | COMPIZ_PLUGIN_20090315 (blur, BlurPluginVTable) |
77 | 29 | 36 | ||
78 | 30 | const unsigned short BLUR_GAUSSIAN_RADIUS_MAX = 15; | ||
79 | 31 | |||
80 | 32 | const unsigned short BLUR_STATE_CLIENT = 0; | ||
81 | 33 | const unsigned short BLUR_STATE_DECOR = 1; | ||
82 | 34 | const unsigned short BLUR_STATE_NUM = 2; | ||
83 | 35 | |||
84 | 36 | /* pascal triangle based kernel generator */ | 37 | /* pascal triangle based kernel generator */ |
86 | 37 | static int | 38 | namespace |
87 | 39 | { | ||
88 | 40 | int | ||
89 | 38 | blurCreateGaussianLinearKernel (int radius, | 41 | blurCreateGaussianLinearKernel (int radius, |
90 | 39 | float strength, | 42 | float strength, |
91 | 40 | float *amp, | 43 | float *amp, |
92 | @@ -106,6 +109,7 @@ | |||
93 | 106 | 109 | ||
94 | 107 | return radius; | 110 | return radius; |
95 | 108 | } | 111 | } |
96 | 112 | } | ||
97 | 109 | 113 | ||
98 | 110 | void | 114 | void |
99 | 111 | BlurScreen::updateFilterRadius () | 115 | BlurScreen::updateFilterRadius () |
100 | @@ -137,20 +141,11 @@ | |||
101 | 137 | { | 141 | { |
102 | 138 | updateFilterRadius (); | 142 | updateFilterRadius (); |
103 | 139 | 143 | ||
104 | 140 | foreach (BlurFunction &bf, srcBlurFunctions) | ||
105 | 141 | GLFragment::destroyFragmentFunction (bf.id); | ||
106 | 142 | srcBlurFunctions.clear (); | 144 | srcBlurFunctions.clear (); |
107 | 143 | foreach (BlurFunction &bf, dstBlurFunctions) | ||
108 | 144 | GLFragment::destroyFragmentFunction (bf.id); | ||
109 | 145 | dstBlurFunctions.clear (); | 145 | dstBlurFunctions.clear (); |
110 | 146 | 146 | ||
118 | 147 | width = height = 0; | 147 | program.reset (); |
119 | 148 | 148 | texture.clear (); | |
113 | 149 | if (program) | ||
114 | 150 | { | ||
115 | 151 | GL::deletePrograms (1, &program); | ||
116 | 152 | program = 0; | ||
117 | 153 | } | ||
120 | 154 | } | 149 | } |
121 | 155 | 150 | ||
122 | 156 | static CompRegion | 151 | static CompRegion |
123 | @@ -249,7 +244,6 @@ | |||
124 | 249 | int threshold, | 244 | int threshold, |
125 | 250 | std::vector<BlurBox> box) | 245 | std::vector<BlurBox> box) |
126 | 251 | { | 246 | { |
127 | 252 | |||
128 | 253 | this->state[state].threshold = threshold; | 247 | this->state[state].threshold = threshold; |
129 | 254 | this->state[state].box = box; | 248 | this->state[state].box = box; |
130 | 255 | 249 | ||
131 | @@ -289,7 +283,7 @@ | |||
132 | 289 | 283 | ||
133 | 290 | match = &bScreen->optionGetFocusBlurMatch (); | 284 | match = &bScreen->optionGetFocusBlurMatch (); |
134 | 291 | 285 | ||
136 | 292 | focus = GL::fragmentProgram && match->evaluate (window); | 286 | focus = GL::shaders && match->evaluate (window); |
137 | 293 | if (focus != focusBlur) | 287 | if (focus != focusBlur) |
138 | 294 | { | 288 | { |
139 | 295 | focusBlur = focus; | 289 | focusBlur = focus; |
140 | @@ -421,49 +415,75 @@ | |||
141 | 421 | } | 415 | } |
142 | 422 | 416 | ||
143 | 423 | cScreen->preparePaint (msSinceLastPaint); | 417 | cScreen->preparePaint (msSinceLastPaint); |
146 | 424 | 418 | } | |
147 | 425 | if (cScreen->damageMask () & COMPOSITE_SCREEN_DAMAGE_REGION_MASK) | 419 | |
148 | 420 | bool | ||
149 | 421 | BlurScreen::markAreaDirty (const CompRegion &r) | ||
150 | 422 | { | ||
151 | 423 | return allowAreaDirtyOnOwnDamageBuffer; | ||
152 | 424 | } | ||
153 | 425 | |||
154 | 426 | void | ||
155 | 427 | BlurScreen::damageCutoff () | ||
156 | 428 | { | ||
157 | 429 | if (alphaBlur) | ||
158 | 426 | { | 430 | { |
161 | 427 | /* walk from bottom to top and expand damage */ | 431 | this->output = &screen->fullscreenOutput (); |
162 | 428 | if (alphaBlur) | 432 | |
163 | 433 | /* We need to do a primary pass here with glPaint to check which | ||
164 | 434 | * regions of the backbuffer need to be updated. | ||
165 | 435 | * | ||
166 | 436 | * Because the backbuffer is effectively partially undefined, we are completely | ||
167 | 437 | * reliant on what core is telling us the repair regions of the | ||
168 | 438 | * backbuffer need to be - but obviously we can't completely rely | ||
169 | 439 | * on it because of a feedback effect, as we need to expand | ||
170 | 440 | * the repair region slightly so that the texture sampler | ||
171 | 441 | * doesn't go out of range of the damage region. If we were to | ||
172 | 442 | * simply expand the damage region, then that would feedback to us | ||
173 | 443 | * on the next frame, until the damage region eventually became infinite. | ||
174 | 444 | * | ||
175 | 445 | * As such, we have a tracker in core to track all damage except the effect | ||
176 | 446 | * of expanding the damage region that came back to us. We then use | ||
177 | 447 | * this tracker along with the frame age to determine what damage really | ||
178 | 448 | * needs to be expanded in order to determine the backbuffer update region, | ||
179 | 449 | * and then use the real damage in order to determine what blur regions | ||
180 | 450 | * should be updated | ||
181 | 451 | */ | ||
182 | 452 | backbufferUpdateRegionThisFrame &= emptyRegion; | ||
183 | 453 | CompRegion frameAgeDamage = damageQuery->damageForFrameAge (cScreen->getFrameAge ()); | ||
184 | 454 | foreach (CompWindow *w, screen->windows ()) | ||
185 | 429 | { | 455 | { |
221 | 430 | int x1, y1, x2, y2; | 456 | /* Skip windows that would not have glPaint called on them */ |
222 | 431 | int count = 0; | 457 | if (w->destroyed ()) |
223 | 432 | CompRegion damage (cScreen->currentDamage ()); | 458 | continue; |
224 | 433 | 459 | ||
225 | 434 | foreach (CompWindow *w, screen->windows ()) | 460 | if (!w->shaded () && !w->isViewable ()) |
226 | 435 | { | 461 | continue; |
227 | 436 | BLUR_WINDOW (w); | 462 | |
228 | 437 | 463 | BlurWindow *bw = BlurWindow::get (w); | |
229 | 438 | if (!w->isViewable () || !CompositeWindow::get (w)->damaged ()) | 464 | |
230 | 439 | continue; | 465 | if (!bw->cWindow->redirected ()) |
231 | 440 | 466 | continue; | |
232 | 441 | if (!bw->region.isEmpty ()) | 467 | |
233 | 442 | { | 468 | if (!bw->projectedBlurRegion.isEmpty ()) |
234 | 443 | CompRect r = bw->region.boundingRect (); | 469 | bw->projectedBlurRegion &= emptyRegion; |
235 | 444 | CompRect d = damage.boundingRect (); | 470 | |
236 | 445 | x1 = r.x1 () - filterRadius; | 471 | GLMatrix screenSpace; |
237 | 446 | y1 = r.y1 () - filterRadius; | 472 | screenSpace.toScreenSpace (this->output, -DEFAULT_Z_CAMERA); |
238 | 447 | x2 = r.x2 () + filterRadius; | 473 | |
239 | 448 | y2 = r.y2 () + filterRadius; | 474 | bw->gWindow->glPaint (bw->gWindow->paintAttrib (), screenSpace, |
240 | 449 | 475 | frameAgeDamage, | |
241 | 450 | if (x1 < d.x2 () && | 476 | PAINT_WINDOW_NO_CORE_INSTANCE_MASK); |
242 | 451 | y1 < d.y2 () && | 477 | |
243 | 452 | x2 > d.x1 () && | 478 | backbufferUpdateRegionThisFrame += bw->projectedBlurRegion; |
209 | 453 | y2 > d.y1 ()) | ||
210 | 454 | { | ||
211 | 455 | damage.shrink (-filterRadius, -filterRadius); | ||
212 | 456 | count++; | ||
213 | 457 | } | ||
214 | 458 | } | ||
215 | 459 | } | ||
216 | 460 | |||
217 | 461 | if (count) | ||
218 | 462 | cScreen->damageRegion (damage); | ||
219 | 463 | |||
220 | 464 | this->count = count; | ||
244 | 465 | } | 479 | } |
245 | 480 | |||
246 | 481 | allowAreaDirtyOnOwnDamageBuffer = false; | ||
247 | 482 | cScreen->damageRegion (backbufferUpdateRegionThisFrame); | ||
248 | 483 | allowAreaDirtyOnOwnDamageBuffer = true; | ||
249 | 466 | } | 484 | } |
250 | 485 | |||
251 | 486 | cScreen->damageCutoff (); | ||
252 | 467 | } | 487 | } |
253 | 468 | 488 | ||
254 | 469 | bool | 489 | bool |
255 | @@ -471,23 +491,10 @@ | |||
256 | 471 | const GLMatrix &transform, const CompRegion ®ion, | 491 | const GLMatrix &transform, const CompRegion ®ion, |
257 | 472 | CompOutput *output, unsigned int mask) | 492 | CompOutput *output, unsigned int mask) |
258 | 473 | { | 493 | { |
259 | 474 | bool status; | ||
260 | 475 | |||
261 | 476 | if (alphaBlur) | 494 | if (alphaBlur) |
262 | 477 | { | 495 | { |
263 | 478 | stencilBox = region.boundingRect (); | 496 | stencilBox = region.boundingRect (); |
264 | 479 | this->region = region; | 497 | this->region = region; |
265 | 480 | |||
266 | 481 | if (mask & PAINT_SCREEN_REGION_MASK) | ||
267 | 482 | { | ||
268 | 483 | /* we need to redraw more than the screen region being updated */ | ||
269 | 484 | if (count) | ||
270 | 485 | { | ||
271 | 486 | this->region.shrink (-filterRadius * 2, -filterRadius * 2); | ||
272 | 487 | |||
273 | 488 | this->region &= screen->region (); | ||
274 | 489 | } | ||
275 | 490 | } | ||
276 | 491 | } | 498 | } |
277 | 492 | 499 | ||
278 | 493 | if (!blurOcclusion) | 500 | if (!blurOcclusion) |
279 | @@ -500,12 +507,7 @@ | |||
280 | 500 | 507 | ||
281 | 501 | this->output = output; | 508 | this->output = output; |
282 | 502 | 509 | ||
289 | 503 | if (alphaBlur) | 510 | return gScreen->glPaintOutput (sAttrib, transform, region, output, mask); |
284 | 504 | status = gScreen->glPaintOutput (sAttrib, transform, this->region, output, mask); | ||
285 | 505 | else | ||
286 | 506 | status = gScreen->glPaintOutput (sAttrib, transform, region, output, mask); | ||
287 | 507 | |||
288 | 508 | return status; | ||
290 | 509 | } | 511 | } |
291 | 510 | 512 | ||
292 | 511 | void | 513 | void |
293 | @@ -542,12 +544,42 @@ | |||
294 | 542 | cScreen->donePaint (); | 544 | cScreen->donePaint (); |
295 | 543 | } | 545 | } |
296 | 544 | 546 | ||
297 | 547 | void | ||
298 | 548 | BlurWindow::glTransformationComplete (const GLMatrix &matrix, | ||
299 | 549 | const CompRegion ®ion, | ||
300 | 550 | unsigned int mask) | ||
301 | 551 | { | ||
302 | 552 | gWindow->glTransformationComplete (matrix, region, mask); | ||
303 | 553 | |||
304 | 554 | int clientThreshold; | ||
305 | 555 | const CompRegion *reg = NULL; | ||
306 | 556 | |||
307 | 557 | /* only care about client window blurring when it's translucent */ | ||
308 | 558 | if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) | ||
309 | 559 | clientThreshold = state[BLUR_STATE_CLIENT].threshold; | ||
310 | 560 | else | ||
311 | 561 | clientThreshold = 0; | ||
312 | 562 | |||
313 | 563 | if (mask & PAINT_WINDOW_TRANSFORMED_MASK) | ||
314 | 564 | reg = &infiniteRegion; | ||
315 | 565 | else | ||
316 | 566 | reg = ®ion; | ||
317 | 567 | |||
318 | 568 | bScreen->tmpRegion = this->region.intersected (*reg); | ||
319 | 569 | |||
320 | 570 | if (state[BLUR_STATE_DECOR].threshold || clientThreshold) | ||
321 | 571 | { | ||
322 | 572 | determineBlurRegion (bScreen->optionGetFilter (), | ||
323 | 573 | matrix, | ||
324 | 574 | clientThreshold); | ||
325 | 575 | } | ||
326 | 576 | } | ||
327 | 577 | |||
328 | 545 | bool | 578 | bool |
329 | 546 | BlurWindow::glPaint (const GLWindowPaintAttrib &attrib, | 579 | BlurWindow::glPaint (const GLWindowPaintAttrib &attrib, |
330 | 547 | const GLMatrix &transform, | 580 | const GLMatrix &transform, |
331 | 548 | const CompRegion ®ion, unsigned int mask) | 581 | const CompRegion ®ion, unsigned int mask) |
332 | 549 | { | 582 | { |
333 | 550 | |||
334 | 551 | bool status = gWindow->glPaint (attrib, transform, region, mask); | 583 | bool status = gWindow->glPaint (attrib, transform, region, mask); |
335 | 552 | 584 | ||
336 | 553 | if (!bScreen->blurOcclusion && | 585 | if (!bScreen->blurOcclusion && |
337 | @@ -564,307 +596,359 @@ | |||
338 | 564 | return status; | 596 | return status; |
339 | 565 | } | 597 | } |
340 | 566 | 598 | ||
346 | 567 | GLFragment::FunctionId | 599 | namespace |
347 | 568 | BlurScreen::getSrcBlurFragmentFunction (GLTexture *texture, | 600 | { |
348 | 569 | int param) | 601 | struct SamplerInfo |
349 | 570 | { | 602 | { |
350 | 571 | GLFragment::FunctionData data; | 603 | GLint target; |
351 | 604 | CompString func; | ||
352 | 605 | }; | ||
353 | 606 | |||
354 | 607 | SamplerInfo | ||
355 | 608 | getSamplerInfoForSize (const CompSize &size) | ||
356 | 609 | { | ||
357 | 610 | SamplerInfo info; | ||
358 | 611 | |||
359 | 612 | #ifdef USE_GLES | ||
360 | 613 | info.target = GL_TEXTURE_2D; | ||
361 | 614 | info.func = "texture2D"; | ||
362 | 615 | #else | ||
363 | 616 | if (GL::textureNonPowerOfTwo || | ||
364 | 617 | (POWER_OF_TWO (size.width ()) && POWER_OF_TWO (size.height ()))) | ||
365 | 618 | { | ||
366 | 619 | info.target = GL_TEXTURE_2D; | ||
367 | 620 | info.func = "texture2D"; | ||
368 | 621 | } | ||
369 | 622 | else | ||
370 | 623 | { | ||
371 | 624 | info.target = GL_TEXTURE_RECTANGLE_NV; | ||
372 | 625 | info.func = "textureRECT"; | ||
373 | 626 | } | ||
374 | 627 | #endif | ||
375 | 628 | |||
376 | 629 | return info; | ||
377 | 630 | } | ||
378 | 631 | } | ||
379 | 632 | |||
380 | 633 | /* XXX: param is redundant */ | ||
381 | 634 | const CompString & | ||
382 | 635 | BlurScreen::getSrcBlurFragmentFunction (GLTexture *texture) | ||
383 | 636 | { | ||
384 | 572 | BlurFunction function; | 637 | BlurFunction function; |
438 | 573 | int target; | 638 | std::stringstream data (std::stringstream::out); |
439 | 574 | 639 | ||
440 | 575 | if (texture->target () == GL_TEXTURE_2D) | 640 | SamplerInfo info (getSamplerInfoForSize (CompSize (texture->width (), |
441 | 576 | target = COMP_FETCH_TARGET_2D; | 641 | texture->height ()))); |
442 | 577 | else | 642 | |
443 | 578 | target = COMP_FETCH_TARGET_RECT; | 643 | foreach (const BlurFunction &bf, srcBlurFunctions) |
444 | 579 | 644 | if (bf.target == info.target) | |
445 | 580 | foreach (BlurFunction &bf, srcBlurFunctions) | 645 | return bf.shader; |
446 | 581 | if (bf.param == param && bf.target == target) | 646 | |
447 | 582 | return bf.id; | 647 | data << "uniform vec4 focusblur_input_offset;\n"\ |
448 | 583 | 648 | "\n"\ | |
449 | 584 | if (data.status ()) | 649 | "void focusblur_fragment ()\n"\ |
450 | 585 | { | 650 | "{\n"; |
451 | 586 | static const char *temp[] = { "offset0", "offset1", "sum" }; | 651 | |
452 | 587 | unsigned int i; | 652 | if (optionGetFilter () == BlurOptions::Filter4xbilinear) |
453 | 588 | 653 | data << " float blur_offset0, blur_offset1;\n"\ | |
454 | 589 | for (i = 0; i < sizeof (temp) / sizeof (temp[0]); i++) | 654 | " vec4 blur_sum;\n"\ |
455 | 590 | data.addTempHeaderOp (temp[i]); | 655 | " vec4 offset0 = focusblur_input_offset.xyzw * vec4 (1.0, 1.0, 0.0, 0.0);\n"\ |
456 | 591 | 656 | " vec4 offset1 = focusblur_input_offset.zwww * vec4 (1.0, 1.0, 0.0, 0.0);\n" | |
457 | 592 | data.addDataOp ( | 657 | " vec4 output = texture2D (texture0, vTexCoord0 + offset0);\n"\ |
458 | 593 | "MUL offset0, program.env[%d].xyzw, { 1.0, 1.0, 0.0, 0.0 };" | 658 | " blur_sum = output * 0.25;\n"\ |
459 | 594 | "MUL offset1, program.env[%d].zwww, { 1.0, 1.0, 0.0, 0.0 };", | 659 | " output = " << info.func << " (texture0, vTexCoord0 - offset0);\n"\ |
460 | 595 | param, param); | 660 | " blur_sum += output * 0.25;\n"\ |
461 | 596 | 661 | " output = " << info.func << " (texture0, vTexCoord0 + offset1);\n"\ | |
462 | 597 | 662 | " blur_sum += output * 0.25;\n"\ | |
463 | 598 | switch (optionGetFilter ()) { | 663 | " output = " << info.func << " (texture0, vTexCoord0 - offset1);\n"\ |
464 | 599 | case BlurOptions::Filter4xbilinear: | 664 | " output = output * 0.25 + blur_sum;\n"\ |
465 | 600 | default: | 665 | " gl_FragColor = output;\n"; |
466 | 601 | data.addFetchOp ("output", "offset0", target); | 666 | |
467 | 602 | data.addDataOp ("MUL sum, output, 0.25;"); | 667 | data << "}\n"; |
468 | 603 | data.addFetchOp ("output", "-offset0", target); | 668 | |
469 | 604 | data.addDataOp ("MAD sum, output, 0.25, sum;"); | 669 | function.shader = data.str (); |
470 | 605 | data.addFetchOp ("output", "offset1", target); | 670 | function.target = info.target; |
471 | 606 | data.addDataOp ("MAD sum, output, 0.25, sum;"); | 671 | |
472 | 607 | data.addFetchOp ("output", "-offset1", target); | 672 | srcBlurFunctions.push_back (function); |
473 | 608 | data.addDataOp ("MAD output, output, 0.25, sum;"); | 673 | |
474 | 609 | break; | 674 | return srcBlurFunctions.back ().shader; |
422 | 610 | } | ||
423 | 611 | |||
424 | 612 | if (!data.status ()) | ||
425 | 613 | return 0; | ||
426 | 614 | |||
427 | 615 | function.id = data.createFragmentFunction ("blur"); | ||
428 | 616 | function.target = target; | ||
429 | 617 | function.param = param; | ||
430 | 618 | function.unit = 0; | ||
431 | 619 | |||
432 | 620 | srcBlurFunctions.push_back (function); | ||
433 | 621 | |||
434 | 622 | return function.id; | ||
435 | 623 | } | ||
436 | 624 | |||
437 | 625 | return 0; | ||
475 | 626 | } | 675 | } |
476 | 627 | 676 | ||
478 | 628 | GLFragment::FunctionId | 677 | /* This seems incomplete to me */ |
479 | 678 | |||
480 | 679 | const CompString & | ||
481 | 629 | BlurScreen::getDstBlurFragmentFunction (GLTexture *texture, | 680 | BlurScreen::getDstBlurFragmentFunction (GLTexture *texture, |
484 | 630 | int param, | 681 | int unit, |
483 | 631 | int unit, | ||
485 | 632 | int numITC, | 682 | int numITC, |
486 | 633 | int startTC) | 683 | int startTC) |
487 | 634 | { | 684 | { |
492 | 635 | BlurFunction function; | 685 | BlurFunction function; |
493 | 636 | GLFragment::FunctionData data; | 686 | std::stringstream data (std::stringstream::out); |
494 | 637 | int target; | 687 | int saturation = optionGetSaturation (); |
491 | 638 | char *targetString; | ||
495 | 639 | 688 | ||
506 | 640 | if (texture->target () == GL_TEXTURE_2D) | 689 | SamplerInfo info (getSamplerInfoForSize (CompSize (texture->width (), |
507 | 641 | { | 690 | texture->height ()))); |
498 | 642 | target = COMP_FETCH_TARGET_2D; | ||
499 | 643 | targetString = (char *) "2D"; | ||
500 | 644 | } | ||
501 | 645 | else | ||
502 | 646 | { | ||
503 | 647 | target = COMP_FETCH_TARGET_RECT; | ||
504 | 648 | targetString = (char *) "RECT"; | ||
505 | 649 | } | ||
508 | 650 | 691 | ||
509 | 651 | foreach (BlurFunction &function, dstBlurFunctions) | 692 | foreach (BlurFunction &function, dstBlurFunctions) |
513 | 652 | if (function.param == param && | 693 | if (function.target == info.target && |
511 | 653 | function.target == target && | ||
512 | 654 | function.unit == unit && | ||
514 | 655 | function.numITC == numITC && | 694 | function.numITC == numITC && |
727 | 656 | function.startTC == startTC) | 695 | function.startTC == startTC && |
728 | 657 | return function.id; | 696 | function.saturation == saturation) |
729 | 658 | 697 | return function.shader; | |
730 | 659 | if (data.status ()) | 698 | |
731 | 660 | { | 699 | data << "uniform vec4 blur_translation;\n"\ |
732 | 661 | static const char *temp[] = { "fCoord", "mask", "sum", "dst" }; | 700 | "uniform vec4 blur_threshold;\n"; |
733 | 662 | int i, j; | 701 | |
734 | 663 | char str[1024]; | 702 | int i, j; |
735 | 664 | int saturation = optionGetSaturation (); | 703 | /* These are always initialized if running a gaussian shader */ |
736 | 665 | int numIndirect; | 704 | int numIndirect = 0; |
737 | 666 | int numIndirectOp; | 705 | int numIndirectOp = 0; |
738 | 667 | int base, end, ITCbase; | 706 | int base, end, ITCbase; |
739 | 668 | 707 | ||
740 | 669 | for (i = 0; (unsigned int) i < sizeof (temp) / sizeof (temp[0]); i++) | 708 | /* Set per-shader uniforms */ |
741 | 670 | data.addTempHeaderOp (temp[i]); | 709 | switch (optionGetFilter ()) |
742 | 671 | 710 | { | |
743 | 672 | if (saturation < 100) | 711 | case BlurOptions::Filter4xbilinear: |
744 | 673 | data.addTempHeaderOp ("sat"); | 712 | data << "uniform vec4 blur_dxdy;\n"; |
745 | 674 | 713 | break; | |
746 | 675 | switch (optionGetFilter ()) { | 714 | default: |
747 | 676 | case BlurOptions::Filter4xbilinear: { | 715 | break; |
748 | 677 | static const char *filterTemp[] = { | 716 | } |
749 | 678 | "t0", "t1", "t2", "t3", | 717 | |
750 | 679 | "s0", "s1", "s2", "s3" | 718 | data << "\n"\ |
751 | 680 | }; | 719 | "void blur_fragment ()\n"\ |
752 | 681 | 720 | "{\n"\ | |
753 | 682 | for (i = 0; | 721 | " vec4 blur_sum, blur_dst, blur_output;\n"\ |
754 | 683 | (unsigned int) i < sizeof (filterTemp) / sizeof (filterTemp[0]); | 722 | " vec2 blur_fCoord;\n"\ |
755 | 684 | i++) | 723 | " vec4 blur_mask;\n"; |
756 | 685 | data.addTempHeaderOp (filterTemp[i]); | 724 | |
757 | 686 | 725 | if (saturation < 100) | |
758 | 687 | data.addFetchOp ("output", NULL, target); | 726 | data << " float blur_sat;\n"; |
759 | 688 | data.addColorOp ("output", "output"); | 727 | |
760 | 689 | 728 | /* Define per-filter temporaries */ | |
761 | 690 | data.addDataOp ( | 729 | switch (optionGetFilter ()) |
762 | 691 | "MUL fCoord, fragment.position, program.env[%d];", | 730 | { |
763 | 692 | param); | 731 | case BlurOptions::Filter4xbilinear: |
764 | 693 | 732 | { | |
765 | 694 | 733 | static const char *filterTemp[] = { | |
766 | 695 | data.addDataOp ( | 734 | "blur_t0", "blur_t1", "blur_t2", "blur_t3", |
767 | 696 | "ADD t0, fCoord, program.env[%d];" | 735 | }; |
768 | 697 | "TEX s0, t0, texture[%d], %s;" | 736 | |
769 | 698 | 737 | static const char *filterSampleTemp[] = { | |
770 | 699 | "SUB t1, fCoord, program.env[%d];" | 738 | "blur_s0", "blur_s1", "blur_s2", "blur_s3" |
771 | 700 | "TEX s1, t1, texture[%d], %s;" | 739 | }; |
772 | 701 | 740 | ||
773 | 702 | "MAD t2, program.env[%d], { -1.0, 1.0, 0.0, 0.0 }, fCoord;" | 741 | for (i = 0; |
774 | 703 | "TEX s2, t2, texture[%d], %s;" | 742 | (unsigned int) i < sizeof (filterTemp) / sizeof (filterTemp[0]); |
775 | 704 | 743 | ++i) | |
776 | 705 | "MAD t3, program.env[%d], { 1.0, -1.0, 0.0, 0.0 }, fCoord;" | 744 | data << " vec2 " << filterTemp[i] << ";\n"; |
777 | 706 | "TEX s3, t3, texture[%d], %s;" | 745 | |
778 | 707 | 746 | for (i = 0; | |
779 | 708 | "MUL_SAT mask, output.a, program.env[%d];" | 747 | (unsigned int) i < sizeof (filterSampleTemp) / sizeof (filterSampleTemp[0]); |
780 | 709 | 748 | ++i) | |
781 | 710 | "MUL sum, s0, 0.25;" | 749 | data << " vec4 " << filterSampleTemp[i] << ";\n"; |
782 | 711 | "MAD sum, s1, 0.25, sum;" | 750 | } |
783 | 712 | "MAD sum, s2, 0.25, sum;" | 751 | break; |
784 | 713 | "MAD sum, s3, 0.25, sum;", | 752 | case BlurOptions::FilterGaussian: |
785 | 714 | 753 | { | |
786 | 715 | param + 2, unit, targetString, | 754 | /* try to use only half of the available temporaries to keep |
787 | 716 | param + 2, unit, targetString, | 755 | other plugins working */ |
788 | 717 | param + 2, unit, targetString, | 756 | if ((maxTemp / 2) - 4 > |
789 | 718 | param + 2, unit, targetString, | 757 | (numTexop + (numTexop - numITC)) * 2) |
790 | 719 | param + 1); | 758 | { |
791 | 720 | 759 | numIndirect = 1; | |
792 | 721 | } break; | 760 | numIndirectOp = numTexop; |
793 | 722 | case BlurOptions::FilterGaussian: { | 761 | } |
794 | 723 | 762 | else | |
795 | 724 | /* try to use only half of the available temporaries to keep | 763 | { |
796 | 725 | other plugins working */ | 764 | i = MAX (((maxTemp / 2) - 4) / 4, 1); |
797 | 726 | if ((maxTemp / 2) - 4 > | 765 | numIndirect = ceil ((float)numTexop / (float)i); |
798 | 727 | (numTexop + (numTexop - numITC)) * 2) | 766 | numIndirectOp = ceil ((float)numTexop / (float)numIndirect); |
799 | 728 | { | 767 | } |
800 | 729 | numIndirect = 1; | 768 | |
801 | 730 | numIndirectOp = numTexop; | 769 | /* we need to define all coordinate temporaries if we have |
802 | 731 | } | 770 | multiple indirection steps */ |
803 | 732 | else | 771 | j = (numIndirect > 1) ? 0 : numITC; |
804 | 733 | { | 772 | |
805 | 734 | i = MAX (((maxTemp / 2) - 4) / 4, 1); | 773 | for (i = 0; i < numIndirectOp * 2; i++) |
806 | 735 | numIndirect = ceil ((float)numTexop / (float)i); | 774 | data << " vec4 blur_pix_" << i << ";\n"; |
807 | 736 | numIndirectOp = ceil ((float)numTexop / (float)numIndirect); | 775 | |
808 | 737 | } | 776 | for (i = j * 2; i < numIndirectOp * 2; i++) |
809 | 738 | 777 | data << " vec2 blur_coord_" << i << ";\n"; | |
810 | 739 | /* we need to define all coordinate temporaries if we have | 778 | } |
811 | 740 | multiple indirection steps */ | 779 | break; |
812 | 741 | j = (numIndirect > 1) ? 0 : numITC; | 780 | case BlurOptions::FilterMipmap: |
813 | 742 | 781 | { | |
814 | 743 | for (i = 0; i < numIndirectOp * 2; i++) | 782 | data << " float lod_bias;\n"; |
815 | 744 | { | 783 | } |
816 | 745 | snprintf (str, 1024, "pix_%d", i); | 784 | default: |
817 | 746 | data.addTempHeaderOp (str); | 785 | break; |
818 | 747 | } | 786 | } |
819 | 748 | 787 | ||
820 | 749 | for (i = j * 2; i < numIndirectOp * 2; i++) | 788 | /* |
821 | 750 | { | 789 | * blur_output: copy the original gl_FragColor determined by sampling |
822 | 751 | snprintf (str, 1024, "coord_%d", i); | 790 | * the window texture in the core shader |
823 | 752 | data.addTempHeaderOp (str); | 791 | * blur_fCoord: take the fragment co-ordinate in window co-ordinates |
824 | 753 | } | 792 | * and normalize it (eg, blur_translation). Once normalized we can |
825 | 754 | 793 | * sample texUnitN + 1 (for the copy of the backbuffer we wish to blur) | |
826 | 755 | data.addFetchOp ("output", NULL, target); | 794 | * and texUnitN + 2 (scratch fbo for gaussian blurs) |
827 | 756 | data.addColorOp ("output", "output"); | 795 | * blur_mask: take blur_output pixel alpha value, multiply by threshold value |
828 | 757 | 796 | * and clamp between 0 - 1. We will use this later to mix the blur fragments | |
829 | 758 | data.addDataOp ( | 797 | * with the window fragments. |
830 | 759 | "MUL fCoord, fragment.position, program.env[%d];", | 798 | */ |
831 | 760 | param); | 799 | data << "\n"\ |
832 | 761 | 800 | " blur_output = gl_FragColor;\n"\ | |
833 | 762 | 801 | " blur_fCoord = gl_FragCoord.st * blur_translation.st;\n"\ | |
834 | 763 | data.addDataOp ("TEX sum, fCoord, texture[%d], %s;", | 802 | " blur_mask = clamp (blur_output.a * blur_threshold, vec4 (0.0, 0.0, 0.0, 0.), vec4 (1.0, 1.0, 1.0, 1.0));\n"\ |
835 | 764 | unit + 1, targetString); | 803 | "\n"; |
836 | 765 | 804 | ||
837 | 766 | 805 | /* Define filter program */ | |
838 | 767 | data.addDataOp ("MUL_SAT mask, output.a, program.env[%d];" | 806 | switch (optionGetFilter ()) |
839 | 768 | "MUL sum, sum, %f;", | 807 | { |
840 | 769 | param + 1, amp[numTexop]); | 808 | case BlurOptions::Filter4xbilinear: |
841 | 770 | 809 | { | |
842 | 771 | for (j = 0; j < numIndirect; j++) | 810 | data << " blur_t0 = blur_fCoord + blur_dxdy.st;\n"\ |
843 | 772 | { | 811 | " blur_s0 = " << info.func << " (texture1, blur_t0);\n"\ |
844 | 773 | base = j * numIndirectOp; | 812 | " blur_t1 = blur_fCoord - blur_dxdy.st;\n"\ |
845 | 774 | end = MIN ((j + 1) * numIndirectOp, numTexop) - base; | 813 | " blur_s1 = " << info.func << " (texture1, blur_t1);\n"\ |
846 | 775 | 814 | " blur_t2 = blur_fCoord + vec2 (-1.0, 1.0) * blur_dxdy.st;\n"\ | |
847 | 776 | ITCbase = MAX (numITC - base, 0); | 815 | " blur_s2 = " << info.func << " (texture1, blur_t2);\n"\ |
848 | 777 | 816 | " blur_t3 = blur_fCoord + vec2 (1.0, -1.0) * blur_dxdy.st;\n"\ | |
849 | 778 | for (i = ITCbase; i < end; i++) | 817 | " blur_s3 = " << info.func << " (texture1, blur_t3);\n"\ |
850 | 779 | { | 818 | " blur_sum = blur_s0 * 0.25;\n"\ |
851 | 780 | data.addDataOp ( | 819 | " blur_sum += blur_s1 * 0.25;\n"\ |
852 | 781 | "ADD coord_%d, fCoord, {0.0, %g, 0.0, 0.0};" | 820 | " blur_sum += blur_s2 * 0.25;\n"\ |
853 | 782 | "SUB coord_%d, fCoord, {0.0, %g, 0.0, 0.0};", | 821 | " blur_sum += blur_s3 * 0.25;\n"; |
854 | 783 | i * 2, pos[base + i] * ty, | 822 | } break; |
855 | 784 | (i * 2) + 1, pos[base + i] * ty); | 823 | case BlurOptions::FilterGaussian: |
856 | 785 | } | 824 | { |
857 | 786 | 825 | /* Invert y */ | |
858 | 787 | for (i = 0; i < ITCbase; i++) | 826 | data << " blur_fCoord.y = 1.0 - blur_fCoord.y;\n"\ |
859 | 788 | { | 827 | " blur_sum = " << info.func << " (texture2, blur_fCoord);\n"\ |
860 | 789 | data.addDataOp ( | 828 | " blur_sum *= " << amp[numTexop] << ";\n"; |
861 | 790 | "TXP pix_%d, fragment.texcoord[%d], texture[%d], %s;" | 829 | |
862 | 791 | "TXP pix_%d, fragment.texcoord[%d], texture[%d], %s;", | 830 | for (j = 0; j < numIndirect; j++) |
863 | 792 | i * 2, startTC + ((i + base) * 2), | 831 | { |
864 | 793 | unit + 1, targetString, | 832 | base = j * numIndirectOp; |
865 | 794 | (i * 2) + 1, startTC + 1 + ((i + base) * 2), | 833 | end = MIN ((j + 1) * numIndirectOp, numTexop) - base; |
866 | 795 | unit + 1, targetString); | 834 | |
867 | 796 | } | 835 | ITCbase = MAX (numITC - base, 0); |
868 | 797 | 836 | ||
869 | 798 | for (i = ITCbase; i < end; i++) | 837 | for (i = ITCbase; i < end; i++) |
870 | 799 | { | 838 | { |
871 | 800 | data.addDataOp ( | 839 | data << " blur_coord_" << i * 2 << " = blur_fCoord + vec2 (0.0, " << pos[base + i] * ty << ");\n"\ |
872 | 801 | "TEX pix_%d, coord_%d, texture[%d], %s;" | 840 | " blur_coord_" << (i * 2) + 1 << " = blur_fCoord - vec2 (0.0, " << pos[base + i] * ty << ");\n"; |
873 | 802 | "TEX pix_%d, coord_%d, texture[%d], %s;", | 841 | } |
874 | 803 | i * 2, i * 2, | 842 | #if INDEPENDENT_TEX_SUPPORTED |
875 | 804 | unit + 1, targetString, | 843 | for (i = 0; i < ITCbase; i++) |
876 | 805 | (i * 2) + 1, (i * 2) + 1, | 844 | { |
877 | 806 | unit + 1, targetString); | 845 | data << " blur_pix_" + i * 2 + " vTexCoord" |
878 | 807 | } | 846 | data.addDataOp ( |
879 | 808 | 847 | "TXP pix_%d, fragment.texcoord[%d], texture[%d], %s;" | |
880 | 809 | for (i = 0; i < end * 2; i++) | 848 | "TXP pix_%d, fragment.texcoord[%d], texture[%d], %s;", |
881 | 810 | { | 849 | i * 2, startTC + ((i + base) * 2), |
882 | 811 | data.addDataOp ( | 850 | unit + 1, targetString, |
883 | 812 | "MAD sum, pix_%d, %f, sum;", | 851 | (i * 2) + 1, startTC + 1 + ((i + base) * 2), |
884 | 813 | i, amp[base + (i / 2)]); | 852 | unit + 1, targetString); |
885 | 814 | } | 853 | } |
886 | 815 | } | 854 | #endif |
887 | 816 | 855 | for (i = ITCbase; i < end; i++) | |
888 | 817 | } break; | 856 | { |
889 | 818 | case BlurOptions::FilterMipmap: | 857 | data << " blur_pix_" << i * 2 << " = " << info.func << " (texture2, blur_coord_" << i * 2 << ");\n"\ |
890 | 819 | data.addFetchOp ("output", NULL, target); | 858 | " blur_pix_" << (i * 2) + 1 << " = " << info.func << " (texture2, blur_coord_" << (i * 2) + 1 << ");\n"; |
891 | 820 | data.addColorOp ("output", "output"); | 859 | } |
892 | 821 | 860 | ||
893 | 822 | data.addDataOp ( | 861 | for (i = 0; i < end * 2; i++) |
894 | 823 | "MUL fCoord, fragment.position, program.env[%d].xyzz;" | 862 | data << " blur_sum += blur_pix_" << i << " * " << amp[base + (i / 2)] << ";\n"; |
895 | 824 | "MOV fCoord.w, program.env[%d].w;" | 863 | } |
896 | 825 | "TXB sum, fCoord, texture[%d], %s;" | 864 | |
897 | 826 | "MUL_SAT mask, output.a, program.env[%d];", | 865 | } break; |
898 | 827 | param, param, unit, targetString, | 866 | case BlurOptions::FilterMipmap: |
899 | 828 | param + 1); | 867 | data << " lod_bias = blur_translation.w;\n"\ |
900 | 829 | 868 | " blur_sum = " << info.func << " (texture1, blur_fCoord, lod_bias);\n"; | |
901 | 830 | break; | 869 | |
902 | 831 | } | 870 | break; |
903 | 832 | 871 | } | |
904 | 833 | if (saturation < 100) | 872 | |
905 | 834 | { | 873 | if (saturation < 100) |
906 | 835 | data.addDataOp ( | 874 | { |
907 | 836 | "MUL sat, sum, { 1.0, 1.0, 1.0, 0.0 };" | 875 | data << " blur_sat = blur_sum * vec4 (1.0, 1.0, 1.0, 0.0);\n"\ |
908 | 837 | "DP3 sat, sat, { %f, %f, %f, %f };" | 876 | " blur_sat = dot (blur_sat, vec4 (" << |
909 | 838 | "LRP sum.xyz, %f, sum, sat;", | 877 | RED_SATURATION_WEIGHT << ", " << GREEN_SATURATION_WEIGHT << ", " << |
910 | 839 | RED_SATURATION_WEIGHT, GREEN_SATURATION_WEIGHT, | 878 | BLUE_SATURATION_WEIGHT << ", 0.0f);\n"\ |
911 | 840 | BLUE_SATURATION_WEIGHT, 0.0f, saturation / 100.0f); | 879 | " blur_sum.xyz = mix (" << saturation / 100.f << ", blur_sat);\n"; |
912 | 841 | } | 880 | } |
913 | 842 | 881 | ||
914 | 843 | data.addDataOp ( | 882 | data << " blur_dst = (blur_mask * -blur_output.a) + blur_mask;\n"\ |
915 | 844 | "MAD dst, mask, -output.a, mask;" | 883 | " blur_output.rgb = blur_sum.rgb * blur_dst.a + blur_output.rgb;\n"\ |
916 | 845 | "MAD output.rgb, sum, dst.a, output;" | 884 | " blur_output.a += blur_dst.a;\n"\ |
917 | 846 | "ADD output.a, output.a, dst.a;"); | 885 | " gl_FragColor = blur_output;\n"\ |
918 | 847 | 886 | "}"; | |
919 | 848 | if (!data.status ()) | 887 | |
920 | 849 | { | 888 | function.shader = data.str (); |
921 | 850 | return 0; | 889 | function.target = texture->target (); |
922 | 851 | } | 890 | function.numITC = numITC; |
923 | 852 | 891 | function.startTC = startTC; | |
924 | 853 | 892 | function.saturation = saturation; | |
925 | 854 | 893 | ||
926 | 855 | function.id = data.createFragmentFunction ("blur"); | 894 | dstBlurFunctions.push_back (function); |
927 | 856 | function.target = target; | 895 | |
928 | 857 | function.param = param; | 896 | return dstBlurFunctions.back ().shader; |
929 | 858 | function.unit = unit; | 897 | } |
930 | 859 | function.numITC = numITC; | 898 | |
931 | 860 | function.startTC = startTC; | 899 | namespace |
932 | 861 | 900 | { | |
933 | 862 | dstBlurFunctions.push_back (function); | 901 | bool |
934 | 863 | 902 | project (float objx, float objy, float objz, | |
935 | 864 | return function.id; | 903 | const float modelview[16], const float projection[16], |
936 | 865 | } | 904 | const GLint viewport[4], |
937 | 866 | 905 | float *winx, float *winy, float *winz) | |
938 | 867 | return 0; | 906 | { |
939 | 907 | unsigned int i; | ||
940 | 908 | float in[4]; | ||
941 | 909 | float out[4]; | ||
942 | 910 | |||
943 | 911 | in[0] = objx; | ||
944 | 912 | in[1] = objy; | ||
945 | 913 | in[2] = objz; | ||
946 | 914 | in[3] = 1.0; | ||
947 | 915 | |||
948 | 916 | for (i = 0; i < 4; i++) { | ||
949 | 917 | out[i] = | ||
950 | 918 | in[0] * modelview[i] + | ||
951 | 919 | in[1] * modelview[4 + i] + | ||
952 | 920 | in[2] * modelview[8 + i] + | ||
953 | 921 | in[3] * modelview[12 + i]; | ||
954 | 922 | } | ||
955 | 923 | |||
956 | 924 | for (i = 0; i < 4; i++) { | ||
957 | 925 | in[i] = | ||
958 | 926 | out[0] * projection[i] + | ||
959 | 927 | out[1] * projection[4 + i] + | ||
960 | 928 | out[2] * projection[8 + i] + | ||
961 | 929 | out[3] * projection[12 + i]; | ||
962 | 930 | } | ||
963 | 931 | |||
964 | 932 | if (in[3] == 0.0) | ||
965 | 933 | return false; | ||
966 | 934 | |||
967 | 935 | in[0] /= in[3]; | ||
968 | 936 | in[1] /= in[3]; | ||
969 | 937 | in[2] /= in[3]; | ||
970 | 938 | /* Map x, y and z to range 0-1 */ | ||
971 | 939 | in[0] = in[0] * 0.5 + 0.5; | ||
972 | 940 | in[1] = in[1] * 0.5 + 0.5; | ||
973 | 941 | in[2] = in[2] * 0.5 + 0.5; | ||
974 | 942 | |||
975 | 943 | /* Map x,y to viewport */ | ||
976 | 944 | in[0] = in[0] * viewport[2] + viewport[0]; | ||
977 | 945 | in[1] = in[1] * viewport[3] + viewport[1]; | ||
978 | 946 | |||
979 | 947 | *winx = in[0]; | ||
980 | 948 | *winy = in[1]; | ||
981 | 949 | *winz = in[2]; | ||
982 | 950 | return true; | ||
983 | 951 | } | ||
984 | 868 | } | 952 | } |
985 | 869 | 953 | ||
986 | 870 | bool | 954 | bool |
987 | @@ -874,11 +958,11 @@ | |||
988 | 874 | float *scr, | 958 | float *scr, |
989 | 875 | int n) | 959 | int n) |
990 | 876 | { | 960 | { |
996 | 877 | GLdouble dProjection[16]; | 961 | GLfloat dProjection[16]; |
997 | 878 | GLdouble dModel[16]; | 962 | GLfloat dModel[16]; |
998 | 879 | GLint viewport[4]; | 963 | GLint viewport[4]; |
999 | 880 | double x, y, z; | 964 | float x, y, z; |
1000 | 881 | int i; | 965 | int i; |
1001 | 882 | 966 | ||
1002 | 883 | viewport[0] = output->x1 (); | 967 | viewport[0] = output->x1 (); |
1003 | 884 | viewport[1] = screen->height () - output->y2 (); | 968 | viewport[1] = screen->height () - output->y2 (); |
1004 | @@ -888,14 +972,14 @@ | |||
1005 | 888 | for (i = 0; i < 16; i++) | 972 | for (i = 0; i < 16; i++) |
1006 | 889 | { | 973 | { |
1007 | 890 | dModel[i] = transform.getMatrix ()[i]; | 974 | dModel[i] = transform.getMatrix ()[i]; |
1009 | 891 | dProjection[i] = gScreen->projectionMatrix ()[i]; | 975 | dProjection[i] = gScreen->projectionMatrix ()->getMatrix ()[i]; |
1010 | 892 | } | 976 | } |
1011 | 893 | 977 | ||
1012 | 894 | while (n--) | 978 | while (n--) |
1013 | 895 | { | 979 | { |
1017 | 896 | if (!gluProject (object[0], object[1], object[2], | 980 | if (!project (object[0], object[1], object[2], |
1018 | 897 | dModel, dProjection, viewport, | 981 | dModel, dProjection, viewport, |
1019 | 898 | &x, &y, &z)) | 982 | &x, &y, &z)) |
1020 | 899 | return false; | 983 | return false; |
1021 | 900 | 984 | ||
1022 | 901 | scr[0] = x; | 985 | scr[0] = x; |
1023 | @@ -909,57 +993,56 @@ | |||
1024 | 909 | } | 993 | } |
1025 | 910 | 994 | ||
1026 | 911 | bool | 995 | bool |
1029 | 912 | BlurScreen::loadFragmentProgram (GLuint *program, | 996 | BlurScreen::loadFragmentProgram (boost::shared_ptr <GLProgram> &program, |
1030 | 913 | const char *string) | 997 | const char *vertex, |
1031 | 998 | const char *fragment) | ||
1032 | 914 | { | 999 | { |
1048 | 915 | GLint errorPos; | 1000 | if (!program) |
1049 | 916 | 1001 | program.reset (new GLProgram (CompString (vertex), | |
1050 | 917 | /* clear errors */ | 1002 | CompString (fragment))); |
1051 | 918 | glGetError (); | 1003 | |
1052 | 919 | 1004 | if (program && program->valid ()) | |
1053 | 920 | if (!*program) | 1005 | return true; |
1054 | 921 | (*GL::genPrograms) (1, program); | 1006 | else |
1040 | 922 | |||
1041 | 923 | (*GL::bindProgram) (GL_FRAGMENT_PROGRAM_ARB, *program); | ||
1042 | 924 | (*GL::programString) (GL_FRAGMENT_PROGRAM_ARB, | ||
1043 | 925 | GL_PROGRAM_FORMAT_ASCII_ARB, | ||
1044 | 926 | strlen (string), string); | ||
1045 | 927 | |||
1046 | 928 | glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); | ||
1047 | 929 | if (glGetError () != GL_NO_ERROR || errorPos != -1) | ||
1055 | 930 | { | 1007 | { |
1056 | 1008 | program.reset (); | ||
1057 | 931 | compLogMessage ("blur", CompLogLevelError, | 1009 | compLogMessage ("blur", CompLogLevelError, |
1063 | 932 | "Failed to load blur program %s", string); | 1010 | "Failed to load blur program %s", fragment); |
1059 | 933 | |||
1060 | 934 | (*GL::deletePrograms) (1, program); | ||
1061 | 935 | *program = 0; | ||
1062 | 936 | |||
1064 | 937 | return false; | 1011 | return false; |
1065 | 938 | } | 1012 | } |
1066 | 939 | |||
1067 | 940 | return true; | ||
1068 | 941 | } | 1013 | } |
1069 | 942 | 1014 | ||
1070 | 943 | bool | 1015 | bool |
1071 | 944 | BlurScreen::loadFilterProgram (int numITC) | 1016 | BlurScreen::loadFilterProgram (int numITC) |
1072 | 945 | { | 1017 | { |
1076 | 946 | char buffer[4096]; | 1018 | std::stringstream svtx; |
1077 | 947 | char *targetString; | 1019 | |
1078 | 948 | char *str = buffer; | 1020 | /* A simple pass-thru vertex shader */ |
1079 | 1021 | svtx << "#ifdef GL_ES\n"\ | ||
1080 | 1022 | "precision mediump float;\n"\ | ||
1081 | 1023 | "#endif\n"\ | ||
1082 | 1024 | "uniform mat4 modelview;\n"\ | ||
1083 | 1025 | "uniform mat4 projection;\n"\ | ||
1084 | 1026 | "attribute vec4 position;\n"\ | ||
1085 | 1027 | "attribute vec2 texCoord0;\n"\ | ||
1086 | 1028 | "varying vec2 vTexCoord0;\n"\ | ||
1087 | 1029 | "\n"\ | ||
1088 | 1030 | "void main ()\n"\ | ||
1089 | 1031 | "{\n"\ | ||
1090 | 1032 | " vTexCoord0 = texCoord0;\n"\ | ||
1091 | 1033 | " gl_Position = projection * modelview * position;\n"\ | ||
1092 | 1034 | "}"; | ||
1093 | 1035 | |||
1094 | 1036 | std::stringstream str; | ||
1095 | 949 | int i, j; | 1037 | int i, j; |
1096 | 950 | int numIndirect; | 1038 | int numIndirect; |
1097 | 951 | int numIndirectOp; | 1039 | int numIndirectOp; |
1098 | 952 | int base, end, ITCbase; | 1040 | int base, end, ITCbase; |
1099 | 953 | 1041 | ||
1104 | 954 | if (target == GL_TEXTURE_2D) | 1042 | SamplerInfo info (getSamplerInfoForSize (*screen)); |
1101 | 955 | targetString = (char *) "2D"; | ||
1102 | 956 | else | ||
1103 | 957 | targetString = (char *) "RECT"; | ||
1105 | 958 | 1043 | ||
1110 | 959 | str += sprintf (str, | 1044 | str << "varying vec2 vTexCoord0;\n"\ |
1111 | 960 | "!!ARBfp1.0" | 1045 | "uniform sampler2D texture0;\n"; |
1108 | 961 | "ATTRIB texcoord = fragment.texcoord[0];" | ||
1109 | 962 | "TEMP sum;"); | ||
1112 | 963 | 1046 | ||
1113 | 964 | if (maxTemp - 1 > (numTexop + (numTexop - numITC)) * 2) | 1047 | if (maxTemp - 1 > (numTexop + (numTexop - numITC)) * 2) |
1114 | 965 | { | 1048 | { |
1115 | @@ -977,19 +1060,19 @@ | |||
1116 | 977 | multiple indirection steps */ | 1060 | multiple indirection steps */ |
1117 | 978 | j = (numIndirect > 1) ? 0 : numITC; | 1061 | j = (numIndirect > 1) ? 0 : numITC; |
1118 | 979 | 1062 | ||
1119 | 1063 | str << "\n"\ | ||
1120 | 1064 | "void main ()\n"\ | ||
1121 | 1065 | "{\n"; | ||
1122 | 1066 | |||
1123 | 980 | for (i = 0; i < numIndirectOp; i++) | 1067 | for (i = 0; i < numIndirectOp; i++) |
1125 | 981 | str += sprintf (str,"TEMP pix_%d, pix_%d;", i * 2, (i * 2) + 1); | 1068 | str << " vec4 blur_pix_" << i * 2 << ", blur_pix_" << (i * 2) + 1 << ";\n"; |
1126 | 982 | 1069 | ||
1127 | 983 | for (i = j; i < numIndirectOp; i++) | 1070 | for (i = j; i < numIndirectOp; i++) |
1137 | 984 | str += sprintf (str,"TEMP coord_%d, coord_%d;", i * 2, (i * 2) + 1); | 1071 | str << " vec2 blur_coord_" << i * 2 << ", blur_coord_" << (i * 2) + 1 << ";\n"; |
1138 | 985 | 1072 | ||
1139 | 986 | str += sprintf (str, | 1073 | str << " vec4 blur_sum;\n"; |
1140 | 987 | "TEX sum, texcoord, texture[0], %s;", | 1074 | str << " blur_sum = " << info.func << " (texture0, vTexCoord0);\n"\ |
1141 | 988 | targetString); | 1075 | " blur_sum = blur_sum * " << amp[numTexop] << ";\n"; |
1133 | 989 | |||
1134 | 990 | str += sprintf (str, | ||
1135 | 991 | "MUL sum, sum, %f;", | ||
1136 | 992 | amp[numTexop]); | ||
1142 | 993 | 1076 | ||
1143 | 994 | for (j = 0; j < numIndirect; j++) | 1077 | for (j = 0; j < numIndirect; j++) |
1144 | 995 | { | 1078 | { |
1145 | @@ -999,37 +1082,30 @@ | |||
1146 | 999 | ITCbase = MAX (numITC - base, 0); | 1082 | ITCbase = MAX (numITC - base, 0); |
1147 | 1000 | 1083 | ||
1148 | 1001 | for (i = ITCbase; i < end; i++) | 1084 | for (i = ITCbase; i < end; i++) |
1155 | 1002 | str += sprintf (str, | 1085 | str << " blur_coord_" << i * 2 << " = vTexCoord0 + vec2 (" << pos[base + i] * tx << ", 0.0);\n"\ |
1156 | 1003 | "ADD coord_%d, texcoord, {%g, 0.0, 0.0, 0.0};" | 1086 | " blur_coord_" << (i * 2) + 1 << " = vTexCoord0 - vec2 (" << pos[base + i] * tx << ", 0.0);\n"; |
1157 | 1004 | "SUB coord_%d, texcoord, {%g, 0.0, 0.0, 0.0};", | 1087 | #if INDEPENDENT_TEX_SUPPORTED |
1152 | 1005 | i * 2, pos[base + i] * tx, | ||
1153 | 1006 | (i * 2) + 1, pos[base + i] * tx); | ||
1154 | 1007 | |||
1158 | 1008 | for (i = 0; i < ITCbase; i++) | 1088 | for (i = 0; i < ITCbase; i++) |
1160 | 1009 | str += sprintf (str, | 1089 | str << sprintf (str, |
1161 | 1010 | "TEX pix_%d, fragment.texcoord[%d], texture[0], %s;" | 1090 | "TEX pix_%d, fragment.texcoord[%d], texture[0], %s;" |
1162 | 1011 | "TEX pix_%d, fragment.texcoord[%d], texture[0], %s;", | 1091 | "TEX pix_%d, fragment.texcoord[%d], texture[0], %s;", |
1163 | 1012 | i * 2, ((i + base) * 2) + 1, targetString, | 1092 | i * 2, ((i + base) * 2) + 1, targetString, |
1164 | 1013 | (i * 2) + 1, ((i + base) * 2) + 2, targetString); | 1093 | (i * 2) + 1, ((i + base) * 2) + 2, targetString); |
1166 | 1014 | 1094 | #endif | |
1167 | 1015 | for (i = ITCbase; i < end; i++) | 1095 | for (i = ITCbase; i < end; i++) |
1173 | 1016 | str += sprintf (str, | 1096 | str << " blur_pix_" << (i * 2) << " = " << info.func << " (texture0, blur_coord_" << i * 2 << ");\n"\ |
1174 | 1017 | "TEX pix_%d, coord_%d, texture[0], %s;" | 1097 | " blur_pix_" << (i * 2) + 1 << " = " << info.func << " (texture0, blur_coord_" << (i * 2) + 1 << ");\n"; |
1170 | 1018 | "TEX pix_%d, coord_%d, texture[0], %s;", | ||
1171 | 1019 | i * 2, i * 2, targetString, | ||
1172 | 1020 | (i * 2) + 1, (i * 2) + 1, targetString); | ||
1175 | 1021 | 1098 | ||
1176 | 1022 | for (i = 0; i < end * 2; i++) | 1099 | for (i = 0; i < end * 2; i++) |
1180 | 1023 | str += sprintf (str, | 1100 | str << " blur_sum += blur_pix_" << i << " * " << amp[base + (i / 2)] << ";\n"; |
1178 | 1024 | "MAD sum, pix_%d, %f, sum;", | ||
1179 | 1025 | i, amp[base + (i / 2)]); | ||
1181 | 1026 | } | 1101 | } |
1182 | 1027 | 1102 | ||
1186 | 1028 | str += sprintf (str, | 1103 | str << " gl_FragColor = blur_sum;\n"\ |
1187 | 1029 | "MOV result.color, sum;" | 1104 | "}"; |
1185 | 1030 | "END"); | ||
1188 | 1031 | 1105 | ||
1190 | 1032 | return loadFragmentProgram (&program, buffer); | 1106 | return loadFragmentProgram (program, |
1191 | 1107 | svtx.str ().c_str (), | ||
1192 | 1108 | str.str ().c_str ()); | ||
1193 | 1033 | } | 1109 | } |
1194 | 1034 | 1110 | ||
1195 | 1035 | bool | 1111 | bool |
1196 | @@ -1038,51 +1114,7 @@ | |||
1197 | 1038 | if (!fbo) | 1114 | if (!fbo) |
1198 | 1039 | return false; | 1115 | return false; |
1199 | 1040 | 1116 | ||
1245 | 1041 | (*GL::bindFramebuffer) (GL_FRAMEBUFFER_EXT, fbo); | 1117 | oldDrawFramebuffer = fbo->bind (); |
1201 | 1042 | |||
1202 | 1043 | /* bind texture and check status the first time */ | ||
1203 | 1044 | if (!fboStatus) | ||
1204 | 1045 | { | ||
1205 | 1046 | (*GL::framebufferTexture2D) (GL_FRAMEBUFFER_EXT, | ||
1206 | 1047 | GL_COLOR_ATTACHMENT0_EXT, | ||
1207 | 1048 | target, texture[1], | ||
1208 | 1049 | 0); | ||
1209 | 1050 | |||
1210 | 1051 | int currStatus = (*GL::checkFramebufferStatus) (GL_FRAMEBUFFER_EXT); | ||
1211 | 1052 | if (currStatus != GL_FRAMEBUFFER_COMPLETE_EXT) | ||
1212 | 1053 | { | ||
1213 | 1054 | compLogMessage ("blur", CompLogLevelError, | ||
1214 | 1055 | "Framebuffer incomplete"); | ||
1215 | 1056 | |||
1216 | 1057 | (*GL::bindFramebuffer) (GL_FRAMEBUFFER_EXT, 0); | ||
1217 | 1058 | (*GL::deleteFramebuffers) (1, &fbo); | ||
1218 | 1059 | |||
1219 | 1060 | fbo = 0; | ||
1220 | 1061 | |||
1221 | 1062 | return false; | ||
1222 | 1063 | } | ||
1223 | 1064 | else | ||
1224 | 1065 | fboStatus = true; | ||
1225 | 1066 | } | ||
1226 | 1067 | |||
1227 | 1068 | glPushAttrib (GL_VIEWPORT_BIT | GL_ENABLE_BIT); | ||
1228 | 1069 | |||
1229 | 1070 | glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT); | ||
1230 | 1071 | glReadBuffer (GL_COLOR_ATTACHMENT0_EXT); | ||
1231 | 1072 | |||
1232 | 1073 | glDisable (GL_CLIP_PLANE0); | ||
1233 | 1074 | glDisable (GL_CLIP_PLANE1); | ||
1234 | 1075 | glDisable (GL_CLIP_PLANE2); | ||
1235 | 1076 | glDisable (GL_CLIP_PLANE3); | ||
1236 | 1077 | |||
1237 | 1078 | glViewport (0, 0, width, height); | ||
1238 | 1079 | glMatrixMode (GL_PROJECTION); | ||
1239 | 1080 | glPushMatrix (); | ||
1240 | 1081 | glLoadIdentity (); | ||
1241 | 1082 | glOrtho (0.0, width, 0.0, height, -1.0, 1.0); | ||
1242 | 1083 | glMatrixMode (GL_MODELVIEW); | ||
1243 | 1084 | glPushMatrix (); | ||
1244 | 1085 | glLoadIdentity (); | ||
1246 | 1086 | 1118 | ||
1247 | 1087 | return true; | 1119 | return true; |
1248 | 1088 | } | 1120 | } |
1249 | @@ -1090,37 +1122,22 @@ | |||
1250 | 1090 | void | 1122 | void |
1251 | 1091 | BlurScreen::fboEpilogue () | 1123 | BlurScreen::fboEpilogue () |
1252 | 1092 | { | 1124 | { |
1274 | 1093 | (*GL::bindFramebuffer) (GL_FRAMEBUFFER_EXT, 0); | 1125 | oldDrawFramebuffer->bind (); |
1275 | 1094 | 1126 | ||
1276 | 1095 | glMatrixMode (GL_PROJECTION); | 1127 | fbo->tex ()->enable (GLTexture::Good); |
1277 | 1096 | glLoadIdentity (); | 1128 | //GL::generateMipmap (fbo->tex ()->target ()); |
1278 | 1097 | glMatrixMode (GL_MODELVIEW); | 1129 | |
1279 | 1098 | glLoadIdentity (); | 1130 | fbo->tex ()->disable (); |
1259 | 1099 | glDepthRange (0, 1); | ||
1260 | 1100 | glViewport (-1, -1, 2, 2); | ||
1261 | 1101 | glRasterPos2f (0, 0); | ||
1262 | 1102 | |||
1263 | 1103 | gScreen->resetRasterPos (); | ||
1264 | 1104 | |||
1265 | 1105 | glMatrixMode (GL_PROJECTION); | ||
1266 | 1106 | glPopMatrix (); | ||
1267 | 1107 | glMatrixMode (GL_MODELVIEW); | ||
1268 | 1108 | glPopMatrix (); | ||
1269 | 1109 | |||
1270 | 1110 | glDrawBuffer (GL_BACK); | ||
1271 | 1111 | glReadBuffer (GL_BACK); | ||
1272 | 1112 | |||
1273 | 1113 | glPopAttrib (); | ||
1280 | 1114 | } | 1131 | } |
1281 | 1115 | 1132 | ||
1282 | 1116 | bool | 1133 | bool |
1283 | 1117 | BlurScreen::fboUpdate (BoxPtr pBox, | 1134 | BlurScreen::fboUpdate (BoxPtr pBox, |
1284 | 1118 | int nBox) | 1135 | int nBox) |
1285 | 1119 | { | 1136 | { |
1287 | 1120 | int i, y, iTC = 0; | 1137 | float iTC = 0; |
1288 | 1121 | bool wasCulled = glIsEnabled (GL_CULL_FACE); | 1138 | bool wasCulled = glIsEnabled (GL_CULL_FACE); |
1289 | 1122 | 1139 | ||
1291 | 1123 | if (GL::maxTextureUnits && optionGetIndependentTex ()) | 1140 | if (GL::maxTextureUnits && optionGetIndependentTex () && false) |
1292 | 1124 | iTC = MIN ((GL::maxTextureUnits - 1) / 2, numTexop); | 1141 | iTC = MIN ((GL::maxTextureUnits - 1) / 2, numTexop); |
1293 | 1125 | 1142 | ||
1294 | 1126 | if (!program) | 1143 | if (!program) |
1295 | @@ -1131,83 +1148,51 @@ | |||
1296 | 1131 | return false; | 1148 | return false; |
1297 | 1132 | 1149 | ||
1298 | 1133 | glDisable (GL_CULL_FACE); | 1150 | glDisable (GL_CULL_FACE); |
1308 | 1134 | 1151 | GL::activeTexture (GL_TEXTURE0); | |
1309 | 1135 | glDisableClientState (GL_TEXTURE_COORD_ARRAY); | 1152 | texture[0]->enable (GLTexture::Good); |
1310 | 1136 | 1153 | ||
1311 | 1137 | glBindTexture (target, texture[0]); | 1154 | GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer (); |
1303 | 1138 | |||
1304 | 1139 | glEnable (GL_FRAGMENT_PROGRAM_ARB); | ||
1305 | 1140 | (*GL::bindProgram) (GL_FRAGMENT_PROGRAM_ARB, program); | ||
1306 | 1141 | |||
1307 | 1142 | glBegin (GL_QUADS); | ||
1312 | 1143 | 1155 | ||
1313 | 1144 | while (nBox--) | 1156 | while (nBox--) |
1314 | 1145 | { | 1157 | { |
1370 | 1146 | y = screen->height () - pBox->y2; | 1158 | float x1 = pBox->x1; |
1371 | 1147 | 1159 | float x2 = pBox->x2; | |
1372 | 1148 | for (i = 0; i < iTC; i++) | 1160 | float y1 = screen->height () - pBox->y2; |
1373 | 1149 | { | 1161 | float y2 = screen->height () - pBox->y1; |
1374 | 1150 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2), | 1162 | |
1375 | 1151 | tx * (pBox->x1 + pos[i]), | 1163 | GLfloat texCoords[] = |
1376 | 1152 | ty * y); | 1164 | { |
1377 | 1153 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2) + 1, | 1165 | tx * x1, ty * y1, |
1378 | 1154 | tx * (pBox->x1 - pos[i]), | 1166 | tx * x1, ty * y2, |
1379 | 1155 | ty * y); | 1167 | tx * x2, ty * y1, |
1380 | 1156 | } | 1168 | tx * x2, ty * y2 |
1381 | 1157 | 1169 | }; | |
1382 | 1158 | glTexCoord2f (tx * pBox->x1, ty * y); | 1170 | |
1383 | 1159 | glVertex2i (pBox->x1, y); | 1171 | GLfloat vertices[] = |
1384 | 1160 | 1172 | { | |
1385 | 1161 | for (i = 0; i < iTC; i++) | 1173 | x1, y1, 0, |
1386 | 1162 | { | 1174 | x1, y2, 0, |
1387 | 1163 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2), | 1175 | x2, y1, 0, |
1388 | 1164 | tx * (pBox->x2 + pos[i]), | 1176 | x2, y2, 0 |
1389 | 1165 | ty * y); | 1177 | }; |
1390 | 1166 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2) + 1, | 1178 | |
1391 | 1167 | tx * (pBox->x2 - pos[i]), | 1179 | GLMatrix mv; |
1392 | 1168 | ty * y); | 1180 | mv.toScreenSpace (output, -DEFAULT_Z_CAMERA); |
1393 | 1169 | } | 1181 | |
1394 | 1170 | 1182 | streamingBuffer->begin (GL_TRIANGLE_STRIP); | |
1395 | 1171 | glTexCoord2f (tx * pBox->x2, ty * y); | 1183 | streamingBuffer->setProgram (program.get ()); |
1396 | 1172 | glVertex2i (pBox->x2, y); | 1184 | streamingBuffer->addTexCoords (0, 4, texCoords); |
1397 | 1173 | 1185 | streamingBuffer->addVertices (4, vertices); | |
1398 | 1174 | y = screen->height () - pBox->y1; | 1186 | |
1399 | 1175 | 1187 | if (streamingBuffer->end ()) | |
1400 | 1176 | for (i = 0; i < iTC; i++) | 1188 | streamingBuffer->render (mv); |
1401 | 1177 | { | 1189 | |
1402 | 1178 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2), | 1190 | /* Unset program */ |
1403 | 1179 | tx * (pBox->x2 + pos[i]), | 1191 | streamingBuffer->setProgram (NULL); |
1349 | 1180 | ty * y); | ||
1350 | 1181 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2) + 1, | ||
1351 | 1182 | tx * (pBox->x2 - pos[i]), | ||
1352 | 1183 | ty * y); | ||
1353 | 1184 | } | ||
1354 | 1185 | |||
1355 | 1186 | glTexCoord2f (tx * pBox->x2, ty * y); | ||
1356 | 1187 | glVertex2i (pBox->x2, y); | ||
1357 | 1188 | |||
1358 | 1189 | for (i = 0; i < iTC; i++) | ||
1359 | 1190 | { | ||
1360 | 1191 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2), | ||
1361 | 1192 | tx * (pBox->x1 + pos[i]), | ||
1362 | 1193 | ty * y); | ||
1363 | 1194 | (*GL::multiTexCoord2f) (GL_TEXTURE1_ARB + (i * 2) + 1, | ||
1364 | 1195 | tx * (pBox->x1 - pos[i]), | ||
1365 | 1196 | ty * y); | ||
1366 | 1197 | } | ||
1367 | 1198 | |||
1368 | 1199 | glTexCoord2f (tx * pBox->x1, ty * y); | ||
1369 | 1200 | glVertex2i (pBox->x1, y); | ||
1404 | 1201 | 1192 | ||
1405 | 1202 | pBox++; | 1193 | pBox++; |
1406 | 1203 | } | 1194 | } |
1407 | 1204 | 1195 | ||
1408 | 1205 | glEnd (); | ||
1409 | 1206 | |||
1410 | 1207 | glDisable (GL_FRAGMENT_PROGRAM_ARB); | ||
1411 | 1208 | |||
1412 | 1209 | glEnableClientState (GL_TEXTURE_COORD_ARRAY); | ||
1413 | 1210 | |||
1414 | 1211 | if (wasCulled) | 1196 | if (wasCulled) |
1415 | 1212 | glEnable (GL_CULL_FACE); | 1197 | glEnable (GL_CULL_FACE); |
1416 | 1213 | 1198 | ||
1417 | @@ -1231,92 +1216,70 @@ | |||
1418 | 1231 | float *scr; | 1216 | float *scr; |
1419 | 1232 | 1217 | ||
1420 | 1233 | GLTexture::MatrixList ml; | 1218 | GLTexture::MatrixList ml; |
1421 | 1234 | GLWindow::Geometry *gm; | ||
1422 | 1235 | 1219 | ||
1424 | 1236 | gWindow->geometry ().reset (); | 1220 | gWindow->vertexBuffer ()->begin (); |
1425 | 1237 | gWindow->glAddGeometry (ml, bScreen->tmpRegion2, infiniteRegion); | 1221 | gWindow->glAddGeometry (ml, bScreen->tmpRegion2, infiniteRegion); |
1426 | 1238 | 1222 | ||
1428 | 1239 | if (!gWindow->geometry ().vCount) | 1223 | if (!gWindow->vertexBuffer ()->end ()) |
1429 | 1240 | return; | 1224 | return; |
1430 | 1241 | 1225 | ||
1432 | 1242 | gm = &gWindow->geometry (); | 1226 | GLVertexBuffer *vb = gWindow->vertexBuffer (); |
1433 | 1243 | 1227 | ||
1435 | 1244 | nVertices = (gm->indexCount) ? gm->indexCount: gm->vCount; | 1228 | nVertices = vb->countVertices (); |
1436 | 1245 | nQuadCombine = 1; | 1229 | nQuadCombine = 1; |
1437 | 1246 | 1230 | ||
1443 | 1247 | stride = gm->vertexStride; | 1231 | stride = vb->getVertexStride (); |
1444 | 1248 | vert = gm->vertices + (stride - 3); | 1232 | vert = vb->getVertices () + (stride - 3); |
1445 | 1249 | 1233 | ||
1446 | 1250 | /* we need to find the best value here */ | 1234 | /* construct quads from bounding vertices */ |
1447 | 1251 | if (nVertices <= MAX_VERTEX_PROJECT_COUNT) | 1235 | minX = screen->width (); |
1448 | 1236 | maxX = 0; | ||
1449 | 1237 | minY = screen->height (); | ||
1450 | 1238 | maxY = 0; | ||
1451 | 1239 | minZ = 1000000; | ||
1452 | 1240 | maxZ = -1000000; | ||
1453 | 1241 | |||
1454 | 1242 | for (i = 0; i < vb->countVertices (); i++) | ||
1455 | 1252 | { | 1243 | { |
1471 | 1253 | for (i = 0; i < nVertices; i++) | 1244 | v = vert + (stride * i); |
1472 | 1254 | { | 1245 | |
1473 | 1255 | if (gm->indexCount) | 1246 | if (v[0] < minX) |
1474 | 1256 | { | 1247 | minX = v[0]; |
1475 | 1257 | v = vert + (stride * gm->indices[i]); | 1248 | |
1476 | 1258 | } | 1249 | if (v[0] > maxX) |
1477 | 1259 | else | 1250 | maxX = v[0]; |
1478 | 1260 | { | 1251 | |
1479 | 1261 | v = vert + (stride * i); | 1252 | if (v[1] < minY) |
1480 | 1262 | } | 1253 | minY = v[1]; |
1481 | 1263 | 1254 | ||
1482 | 1264 | vertices[i * 3] = v[0]; | 1255 | if (v[1] > maxY) |
1483 | 1265 | vertices[(i * 3) + 1] = v[1]; | 1256 | maxY = v[1]; |
1484 | 1266 | vertices[(i * 3) + 2] = v[2]; | 1257 | |
1485 | 1267 | } | 1258 | if (v[2] < minZ) |
1486 | 1259 | minZ = v[2]; | ||
1487 | 1260 | |||
1488 | 1261 | if (v[2] > maxZ) | ||
1489 | 1262 | maxZ = v[2]; | ||
1490 | 1268 | } | 1263 | } |
1492 | 1269 | else | 1264 | |
1493 | 1265 | vertices[0] = vertices[9] = minX; | ||
1494 | 1266 | vertices[1] = vertices[4] = minY; | ||
1495 | 1267 | vertices[3] = vertices[6] = maxX; | ||
1496 | 1268 | vertices[7] = vertices[10] = maxY; | ||
1497 | 1269 | vertices[2] = vertices[5] = maxZ; | ||
1498 | 1270 | vertices[8] = vertices[11] = maxZ; | ||
1499 | 1271 | |||
1500 | 1272 | nVertices = 4; | ||
1501 | 1273 | |||
1502 | 1274 | if (maxZ != minZ) | ||
1503 | 1270 | { | 1275 | { |
1553 | 1271 | minX = screen->width (); | 1276 | vertices[12] = vertices[21] = minX; |
1554 | 1272 | maxX = 0; | 1277 | vertices[13] = vertices[16] = minY; |
1555 | 1273 | minY = screen->height (); | 1278 | vertices[15] = vertices[18] = maxX; |
1556 | 1274 | maxY = 0; | 1279 | vertices[19] = vertices[22] = maxY; |
1557 | 1275 | minZ = 1000000; | 1280 | vertices[14] = vertices[17] = minZ; |
1558 | 1276 | maxZ = -1000000; | 1281 | vertices[20] = vertices[23] = minZ; |
1559 | 1277 | 1282 | nQuadCombine = 2; | |
1511 | 1278 | for (i = 0; i < gm->vCount; i++) | ||
1512 | 1279 | { | ||
1513 | 1280 | v = vert + (stride * i); | ||
1514 | 1281 | |||
1515 | 1282 | if (v[0] < minX) | ||
1516 | 1283 | minX = v[0]; | ||
1517 | 1284 | |||
1518 | 1285 | if (v[0] > maxX) | ||
1519 | 1286 | maxX = v[0]; | ||
1520 | 1287 | |||
1521 | 1288 | if (v[1] < minY) | ||
1522 | 1289 | minY = v[1]; | ||
1523 | 1290 | |||
1524 | 1291 | if (v[1] > maxY) | ||
1525 | 1292 | maxY = v[1]; | ||
1526 | 1293 | |||
1527 | 1294 | if (v[2] < minZ) | ||
1528 | 1295 | minZ = v[2]; | ||
1529 | 1296 | |||
1530 | 1297 | if (v[2] > maxZ) | ||
1531 | 1298 | maxZ = v[2]; | ||
1532 | 1299 | } | ||
1533 | 1300 | |||
1534 | 1301 | vertices[0] = vertices[9] = minX; | ||
1535 | 1302 | vertices[1] = vertices[4] = minY; | ||
1536 | 1303 | vertices[3] = vertices[6] = maxX; | ||
1537 | 1304 | vertices[7] = vertices[10] = maxY; | ||
1538 | 1305 | vertices[2] = vertices[5] = maxZ; | ||
1539 | 1306 | vertices[8] = vertices[11] = maxZ; | ||
1540 | 1307 | |||
1541 | 1308 | nVertices = 4; | ||
1542 | 1309 | |||
1543 | 1310 | if (maxZ != minZ) | ||
1544 | 1311 | { | ||
1545 | 1312 | vertices[12] = vertices[21] = minX; | ||
1546 | 1313 | vertices[13] = vertices[16] = minY; | ||
1547 | 1314 | vertices[15] = vertices[18] = maxX; | ||
1548 | 1315 | vertices[19] = vertices[22] = maxY; | ||
1549 | 1316 | vertices[14] = vertices[17] = minZ; | ||
1550 | 1317 | vertices[20] = vertices[23] = minZ; | ||
1551 | 1318 | nQuadCombine = 2; | ||
1552 | 1319 | } | ||
1560 | 1320 | } | 1283 | } |
1561 | 1321 | 1284 | ||
1562 | 1322 | if (!bScreen->projectVertices (output, transform, vertices, scrv, | 1285 | if (!bScreen->projectVertices (output, transform, vertices, scrv, |
1563 | @@ -1349,10 +1312,10 @@ | |||
1564 | 1349 | 1312 | ||
1565 | 1350 | int x1, y1, x2, y2; | 1313 | int x1, y1, x2, y2; |
1566 | 1351 | 1314 | ||
1571 | 1352 | x1 = minX - bScreen->filterRadius; | 1315 | x1 = minX - bScreen->filterRadius - 0.5; |
1572 | 1353 | y1 = screen->height () - maxY - bScreen->filterRadius; | 1316 | y1 = screen->height () - maxY - bScreen->filterRadius - 0.5; |
1573 | 1354 | x2 = maxX + bScreen->filterRadius + 0.5f; | 1317 | x2 = maxX + bScreen->filterRadius + 0.5; |
1574 | 1355 | y2 = screen->height () - minY + bScreen->filterRadius + 0.5f; | 1318 | y2 = screen->height () - minY + bScreen->filterRadius + 0.5; |
1575 | 1356 | 1319 | ||
1576 | 1357 | 1320 | ||
1577 | 1358 | bScreen->tmpRegion3 += CompRect (x1, y1, x2 - x1, y2 - y1); | 1321 | bScreen->tmpRegion3 += CompRect (x1, y1, x2 - x1, y2 - y1); |
1578 | @@ -1360,21 +1323,15 @@ | |||
1579 | 1360 | } | 1323 | } |
1580 | 1361 | } | 1324 | } |
1581 | 1362 | 1325 | ||
1586 | 1363 | bool | 1326 | void |
1587 | 1364 | BlurWindow::updateDstTexture (const GLMatrix &transform, | 1327 | BlurWindow::determineBlurRegion (int filter, |
1588 | 1365 | CompRect *pExtents, | 1328 | const GLMatrix &transform, |
1589 | 1366 | int clientThreshold) | 1329 | int clientThreshold) |
1590 | 1367 | { | 1330 | { |
1591 | 1368 | int y; | ||
1592 | 1369 | int filter; | ||
1593 | 1370 | |||
1594 | 1371 | filter = bScreen->optionGetFilter (); | ||
1595 | 1372 | |||
1596 | 1373 | bScreen->tmpRegion3 = CompRegion (); | 1331 | bScreen->tmpRegion3 = CompRegion (); |
1597 | 1374 | 1332 | ||
1598 | 1375 | if (filter == BlurOptions::FilterGaussian) | 1333 | if (filter == BlurOptions::FilterGaussian) |
1599 | 1376 | { | 1334 | { |
1600 | 1377 | |||
1601 | 1378 | if (state[BLUR_STATE_DECOR].threshold) | 1335 | if (state[BLUR_STATE_DECOR].threshold) |
1602 | 1379 | { | 1336 | { |
1603 | 1380 | int xx, yy, ww, hh; | 1337 | int xx, yy, ww, hh; |
1604 | @@ -1394,7 +1351,7 @@ | |||
1605 | 1394 | // bottom | 1351 | // bottom |
1606 | 1395 | xx = window->x () - window->output ().left; | 1352 | xx = window->x () - window->output ().left; |
1607 | 1396 | yy = window->y () + window->height (); | 1353 | yy = window->y () + window->height (); |
1609 | 1397 | ww = window->width () + window->output ().left + | 1354 | ww = window->width () + window->output ().left + |
1610 | 1398 | window->output ().right; | 1355 | window->output ().right; |
1611 | 1399 | hh = window->output ().bottom; | 1356 | hh = window->output ().bottom; |
1612 | 1400 | 1357 | ||
1613 | @@ -1410,7 +1367,7 @@ | |||
1614 | 1410 | ww = window->output ().left; | 1367 | ww = window->output ().left; |
1615 | 1411 | hh = window->height (); | 1368 | hh = window->height (); |
1616 | 1412 | 1369 | ||
1618 | 1413 | bScreen->tmpRegion2 = bScreen->tmpRegion.intersected ( | 1370 | bScreen->tmpRegion2 = bScreen->tmpRegion.intersected ( |
1619 | 1414 | CompRect (xx, yy, ww, hh)); | 1371 | CompRect (xx, yy, ww, hh)); |
1620 | 1415 | 1372 | ||
1621 | 1416 | if (!bScreen->tmpRegion2.isEmpty ()) | 1373 | if (!bScreen->tmpRegion2.isEmpty ()) |
1622 | @@ -1422,7 +1379,7 @@ | |||
1623 | 1422 | ww = window->output ().right; | 1379 | ww = window->output ().right; |
1624 | 1423 | hh = window->height (); | 1380 | hh = window->height (); |
1625 | 1424 | 1381 | ||
1627 | 1425 | bScreen->tmpRegion2 = bScreen->tmpRegion.intersected ( | 1382 | bScreen->tmpRegion2 = bScreen->tmpRegion.intersected ( |
1628 | 1426 | CompRect (xx, yy, ww, hh)); | 1383 | CompRect (xx, yy, ww, hh)); |
1629 | 1427 | 1384 | ||
1630 | 1428 | if (!bScreen->tmpRegion2.isEmpty ()) | 1385 | if (!bScreen->tmpRegion2.isEmpty ()) |
1631 | @@ -1451,141 +1408,147 @@ | |||
1632 | 1451 | projectRegion (bScreen->output, transform); | 1408 | projectRegion (bScreen->output, transform); |
1633 | 1452 | } | 1409 | } |
1634 | 1453 | 1410 | ||
1636 | 1454 | bScreen->tmpRegion = bScreen->region.intersected (bScreen->tmpRegion3); | 1411 | projectedBlurRegion = bScreen->tmpRegion3; |
1637 | 1412 | } | ||
1638 | 1413 | |||
1639 | 1414 | bool | ||
1640 | 1415 | BlurWindow::updateDstTexture (const GLMatrix &transform, | ||
1641 | 1416 | CompRect *pExtents, | ||
1642 | 1417 | unsigned int mask) | ||
1643 | 1418 | { | ||
1644 | 1419 | bool ret = false; | ||
1645 | 1420 | int filter = bScreen->optionGetFilter (); | ||
1646 | 1421 | |||
1647 | 1422 | /* Paint region n projected region */ | ||
1648 | 1423 | bScreen->tmpRegion = bScreen->region.intersected (projectedBlurRegion); | ||
1649 | 1424 | |||
1650 | 1425 | if (!bScreen->blurOcclusion && | ||
1651 | 1426 | !(mask & PAINT_WINDOW_TRANSFORMED_MASK)) | ||
1652 | 1427 | bScreen->tmpRegion -= clip; | ||
1653 | 1455 | 1428 | ||
1654 | 1456 | if (bScreen->tmpRegion.isEmpty ()) | 1429 | if (bScreen->tmpRegion.isEmpty ()) |
1655 | 1457 | return false; | 1430 | return false; |
1656 | 1458 | 1431 | ||
1658 | 1459 | *pExtents = bScreen->tmpRegion.boundingRect (); | 1432 | CompRect br (bScreen->tmpRegion.boundingRect ()); |
1659 | 1460 | 1433 | ||
1662 | 1461 | if (!bScreen->texture[0] || bScreen->width != screen->width () || | 1434 | if (bScreen->texture.empty () || |
1663 | 1462 | bScreen->height != screen->height ()) | 1435 | CompSize (bScreen->texture[0]->width (), |
1664 | 1436 | bScreen->texture[0]->height ()) != | ||
1665 | 1437 | static_cast <const CompSize &> (*screen)) | ||
1666 | 1463 | { | 1438 | { |
1674 | 1464 | int i, textures = 1; | 1439 | bScreen->texture = GLTexture::imageDataToTexture (NULL, |
1675 | 1465 | 1440 | *screen, | |
1676 | 1466 | bScreen->width = screen->width (); | 1441 | GL_RGB, |
1677 | 1467 | bScreen->height = screen->height (); | 1442 | #if IMAGE_BYTE_ORDER == MSBFirst |
1678 | 1468 | 1443 | GL_UNSIGNED_INT_8_8_8_8_REV); | |
1679 | 1469 | if (GL::textureNonPowerOfTwo || | 1444 | #else |
1680 | 1470 | (POWER_OF_TWO (bScreen->width) && POWER_OF_TWO (bScreen->height))) | 1445 | GL_UNSIGNED_BYTE); |
1681 | 1446 | #endif | ||
1682 | 1447 | |||
1683 | 1448 | if (bScreen->texture[0]->target () == GL_TEXTURE_2D) | ||
1684 | 1471 | { | 1449 | { |
1688 | 1472 | bScreen->target = GL_TEXTURE_2D; | 1450 | bScreen->tx = 1.0f / bScreen->texture[0]->width (); |
1689 | 1473 | bScreen->tx = 1.0f / bScreen->width; | 1451 | bScreen->ty = 1.0f / bScreen->texture[0]->height (); |
1687 | 1474 | bScreen->ty = 1.0f / bScreen->height; | ||
1690 | 1475 | } | 1452 | } |
1691 | 1476 | else | 1453 | else |
1692 | 1477 | { | 1454 | { |
1693 | 1478 | bScreen->target = GL_TEXTURE_RECTANGLE_NV; | ||
1694 | 1479 | bScreen->tx = 1; | 1455 | bScreen->tx = 1; |
1695 | 1480 | bScreen->ty = 1; | 1456 | bScreen->ty = 1; |
1696 | 1481 | } | 1457 | } |
1697 | 1482 | 1458 | ||
1698 | 1483 | if (filter == BlurOptions::FilterGaussian) | 1459 | if (filter == BlurOptions::FilterGaussian) |
1699 | 1484 | { | 1460 | { |
1704 | 1485 | if (GL::fbo && !bScreen->fbo) | 1461 | bScreen->fbo->allocate (*screen, |
1705 | 1486 | (*GL::genFramebuffers) (1, &bScreen->fbo); | 1462 | NULL, |
1706 | 1487 | 1463 | GL_BGRA); | |
1707 | 1488 | if (!bScreen->fbo) | 1464 | |
1708 | 1465 | /* We have to bind it in order to get a status */ | ||
1709 | 1466 | GLFramebufferObject *old = bScreen->fbo->bind(); | ||
1710 | 1467 | bool status = bScreen->fbo->checkStatus (); | ||
1711 | 1468 | old->bind(); | ||
1712 | 1469 | |||
1713 | 1470 | if (!status) | ||
1714 | 1489 | compLogMessage ("blur", CompLogLevelError, | 1471 | compLogMessage ("blur", CompLogLevelError, |
1715 | 1490 | "Failed to create framebuffer object"); | 1472 | "Failed to create framebuffer object"); |
1716 | 1491 | 1473 | ||
1746 | 1492 | textures = 2; | 1474 | else |
1718 | 1493 | } | ||
1719 | 1494 | |||
1720 | 1495 | bScreen->fboStatus = false; | ||
1721 | 1496 | |||
1722 | 1497 | for (i = 0; i < textures; i++) | ||
1723 | 1498 | { | ||
1724 | 1499 | if (!bScreen->texture[i]) | ||
1725 | 1500 | glGenTextures (1, &bScreen->texture[i]); | ||
1726 | 1501 | |||
1727 | 1502 | glBindTexture (bScreen->target, bScreen->texture[i]); | ||
1728 | 1503 | |||
1729 | 1504 | glTexImage2D (bScreen->target, 0, GL_RGB, | ||
1730 | 1505 | bScreen->width, | ||
1731 | 1506 | bScreen->height, | ||
1732 | 1507 | 0, GL_BGRA, | ||
1733 | 1508 | |||
1734 | 1509 | #if IMAGE_BYTE_ORDER == MSBFirst | ||
1735 | 1510 | GL_UNSIGNED_INT_8_8_8_8_REV, | ||
1736 | 1511 | #else | ||
1737 | 1512 | GL_UNSIGNED_BYTE, | ||
1738 | 1513 | #endif | ||
1739 | 1514 | |||
1740 | 1515 | NULL); | ||
1741 | 1516 | |||
1742 | 1517 | glTexParameteri (bScreen->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
1743 | 1518 | glTexParameteri (bScreen->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
1744 | 1519 | |||
1745 | 1520 | if (filter == BlurOptions::FilterMipmap) | ||
1747 | 1521 | { | 1475 | { |
1767 | 1522 | if (!GL::fbo) | 1476 | unsigned int filter = (bScreen->gScreen->driverHasBrokenFBOMipmaps () ? |
1768 | 1523 | { | 1477 | GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR); |
1769 | 1524 | compLogMessage ("blur", CompLogLevelWarn, | 1478 | bScreen->gScreen->setTextureFilter (filter); |
1770 | 1525 | "GL_EXT_framebuffer_object extension " | 1479 | |
1771 | 1526 | "is required for mipmap filter"); | 1480 | bScreen->fbo->tex ()->enable (GLTexture::Good); |
1772 | 1527 | } | 1481 | |
1773 | 1528 | else if (bScreen->target != GL_TEXTURE_2D) | 1482 | const CompRect &r (*bScreen->fbo->tex ()); |
1774 | 1529 | { | 1483 | |
1775 | 1530 | compLogMessage ("blur", CompLogLevelWarn, | 1484 | glCopyTexSubImage2D (bScreen->fbo->tex ()->target (), |
1776 | 1531 | "GL_ARB_texture_non_power_of_two " | 1485 | 0, 0, 0, 0, 0, |
1777 | 1532 | "extension is required for mipmap filter"); | 1486 | r.width (), |
1778 | 1533 | } | 1487 | r.height ()); |
1779 | 1534 | else | 1488 | |
1780 | 1535 | { | 1489 | if (!bScreen->gScreen->driverHasBrokenFBOMipmaps ()) |
1781 | 1536 | glTexParameteri (bScreen->target, GL_TEXTURE_MIN_FILTER, | 1490 | GL::generateMipmap (bScreen->fbo->tex ()->target ()); |
1782 | 1537 | GL_LINEAR_MIPMAP_LINEAR); | 1491 | |
1783 | 1538 | glTexParameteri (bScreen->target, GL_TEXTURE_MAG_FILTER, | 1492 | bScreen->fbo->tex ()->disable (); |
1765 | 1539 | GL_LINEAR_MIPMAP_LINEAR); | ||
1766 | 1540 | } | ||
1784 | 1541 | } | 1493 | } |
1785 | 1542 | |||
1786 | 1543 | glTexParameteri (bScreen->target, GL_TEXTURE_WRAP_S, | ||
1787 | 1544 | GL_CLAMP_TO_EDGE); | ||
1788 | 1545 | glTexParameteri (bScreen->target, GL_TEXTURE_WRAP_T, | ||
1789 | 1546 | GL_CLAMP_TO_EDGE); | ||
1790 | 1547 | |||
1791 | 1548 | glCopyTexSubImage2D (bScreen->target, 0, 0, 0, 0, 0, | ||
1792 | 1549 | bScreen->width, bScreen->height); | ||
1793 | 1550 | } | 1494 | } |
1794 | 1495 | |||
1795 | 1496 | /* Set update region to entire screen */ | ||
1796 | 1497 | br.setGeometry (0, 0, | ||
1797 | 1498 | screen->width (), | ||
1798 | 1499 | screen->height ()); | ||
1799 | 1551 | } | 1500 | } |
1801 | 1552 | else | 1501 | |
1802 | 1502 | *pExtents = br; | ||
1803 | 1503 | |||
1804 | 1504 | CompRegion *updateRegion = NULL; | ||
1805 | 1505 | updateRegion = &bScreen->tmpRegion; | ||
1806 | 1506 | |||
1807 | 1507 | foreach (GLTexture *tex, bScreen->texture) | ||
1808 | 1553 | { | 1508 | { |
1837 | 1554 | glBindTexture (bScreen->target, bScreen->texture[0]); | 1509 | /* We need to set the active texture filter to GL_LINEAR_MIPMAP_LINEAR */ |
1838 | 1555 | 1510 | if (filter == BlurOptions::FilterMipmap && | |
1839 | 1556 | CompRect br = bScreen->tmpRegion.boundingRect (); | 1511 | !bScreen->gScreen->driverHasBrokenFBOMipmaps ()) |
1840 | 1557 | 1512 | bScreen->gScreen->setTextureFilter (GL_LINEAR_MIPMAP_LINEAR); | |
1841 | 1558 | y = screen->height () - br.y2 (); | 1513 | |
1842 | 1559 | 1514 | tex->enable (GLTexture::Good); | |
1843 | 1560 | glCopyTexSubImage2D (bScreen->target, 0, | 1515 | |
1844 | 1561 | br.x1 (), y, | 1516 | CompRect::vector rects (updateRegion->rects ()); |
1845 | 1562 | br.x1 (), y, | 1517 | |
1846 | 1563 | br.width (), | 1518 | foreach (const CompRect &r, rects) |
1847 | 1564 | br.height ()); | 1519 | { |
1848 | 1565 | } | 1520 | int y = screen->height () - r.y2 (); |
1849 | 1566 | 1521 | ||
1850 | 1567 | switch (filter) { | 1522 | glCopyTexSubImage2D (bScreen->texture[0]->target (), 0, |
1851 | 1568 | case BlurOptions::FilterGaussian: | 1523 | r.x1 (), y, |
1852 | 1569 | return bScreen->fboUpdate (bScreen->tmpRegion.handle ()->rects, | 1524 | r.x1 (), y, |
1853 | 1570 | bScreen->tmpRegion.numRects ()); | 1525 | r.width (), |
1854 | 1571 | case BlurOptions::FilterMipmap: | 1526 | r.height ()); |
1855 | 1572 | if (GL::generateMipmap) | 1527 | } |
1856 | 1573 | (*GL::generateMipmap) (bScreen->target); | 1528 | |
1857 | 1574 | break; | 1529 | /* Force mipmap regeneration, because GLTexture assumes static |
1858 | 1575 | case BlurOptions::Filter4xbilinear: | 1530 | * textures and won't do it for us */ |
1859 | 1576 | break; | 1531 | if (filter == BlurOptions::FilterMipmap && |
1860 | 1577 | } | 1532 | !bScreen->gScreen->driverHasBrokenFBOMipmaps ()) |
1861 | 1578 | 1533 | GL::generateMipmap (tex->target ()); | |
1862 | 1579 | glBindTexture (bScreen->target, 0); | 1534 | |
1863 | 1580 | 1535 | if (filter == BlurOptions::FilterGaussian) | |
1864 | 1581 | return true; | 1536 | ret |= bScreen->fboUpdate (updateRegion->handle ()->rects, |
1865 | 1537 | updateRegion->numRects ()); | ||
1866 | 1538 | else | ||
1867 | 1539 | ret = true; | ||
1868 | 1540 | |||
1869 | 1541 | tex->disable (); | ||
1870 | 1542 | } | ||
1871 | 1543 | |||
1872 | 1544 | return ret; | ||
1873 | 1582 | } | 1545 | } |
1874 | 1583 | 1546 | ||
1875 | 1584 | bool | 1547 | bool |
1880 | 1585 | BlurWindow::glDraw (const GLMatrix &transform, | 1548 | BlurWindow::glDraw (const GLMatrix &transform, |
1881 | 1586 | GLFragment::Attrib &attrib, | 1549 | const GLWindowPaintAttrib &attrib, |
1882 | 1587 | const CompRegion ®ion, | 1550 | const CompRegion ®ion, |
1883 | 1588 | unsigned int mask) | 1551 | unsigned int mask) |
1884 | 1589 | { | 1552 | { |
1885 | 1590 | bool status; | 1553 | bool status; |
1886 | 1591 | 1554 | ||
1887 | @@ -1603,22 +1566,11 @@ | |||
1888 | 1603 | { | 1566 | { |
1889 | 1604 | bool clipped = false; | 1567 | bool clipped = false; |
1890 | 1605 | CompRect box (0, 0, 0, 0); | 1568 | CompRect box (0, 0, 0, 0); |
1891 | 1606 | CompRegion reg; | ||
1892 | 1607 | 1569 | ||
1894 | 1608 | bScreen->mvp = GLMatrix (bScreen->gScreen->projectionMatrix ()); | 1570 | bScreen->mvp = *(bScreen->gScreen->projectionMatrix ()); |
1895 | 1609 | bScreen->mvp *= transform; | 1571 | bScreen->mvp *= transform; |
1896 | 1610 | 1572 | ||
1908 | 1611 | if (mask & PAINT_WINDOW_TRANSFORMED_MASK) | 1573 | if (updateDstTexture (transform, &box, mask)) |
1898 | 1612 | reg = infiniteRegion; | ||
1899 | 1613 | else | ||
1900 | 1614 | reg = region; | ||
1901 | 1615 | |||
1902 | 1616 | bScreen->tmpRegion = this->region.intersected (reg); | ||
1903 | 1617 | if (!bScreen->blurOcclusion && | ||
1904 | 1618 | !(mask & PAINT_WINDOW_TRANSFORMED_MASK)) | ||
1905 | 1619 | bScreen->tmpRegion -= clip; | ||
1906 | 1620 | |||
1907 | 1621 | if (updateDstTexture (transform, &box, clientThreshold)) | ||
1909 | 1622 | { | 1574 | { |
1910 | 1623 | if (clientThreshold) | 1575 | if (clientThreshold) |
1911 | 1624 | { | 1576 | { |
1912 | @@ -1672,11 +1624,17 @@ | |||
1913 | 1672 | if (clipped) | 1624 | if (clipped) |
1914 | 1673 | { | 1625 | { |
1915 | 1674 | GLTexture::MatrixList ml; | 1626 | GLTexture::MatrixList ml; |
1921 | 1675 | 1627 | const CompRegion *reg = NULL; | |
1922 | 1676 | gWindow->geometry ().reset (); | 1628 | |
1923 | 1677 | 1629 | if (mask & PAINT_WINDOW_TRANSFORMED_MASK) | |
1924 | 1678 | gWindow->glAddGeometry (ml, bScreen->tmpRegion, reg); | 1630 | reg = &infiniteRegion; |
1925 | 1679 | if (gWindow->geometry ().vCount) | 1631 | else |
1926 | 1632 | reg = ®ion; | ||
1927 | 1633 | |||
1928 | 1634 | gWindow->vertexBuffer ()->begin (); | ||
1929 | 1635 | gWindow->glAddGeometry (ml, bScreen->tmpRegion, *reg); | ||
1930 | 1636 | gWindow->vertexBuffer ()->color4f (1.0, 1.0, 1.0, 1.0); | ||
1931 | 1637 | if (gWindow->vertexBuffer ()->end ()) | ||
1932 | 1680 | { | 1638 | { |
1933 | 1681 | CompRect clearBox = bScreen->stencilBox; | 1639 | CompRect clearBox = bScreen->stencilBox; |
1934 | 1682 | 1640 | ||
1935 | @@ -1684,28 +1642,44 @@ | |||
1936 | 1684 | 1642 | ||
1937 | 1685 | glEnable (GL_STENCIL_TEST); | 1643 | glEnable (GL_STENCIL_TEST); |
1938 | 1686 | glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | 1644 | glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
1939 | 1645 | glStencilMask (1); | ||
1940 | 1687 | 1646 | ||
1941 | 1688 | if (clearBox.x2 () > clearBox.x1 () && | 1647 | if (clearBox.x2 () > clearBox.x1 () && |
1942 | 1689 | clearBox.y2 () > clearBox.y1 ()) | 1648 | clearBox.y2 () > clearBox.y1 ()) |
1943 | 1690 | { | 1649 | { |
1946 | 1691 | glPushAttrib (GL_SCISSOR_BIT); | 1650 | /* We might have a previous scissor region, so we need |
1947 | 1692 | glEnable (GL_SCISSOR_TEST); | 1651 | * to fetch it, however slow that might be .. */ |
1948 | 1652 | GLint scissorBox[4]; | ||
1949 | 1653 | GLboolean scissorEnabled; | ||
1950 | 1654 | |||
1951 | 1655 | scissorEnabled = glIsEnabled (GL_SCISSOR_TEST); | ||
1952 | 1656 | glGetIntegerv (GL_SCISSOR_BOX, scissorBox); | ||
1953 | 1657 | |||
1954 | 1658 | if (!scissorEnabled) | ||
1955 | 1659 | glEnable (GL_SCISSOR_TEST); | ||
1956 | 1660 | |||
1957 | 1693 | glScissor (clearBox.x1 (), | 1661 | glScissor (clearBox.x1 (), |
1958 | 1694 | screen->height () - clearBox.y2 (), | 1662 | screen->height () - clearBox.y2 (), |
1959 | 1695 | clearBox.width (), | 1663 | clearBox.width (), |
1960 | 1696 | clearBox.height ()); | 1664 | clearBox.height ()); |
1961 | 1665 | glClearStencil (0); | ||
1962 | 1697 | glClear (GL_STENCIL_BUFFER_BIT); | 1666 | glClear (GL_STENCIL_BUFFER_BIT); |
1964 | 1698 | glPopAttrib (); | 1667 | |
1965 | 1668 | if (!scissorEnabled) | ||
1966 | 1669 | glDisable (GL_SCISSOR_TEST); | ||
1967 | 1670 | |||
1968 | 1671 | glScissor (scissorBox[0], scissorBox[1], | ||
1969 | 1672 | scissorBox[2], scissorBox[3]); | ||
1970 | 1699 | } | 1673 | } |
1971 | 1700 | 1674 | ||
1973 | 1701 | glStencilFunc (GL_ALWAYS, 0x1, ~0); | 1675 | glStencilFunc (GL_ALWAYS, 1, 1); |
1974 | 1702 | glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); | 1676 | glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); |
1975 | 1703 | 1677 | ||
1979 | 1704 | glDisableClientState (GL_TEXTURE_COORD_ARRAY); | 1678 | /* Render a white polygon where the window is */ |
1980 | 1705 | gWindow->glDrawGeometry (); | 1679 | gWindow->vertexBuffer ()->render (transform); |
1978 | 1706 | glEnableClientState (GL_TEXTURE_COORD_ARRAY); | ||
1981 | 1707 | 1680 | ||
1982 | 1708 | glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 1681 | glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
1983 | 1682 | glStencilMask (0); | ||
1984 | 1709 | glDisable (GL_STENCIL_TEST); | 1683 | glDisable (GL_STENCIL_TEST); |
1985 | 1710 | } | 1684 | } |
1986 | 1711 | } | 1685 | } |
1987 | @@ -1720,10 +1694,248 @@ | |||
1988 | 1720 | return status; | 1694 | return status; |
1989 | 1721 | } | 1695 | } |
1990 | 1722 | 1696 | ||
1991 | 1697 | namespace | ||
1992 | 1698 | { | ||
1993 | 1699 | void setupShadersAndUniformsForDstBlur (GLTexture *texture, | ||
1994 | 1700 | GLWindow *gWindow, | ||
1995 | 1701 | BlurScreen *bScreen, | ||
1996 | 1702 | int &unit, | ||
1997 | 1703 | int &iTC, | ||
1998 | 1704 | float threshold) | ||
1999 | 1705 | { | ||
2000 | 1706 | GLfloat dx, dy; | ||
2001 | 1707 | |||
2002 | 1708 | switch (bScreen->optionGetFilter ()) | ||
2003 | 1709 | { | ||
2004 | 1710 | case BlurOptions::Filter4xbilinear: | ||
2005 | 1711 | { | ||
2006 | 1712 | dx = bScreen->tx / 2.1f; | ||
2007 | 1713 | dy = bScreen->ty / 2.1f; | ||
2008 | 1714 | |||
2009 | 1715 | unit = 1; // FIXME!! | ||
2010 | 1716 | |||
2011 | 1717 | const CompString &function ( | ||
2012 | 1718 | bScreen->getDstBlurFragmentFunction ( | ||
2013 | 1719 | texture, unit, 0, 0)); | ||
2014 | 1720 | |||
2015 | 1721 | if (!function.empty ()) | ||
2016 | 1722 | { | ||
2017 | 1723 | (*GL::activeTexture) (GL_TEXTURE0 + unit); | ||
2018 | 1724 | bScreen->texture[0]->enable (GLTexture::Good); | ||
2019 | 1725 | gWindow->vertexBuffer ()->addTexCoords (unit, 0, NULL); | ||
2020 | 1726 | (*GL::activeTexture) (GL_TEXTURE0); | ||
2021 | 1727 | |||
2022 | 1728 | gWindow->addShaders ("blur", | ||
2023 | 1729 | "", | ||
2024 | 1730 | function); | ||
2025 | 1731 | |||
2026 | 1732 | gWindow->vertexBuffer ()->addUniform4f ("blur_translation", | ||
2027 | 1733 | bScreen->tx, bScreen->ty, | ||
2028 | 1734 | 0.0f, 0.0f); | ||
2029 | 1735 | |||
2030 | 1736 | gWindow->vertexBuffer ()->addUniform4f ("blur_threshold", | ||
2031 | 1737 | threshold, | ||
2032 | 1738 | threshold, | ||
2033 | 1739 | threshold, | ||
2034 | 1740 | threshold); | ||
2035 | 1741 | |||
2036 | 1742 | gWindow->vertexBuffer ()->addUniform4f ("blur_dxdy", | ||
2037 | 1743 | dx, dy, 0.0, 0.0); | ||
2038 | 1744 | } | ||
2039 | 1745 | } | ||
2040 | 1746 | break; | ||
2041 | 1747 | case BlurOptions::FilterGaussian: | ||
2042 | 1748 | { | ||
2043 | 1749 | #if INDEPENDENT_TEX_SUPPORTED | ||
2044 | 1750 | if (bScreen->optionGetIndependentTex ()) | ||
2045 | 1751 | { | ||
2046 | 1752 | /* leave one free texture unit for fragment position */ | ||
2047 | 1753 | iTC = MAX (0, GL::maxTextureUnits - | ||
2048 | 1754 | (gWindow->geometry ().texUnits + 1)); | ||
2049 | 1755 | if (iTC) | ||
2050 | 1756 | iTC = MIN (iTC / 2, bScreen->numTexop); | ||
2051 | 1757 | } | ||
2052 | 1758 | #endif | ||
2053 | 1759 | unit = 1; | ||
2054 | 1760 | |||
2055 | 1761 | const CompString &function ( | ||
2056 | 1762 | bScreen->getDstBlurFragmentFunction ( | ||
2057 | 1763 | texture, unit, iTC, | ||
2058 | 1764 | gWindow->vertexBuffer ()->countTextures ())); | ||
2059 | 1765 | |||
2060 | 1766 | if (!function.empty ()) | ||
2061 | 1767 | { | ||
2062 | 1768 | gWindow->addShaders ("blur", | ||
2063 | 1769 | "", | ||
2064 | 1770 | function); | ||
2065 | 1771 | |||
2066 | 1772 | (*GL::activeTexture) (GL_TEXTURE0 + unit); | ||
2067 | 1773 | bScreen->texture[0]->enable (GLTexture::Good); | ||
2068 | 1774 | gWindow->vertexBuffer ()->addTexCoords (unit, 0, NULL); | ||
2069 | 1775 | (*GL::activeTexture) (GL_TEXTURE0 + unit + 1); | ||
2070 | 1776 | bScreen->fbo->tex ()->enable (GLTexture::Good); | ||
2071 | 1777 | gWindow->vertexBuffer ()->addTexCoords (unit + 1, 0, NULL); | ||
2072 | 1778 | (*GL::activeTexture) (GL_TEXTURE0); | ||
2073 | 1779 | |||
2074 | 1780 | gWindow->vertexBuffer ()->addUniform4f ("blur_translation", | ||
2075 | 1781 | bScreen->tx, bScreen->ty, | ||
2076 | 1782 | 0.0f, 0.0f); | ||
2077 | 1783 | |||
2078 | 1784 | gWindow->vertexBuffer ()->addUniform4f ("blur_threshold", | ||
2079 | 1785 | threshold, | ||
2080 | 1786 | threshold, | ||
2081 | 1787 | threshold, | ||
2082 | 1788 | threshold); | ||
2083 | 1789 | #if INDEPENDENT_TEX_SUPPORTED | ||
2084 | 1790 | if (iTC) | ||
2085 | 1791 | { | ||
2086 | 1792 | GLMatrix tm, rm; | ||
2087 | 1793 | float s_gen[4], t_gen[4], q_gen[4]; | ||
2088 | 1794 | |||
2089 | 1795 | for (unsigned int i = 0; i < 16; i++) | ||
2090 | 1796 | tm[i] = 0; | ||
2091 | 1797 | tm[0] = (bScreen->output->width () / 2.0) * | ||
2092 | 1798 | bScreen->tx; | ||
2093 | 1799 | tm[5] = (bScreen->output->height () / 2.0) * | ||
2094 | 1800 | bScreen->ty; | ||
2095 | 1801 | tm[10] = 1; | ||
2096 | 1802 | |||
2097 | 1803 | tm[12] = (bScreen->output->width () / 2.0 + | ||
2098 | 1804 | bScreen->output->x1 ()) * bScreen->tx; | ||
2099 | 1805 | tm[13] = (bScreen->output->height () / 2.0 + | ||
2100 | 1806 | screen->height () - | ||
2101 | 1807 | bScreen->output->y2 ()) * bScreen->ty; | ||
2102 | 1808 | tm[14] = 1; | ||
2103 | 1809 | tm[15] = 1; | ||
2104 | 1810 | |||
2105 | 1811 | tm *= bScreen->mvp; | ||
2106 | 1812 | |||
2107 | 1813 | for (int i = 0; i < iTC; i++) | ||
2108 | 1814 | { | ||
2109 | 1815 | (*GL::activeTexture) (GL_TEXTURE0 + | ||
2110 | 1816 | gWindow->geometry ().texUnits + (i * 2)); | ||
2111 | 1817 | |||
2112 | 1818 | rm.reset (); | ||
2113 | 1819 | rm[13] = bScreen->ty * bScreen->pos[i]; | ||
2114 | 1820 | rm *= tm; | ||
2115 | 1821 | |||
2116 | 1822 | s_gen[0] = rm[0]; | ||
2117 | 1823 | s_gen[1] = rm[4]; | ||
2118 | 1824 | s_gen[2] = rm[8]; | ||
2119 | 1825 | s_gen[3] = rm[12]; | ||
2120 | 1826 | t_gen[0] = rm[1]; | ||
2121 | 1827 | t_gen[1] = rm[5]; | ||
2122 | 1828 | t_gen[2] = rm[9]; | ||
2123 | 1829 | t_gen[3] = rm[13]; | ||
2124 | 1830 | q_gen[0] = rm[3]; | ||
2125 | 1831 | q_gen[1] = rm[7]; | ||
2126 | 1832 | q_gen[2] = rm[11]; | ||
2127 | 1833 | q_gen[3] = rm[15]; | ||
2128 | 1834 | |||
2129 | 1835 | glTexGenfv (GL_T, GL_OBJECT_PLANE, t_gen); | ||
2130 | 1836 | glTexGenfv (GL_S, GL_OBJECT_PLANE, s_gen); | ||
2131 | 1837 | glTexGenfv (GL_Q, GL_OBJECT_PLANE, q_gen); | ||
2132 | 1838 | |||
2133 | 1839 | glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, | ||
2134 | 1840 | GL_OBJECT_LINEAR); | ||
2135 | 1841 | glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, | ||
2136 | 1842 | GL_OBJECT_LINEAR); | ||
2137 | 1843 | glTexGeni (GL_Q, GL_TEXTURE_GEN_MODE, | ||
2138 | 1844 | GL_OBJECT_LINEAR); | ||
2139 | 1845 | |||
2140 | 1846 | glEnable (GL_TEXTURE_GEN_S); | ||
2141 | 1847 | glEnable (GL_TEXTURE_GEN_T); | ||
2142 | 1848 | glEnable (GL_TEXTURE_GEN_Q); | ||
2143 | 1849 | |||
2144 | 1850 | (*GL::activeTexture) (GL_TEXTURE0 + | ||
2145 | 1851 | gWindow->geometry ().texUnits + | ||
2146 | 1852 | 1 + (i * 2)); | ||
2147 | 1853 | |||
2148 | 1854 | rm.reset (); | ||
2149 | 1855 | |||
2150 | 1856 | rm[13] = -bScreen->ty * bScreen->pos[i]; | ||
2151 | 1857 | rm *= tm; | ||
2152 | 1858 | |||
2153 | 1859 | s_gen[0] = rm[0]; | ||
2154 | 1860 | s_gen[1] = rm[4]; | ||
2155 | 1861 | s_gen[2] = rm[8]; | ||
2156 | 1862 | s_gen[3] = rm[12]; | ||
2157 | 1863 | t_gen[0] = rm[1]; | ||
2158 | 1864 | t_gen[1] = rm[5]; | ||
2159 | 1865 | t_gen[2] = rm[9]; | ||
2160 | 1866 | t_gen[3] = rm[13]; | ||
2161 | 1867 | q_gen[0] = rm[3]; | ||
2162 | 1868 | q_gen[1] = rm[7]; | ||
2163 | 1869 | q_gen[2] = rm[11]; | ||
2164 | 1870 | q_gen[3] = rm[15]; | ||
2165 | 1871 | |||
2166 | 1872 | glTexGenfv (GL_T, GL_OBJECT_PLANE, t_gen); | ||
2167 | 1873 | glTexGenfv (GL_S, GL_OBJECT_PLANE, s_gen); | ||
2168 | 1874 | glTexGenfv (GL_Q, GL_OBJECT_PLANE, q_gen); | ||
2169 | 1875 | |||
2170 | 1876 | glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, | ||
2171 | 1877 | GL_OBJECT_LINEAR); | ||
2172 | 1878 | glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, | ||
2173 | 1879 | GL_OBJECT_LINEAR); | ||
2174 | 1880 | glTexGeni (GL_Q, GL_TEXTURE_GEN_MODE, | ||
2175 | 1881 | GL_OBJECT_LINEAR); | ||
2176 | 1882 | |||
2177 | 1883 | glEnable (GL_TEXTURE_GEN_S); | ||
2178 | 1884 | glEnable (GL_TEXTURE_GEN_T); | ||
2179 | 1885 | glEnable (GL_TEXTURE_GEN_Q); | ||
2180 | 1886 | } | ||
2181 | 1887 | |||
2182 | 1888 | (*GL::activeTexture) (GL_TEXTURE0); | ||
2183 | 1889 | } | ||
2184 | 1890 | #endif | ||
2185 | 1891 | } | ||
2186 | 1892 | } | ||
2187 | 1893 | break; | ||
2188 | 1894 | case BlurOptions::FilterMipmap: | ||
2189 | 1895 | { | ||
2190 | 1896 | unit = 1; // FIXME!! | ||
2191 | 1897 | |||
2192 | 1898 | const CompString &function ( | ||
2193 | 1899 | bScreen->getDstBlurFragmentFunction (texture, | ||
2194 | 1900 | unit, | ||
2195 | 1901 | 0, | ||
2196 | 1902 | 0)); | ||
2197 | 1903 | |||
2198 | 1904 | if (!function.empty ()) | ||
2199 | 1905 | { | ||
2200 | 1906 | float lod = | ||
2201 | 1907 | bScreen->optionGetMipmapLod (); | ||
2202 | 1908 | |||
2203 | 1909 | gWindow->addShaders ("blur", | ||
2204 | 1910 | "", | ||
2205 | 1911 | function); | ||
2206 | 1912 | |||
2207 | 1913 | (*GL::activeTexture) (GL_TEXTURE0 + unit); | ||
2208 | 1914 | bScreen->texture[0]->enable (GLTexture::Good); | ||
2209 | 1915 | gWindow->vertexBuffer ()->addTexCoords (unit, 0, NULL); | ||
2210 | 1916 | (*GL::activeTexture) (GL_TEXTURE0); | ||
2211 | 1917 | |||
2212 | 1918 | gWindow->vertexBuffer ()->addUniform4f ("blur_translation", | ||
2213 | 1919 | bScreen->tx, bScreen->ty, | ||
2214 | 1920 | 0.0f, lod); | ||
2215 | 1921 | |||
2216 | 1922 | gWindow->vertexBuffer ()->addUniform4f ("blur_threshold", | ||
2217 | 1923 | threshold, | ||
2218 | 1924 | threshold, | ||
2219 | 1925 | threshold, | ||
2220 | 1926 | threshold); | ||
2221 | 1927 | } | ||
2222 | 1928 | } | ||
2223 | 1929 | break; | ||
2224 | 1930 | } | ||
2225 | 1931 | } | ||
2226 | 1932 | } | ||
2227 | 1933 | |||
2228 | 1723 | void | 1934 | void |
2232 | 1724 | BlurWindow::glDrawTexture (GLTexture *texture, | 1935 | BlurWindow::glDrawTexture (GLTexture *texture, |
2233 | 1725 | GLFragment::Attrib &attrib, | 1936 | const GLMatrix &matrix, |
2234 | 1726 | unsigned int mask) | 1937 | const GLWindowPaintAttrib &attrib, |
2235 | 1938 | unsigned int mask) | ||
2236 | 1727 | { | 1939 | { |
2237 | 1728 | int state = BLUR_STATE_DECOR; | 1940 | int state = BLUR_STATE_DECOR; |
2238 | 1729 | 1941 | ||
2239 | @@ -1733,295 +1945,108 @@ | |||
2240 | 1733 | 1945 | ||
2241 | 1734 | if (blur || this->state[state].active) | 1946 | if (blur || this->state[state].active) |
2242 | 1735 | { | 1947 | { |
2243 | 1736 | GLFragment::Attrib fa (attrib); | ||
2244 | 1737 | int param, function; | ||
2245 | 1738 | int unit = 0; | 1948 | int unit = 0; |
2246 | 1739 | GLfloat dx, dy; | ||
2247 | 1740 | int iTC = 0; | 1949 | int iTC = 0; |
2248 | 1741 | 1950 | ||
2249 | 1742 | if (blur) | 1951 | if (blur) |
2250 | 1743 | { | 1952 | { |
2255 | 1744 | param = fa.allocParameters (1); | 1953 | GLfloat dx, dy; |
2256 | 1745 | 1954 | ||
2257 | 1746 | function = bScreen->getSrcBlurFragmentFunction (texture, param); | 1955 | const CompString &function ( |
2258 | 1747 | if (function) | 1956 | bScreen->getSrcBlurFragmentFunction (texture)); |
2259 | 1957 | |||
2260 | 1958 | if (!function.empty ()) | ||
2261 | 1748 | { | 1959 | { |
2263 | 1749 | fa.addFunction (function); | 1960 | gWindow->addShaders ("focusblur", |
2264 | 1961 | "", | ||
2265 | 1962 | function); | ||
2266 | 1750 | 1963 | ||
2267 | 1751 | dx = ((texture->matrix ().xx / 2.1f) * blur) / 65535.0f; | 1964 | dx = ((texture->matrix ().xx / 2.1f) * blur) / 65535.0f; |
2268 | 1752 | dy = ((texture->matrix ().yy / 2.1f) * blur) / 65535.0f; | 1965 | dy = ((texture->matrix ().yy / 2.1f) * blur) / 65535.0f; |
2269 | 1753 | 1966 | ||
2272 | 1754 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | 1967 | gWindow->vertexBuffer ()->addUniform4f ("focusblur_input_offset", |
2273 | 1755 | param, dx, dy, dx, -dy); | 1968 | dx, dy, dx, -dy); |
2274 | 1756 | 1969 | ||
2275 | 1757 | /* bi-linear filtering is required */ | 1970 | /* bi-linear filtering is required */ |
2276 | 1758 | mask |= PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK; | 1971 | mask |= PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK; |
2277 | 1759 | } | 1972 | } |
2278 | 1760 | } | 1973 | } |
2279 | 1761 | 1974 | ||
2280 | 1975 | /* We are drawing the scraped texture, blur it */ | ||
2281 | 1762 | if (this->state[state].active) | 1976 | if (this->state[state].active) |
2282 | 1763 | { | 1977 | { |
2488 | 1764 | GLFragment::Attrib dstFa (fa); | 1978 | setupShadersAndUniformsForDstBlur (texture, |
2489 | 1765 | float threshold = (float) this->state[state].threshold; | 1979 | gWindow, |
2490 | 1766 | 1980 | bScreen, | |
2491 | 1767 | switch (bScreen->optionGetFilter ()) { | 1981 | unit, |
2492 | 1768 | case BlurOptions::Filter4xbilinear: | 1982 | iTC, |
2493 | 1769 | dx = bScreen->tx / 2.1f; | 1983 | this->state[state].threshold); |
2289 | 1770 | dy = bScreen->ty / 2.1f; | ||
2290 | 1771 | |||
2291 | 1772 | param = dstFa.allocParameters (3); | ||
2292 | 1773 | unit = dstFa.allocTextureUnits (1); | ||
2293 | 1774 | |||
2294 | 1775 | function = bScreen->getDstBlurFragmentFunction ( | ||
2295 | 1776 | texture, param, unit, 0, 0); | ||
2296 | 1777 | if (function) | ||
2297 | 1778 | { | ||
2298 | 1779 | dstFa.addFunction (function); | ||
2299 | 1780 | |||
2300 | 1781 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit); | ||
2301 | 1782 | glBindTexture (bScreen->target, bScreen->texture[0]); | ||
2302 | 1783 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | ||
2303 | 1784 | |||
2304 | 1785 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2305 | 1786 | param, | ||
2306 | 1787 | bScreen->tx, bScreen->ty, | ||
2307 | 1788 | 0.0f, 0.0f); | ||
2308 | 1789 | |||
2309 | 1790 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2310 | 1791 | param + 1, | ||
2311 | 1792 | threshold, threshold, | ||
2312 | 1793 | threshold, threshold); | ||
2313 | 1794 | |||
2314 | 1795 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2315 | 1796 | param + 2, | ||
2316 | 1797 | dx, dy, 0.0f, 0.0f); | ||
2317 | 1798 | } | ||
2318 | 1799 | break; | ||
2319 | 1800 | case BlurOptions::FilterGaussian: | ||
2320 | 1801 | if (bScreen->optionGetIndependentTex ()) | ||
2321 | 1802 | { | ||
2322 | 1803 | /* leave one free texture unit for fragment position */ | ||
2323 | 1804 | iTC = MAX (0, GL::maxTextureUnits - | ||
2324 | 1805 | (gWindow->geometry ().texUnits + 1)); | ||
2325 | 1806 | if (iTC) | ||
2326 | 1807 | iTC = MIN (iTC / 2, bScreen->numTexop); | ||
2327 | 1808 | } | ||
2328 | 1809 | |||
2329 | 1810 | param = dstFa.allocParameters (2); | ||
2330 | 1811 | unit = dstFa.allocTextureUnits (2); | ||
2331 | 1812 | |||
2332 | 1813 | function = bScreen->getDstBlurFragmentFunction ( | ||
2333 | 1814 | texture, param, unit, iTC, | ||
2334 | 1815 | gWindow->geometry ().texUnits); | ||
2335 | 1816 | |||
2336 | 1817 | if (function) | ||
2337 | 1818 | { | ||
2338 | 1819 | dstFa.addFunction (function); | ||
2339 | 1820 | |||
2340 | 1821 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit); | ||
2341 | 1822 | glBindTexture (bScreen->target, bScreen->texture[0]); | ||
2342 | 1823 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit + 1); | ||
2343 | 1824 | glBindTexture (bScreen->target, bScreen->texture[1]); | ||
2344 | 1825 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | ||
2345 | 1826 | |||
2346 | 1827 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2347 | 1828 | param, bScreen->tx, | ||
2348 | 1829 | bScreen->ty, 0.0f, 0.0f); | ||
2349 | 1830 | |||
2350 | 1831 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2351 | 1832 | param + 1, | ||
2352 | 1833 | threshold, threshold, | ||
2353 | 1834 | threshold, threshold); | ||
2354 | 1835 | |||
2355 | 1836 | if (iTC) | ||
2356 | 1837 | { | ||
2357 | 1838 | GLMatrix tm, rm; | ||
2358 | 1839 | float s_gen[4], t_gen[4], q_gen[4]; | ||
2359 | 1840 | |||
2360 | 1841 | for (unsigned int i = 0; i < 16; i++) | ||
2361 | 1842 | tm[i] = 0; | ||
2362 | 1843 | tm[0] = (bScreen->output->width () / 2.0) * | ||
2363 | 1844 | bScreen->tx; | ||
2364 | 1845 | tm[5] = (bScreen->output->height () / 2.0) * | ||
2365 | 1846 | bScreen->ty; | ||
2366 | 1847 | tm[10] = 1; | ||
2367 | 1848 | |||
2368 | 1849 | tm[12] = (bScreen->output->width () / 2.0 + | ||
2369 | 1850 | bScreen->output->x1 ()) * bScreen->tx; | ||
2370 | 1851 | tm[13] = (bScreen->output->height () / 2.0 + | ||
2371 | 1852 | screen->height () - | ||
2372 | 1853 | bScreen->output->y2 ()) * bScreen->ty; | ||
2373 | 1854 | tm[14] = 1; | ||
2374 | 1855 | tm[15] = 1; | ||
2375 | 1856 | |||
2376 | 1857 | tm *= bScreen->mvp; | ||
2377 | 1858 | |||
2378 | 1859 | for (int i = 0; i < iTC; i++) | ||
2379 | 1860 | { | ||
2380 | 1861 | (*GL::activeTexture) (GL_TEXTURE0_ARB + | ||
2381 | 1862 | gWindow->geometry ().texUnits + (i * 2)); | ||
2382 | 1863 | |||
2383 | 1864 | rm.reset (); | ||
2384 | 1865 | rm[13] = bScreen->ty * bScreen->pos[i]; | ||
2385 | 1866 | rm *= tm; | ||
2386 | 1867 | |||
2387 | 1868 | s_gen[0] = rm[0]; | ||
2388 | 1869 | s_gen[1] = rm[4]; | ||
2389 | 1870 | s_gen[2] = rm[8]; | ||
2390 | 1871 | s_gen[3] = rm[12]; | ||
2391 | 1872 | t_gen[0] = rm[1]; | ||
2392 | 1873 | t_gen[1] = rm[5]; | ||
2393 | 1874 | t_gen[2] = rm[9]; | ||
2394 | 1875 | t_gen[3] = rm[13]; | ||
2395 | 1876 | q_gen[0] = rm[3]; | ||
2396 | 1877 | q_gen[1] = rm[7]; | ||
2397 | 1878 | q_gen[2] = rm[11]; | ||
2398 | 1879 | q_gen[3] = rm[15]; | ||
2399 | 1880 | |||
2400 | 1881 | glTexGenfv (GL_T, GL_OBJECT_PLANE, t_gen); | ||
2401 | 1882 | glTexGenfv (GL_S, GL_OBJECT_PLANE, s_gen); | ||
2402 | 1883 | glTexGenfv (GL_Q, GL_OBJECT_PLANE, q_gen); | ||
2403 | 1884 | |||
2404 | 1885 | glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, | ||
2405 | 1886 | GL_OBJECT_LINEAR); | ||
2406 | 1887 | glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, | ||
2407 | 1888 | GL_OBJECT_LINEAR); | ||
2408 | 1889 | glTexGeni (GL_Q, GL_TEXTURE_GEN_MODE, | ||
2409 | 1890 | GL_OBJECT_LINEAR); | ||
2410 | 1891 | |||
2411 | 1892 | glEnable (GL_TEXTURE_GEN_S); | ||
2412 | 1893 | glEnable (GL_TEXTURE_GEN_T); | ||
2413 | 1894 | glEnable (GL_TEXTURE_GEN_Q); | ||
2414 | 1895 | |||
2415 | 1896 | (*GL::activeTexture) (GL_TEXTURE0_ARB + | ||
2416 | 1897 | gWindow->geometry ().texUnits + | ||
2417 | 1898 | 1 + (i * 2)); | ||
2418 | 1899 | |||
2419 | 1900 | rm.reset (); | ||
2420 | 1901 | |||
2421 | 1902 | rm[13] = -bScreen->ty * bScreen->pos[i]; | ||
2422 | 1903 | rm *= tm; | ||
2423 | 1904 | |||
2424 | 1905 | s_gen[0] = rm[0]; | ||
2425 | 1906 | s_gen[1] = rm[4]; | ||
2426 | 1907 | s_gen[2] = rm[8]; | ||
2427 | 1908 | s_gen[3] = rm[12]; | ||
2428 | 1909 | t_gen[0] = rm[1]; | ||
2429 | 1910 | t_gen[1] = rm[5]; | ||
2430 | 1911 | t_gen[2] = rm[9]; | ||
2431 | 1912 | t_gen[3] = rm[13]; | ||
2432 | 1913 | q_gen[0] = rm[3]; | ||
2433 | 1914 | q_gen[1] = rm[7]; | ||
2434 | 1915 | q_gen[2] = rm[11]; | ||
2435 | 1916 | q_gen[3] = rm[15]; | ||
2436 | 1917 | |||
2437 | 1918 | glTexGenfv (GL_T, GL_OBJECT_PLANE, t_gen); | ||
2438 | 1919 | glTexGenfv (GL_S, GL_OBJECT_PLANE, s_gen); | ||
2439 | 1920 | glTexGenfv (GL_Q, GL_OBJECT_PLANE, q_gen); | ||
2440 | 1921 | |||
2441 | 1922 | glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, | ||
2442 | 1923 | GL_OBJECT_LINEAR); | ||
2443 | 1924 | glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, | ||
2444 | 1925 | GL_OBJECT_LINEAR); | ||
2445 | 1926 | glTexGeni (GL_Q, GL_TEXTURE_GEN_MODE, | ||
2446 | 1927 | GL_OBJECT_LINEAR); | ||
2447 | 1928 | |||
2448 | 1929 | glEnable (GL_TEXTURE_GEN_S); | ||
2449 | 1930 | glEnable (GL_TEXTURE_GEN_T); | ||
2450 | 1931 | glEnable (GL_TEXTURE_GEN_Q); | ||
2451 | 1932 | } | ||
2452 | 1933 | |||
2453 | 1934 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | ||
2454 | 1935 | } | ||
2455 | 1936 | |||
2456 | 1937 | } | ||
2457 | 1938 | break; | ||
2458 | 1939 | case BlurOptions::FilterMipmap: | ||
2459 | 1940 | param = dstFa.allocParameters (2); | ||
2460 | 1941 | unit = dstFa.allocTextureUnits (1); | ||
2461 | 1942 | |||
2462 | 1943 | function = | ||
2463 | 1944 | bScreen->getDstBlurFragmentFunction (texture, param, | ||
2464 | 1945 | unit, 0, 0); | ||
2465 | 1946 | if (function) | ||
2466 | 1947 | { | ||
2467 | 1948 | float lod = | ||
2468 | 1949 | bScreen->optionGetMipmapLod (); | ||
2469 | 1950 | |||
2470 | 1951 | dstFa.addFunction (function); | ||
2471 | 1952 | |||
2472 | 1953 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit); | ||
2473 | 1954 | glBindTexture (bScreen->target, bScreen->texture[0]); | ||
2474 | 1955 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | ||
2475 | 1956 | |||
2476 | 1957 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2477 | 1958 | param, | ||
2478 | 1959 | bScreen->tx, bScreen->ty, | ||
2479 | 1960 | 0.0f, lod); | ||
2480 | 1961 | |||
2481 | 1962 | (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, | ||
2482 | 1963 | param + 1, | ||
2483 | 1964 | threshold, threshold, | ||
2484 | 1965 | threshold, threshold); | ||
2485 | 1966 | } | ||
2486 | 1967 | break; | ||
2487 | 1968 | } | ||
2494 | 1969 | 1984 | ||
2495 | 1970 | if (this->state[state].clipped || | 1985 | if (this->state[state].clipped || |
2496 | 1971 | (!bScreen->blurOcclusion && !clip.isEmpty ())) | 1986 | (!bScreen->blurOcclusion && !clip.isEmpty ())) |
2497 | 1972 | { | 1987 | { |
2498 | 1973 | glEnable (GL_STENCIL_TEST); | 1988 | glEnable (GL_STENCIL_TEST); |
2499 | 1974 | 1989 | ||
2500 | 1990 | /* Don't touch the stencil buffer */ | ||
2501 | 1975 | glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); | 1991 | glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); |
2508 | 1976 | glStencilFunc (GL_EQUAL, 0x1, ~0); | 1992 | |
2509 | 1977 | 1993 | /* Draw region with blur only where the stencil test passes */ | |
2510 | 1978 | /* draw region with destination blur */ | 1994 | glStencilFunc (GL_EQUAL, 1, 1); |
2511 | 1979 | gWindow->glDrawTexture (texture, dstFa, mask); | 1995 | |
2512 | 1980 | 1996 | /* draw region with destination blur - we are relying | |
2513 | 1981 | glStencilFunc (GL_EQUAL, 0, ~0); | 1997 | * on a fairly awkward side-effect here which clears our |
2514 | 1998 | * active shader once this call is complete */ | ||
2515 | 1999 | gWindow->glDrawTexture (texture, matrix, attrib, mask); | ||
2516 | 2000 | |||
2517 | 2001 | /* Allow drawing in everywhere but where we just drew */ | ||
2518 | 2002 | glStencilFunc (GL_EQUAL, 0, 1); | ||
2519 | 1982 | 2003 | ||
2520 | 1983 | /* draw region without destination blur */ | 2004 | /* draw region without destination blur */ |
2522 | 1984 | gWindow->glDrawTexture (texture, fa, mask); | 2005 | gWindow->glDrawTexture (texture, matrix, attrib, mask); |
2523 | 1985 | 2006 | ||
2524 | 1986 | glDisable (GL_STENCIL_TEST); | 2007 | glDisable (GL_STENCIL_TEST); |
2525 | 1987 | } | 2008 | } |
2526 | 1988 | else | 2009 | else |
2527 | 1989 | { | 2010 | { |
2528 | 1990 | /* draw with destination blur */ | 2011 | /* draw with destination blur */ |
2530 | 1991 | gWindow->glDrawTexture (texture, dstFa, mask); | 2012 | gWindow->glDrawTexture (texture, matrix, attrib, mask); |
2531 | 1992 | } | 2013 | } |
2532 | 1993 | } | 2014 | } |
2533 | 1994 | else | 2015 | else |
2534 | 1995 | { | 2016 | { |
2536 | 1996 | gWindow->glDrawTexture (texture, fa, mask); | 2017 | gWindow->glDrawTexture (texture, matrix, attrib, mask); |
2537 | 1997 | } | 2018 | } |
2538 | 1998 | 2019 | ||
2539 | 1999 | if (unit) | 2020 | if (unit) |
2540 | 2000 | { | 2021 | { |
2546 | 2001 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit); | 2022 | (*GL::activeTexture) (GL_TEXTURE0 + unit); |
2547 | 2002 | glBindTexture (bScreen->target, 0); | 2023 | bScreen->texture[0]->disable (); |
2548 | 2003 | (*GL::activeTexture) (GL_TEXTURE0_ARB + unit + 1); | 2024 | (*GL::activeTexture) (GL_TEXTURE0 + unit + 1); |
2549 | 2004 | glBindTexture (bScreen->target, 0); | 2025 | if (bScreen->fbo && |
2550 | 2005 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | 2026 | bScreen->fbo->tex ()) |
2551 | 2027 | bScreen->fbo->tex ()->disable (); | ||
2552 | 2028 | (*GL::activeTexture) (GL_TEXTURE0); | ||
2553 | 2006 | } | 2029 | } |
2554 | 2007 | 2030 | ||
2555 | 2031 | #if INDEPENDENT_TEX_SUPPORTED | ||
2556 | 2008 | if (iTC) | 2032 | if (iTC) |
2557 | 2009 | { | 2033 | { |
2558 | 2010 | int i; | 2034 | int i; |
2559 | 2011 | for (i = gWindow->geometry ().texUnits; | 2035 | for (i = gWindow->geometry ().texUnits; |
2560 | 2012 | i < gWindow->geometry ().texUnits + (2 * iTC); i++) | 2036 | i < gWindow->geometry ().texUnits + (2 * iTC); i++) |
2561 | 2013 | { | 2037 | { |
2563 | 2014 | (*GL::activeTexture) (GL_TEXTURE0_ARB + i); | 2038 | (*GL::activeTexture) (GL_TEXTURE0 + i); |
2564 | 2015 | glDisable (GL_TEXTURE_GEN_S); | 2039 | glDisable (GL_TEXTURE_GEN_S); |
2565 | 2016 | glDisable (GL_TEXTURE_GEN_T); | 2040 | glDisable (GL_TEXTURE_GEN_T); |
2566 | 2017 | glDisable (GL_TEXTURE_GEN_Q); | 2041 | glDisable (GL_TEXTURE_GEN_Q); |
2567 | 2018 | } | 2042 | } |
2569 | 2019 | (*GL::activeTexture) (GL_TEXTURE0_ARB); | 2043 | (*GL::activeTexture) (GL_TEXTURE0); |
2570 | 2020 | } | 2044 | } |
2571 | 2045 | #endif | ||
2572 | 2021 | } | 2046 | } |
2573 | 2022 | else | 2047 | else |
2574 | 2023 | { | 2048 | { |
2576 | 2024 | gWindow->glDrawTexture (texture, attrib, mask); | 2049 | gWindow->glDrawTexture (texture, matrix, attrib, mask); |
2577 | 2025 | } | 2050 | } |
2578 | 2026 | } | 2051 | } |
2579 | 2027 | 2052 | ||
2580 | @@ -2115,7 +2140,7 @@ | |||
2581 | 2115 | screen->activeWindow ()); | 2140 | screen->activeWindow ()); |
2582 | 2116 | 2141 | ||
2583 | 2117 | w = screen->findWindow (xid); | 2142 | w = screen->findWindow (xid); |
2585 | 2118 | if (w && GL::fragmentProgram) | 2143 | if (w && GL::shaders) |
2586 | 2119 | { | 2144 | { |
2587 | 2120 | BLUR_SCREEN (screen); | 2145 | BLUR_SCREEN (screen); |
2588 | 2121 | BLUR_WINDOW (w); | 2146 | BLUR_WINDOW (w); |
2589 | @@ -2175,7 +2200,7 @@ | |||
2590 | 2175 | cScreen->damageScreen (); | 2200 | cScreen->damageScreen (); |
2591 | 2176 | break; | 2201 | break; |
2592 | 2177 | case BlurOptions::AlphaBlur: | 2202 | case BlurOptions::AlphaBlur: |
2594 | 2178 | if (GL::fragmentProgram && optionGetAlphaBlur ()) | 2203 | if (GL::shaders && optionGetAlphaBlur ()) |
2595 | 2179 | alphaBlur = true; | 2204 | alphaBlur = true; |
2596 | 2180 | else | 2205 | else |
2597 | 2181 | alphaBlur = false; | 2206 | alphaBlur = false; |
2598 | @@ -2228,12 +2253,15 @@ | |||
2599 | 2228 | dstBlurFunctions (0), | 2253 | dstBlurFunctions (0), |
2600 | 2229 | output (NULL), | 2254 | output (NULL), |
2601 | 2230 | count (0), | 2255 | count (0), |
2602 | 2231 | program (0), | ||
2603 | 2232 | maxTemp (32), | 2256 | maxTemp (32), |
2606 | 2233 | fbo (0), | 2257 | fbo (new GLFramebufferObject ()), |
2607 | 2234 | fboStatus (0) | 2258 | oldDrawFramebuffer (NULL), |
2608 | 2259 | determineProjectedBlurRegionsPass (false), | ||
2609 | 2260 | damageQuery (cScreen->getDamageQuery (boost::bind ( | ||
2610 | 2261 | &BlurScreen::markAreaDirty, | ||
2611 | 2262 | this, | ||
2612 | 2263 | _1))) | ||
2613 | 2235 | { | 2264 | { |
2614 | 2236 | |||
2615 | 2237 | blurAtom[BLUR_STATE_CLIENT] = | 2265 | blurAtom[BLUR_STATE_CLIENT] = |
2616 | 2238 | XInternAtom (screen->dpy (), "_COMPIZ_WM_WINDOW_BLUR", 0); | 2266 | XInternAtom (screen->dpy (), "_COMPIZ_WM_WINDOW_BLUR", 0); |
2617 | 2239 | blurAtom[BLUR_STATE_DECOR] = | 2267 | blurAtom[BLUR_STATE_DECOR] = |
2618 | @@ -2242,27 +2270,20 @@ | |||
2619 | 2242 | blurTime = 1000.0f / optionGetBlurSpeed (); | 2270 | blurTime = 1000.0f / optionGetBlurSpeed (); |
2620 | 2243 | blurOcclusion = optionGetOcclusion (); | 2271 | blurOcclusion = optionGetOcclusion (); |
2621 | 2244 | 2272 | ||
2622 | 2245 | for (int i = 0; i < 2; i++) | ||
2623 | 2246 | texture[i] = 0; | ||
2624 | 2247 | |||
2625 | 2248 | glGetIntegerv (GL_STENCIL_BITS, &stencilBits); | 2273 | glGetIntegerv (GL_STENCIL_BITS, &stencilBits); |
2626 | 2249 | if (!stencilBits) | 2274 | if (!stencilBits) |
2627 | 2250 | compLogMessage ("blur", CompLogLevelWarn, | 2275 | compLogMessage ("blur", CompLogLevelWarn, |
2628 | 2251 | "No stencil buffer. Region based blur disabled"); | 2276 | "No stencil buffer. Region based blur disabled"); |
2629 | 2252 | 2277 | ||
2632 | 2253 | /* We need GL_ARB_fragment_program for blur */ | 2278 | /* We need GL_ARB_shading_language_100 for blur */ |
2633 | 2254 | if (GL::fragmentProgram) | 2279 | if (GL::shaders) |
2634 | 2255 | alphaBlur = optionGetAlphaBlur (); | 2280 | alphaBlur = optionGetAlphaBlur (); |
2635 | 2256 | else | 2281 | else |
2636 | 2257 | alphaBlur = false; | 2282 | alphaBlur = false; |
2637 | 2258 | 2283 | ||
2639 | 2259 | if (GL::fragmentProgram) | 2284 | if (GL::shaders) |
2640 | 2260 | { | 2285 | { |
2646 | 2261 | int tmp[4]; | 2286 | maxTemp = 1024; // FIXME!!!!!!! |
2642 | 2262 | GL::getProgramiv (GL_FRAGMENT_PROGRAM_ARB, | ||
2643 | 2263 | GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, | ||
2644 | 2264 | tmp); | ||
2645 | 2265 | maxTemp = tmp[0]; | ||
2647 | 2266 | } | 2287 | } |
2648 | 2267 | 2288 | ||
2649 | 2268 | updateFilterRadius (); | 2289 | updateFilterRadius (); |
2650 | @@ -2277,20 +2298,7 @@ | |||
2651 | 2277 | 2298 | ||
2652 | 2278 | BlurScreen::~BlurScreen () | 2299 | BlurScreen::~BlurScreen () |
2653 | 2279 | { | 2300 | { |
2654 | 2280 | foreach (BlurFunction &bf, srcBlurFunctions) | ||
2655 | 2281 | GLFragment::destroyFragmentFunction (bf.id); | ||
2656 | 2282 | foreach (BlurFunction &bf, dstBlurFunctions) | ||
2657 | 2283 | GLFragment::destroyFragmentFunction (bf.id); | ||
2658 | 2284 | |||
2659 | 2285 | cScreen->damageScreen (); | 2301 | cScreen->damageScreen (); |
2660 | 2286 | |||
2661 | 2287 | if (fbo) | ||
2662 | 2288 | (*GL::deleteFramebuffers) (1, &fbo); | ||
2663 | 2289 | |||
2664 | 2290 | for (int i = 0; i < 2; i++) | ||
2665 | 2291 | if (texture[i]) | ||
2666 | 2292 | glDeleteTextures (1, &texture[i]); | ||
2667 | 2293 | |||
2668 | 2294 | } | 2302 | } |
2669 | 2295 | 2303 | ||
2670 | 2296 | BlurWindow::BlurWindow (CompWindow *w) : | 2304 | BlurWindow::BlurWindow (CompWindow *w) : |
2671 | @@ -2329,10 +2337,11 @@ | |||
2672 | 2329 | bool | 2337 | bool |
2673 | 2330 | BlurPluginVTable::init () | 2338 | BlurPluginVTable::init () |
2674 | 2331 | { | 2339 | { |
2679 | 2332 | if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) && | 2340 | if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) | |
2680 | 2333 | CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) && | 2341 | !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) | |
2681 | 2334 | CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI)) | 2342 | !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI)) |
2682 | 2335 | return true; | 2343 | return false; |
2683 | 2336 | 2344 | ||
2685 | 2337 | return false; | 2345 | return true; |
2686 | 2338 | } | 2346 | } |
2687 | 2347 | |||
2688 | 2339 | 2348 | ||
2689 | === modified file 'plugins/blur/src/blur.h' | |||
2690 | --- plugins/blur/src/blur.h 2012-09-07 22:37:20 +0000 | |||
2691 | +++ plugins/blur/src/blur.h 2016-05-14 02:33:05 +0000 | |||
2692 | @@ -23,32 +23,35 @@ | |||
2693 | 23 | * Author: David Reveman <davidr@novell.com> | 23 | * Author: David Reveman <davidr@novell.com> |
2694 | 24 | */ | 24 | */ |
2695 | 25 | 25 | ||
2696 | 26 | #include <iosfwd> | ||
2697 | 27 | #include <boost/shared_ptr.hpp> | ||
2698 | 28 | |||
2699 | 29 | #include <stdlib.h> | ||
2700 | 30 | #include <string.h> | ||
2701 | 31 | #include <math.h> | ||
2702 | 32 | #include <X11/Xatom.h> | ||
2703 | 33 | |||
2704 | 26 | #include "blur_options.h" | 34 | #include "blur_options.h" |
2705 | 27 | 35 | ||
2706 | 28 | #include <composite/composite.h> | 36 | #include <composite/composite.h> |
2707 | 29 | #include <opengl/opengl.h> | 37 | #include <opengl/opengl.h> |
2708 | 38 | #include <opengl/program.h> | ||
2709 | 30 | #include <decoration.h> | 39 | #include <decoration.h> |
2710 | 31 | 40 | ||
2726 | 32 | #include <stdlib.h> | 41 | |
2727 | 33 | #include <string.h> | 42 | const unsigned short BLUR_GAUSSIAN_RADIUS_MAX = 15; |
2728 | 34 | #include <math.h> | 43 | |
2729 | 35 | 44 | const unsigned short BLUR_STATE_CLIENT = 0; | |
2730 | 36 | 45 | const unsigned short BLUR_STATE_DECOR = 1; | |
2731 | 37 | #include <X11/Xatom.h> | 46 | const unsigned short BLUR_STATE_NUM = 2; |
2732 | 38 | #include <GL/glu.h> | 47 | |
2733 | 39 | 48 | struct BlurFunction | |
2734 | 40 | 49 | { | |
2735 | 41 | extern const unsigned short BLUR_GAUSSIAN_RADIUS_MAX; | 50 | CompString shader; |
2721 | 42 | |||
2722 | 43 | struct BlurFunction { | ||
2723 | 44 | |||
2724 | 45 | GLFragment::FunctionId id; | ||
2725 | 46 | |||
2736 | 47 | int target; | 51 | int target; |
2737 | 48 | int param; | ||
2738 | 49 | int unit; | ||
2739 | 50 | int startTC; | 52 | int startTC; |
2740 | 51 | int numITC; | 53 | int numITC; |
2741 | 54 | int saturation; | ||
2742 | 52 | }; | 55 | }; |
2743 | 53 | 56 | ||
2744 | 54 | struct BlurBox { | 57 | struct BlurBox { |
2745 | @@ -56,10 +59,6 @@ | |||
2746 | 56 | decor_point_t p2; | 59 | decor_point_t p2; |
2747 | 57 | }; | 60 | }; |
2748 | 58 | 61 | ||
2749 | 59 | extern const unsigned short BLUR_STATE_CLIENT; | ||
2750 | 60 | extern const unsigned short BLUR_STATE_DECOR; | ||
2751 | 61 | extern const unsigned short BLUR_STATE_NUM; | ||
2752 | 62 | |||
2753 | 63 | struct BlurState { | 62 | struct BlurState { |
2754 | 64 | int threshold; | 63 | int threshold; |
2755 | 65 | std::vector<BlurBox> box; | 64 | std::vector<BlurBox> box; |
2756 | @@ -88,6 +87,8 @@ | |||
2757 | 88 | void preparePaint (int); | 87 | void preparePaint (int); |
2758 | 89 | void donePaint (); | 88 | void donePaint (); |
2759 | 90 | 89 | ||
2760 | 90 | void damageCutoff (); | ||
2761 | 91 | |||
2762 | 91 | bool glPaintOutput (const GLScreenPaintAttrib &, | 92 | bool glPaintOutput (const GLScreenPaintAttrib &, |
2763 | 92 | const GLMatrix &, const CompRegion &, | 93 | const GLMatrix &, const CompRegion &, |
2764 | 93 | CompOutput *, unsigned int); | 94 | CompOutput *, unsigned int); |
2765 | @@ -99,12 +100,11 @@ | |||
2766 | 99 | void updateFilterRadius (); | 100 | void updateFilterRadius (); |
2767 | 100 | void blurReset (); | 101 | void blurReset (); |
2768 | 101 | 102 | ||
2775 | 102 | GLFragment::FunctionId getSrcBlurFragmentFunction (GLTexture *, int); | 103 | const CompString & getSrcBlurFragmentFunction (GLTexture *); |
2776 | 103 | GLFragment::FunctionId getDstBlurFragmentFunction (GLTexture *texture, | 104 | const CompString & getDstBlurFragmentFunction (GLTexture *texture, |
2777 | 104 | int param, | 105 | int unit, |
2778 | 105 | int unit, | 106 | int numITC, |
2779 | 106 | int numITC, | 107 | int startTC); |
2774 | 107 | int startTC); | ||
2780 | 108 | 108 | ||
2781 | 109 | bool projectVertices (CompOutput *output, | 109 | bool projectVertices (CompOutput *output, |
2782 | 110 | const GLMatrix &transform, | 110 | const GLMatrix &transform, |
2783 | @@ -112,8 +112,9 @@ | |||
2784 | 112 | float *scr, | 112 | float *scr, |
2785 | 113 | int n); | 113 | int n); |
2786 | 114 | 114 | ||
2789 | 115 | bool loadFragmentProgram (GLuint *program, | 115 | bool loadFragmentProgram (boost::shared_ptr <GLProgram> &program, |
2790 | 116 | const char *string); | 116 | const char *vertex, |
2791 | 117 | const char *fragment); | ||
2792 | 117 | 118 | ||
2793 | 118 | bool loadFilterProgram (int numITC); | 119 | bool loadFilterProgram (int numITC); |
2794 | 119 | 120 | ||
2795 | @@ -152,24 +153,34 @@ | |||
2796 | 152 | CompOutput *output; | 153 | CompOutput *output; |
2797 | 153 | int count; | 154 | int count; |
2798 | 154 | 155 | ||
2800 | 155 | GLuint texture[2]; | 156 | GLTexture::List texture; |
2801 | 156 | 157 | ||
2802 | 157 | GLenum target; | ||
2803 | 158 | float tx; | 158 | float tx; |
2804 | 159 | float ty; | 159 | float ty; |
2805 | 160 | int width; | 160 | int width; |
2806 | 161 | int height; | 161 | int height; |
2807 | 162 | 162 | ||
2809 | 163 | GLuint program; | 163 | boost::shared_ptr <GLProgram> program; |
2810 | 164 | int maxTemp; | 164 | int maxTemp; |
2813 | 165 | GLuint fbo; | 165 | boost::shared_ptr <GLFramebufferObject> fbo; |
2814 | 166 | bool fboStatus; | 166 | |
2815 | 167 | GLFramebufferObject *oldDrawFramebuffer; | ||
2816 | 167 | 168 | ||
2817 | 168 | float amp[BLUR_GAUSSIAN_RADIUS_MAX]; | 169 | float amp[BLUR_GAUSSIAN_RADIUS_MAX]; |
2818 | 169 | float pos[BLUR_GAUSSIAN_RADIUS_MAX]; | 170 | float pos[BLUR_GAUSSIAN_RADIUS_MAX]; |
2819 | 170 | int numTexop; | 171 | int numTexop; |
2820 | 171 | 172 | ||
2821 | 172 | GLMatrix mvp; | 173 | GLMatrix mvp; |
2822 | 174 | |||
2823 | 175 | bool determineProjectedBlurRegionsPass; | ||
2824 | 176 | bool allowAreaDirtyOnOwnDamageBuffer; | ||
2825 | 177 | CompRegion backbufferUpdateRegionThisFrame; | ||
2826 | 178 | |||
2827 | 179 | compiz::composite::buffertracking::AgeDamageQuery::Ptr damageQuery; | ||
2828 | 180 | |||
2829 | 181 | private: | ||
2830 | 182 | |||
2831 | 183 | bool markAreaDirty (const CompRegion &r); | ||
2832 | 173 | }; | 184 | }; |
2833 | 174 | 185 | ||
2834 | 175 | class BlurWindow : | 186 | class BlurWindow : |
2835 | @@ -188,11 +199,16 @@ | |||
2836 | 188 | 199 | ||
2837 | 189 | bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &, | 200 | bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &, |
2838 | 190 | const CompRegion &, unsigned int); | 201 | const CompRegion &, unsigned int); |
2840 | 191 | bool glDraw (const GLMatrix &, GLFragment::Attrib &, | 202 | void glTransformationComplete (const GLMatrix &matrix, |
2841 | 203 | const CompRegion ®ion, | ||
2842 | 204 | unsigned int mask); | ||
2843 | 205 | |||
2844 | 206 | bool glDraw (const GLMatrix &, const GLWindowPaintAttrib &, | ||
2845 | 192 | const CompRegion &, unsigned int); | 207 | const CompRegion &, unsigned int); |
2847 | 193 | void glDrawTexture (GLTexture *texture, GLFragment::Attrib &, | 208 | void glDrawTexture (GLTexture *texture, |
2848 | 209 | const GLMatrix &, | ||
2849 | 210 | const GLWindowPaintAttrib &, | ||
2850 | 194 | unsigned int); | 211 | unsigned int); |
2851 | 195 | |||
2852 | 196 | void updateRegion (); | 212 | void updateRegion (); |
2853 | 197 | 213 | ||
2854 | 198 | void setBlur (int state, | 214 | void setBlur (int state, |
2855 | @@ -206,9 +222,13 @@ | |||
2856 | 206 | void projectRegion (CompOutput *output, | 222 | void projectRegion (CompOutput *output, |
2857 | 207 | const GLMatrix &transform); | 223 | const GLMatrix &transform); |
2858 | 208 | 224 | ||
2859 | 225 | void determineBlurRegion (int filter, | ||
2860 | 226 | const GLMatrix &transform, | ||
2861 | 227 | int clientThreshold); | ||
2862 | 228 | |||
2863 | 209 | bool updateDstTexture (const GLMatrix &transform, | 229 | bool updateDstTexture (const GLMatrix &transform, |
2864 | 210 | CompRect *pExtents, | 230 | CompRect *pExtents, |
2866 | 211 | int clientThreshold); | 231 | unsigned int mask); |
2867 | 212 | 232 | ||
2868 | 213 | public: | 233 | public: |
2869 | 214 | CompWindow *window; | 234 | CompWindow *window; |
2870 | @@ -225,6 +245,7 @@ | |||
2871 | 225 | 245 | ||
2872 | 226 | CompRegion region; | 246 | CompRegion region; |
2873 | 227 | CompRegion clip; | 247 | CompRegion clip; |
2874 | 248 | CompRegion projectedBlurRegion; | ||
2875 | 228 | }; | 249 | }; |
2876 | 229 | 250 | ||
2877 | 230 | #define BLUR_SCREEN(s) \ | 251 | #define BLUR_SCREEN(s) \ |
2878 | 231 | 252 | ||
2879 | === modified file 'plugins/opengl/DRIVERS' | |||
2880 | --- plugins/opengl/DRIVERS 2013-02-17 07:28:12 +0000 | |||
2881 | +++ plugins/opengl/DRIVERS 2016-05-14 02:33:05 +0000 | |||
2882 | @@ -74,3 +74,13 @@ | |||
2883 | 74 | RESOLVED. WORKAROUND: force the usage of the copy-to-texture path | 74 | RESOLVED. WORKAROUND: force the usage of the copy-to-texture path |
2884 | 75 | when using this driver ("Chromium") and binding an externally | 75 | when using this driver ("Chromium") and binding an externally |
2885 | 76 | managed pixmap to a texture | 76 | managed pixmap to a texture |
2886 | 77 | |||
2887 | 78 | vmwgfx | ||
2888 | 79 | ====== | ||
2889 | 80 | |||
2890 | 81 | 1. vmwgfx does not implement glGenerateMipmap for FBO-backed | ||
2891 | 82 | textures. | ||
2892 | 83 | |||
2893 | 84 | RESOLVED. WORKAROUND: do not use glGenerateMipmap with vmwgfx. This | ||
2894 | 85 | means that some functionality, like smoothed blurs will not be | ||
2895 | 86 | available on this driver. | ||
2896 | 77 | 87 | ||
2897 | === modified file 'plugins/opengl/include/opengl/opengl.h' | |||
2898 | --- plugins/opengl/include/opengl/opengl.h 2015-10-26 17:15:43 +0000 | |||
2899 | +++ plugins/opengl/include/opengl/opengl.h 2016-05-14 02:33:05 +0000 | |||
2900 | @@ -59,7 +59,7 @@ | |||
2901 | 59 | #include <opengl/programcache.h> | 59 | #include <opengl/programcache.h> |
2902 | 60 | #include <opengl/shadercache.h> | 60 | #include <opengl/shadercache.h> |
2903 | 61 | 61 | ||
2905 | 62 | #define COMPIZ_OPENGL_ABI 7 | 62 | #define COMPIZ_OPENGL_ABI 8 |
2906 | 63 | 63 | ||
2907 | 64 | /* | 64 | /* |
2908 | 65 | * Some plugins check for #ifdef USE_MODERN_COMPIZ_GL. Support it for now, but | 65 | * Some plugins check for #ifdef USE_MODERN_COMPIZ_GL. Support it for now, but |
2909 | @@ -851,6 +851,8 @@ | |||
2910 | 851 | 851 | ||
2911 | 852 | bool glInitContext (XVisualInfo *); | 852 | bool glInitContext (XVisualInfo *); |
2912 | 853 | 853 | ||
2913 | 854 | bool driverHasBrokenFBOMipmaps () const; | ||
2914 | 855 | |||
2915 | 854 | WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput, | 856 | WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput, |
2916 | 855 | const GLScreenPaintAttrib &, const GLMatrix &, | 857 | const GLScreenPaintAttrib &, const GLMatrix &, |
2917 | 856 | const CompRegion &, CompOutput *, unsigned int); | 858 | const CompRegion &, CompOutput *, unsigned int); |
2918 | @@ -957,12 +959,20 @@ | |||
2919 | 957 | unsigned int max = MAXSHORT); | 959 | unsigned int max = MAXSHORT); |
2920 | 958 | virtual void glDrawTexture (GLTexture *texture, const GLMatrix &, | 960 | virtual void glDrawTexture (GLTexture *texture, const GLMatrix &, |
2921 | 959 | const GLWindowPaintAttrib &, unsigned int); | 961 | const GLWindowPaintAttrib &, unsigned int); |
2922 | 962 | |||
2923 | 963 | /** | ||
2924 | 964 | * Hookable function to notify transformation was complete, plugins | ||
2925 | 965 | * should use the results of transformation from glPaint here | ||
2926 | 966 | */ | ||
2927 | 967 | virtual void glTransformationComplete (const GLMatrix &matrix, | ||
2928 | 968 | const CompRegion ®ion, | ||
2929 | 969 | unsigned int mask); | ||
2930 | 960 | }; | 970 | }; |
2931 | 961 | 971 | ||
2932 | 962 | extern template class PluginClassHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI>; | 972 | extern template class PluginClassHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI>; |
2933 | 963 | 973 | ||
2934 | 964 | class GLWindow : | 974 | class GLWindow : |
2936 | 965 | public WrapableHandler<GLWindowInterface, 4>, | 975 | public WrapableHandler<GLWindowInterface, 5>, |
2937 | 966 | public PluginClassHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI> | 976 | public PluginClassHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI> |
2938 | 967 | { | 977 | { |
2939 | 968 | public: | 978 | public: |
2940 | @@ -1041,6 +1051,8 @@ | |||
2941 | 1041 | WRAPABLE_HND (3, GLWindowInterface, void, glDrawTexture, | 1051 | WRAPABLE_HND (3, GLWindowInterface, void, glDrawTexture, |
2942 | 1042 | GLTexture *texture, const GLMatrix &, | 1052 | GLTexture *texture, const GLMatrix &, |
2943 | 1043 | const GLWindowPaintAttrib &, unsigned int); | 1053 | const GLWindowPaintAttrib &, unsigned int); |
2944 | 1054 | WRAPABLE_HND (4, GLWindowInterface, void, glTransformationComplete, | ||
2945 | 1055 | const GLMatrix &, const CompRegion &, unsigned int); | ||
2946 | 1044 | 1056 | ||
2947 | 1045 | friend class GLScreen; | 1057 | friend class GLScreen; |
2948 | 1046 | friend class PrivateGLScreen; | 1058 | friend class PrivateGLScreen; |
2949 | 1047 | 1059 | ||
2950 | === modified file 'plugins/opengl/include/opengl/program.h' | |||
2951 | --- plugins/opengl/include/opengl/program.h 2012-05-17 10:41:21 +0000 | |||
2952 | +++ plugins/opengl/include/opengl/program.h 2016-05-14 02:33:05 +0000 | |||
2953 | @@ -40,7 +40,7 @@ | |||
2954 | 40 | class GLProgram | 40 | class GLProgram |
2955 | 41 | { | 41 | { |
2956 | 42 | public: | 42 | public: |
2958 | 43 | GLProgram (CompString &vertexShader, CompString &fragmentShader); | 43 | GLProgram (const CompString &vertexShader, const CompString &fragmentShader); |
2959 | 44 | ~GLProgram (); | 44 | ~GLProgram (); |
2960 | 45 | 45 | ||
2961 | 46 | bool valid (); | 46 | bool valid (); |
2962 | 47 | 47 | ||
2963 | === modified file 'plugins/opengl/include/opengl/vertexbuffer.h' | |||
2964 | --- plugins/opengl/include/opengl/vertexbuffer.h 2012-08-14 06:33:22 +0000 | |||
2965 | +++ plugins/opengl/include/opengl/vertexbuffer.h 2016-05-14 02:33:05 +0000 | |||
2966 | @@ -89,6 +89,7 @@ | |||
2967 | 89 | void addTexCoords (GLuint texture, | 89 | void addTexCoords (GLuint texture, |
2968 | 90 | GLuint nTexcoords, | 90 | GLuint nTexcoords, |
2969 | 91 | const GLfloat *texcoords); | 91 | const GLfloat *texcoords); |
2970 | 92 | GLuint countTextures () const; | ||
2971 | 92 | 93 | ||
2972 | 93 | void addUniform (const char *name, GLfloat value); | 94 | void addUniform (const char *name, GLfloat value); |
2973 | 94 | void addUniform (const char *name, GLint value); | 95 | void addUniform (const char *name, GLint value); |
2974 | 95 | 96 | ||
2975 | === modified file 'plugins/opengl/src/paint.cpp' | |||
2976 | --- plugins/opengl/src/paint.cpp 2015-04-07 14:20:32 +0000 | |||
2977 | +++ plugins/opengl/src/paint.cpp 2016-05-14 02:33:05 +0000 | |||
2978 | @@ -1367,6 +1367,14 @@ | |||
2979 | 1367 | return true; | 1367 | return true; |
2980 | 1368 | } | 1368 | } |
2981 | 1369 | 1369 | ||
2982 | 1370 | void | ||
2983 | 1371 | GLWindow::glTransformationComplete (const GLMatrix &matrix, | ||
2984 | 1372 | const CompRegion ®, | ||
2985 | 1373 | unsigned int mask) | ||
2986 | 1374 | { | ||
2987 | 1375 | WRAPABLE_HND_FUNCTN (glTransformationComplete, matrix, reg, mask); | ||
2988 | 1376 | } | ||
2989 | 1377 | |||
2990 | 1370 | bool | 1378 | bool |
2991 | 1371 | GLWindow::glPaint (const GLWindowPaintAttrib &attrib, | 1379 | GLWindow::glPaint (const GLWindowPaintAttrib &attrib, |
2992 | 1372 | const GLMatrix &transform, | 1380 | const GLMatrix &transform, |
2993 | @@ -1384,6 +1392,8 @@ | |||
2994 | 1384 | 1392 | ||
2995 | 1385 | priv->lastMask = mask; | 1393 | priv->lastMask = mask; |
2996 | 1386 | 1394 | ||
2997 | 1395 | glTransformationComplete (transform, region, mask); | ||
2998 | 1396 | |||
2999 | 1387 | if (mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) | 1397 | if (mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) |
3000 | 1388 | { | 1398 | { |
3001 | 1389 | if (mask & PAINT_WINDOW_TRANSFORMED_MASK) | 1399 | if (mask & PAINT_WINDOW_TRANSFORMED_MASK) |
3002 | 1390 | 1400 | ||
3003 | === modified file 'plugins/opengl/src/privates.h' | |||
3004 | --- plugins/opengl/src/privates.h 2015-10-26 17:15:43 +0000 | |||
3005 | +++ plugins/opengl/src/privates.h 2016-05-14 02:33:05 +0000 | |||
3006 | @@ -131,6 +131,7 @@ | |||
3007 | 131 | virtual ~FrameProvider () {} | 131 | virtual ~FrameProvider () {} |
3008 | 132 | 132 | ||
3009 | 133 | virtual GLuint getCurrentFrame () = 0; | 133 | virtual GLuint getCurrentFrame () = 0; |
3010 | 134 | virtual void useCurrentFrame () = 0; | ||
3011 | 134 | virtual void endFrame () = 0; | 135 | virtual void endFrame () = 0; |
3012 | 135 | 136 | ||
3013 | 136 | virtual bool providesPersistence () = 0; | 137 | virtual bool providesPersistence () = 0; |
3014 | @@ -268,6 +269,8 @@ | |||
3015 | 268 | std::vector<XToGLSync*>::size_type currentSyncNum; | 269 | std::vector<XToGLSync*>::size_type currentSyncNum; |
3016 | 269 | XToGLSync *currentSync; | 270 | XToGLSync *currentSync; |
3017 | 270 | std::vector<XToGLSync*>::size_type warmupSyncs; | 271 | std::vector<XToGLSync*>::size_type warmupSyncs; |
3018 | 272 | |||
3019 | 273 | bool driverHasBrokenFBOMipmapImplementation; | ||
3020 | 271 | }; | 274 | }; |
3021 | 272 | 275 | ||
3022 | 273 | class PrivateGLWindow : | 276 | class PrivateGLWindow : |
3023 | 274 | 277 | ||
3024 | === modified file 'plugins/opengl/src/program.cpp' | |||
3025 | --- plugins/opengl/src/program.cpp 2012-12-04 12:15:34 +0000 | |||
3026 | +++ plugins/opengl/src/program.cpp 2016-05-14 02:33:05 +0000 | |||
3027 | @@ -69,7 +69,7 @@ | |||
3028 | 69 | } | 69 | } |
3029 | 70 | } | 70 | } |
3030 | 71 | 71 | ||
3032 | 72 | static bool compileShader (GLuint *shader, GLenum type, CompString &source) | 72 | static bool compileShader (GLuint *shader, GLenum type, const CompString &source) |
3033 | 73 | { | 73 | { |
3034 | 74 | const GLchar *data; | 74 | const GLchar *data; |
3035 | 75 | GLint status; | 75 | GLint status; |
3036 | @@ -84,7 +84,7 @@ | |||
3037 | 84 | return (status == GL_TRUE); | 84 | return (status == GL_TRUE); |
3038 | 85 | } | 85 | } |
3039 | 86 | 86 | ||
3041 | 87 | GLProgram::GLProgram (CompString &vertexShader, CompString &fragmentShader) : | 87 | GLProgram::GLProgram (const CompString &vertexShader, const CompString &fragmentShader) : |
3042 | 88 | priv (new PrivateProgram ()) | 88 | priv (new PrivateProgram ()) |
3043 | 89 | { | 89 | { |
3044 | 90 | GLuint vertex, fragment; | 90 | GLuint vertex, fragment; |
3045 | 91 | 91 | ||
3046 | === modified file 'plugins/opengl/src/screen.cpp' | |||
3047 | --- plugins/opengl/src/screen.cpp 2015-10-26 17:15:43 +0000 | |||
3048 | +++ plugins/opengl/src/screen.cpp 2016-05-14 02:33:05 +0000 | |||
3049 | @@ -345,6 +345,10 @@ | |||
3050 | 345 | return age; | 345 | return age; |
3051 | 346 | } | 346 | } |
3052 | 347 | 347 | ||
3053 | 348 | void useCurrentFrame () | ||
3054 | 349 | { | ||
3055 | 350 | } | ||
3056 | 351 | |||
3057 | 348 | void endFrame () | 352 | void endFrame () |
3058 | 349 | { | 353 | { |
3059 | 350 | } | 354 | } |
3060 | @@ -436,6 +440,10 @@ | |||
3061 | 436 | return 0; | 440 | return 0; |
3062 | 437 | } | 441 | } |
3063 | 438 | 442 | ||
3064 | 443 | void useCurrentFrame () | ||
3065 | 444 | { | ||
3066 | 445 | } | ||
3067 | 446 | |||
3068 | 439 | void endFrame () | 447 | void endFrame () |
3069 | 440 | { | 448 | { |
3070 | 441 | } | 449 | } |
3071 | @@ -468,12 +476,14 @@ | |||
3072 | 468 | 476 | ||
3073 | 469 | unsigned int getCurrentFrame () | 477 | unsigned int getCurrentFrame () |
3074 | 470 | { | 478 | { |
3075 | 479 | return mAge; | ||
3076 | 480 | } | ||
3077 | 481 | |||
3078 | 482 | void useCurrentFrame () | ||
3079 | 483 | { | ||
3080 | 471 | /* We are now using this buffer, reset | 484 | /* We are now using this buffer, reset |
3081 | 472 | * age back to zero */ | 485 | * age back to zero */ |
3082 | 473 | unsigned int lastAge = mAge; | ||
3083 | 474 | mAge = 0; | 486 | mAge = 0; |
3084 | 475 | |||
3085 | 476 | return lastAge; | ||
3086 | 477 | } | 487 | } |
3087 | 478 | 488 | ||
3088 | 479 | void endFrame () | 489 | void endFrame () |
3089 | @@ -526,6 +536,14 @@ | |||
3090 | 526 | return mBackbuffer->getCurrentFrame (); | 536 | return mBackbuffer->getCurrentFrame (); |
3091 | 527 | } | 537 | } |
3092 | 528 | 538 | ||
3093 | 539 | void useCurrentFrame () | ||
3094 | 540 | { | ||
3095 | 541 | if (mPPRequired ()) | ||
3096 | 542 | mScratchbuffer->useCurrentFrame (); | ||
3097 | 543 | else | ||
3098 | 544 | mBackbuffer->useCurrentFrame (); | ||
3099 | 545 | } | ||
3100 | 546 | |||
3101 | 529 | void endFrame () | 547 | void endFrame () |
3102 | 530 | { | 548 | { |
3103 | 531 | mScratchbuffer->endFrame (); | 549 | mScratchbuffer->endFrame (); |
3104 | @@ -896,6 +914,20 @@ | |||
3105 | 896 | priv->incorrectRefreshRate = true; | 914 | priv->incorrectRefreshRate = true; |
3106 | 897 | } | 915 | } |
3107 | 898 | 916 | ||
3108 | 917 | if (glVendor != NULL && strstr (glVendor, "VMware") && | ||
3109 | 918 | glRenderer != NULL && strstr (glRenderer, "on SVGA3D")) | ||
3110 | 919 | { | ||
3111 | 920 | /* vmwgfx has an incomplete glGenerateMipmap implementation. | ||
3112 | 921 | * It does not seem to support generating mipmaps for | ||
3113 | 922 | * FBO backed textures - instead it raises SIGABRT with | ||
3114 | 923 | * an exception stating that the command does not exist. | ||
3115 | 924 | * | ||
3116 | 925 | * This is actually supported in the spec, it just seems | ||
3117 | 926 | * to be unavailable in the driver. | ||
3118 | 927 | */ | ||
3119 | 928 | priv->driverHasBrokenFBOMipmapImplementation = true; | ||
3120 | 929 | } | ||
3121 | 930 | |||
3122 | 899 | if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two")) | 931 | if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two")) |
3123 | 900 | GL::textureNonPowerOfTwo = true; | 932 | GL::textureNonPowerOfTwo = true; |
3124 | 901 | GL::textureNonPowerOfTwoMipmap = GL::textureNonPowerOfTwo; | 933 | GL::textureNonPowerOfTwoMipmap = GL::textureNonPowerOfTwo; |
3125 | @@ -1163,6 +1195,12 @@ | |||
3126 | 1163 | return true; | 1195 | return true; |
3127 | 1164 | } | 1196 | } |
3128 | 1165 | 1197 | ||
3129 | 1198 | bool | ||
3130 | 1199 | GLScreen::driverHasBrokenFBOMipmaps () const | ||
3131 | 1200 | { | ||
3132 | 1201 | return priv->driverHasBrokenFBOMipmapImplementation; | ||
3133 | 1202 | } | ||
3134 | 1203 | |||
3135 | 1166 | 1204 | ||
3136 | 1167 | template class PluginClassHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI>; | 1205 | template class PluginClassHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI>; |
3137 | 1168 | 1206 | ||
3138 | @@ -1536,7 +1574,8 @@ | |||
3139 | 1536 | prevBlacklisted (false), | 1574 | prevBlacklisted (false), |
3140 | 1537 | currentSyncNum (0), | 1575 | currentSyncNum (0), |
3141 | 1538 | currentSync (0), | 1576 | currentSync (0), |
3143 | 1539 | warmupSyncs (0) | 1577 | warmupSyncs (0), |
3144 | 1578 | driverHasBrokenFBOMipmapImplementation (false) | ||
3145 | 1540 | { | 1579 | { |
3146 | 1541 | ScreenInterface::setHandler (screen); | 1580 | ScreenInterface::setHandler (screen); |
3147 | 1542 | CompositeScreenInterface::setHandler (cScreen); | 1581 | CompositeScreenInterface::setHandler (cScreen); |
3148 | @@ -2608,6 +2647,7 @@ | |||
3149 | 2608 | PrivateGLScreen::damageCutoff () | 2647 | PrivateGLScreen::damageCutoff () |
3150 | 2609 | { | 2648 | { |
3151 | 2610 | cScreen->applyDamageForFrameAge (frameProvider->getCurrentFrame ()); | 2649 | cScreen->applyDamageForFrameAge (frameProvider->getCurrentFrame ()); |
3152 | 2650 | frameProvider->useCurrentFrame (); | ||
3153 | 2611 | cScreen->damageCutoff (); | 2651 | cScreen->damageCutoff (); |
3154 | 2612 | } | 2652 | } |
3155 | 2613 | 2653 | ||
3156 | 2614 | 2654 | ||
3157 | === modified file 'plugins/opengl/src/shadercache.cpp' | |||
3158 | --- plugins/opengl/src/shadercache.cpp 2014-10-30 12:47:25 +0000 | |||
3159 | +++ plugins/opengl/src/shadercache.cpp 2016-05-14 02:33:05 +0000 | |||
3160 | @@ -232,10 +232,11 @@ | |||
3161 | 232 | else if (params.color == GLShaderVariableVarying) | 232 | else if (params.color == GLShaderVariableVarying) |
3162 | 233 | ss << "vColor *"; | 233 | ss << "vColor *"; |
3163 | 234 | 234 | ||
3168 | 235 | for (int i = 0; i < params.numTextures; i++) | 235 | /* Sample first texture only */ |
3169 | 236 | ss << " texture2D(texture" << i << ", vTexCoord" << i << ") *"; | 236 | if (params.numTextures) |
3170 | 237 | 237 | ss << " texture2D(texture0, vTexCoord0);\n"; | |
3171 | 238 | ss << " 1.0;\n"; | 238 | else |
3172 | 239 | ss << " 1.0;\n"; | ||
3173 | 239 | 240 | ||
3174 | 240 | if (params.saturation) { | 241 | if (params.saturation) { |
3175 | 241 | ss << "vec3 desaturated = color.rgb * vec3 (0.30, 0.59, 0.11);\n" << | 242 | ss << "vec3 desaturated = color.rgb * vec3 (0.30, 0.59, 0.11);\n" << |
3176 | 242 | 243 | ||
3177 | === modified file 'plugins/opengl/src/vertexbuffer.cpp' | |||
3178 | --- plugins/opengl/src/vertexbuffer.cpp 2015-04-29 11:15:48 +0000 | |||
3179 | +++ plugins/opengl/src/vertexbuffer.cpp 2016-05-14 02:33:05 +0000 | |||
3180 | @@ -240,6 +240,11 @@ | |||
3181 | 240 | data.push_back (texcoords[i]); | 240 | data.push_back (texcoords[i]); |
3182 | 241 | } | 241 | } |
3183 | 242 | 242 | ||
3184 | 243 | GLuint GLVertexBuffer::countTextures () const | ||
3185 | 244 | { | ||
3186 | 245 | return priv->nTextures; | ||
3187 | 246 | } | ||
3188 | 247 | |||
3189 | 243 | void GLVertexBuffer::addUniform (const char *name, GLfloat value) | 248 | void GLVertexBuffer::addUniform (const char *name, GLfloat value) |
3190 | 244 | { | 249 | { |
3191 | 245 | // we're casting to double here to make our template va_arg happy | 250 | // we're casting to double here to make our template va_arg happy |
3192 | 246 | 251 | ||
3193 | === modified file 'plugins/opengl/src/window.cpp' | |||
3194 | --- plugins/opengl/src/window.cpp 2014-10-30 12:47:25 +0000 | |||
3195 | +++ plugins/opengl/src/window.cpp 2016-05-14 02:33:05 +0000 | |||
3196 | @@ -210,6 +210,12 @@ | |||
3197 | 210 | priv->needsRebind = true; | 210 | priv->needsRebind = true; |
3198 | 211 | } | 211 | } |
3199 | 212 | 212 | ||
3200 | 213 | void | ||
3201 | 214 | GLWindowInterface::glTransformationComplete (const GLMatrix &matrix, | ||
3202 | 215 | const CompRegion ®ion, | ||
3203 | 216 | unsigned int mask) | ||
3204 | 217 | WRAPABLE_DEF (glTransformationComplete, matrix, region, mask) | ||
3205 | 218 | |||
3206 | 213 | bool | 219 | bool |
3207 | 214 | GLWindowInterface::glPaint (const GLWindowPaintAttrib &attrib, | 220 | GLWindowInterface::glPaint (const GLWindowPaintAttrib &attrib, |
3208 | 215 | const GLMatrix &transform, | 221 | const GLMatrix &transform, |
FAILED: Continuous integration, rev:4018 jenkins. qa.ubuntu. com/job/ compiz- ci/126/ jenkins. qa.ubuntu. com/job/ compiz- xenial- amd64-ci/ 17/console jenkins. qa.ubuntu. com/job/ compiz- xenial- armhf-ci/ 17 jenkins. qa.ubuntu. com/job/ compiz- xenial- i386-ci/ 17/console
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/compiz- ci/126/ rebuild
http://