Skip to content

Commit 42a121e

Browse files
committed
Make sure framebuffers are unbound when shader feedback would be detected
1 parent ac9dbe1 commit 42a121e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/webgl/p5.Shader.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,15 @@ class Shader {
843843

844844
for (const uniform of this.samplers) {
845845
let tex = uniform.texture;
846-
if (tex === undefined) {
846+
if (
847+
tex === undefined ||
848+
(
849+
false &&
850+
tex.isFramebufferTexture &&
851+
!tex.src.framebuffer.antialias &&
852+
tex.src.framebuffer === this._renderer.activeFramebuffer()
853+
)
854+
) {
847855
// user hasn't yet supplied a texture for this slot.
848856
// (or there may not be one--maybe just lighting),
849857
// so we supply a default texture instead.

test/unit/webgl/p5.Shader.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,28 @@ suite('p5.Shader', function() {
333333
expect(modified.fragSrc()).to.match(/#define AUGMENTED_HOOK_getVertexColor/);
334334
});
335335
});
336+
337+
test('framebuffer textures are unbound when you draw to the framebuffer', function() {
338+
const sh = myp5.baseMaterialShader().modify({
339+
uniforms: {
340+
'sampler2D myTex': null,
341+
},
342+
'vec4 getFinalColor': `(vec4 c) {
343+
return getTexture(myTex, vec2(0.,0.));
344+
}`
345+
});
346+
const fbo = myp5.createFramebuffer();
347+
348+
myp5.shader(sh);
349+
sh.setUniform('myTex', fbo);
350+
351+
fbo.draw(() => myp5.background('red'));
352+
353+
sh.setUniform('myTex', fbo);
354+
myp5.noStroke();
355+
myp5.plane(myp5.width, myp5.height);
356+
assert.deepEqual(myp5.get(0, 0), [255, 0, 0, 255]);
357+
});
336358
});
337359

338360
suite('hookTypes', function() {

0 commit comments

Comments
 (0)