Skip to content

Commit

Permalink
Merge pull request #6783 from davepagurek/fix/filter-on-framebuffer
Browse files Browse the repository at this point in the history
Fix filters run on framebuffers with different sizes from the main canvas
  • Loading branch information
davepagurek authored Jan 31, 2024
2 parents 3d45ce9 + bd51daf commit 8a9d9f6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
46 changes: 46 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}

0 comments on commit 8a9d9f6

Please sign in to comment.