Skip to content

Commit 8a9d9f6

Browse files
authored
Merge pull request #6783 from davepagurek/fix/filter-on-framebuffer
Fix filters run on framebuffers with different sizes from the main canvas
2 parents 3d45ce9 + bd51daf commit 8a9d9f6

File tree

8 files changed

+57
-2
lines changed

8 files changed

+57
-2
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,8 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
11251125
target.filterCamera._resize();
11261126
this._pInst.setCamera(target.filterCamera);
11271127
this._pInst.resetMatrix();
1128-
this._pInst.image(fbo, -this.width / 2, -this.height / 2,
1129-
this.width, this.height);
1128+
this._pInst.image(fbo, -target.width / 2, -target.height / 2,
1129+
target.width, target.height);
11301130
this._pInst.pop();
11311131
this._pInst.pop();
11321132
}

test/unit/visual/cases/webgl.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ visualSuite('WebGL', function() {
2424
});
2525
});
2626

27+
visualSuite('filter', function() {
28+
visualTest('On the main canvas', function(p5, screenshot) {
29+
p5.createCanvas(50, 50, p5.WEBGL);
30+
p5.noStroke();
31+
p5.fill('red');
32+
p5.circle(0, 0, 20);
33+
p5.filter(p5.GRAY);
34+
screenshot();
35+
});
36+
37+
visualTest('On a framebuffer', function(p5, screenshot) {
38+
p5.createCanvas(50, 50, p5.WEBGL);
39+
const fbo = p5.createFramebuffer({ antialias: true });
40+
fbo.begin();
41+
p5.noStroke();
42+
p5.fill('red');
43+
p5.circle(0, 0, 20);
44+
p5.filter(p5.GRAY);
45+
fbo.end();
46+
p5.imageMode(p5.CENTER);
47+
p5.image(fbo, 0, 0);
48+
screenshot();
49+
});
50+
51+
visualTest(
52+
'On a framebuffer sized differently from the main canvas',
53+
function(p5, screenshot) {
54+
p5.createCanvas(50, 50, p5.WEBGL);
55+
const fbo = p5.createFramebuffer({
56+
width: 26,
57+
height: 26,
58+
antialias: true
59+
});
60+
fbo.begin();
61+
p5.noStroke();
62+
p5.fill('red');
63+
p5.circle(0, 0, 20);
64+
p5.filter(p5.GRAY);
65+
fbo.end();
66+
p5.imageMode(p5.CENTER);
67+
p5.image(fbo, 0, 0);
68+
screenshot();
69+
}
70+
);
71+
});
72+
2773
visualSuite('Lights', function() {
2874
visualTest('Fill color and default ambient material', function(p5, screenshot) {
2975
p5.createCanvas(50, 50, p5.WEBGL);
415 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
415 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
413 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)