Skip to content

Commit 8c1a715

Browse files
committed
Make sure camera methods on framebuffers work with push/pop
1 parent 43fd2c0 commit 8c1a715

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/webgl/p5.Camera.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,15 +2945,18 @@ function camera(p5, fn){
29452945
p5.Camera = Camera;
29462946

29472947
RendererGL.prototype.camera = function(...args) {
2948+
this.states.setValue('curCamera', this.states.curCamera.clone());
29482949
this.states.curCamera.camera(...args);
29492950
};
29502951

29512952
RendererGL.prototype.perspective = function(...args) {
2953+
this.states.setValue('curCamera', this.states.curCamera.clone());
29522954
this.states.curCamera.perspective(...args);
29532955
};
29542956

29552957
RendererGL.prototype.linePerspective = function(enable) {
29562958
if (enable !== undefined) {
2959+
this.states.setValue('curCamera', this.states.curCamera.clone());
29572960
// Set the line perspective if enable is provided
29582961
this.states.curCamera.useLinePerspective = enable;
29592962
} else {
@@ -2963,10 +2966,12 @@ function camera(p5, fn){
29632966
};
29642967

29652968
RendererGL.prototype.ortho = function(...args) {
2969+
this.states.setValue('curCamera', this.states.curCamera.clone());
29662970
this.states.curCamera.ortho(...args);
29672971
};
29682972

29692973
RendererGL.prototype.frustum = function(...args) {
2974+
this.states.setValue('curCamera', this.states.curCamera.clone());
29702975
this.states.curCamera.frustum(...args);
29712976
};
29722977

test/unit/visual/cases/webgl.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@ visualSuite('WebGL', function() {
2525
p5.box(20);
2626
screenshot();
2727
});
28+
29+
visualTest('Camera settings on framebuffers reset after push/pop', function(p5, screenshot) {
30+
p5.createCanvas(100, 100, p5.WEBGL);
31+
p5.setAttributes({ antialias: true });
32+
const fbo = p5.createFramebuffer();
33+
34+
p5.background(220);
35+
p5.imageMode(p5.CENTER);
36+
37+
fbo.begin();
38+
p5.push();
39+
p5.ortho();
40+
p5.translate(0, -25);
41+
for (let i = -1; i <= 1; i++) {
42+
p5.push();
43+
p5.translate(i * 35, 0);
44+
p5.box(25, 25, 150);
45+
p5.pop();
46+
}
47+
p5.pop();
48+
49+
50+
p5.push();
51+
p5.translate(0, 25);
52+
for (let i = -1; i <= 1; i++) {
53+
p5.push();
54+
p5.translate(i * 35, 0);
55+
p5.box(25, 25, 150);
56+
p5.pop();
57+
}
58+
p5.pop();
59+
60+
fbo.end();
61+
p5.image(fbo, 0, 0);
62+
screenshot();
63+
});
2864
});
2965

3066
visualSuite('filter', function() {
@@ -758,7 +794,7 @@ visualSuite('WebGL', function() {
758794
screenshot();
759795
});
760796
});
761-
797+
762798
visualSuite('p5.strands', () => {
763799
visualTest('it recovers from p5.strands errors', (p5, screenshot) => {
764800
p5.createCanvas(50, 50, p5.WEBGL);
1007 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)