diff --git a/src/webgl/p5.RendererGL.Retained.js b/src/webgl/p5.RendererGL.Retained.js index fc581a405a..7fc6a05c3f 100644 --- a/src/webgl/p5.RendererGL.Retained.js +++ b/src/webgl/p5.RendererGL.Retained.js @@ -247,15 +247,26 @@ p5.RendererGL.prototype._drawElements = function(drawMode, gId) { p5.RendererGL.prototype._drawPoints = function(vertices, pointBuffers) { const gl = this.GL; const pointShader = this._getImmediatePointShader(); - this._setPointUniforms(pointShader); - // Prepare position and optional per-vertex color buffers if (Array.isArray(pointBuffers)) { + const geom = this.immediateMode.geometry; + + if (geom.vertices !== vertices) { + geom.vertices = vertices; + geom.dirtyFlags.vertices = true; + if (geom.vertexStrokeColors.length > 0) { + geom.vertexStrokeColors.length = 0; + geom.dirtyFlags.vertexStrokeColors = true; + } + } + + this._setPointUniforms(pointShader); + for (const buff of pointBuffers) { - buff._prepareBuffer(this.immediateMode.geometry, pointShader); + buff._prepareBuffer(geom, pointShader); } } else { - // Backward compatibility if a raw GL buffer is passed + this._setPointUniforms(pointShader); this._bindBuffer( pointBuffers, gl.ARRAY_BUFFER, diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index 2f36feb806..079d5d19e7 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -140,5 +140,34 @@ visualSuite('WebGL', function() { p5.box(30); screenshot(); }); + + visualTest( + 'Per-vertex POINTS color does not leak into point()', + (p5, screenshot) => { + p5.createCanvas(100, 100, p5.WEBGL); + p5.background(0); + p5.strokeWeight(8); + + p5.beginShape(p5.POINTS); + p5.stroke(255, 0, 0); + p5.vertex(-30, -20, 0); + p5.stroke(0, 255, 0); + p5.vertex(-10, -20, 0); + p5.stroke(0, 0, 255); + p5.vertex(10, -20, 0); + p5.stroke(255, 255, 0); + p5.vertex(30, -20, 0); + p5.endShape(); + + p5.stroke(255, 0, 255); + p5.point(-20, 20, 0); + p5.stroke(0, 255, 255); + p5.point(0, 20, 0); + p5.stroke(255); + p5.point(20, 20, 0); + + screenshot(); + } + ); }); }); diff --git a/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/000.png b/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/000.png new file mode 100644 index 0000000000..b7209fa77a Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/metadata.json b/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/Strokes/Per-vertex POINTS color does not leak into point()/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file