Skip to content

Commit 809de6b

Browse files
authored
Merge pull request #8322 from processing/fix/fbo-ortho
Make sure camera methods on framebuffers work with push/pop
2 parents d287796 + 7374fbe commit 809de6b

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

src/webgl/p5.Camera.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,8 @@ class Camera {
18441844
_cam.projMatrix = this.projMatrix.copy();
18451845
_cam.yScale = this.yScale;
18461846

1847+
_cam.cameraType = this.cameraType;
1848+
18471849
return _cam;
18481850
}
18491851

@@ -2945,15 +2947,18 @@ function camera(p5, fn){
29452947
p5.Camera = Camera;
29462948

29472949
RendererGL.prototype.camera = function(...args) {
2950+
this.states.setValue('curCamera', this.states.curCamera.clone());
29482951
this.states.curCamera.camera(...args);
29492952
};
29502953

29512954
RendererGL.prototype.perspective = function(...args) {
2955+
this.states.setValue('curCamera', this.states.curCamera.clone());
29522956
this.states.curCamera.perspective(...args);
29532957
};
29542958

29552959
RendererGL.prototype.linePerspective = function(enable) {
29562960
if (enable !== undefined) {
2961+
this.states.setValue('curCamera', this.states.curCamera.clone());
29572962
// Set the line perspective if enable is provided
29582963
this.states.curCamera.useLinePerspective = enable;
29592964
} else {
@@ -2963,10 +2968,12 @@ function camera(p5, fn){
29632968
};
29642969

29652970
RendererGL.prototype.ortho = function(...args) {
2971+
this.states.setValue('curCamera', this.states.curCamera.clone());
29662972
this.states.curCamera.ortho(...args);
29672973
};
29682974

29692975
RendererGL.prototype.frustum = function(...args) {
2976+
this.states.setValue('curCamera', this.states.curCamera.clone());
29702977
this.states.curCamera.frustum(...args);
29712978
};
29722979

src/webgl/p5.Framebuffer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class FramebufferCamera extends Camera {
3131
this.defaultCameraFOV =
3232
2 * Math.atan(this.fbo.height / 2 / this.defaultEyeZ);
3333
}
34+
35+
copy() {
36+
const _cam = super.copy();
37+
_cam.fbo = this.fbo;
38+
return _cam;
39+
}
3440
}
3541

3642
class FramebufferTexture {

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)