Skip to content

Commit 0fb364f

Browse files
committed
Fix setAttributes messing with state
1 parent 9ce1646 commit 0fb364f

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

preview/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,26 @@
2020
import p5 from '../src/app.js';
2121

2222
const sketch = function (p) {
23+
let fbo;
2324
p.setup = async function () {
24-
p.createCanvas(400, 400);
25+
p.createCanvas(400, 400, p.WEBGL);
26+
fbo = p.createFramebuffer()
2527
};
2628

2729
p.draw = function () {
2830
p.push();
2931
p.background(200);
32+
fbo.begin()
33+
p.background('blue')
3034
p.strokeWeight(10);
3135
p.push()
3236
p.stroke('red')
3337
p.line(-100, -100, 100, 100);
3438
p.pop()
3539
p.translate(200, 200)
3640
p.line(-100, -100, 100, 100);
37-
debugger
41+
fbo.end()
42+
p.image(fbo, 0, 0)
3843
p.pop();
3944
};
4045
};

src/webgl/p5.Framebuffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ class Framebuffer {
905905
const cam = new FramebufferCamera(this);
906906
cam._computeCameraDefaultSettings();
907907
cam._setDefaultCamera();
908-
this.renderer.states.setValue('curCamera', cam);
909908
return cam;
910909
}
911910

@@ -1069,6 +1068,7 @@ class Framebuffer {
10691068
// this.renderer.setCamera(this.defaultCamera);
10701069
this.renderer.states.setValue('curCamera', this.defaultCamera);
10711070
// set the projection matrix (which is not normally updated each frame)
1071+
debugger
10721072
this.renderer.states.setValue('uPMatrix', this.renderer.states.uPMatrix.clone());
10731073
this.renderer.states.uPMatrix.set(this.defaultCamera.projMatrix);
10741074
this.renderer.states.setValue('uViewMatrix', this.renderer.states.uViewMatrix.clone());

src/webgl/p5.RendererGL.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ class RendererGL extends Renderer {
181181
this.states.uPMatrix = new Matrix(4);
182182

183183
this.states.curCamera = new Camera(this);
184+
this.states.uPMatrix.set(this.states.curCamera.projMatrix);
185+
this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix);
184186

185187
this.states.enableLighting = false;
186188
this.states.ambientLightColors = [];
@@ -207,24 +209,24 @@ class RendererGL extends Renderer {
207209

208210
this.states.curBlendMode = constants.BLEND;
209211

210-
this.states.setValue('_hasSetAmbient', false);
211-
this.states.setValue('_useSpecularMaterial', false);
212-
this.states.setValue('_useEmissiveMaterial', false);
213-
this.states.setValue('_useNormalMaterial', false);
214-
this.states.setValue('_useShininess', 1);
215-
this.states.setValue('_useMetalness', 0);
212+
this.states._hasSetAmbient = false;
213+
this.states._useSpecularMaterial = false;
214+
this.states._useEmissiveMaterial = false;
215+
this.states._useNormalMaterial = false;
216+
this.states._useShininess = 1;
217+
this.states._useMetalness = 0;
216218

217219
this.states.tint = [255, 255, 255, 255];
218220

219221
this.states.constantAttenuation = 1;
220222
this.states.linearAttenuation = 0;
221223
this.states.quadraticAttenuation = 0;
222224

223-
this.states.setValue('_currentNormal', new Vector(0, 0, 1));
225+
this.states._currentNormal = new Vector(0, 0, 1);
224226

225227
this.states.drawMode = constants.FILL;
226228

227-
this.states.setValue('_tex', null);
229+
this.states._tex = null;
228230
this.states.textureMode = constants.IMAGE;
229231
this.states.textureWrapX = constants.CLAMP;
230232
this.states.textureWrapY = constants.CLAMP;
@@ -2633,9 +2635,7 @@ function rendererGL(p5, fn) {
26332635
}
26342636
}
26352637

2636-
this.push();
26372638
this._renderer._resetContext();
2638-
this.pop();
26392639

26402640
if (this._renderer.states.curCamera) {
26412641
this._renderer.states.curCamera._renderer = this._renderer;

test/unit/webgl/p5.Framebuffer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ suite('p5.Framebuffer', function() {
4848
myp5.box(5, 5, 5);
4949
});
5050

51+
console.log(myp5._renderer.states.uPMatrix.mat4)
5152
// Draw the framebuffer to the canvas
5253
myp5.background(0);
5354
myp5.noStroke();

0 commit comments

Comments
 (0)