From bd51daf02e27277ad542b133724b563b0ad3028a Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Wed, 31 Jan 2024 16:38:52 -0500 Subject: [PATCH] Fix filters run on framebuffers with different sizes from the main canvas --- src/webgl/p5.RendererGL.js | 4 +- test/unit/visual/cases/webgl.js | 46 ++++++++++++++++++ .../000.png | Bin 0 -> 415 bytes .../metadata.json | 3 ++ .../WebGL/filter/On a framebuffer/000.png | Bin 0 -> 415 bytes .../filter/On a framebuffer/metadata.json | 3 ++ .../WebGL/filter/On the main canvas/000.png | Bin 0 -> 413 bytes .../filter/On the main canvas/metadata.json | 3 ++ 8 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png create mode 100644 test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json create mode 100644 test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png create mode 100644 test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json create mode 100644 test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png create mode 100644 test/unit/visual/screenshots/WebGL/filter/On the main canvas/metadata.json diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index dbcfbca1b4..7f1069bfd5 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1125,8 +1125,8 @@ p5.RendererGL = class RendererGL extends p5.Renderer { target.filterCamera._resize(); this._pInst.setCamera(target.filterCamera); this._pInst.resetMatrix(); - this._pInst.image(fbo, -this.width / 2, -this.height / 2, - this.width, this.height); + this._pInst.image(fbo, -target.width / 2, -target.height / 2, + target.width, target.height); this._pInst.pop(); this._pInst.pop(); } diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index c45ebda9a5..0e1b7269e7 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -24,6 +24,52 @@ visualSuite('WebGL', function() { }); }); + visualSuite('filter', function() { + visualTest('On the main canvas', function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + screenshot(); + }); + + visualTest('On a framebuffer', function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + const fbo = p5.createFramebuffer({ antialias: true }); + fbo.begin(); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + fbo.end(); + p5.imageMode(p5.CENTER); + p5.image(fbo, 0, 0); + screenshot(); + }); + + visualTest( + 'On a framebuffer sized differently from the main canvas', + function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + const fbo = p5.createFramebuffer({ + width: 26, + height: 26, + antialias: true + }); + fbo.begin(); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + fbo.end(); + p5.imageMode(p5.CENTER); + p5.image(fbo, 0, 0); + screenshot(); + } + ); + }); + visualSuite('Lights', function() { visualTest('Fill color and default ambient material', function(p5, screenshot) { p5.createCanvas(50, 50, p5.WEBGL); diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png new file mode 100644 index 0000000000000000000000000000000000000000..90ccca1c5d13db664c01a5d531db4fc7f75adc6f GIT binary patch literal 415 zcmV;Q0bu@#P)Px$SxH1eRA@u(mq8AKFc3wD9;#udo=iNMvLihdnjvk{xFBWbPfEzRQ6p{V{nx@c z&_!OuML5Vo&Suh$xDlfSd}|p6E1uSkh@&$a=thi!6;JC%#L*cIG%+%c<9%J%Dc5|< z?=um7_;X6B{075Z#d_`O13NFW$UjFD4*9*h_U0|6026lMsF8bk@P!GsVV%d%|e zNBTm5e5H$5?@6{FOV}`mZjx>`(v`BMrA$vr9~jm{q$o zv4iwTeQ!-S;zo=T@U3MOtaw^CB96{zpc^p?Ry?g65l3e<@CO#ya5L>M^&$WO002ov JPDHLkV1kc~sw)5h literal 0 HcmV?d00001 diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png new file mode 100644 index 0000000000000000000000000000000000000000..90ccca1c5d13db664c01a5d531db4fc7f75adc6f GIT binary patch literal 415 zcmV;Q0bu@#P)Px$SxH1eRA@u(mq8AKFc3wD9;#udo=iNMvLihdnjvk{xFBWbPfEzRQ6p{V{nx@c z&_!OuML5Vo&Suh$xDlfSd}|p6E1uSkh@&$a=thi!6;JC%#L*cIG%+%c<9%J%Dc5|< z?=um7_;X6B{075Z#d_`O13NFW$UjFD4*9*h_U0|6026lMsF8bk@P!GsVV%d%|e zNBTm5e5H$5?@6{FOV}`mZjx>`(v`BMrA$vr9~jm{q$o zv4iwTeQ!-S;zo=T@U3MOtaw^CB96{zpc^p?Ry?g65l3e<@CO#ya5L>M^&$WO002ov JPDHLkV1kc~sw)5h literal 0 HcmV?d00001 diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file diff --git a/test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png b/test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png new file mode 100644 index 0000000000000000000000000000000000000000..176f683c628ab19faf547846bee2a13d8d9f197a GIT binary patch literal 413 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-#^NA%Cx&(BWL^T<;hrvzAsNnZ zr#tdB83?$_@`c{eRCo4U_HIFYl8@(Xf#fM?{`a==NME#A`hLHrh^6e43C#s_WS-pj z*(GQmq{*1S*6ZM`_EP0%FSJB=O+>K6427I_Ec@AYA~IC}=bw4@$1`VLD}Lt4dXnMr zcFwL7u`VkdOeX9V(4UapQ@FKVPDDW2Wu`SN8{5lW?>6b2=JgS2YjnJ|ZSPdp-UCM@ z7VdO7sv6A? z?JCu`-Ww?RUjA|-O(;rv%{QmqHM?Kg-m?G8ekXmc^I|g%g_~TP!WOV6a!Q&7u^G); z=y0J&WX6{7L01!>t4(5aWUplPy1#w>u2sK0_HT?^wk>=5wWt@q%xlX9OdQMhN++s! z^*wjHz;g3zUdvn!t9jCn!YS8x3zjW