Skip to content

Commit

Permalink
Fix clear() on framebuffers on Intel macs
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Sep 20, 2023
1 parent 226f2fe commit 7fec9d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,21 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
const _b = args[2] || 0;
const _a = args[3] || 0;

const activeFramebuffer = this.activeFramebuffer();
if (
activeFramebuffer &&
activeFramebuffer.format === constants.UNSIGNED_BYTE &&
!activeFramebuffer.antialias &&
_a === 0
) {
// Drivers on Intel Macs check for 0,0,0,0 exactly when drawing to a
// framebuffer and ignore the command if it's the only drawing command to
// the framebuffer. To work around it, we can set the alpha to a value so
// low that it still rounds down to 0, but that circumvents the buggy
// check in the driver.
a = 1e-10;
}

this.GL.clearColor(_r * _a, _g * _a, _b * _a, _a);
this.GL.clearDepth(1);
this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT);
Expand Down

0 comments on commit 7fec9d3

Please sign in to comment.