Skip to content

Commit ef4aa35

Browse files
committed
Fix main canvas clipping getting applied to framebuffers
1 parent 918c643 commit ef4aa35

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/webgl/p5.Framebuffer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ class Framebuffer {
849849
this.target._renderer.uMVMatrix.set(
850850
this.target._renderer._curCamera.cameraMatrix
851851
);
852+
this.target._renderer._applyStencilTestIfClipping();
852853
}
853854

854855
/**

test/unit/webgl/p5.RendererGL.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,5 +2462,42 @@ suite('p5.RendererGL', function() {
24622462
}
24632463
}
24642464
);
2465+
2466+
test(
2467+
'Main canvas masks do not apply to framebuffers',
2468+
function() {
2469+
myp5.createCanvas(50, 50, myp5.WEBGL);
2470+
const fbo = myp5.createFramebuffer({ antialias: false });
2471+
myp5.rectMode(myp5.CENTER);
2472+
myp5.background('red');
2473+
expect(myp5._renderer._stencilTestOn).to.equal(false);
2474+
myp5.push();
2475+
myp5.beginClip();
2476+
myp5.rect(-20, -20, 40, 40);
2477+
myp5.endClip();
2478+
expect(myp5._renderer._stencilTestOn).to.equal(true);
2479+
2480+
fbo.begin();
2481+
expect(myp5._renderer._stencilTestOn).to.equal(false);
2482+
myp5.noStroke();
2483+
myp5.fill('blue');
2484+
myp5.rect(0, 0, myp5.width, myp5.height);
2485+
fbo.end();
2486+
2487+
expect(myp5._renderer._stencilTestOn).to.equal(true);
2488+
myp5.pop();
2489+
expect(myp5._renderer._stencilTestOn).to.equal(false);
2490+
2491+
myp5.imageMode(myp5.CENTER);
2492+
myp5.image(fbo, 0, 0);
2493+
2494+
// In the middle of the canvas, the framebuffer's clip and the
2495+
// main canvas's clip intersect, so the blue should show through
2496+
assert.deepEqual(
2497+
myp5.get(myp5.width / 2, myp5.height / 2),
2498+
[0, 0, 255, 255]
2499+
);
2500+
}
2501+
);
24652502
});
24662503
});

0 commit comments

Comments
 (0)