Skip to content

Commit ad56112

Browse files
authored
Merge pull request #8712 from perminder-17/point-position
fix point() origin bug and stale per-vertex color leak
2 parents 9206f8d + dcf79cc commit ad56112

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

src/webgl/p5.RendererGL.Retained.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,26 @@ p5.RendererGL.prototype._drawElements = function(drawMode, gId) {
247247
p5.RendererGL.prototype._drawPoints = function(vertices, pointBuffers) {
248248
const gl = this.GL;
249249
const pointShader = this._getImmediatePointShader();
250-
this._setPointUniforms(pointShader);
251250

252-
// Prepare position and optional per-vertex color buffers
253251
if (Array.isArray(pointBuffers)) {
252+
const geom = this.immediateMode.geometry;
253+
254+
if (geom.vertices !== vertices) {
255+
geom.vertices = vertices;
256+
geom.dirtyFlags.vertices = true;
257+
if (geom.vertexStrokeColors.length > 0) {
258+
geom.vertexStrokeColors.length = 0;
259+
geom.dirtyFlags.vertexStrokeColors = true;
260+
}
261+
}
262+
263+
this._setPointUniforms(pointShader);
264+
254265
for (const buff of pointBuffers) {
255-
buff._prepareBuffer(this.immediateMode.geometry, pointShader);
266+
buff._prepareBuffer(geom, pointShader);
256267
}
257268
} else {
258-
// Backward compatibility if a raw GL buffer is passed
269+
this._setPointUniforms(pointShader);
259270
this._bindBuffer(
260271
pointBuffers,
261272
gl.ARRAY_BUFFER,

test/unit/visual/cases/webgl.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,34 @@ visualSuite('WebGL', function() {
140140
p5.box(30);
141141
screenshot();
142142
});
143+
144+
visualTest(
145+
'Per-vertex POINTS color does not leak into point()',
146+
(p5, screenshot) => {
147+
p5.createCanvas(100, 100, p5.WEBGL);
148+
p5.background(0);
149+
p5.strokeWeight(8);
150+
151+
p5.beginShape(p5.POINTS);
152+
p5.stroke(255, 0, 0);
153+
p5.vertex(-30, -20, 0);
154+
p5.stroke(0, 255, 0);
155+
p5.vertex(-10, -20, 0);
156+
p5.stroke(0, 0, 255);
157+
p5.vertex(10, -20, 0);
158+
p5.stroke(255, 255, 0);
159+
p5.vertex(30, -20, 0);
160+
p5.endShape();
161+
162+
p5.stroke(255, 0, 255);
163+
p5.point(-20, 20, 0);
164+
p5.stroke(0, 255, 255);
165+
p5.point(0, 20, 0);
166+
p5.stroke(255);
167+
p5.point(20, 20, 0);
168+
169+
screenshot();
170+
}
171+
);
143172
});
144173
});
611 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)