* Applies the current filter operation. If the filter requires multiple passes (e.g. blur), * it handles those internally. Make sure setOperation() has been called before applyFilter().
()
| 445 | * it handles those internally. Make sure setOperation() has been called before applyFilter(). |
| 446 | */ |
| 447 | applyFilter() { |
| 448 | if (!this._shader) { |
| 449 | console.error('Cannot apply filter: shader not initialized.'); |
| 450 | return; |
| 451 | } |
| 452 | this.parentRenderer.push(); |
| 453 | this.parentRenderer.resetMatrix(); |
| 454 | // For blur, we typically do two passes: one horizontal, one vertical. |
| 455 | if (this.operation === constants.BLUR && !this.customShader) { |
| 456 | // Horizontal pass |
| 457 | this._shader.setUniform('direction', [1, 0]); |
| 458 | this._renderPass(); |
| 459 | |
| 460 | // Draw the result onto itself |
| 461 | this.parentRenderer.clear(); |
| 462 | this.parentRenderer.drawingContext.drawImage( |
| 463 | this.canvas, |
| 464 | 0, 0, |
| 465 | this.parentRenderer.width, this.parentRenderer.height |
| 466 | ); |
| 467 | |
| 468 | // Vertical pass |
| 469 | this._shader.setUniform('direction', [0, 1]); |
| 470 | this._renderPass(); |
| 471 | |
| 472 | this.parentRenderer.clear(); |
| 473 | this.parentRenderer.drawingContext.drawImage( |
| 474 | this.canvas, |
| 475 | 0, 0, |
| 476 | this.parentRenderer.width, this.parentRenderer.height |
| 477 | ); |
| 478 | } else { |
| 479 | // Single-pass filters |
| 480 | |
| 481 | this._renderPass(); |
| 482 | this.parentRenderer.clear(); |
| 483 | // con |
| 484 | this.parentRenderer.blendMode(constants.BLEND); |
| 485 | |
| 486 | |
| 487 | this.parentRenderer.drawingContext.drawImage( |
| 488 | this.canvas, |
| 489 | 0, 0, |
| 490 | this.parentRenderer.width, this.parentRenderer.height |
| 491 | ); |
| 492 | } |
| 493 | this.parentRenderer.pop(); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | export default FilterRenderer2D; |
no test coverage detected