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 bcd294a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,22 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
const _r = args[0] || 0;
const _g = args[1] || 0;
const _b = args[2] || 0;
const _a = args[3] || 0;
let _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);
Expand Down

0 comments on commit bcd294a

Please sign in to comment.