Skip to content

Commit 7713c08

Browse files
committed
catch issues with per-vertex coloring/styles (fixes processing#3677)
1 parent 5da64f8 commit 7713c08

2 files changed

Lines changed: 42 additions & 37 deletions

File tree

core/src/processing/core/PShape.java

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,11 @@ public class PShape implements PConstants {
116116
"getVertexCount() only works with PATH or GEOMETRY shapes";
117117

118118
public static final String NOT_A_SIMPLE_VERTEX =
119-
"%1$s can not be called on quadratic or bezier vertices";
119+
"%1$s can not be called on quadratic or bezier vertices";
120+
121+
static public final String PER_VERTEX_UNSUPPORTED =
122+
"This renderer does not support %1$s for individual vertices";
120123

121-
// boundary box of this shape
122-
//protected float x;
123-
//protected float y;
124-
//protected float width;
125-
//protected float height;
126124
/**
127125
* ( begin auto-generated from PShape_width.xml )
128126
*
@@ -239,6 +237,8 @@ public class PShape implements PConstants {
239237
/** True if contains 3D data */
240238
protected boolean is3D = false;
241239

240+
protected boolean perVertexStyles = false;
241+
242242
// should this be called vertices (consistent with PGraphics internals)
243243
// or does that hurt flexibility?
244244

@@ -704,8 +704,7 @@ public void vertex(float x, float y, float u, float v) {
704704

705705

706706
public void vertex(float x, float y, float z) {
707-
// why not?
708-
vertex(x, y);
707+
vertex(x, y); // maybe? maybe not?
709708
}
710709

711710

@@ -2388,8 +2387,8 @@ public void setFill(int fill) {
23882387

23892388
this.fillColor = fill;
23902389

2391-
if (vertices != null) {
2392-
for (int i = 0; i < vertices.length; i++) {
2390+
if (vertices != null && perVertexStyles) {
2391+
for (int i = 0; i < vertexCount; i++) {
23932392
setFill(i, fill);
23942393
}
23952394
}
@@ -2402,14 +2401,17 @@ public void setFill(int index, int fill) {
24022401
return;
24032402
}
24042403

2404+
if (!perVertexStyles) {
2405+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setFill()");
2406+
return;
2407+
}
2408+
24052409
// make sure we allocated the vertices array and that vertex exists
2406-
if (vertices == null ||
2407-
index >= vertices.length) {
2410+
if (vertices == null || index >= vertices.length) {
24082411
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getFill()");
24092412
return;
24102413
}
24112414

2412-
24132415
if (image == null) {
24142416
vertices[index][PGraphics.A] = ((fill >> 24) & 0xFF) / 255.0f;
24152417
vertices[index][PGraphics.R] = ((fill >> 16) & 0xFF) / 255.0f;
@@ -2421,8 +2423,7 @@ public void setFill(int index, int fill) {
24212423

24222424
public int getTint(int index) {
24232425
// make sure we allocated the vertices array and that vertex exists
2424-
if (vertices == null ||
2425-
index >= vertices.length) {
2426+
if (vertices == null || index >= vertices.length) {
24262427
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getTint()");
24272428
return this.tintColor;
24282429
}
@@ -2520,8 +2521,9 @@ public void setStroke(int stroke) {
25202521
}
25212522

25222523
strokeColor = stroke;
2523-
if (vertices != null) {
2524-
for (int i = 0; i < vertices.length; i++) {
2524+
2525+
if (vertices != null && perVertexStyles) {
2526+
for (int i = 0; i < vertices.length; i++) {
25252527
setStroke(i, stroke);
25262528
}
25272529
}
@@ -2534,9 +2536,13 @@ public void setStroke(int index, int stroke) {
25342536
return;
25352537
}
25362538

2539+
if (!perVertexStyles) {
2540+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStroke()");
2541+
return;
2542+
}
2543+
25372544
// make sure we allocated the vertices array and that vertex exists
2538-
if (vertices == null ||
2539-
index >= vertices.length) {
2545+
if (vertices == null || index >= vertices.length) {
25402546
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStroke()");
25412547
return;
25422548
}
@@ -2550,13 +2556,11 @@ public void setStroke(int index, int stroke) {
25502556

25512557
public float getStrokeWeight(int index) {
25522558
// make sure we allocated the vertices array and that vertex exists
2553-
if (vertices == null ||
2554-
index >= vertices.length) {
2559+
if (vertices == null || index >= vertices.length) {
25552560
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getStrokeWeight()");
25562561
return strokeWeight;
25572562
}
25582563

2559-
25602564
return vertices[index][PGraphics.SW];
25612565
}
25622566

@@ -2569,8 +2573,8 @@ public void setStrokeWeight(float weight) {
25692573

25702574
strokeWeight = weight;
25712575

2572-
if (vertices != null) {
2573-
for (int i = 0; i < vertices.length; i++) {
2576+
if (vertices != null && perVertexStyles) {
2577+
for (int i = 0; i < vertexCount; i++) {
25742578
setStrokeWeight(i, weight);
25752579
}
25762580
}
@@ -2583,9 +2587,13 @@ public void setStrokeWeight(int index, float weight) {
25832587
return;
25842588
}
25852589

2590+
if (!perVertexStyles) {
2591+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStrokeWeight()");
2592+
return;
2593+
}
2594+
25862595
// make sure we allocated the vertices array and that vertex exists
2587-
if (vertices == null ||
2588-
index >= vertices.length) {
2596+
if (vertices == null || index >= vertices.length) {
25892597
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStrokeWeight()");
25902598
return;
25912599
}
@@ -2615,10 +2623,8 @@ public void setStrokeCap(int cap) {
26152623

26162624

26172625
public int getAmbient(int index) {
2618-
26192626
// make sure we allocated the vertices array and that vertex exists
2620-
if (vertices == null ||
2621-
index >= vertices.length) {
2627+
if (vertices == null || index >= vertices.length) {
26222628
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getAmbient()");
26232629
return ambientColor;
26242630
}
@@ -2653,8 +2659,7 @@ public void setAmbient(int index, int ambient) {
26532659
}
26542660

26552661
// make sure we allocated the vertices array and that vertex exists
2656-
if (vertices == null ||
2657-
index >= vertices.length) {
2662+
if (vertices == null || index >= vertices.length) {
26582663
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setAmbient()");
26592664
return;
26602665
}
@@ -2667,8 +2672,7 @@ public void setAmbient(int index, int ambient) {
26672672

26682673
public int getSpecular(int index) {
26692674
// make sure we allocated the vertices array and that vertex exists
2670-
if (vertices == null ||
2671-
index >= vertices.length) {
2675+
if (vertices == null || index >= vertices.length) {
26722676
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getSpecular()");
26732677
return specularColor;
26742678
}
@@ -2703,8 +2707,7 @@ public void setSpecular(int index, int specular) {
27032707
}
27042708

27052709
// make sure we allocated the vertices array and that vertex exists
2706-
if (vertices == null ||
2707-
index >= vertices.length) {
2710+
if (vertices == null || index >= vertices.length) {
27082711
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setSpecular()");
27092712
return;
27102713
}
@@ -2717,8 +2720,7 @@ public void setSpecular(int index, int specular) {
27172720

27182721
public int getEmissive(int index) {
27192722
// make sure we allocated the vertices array and that vertex exists
2720-
if (vertices == null ||
2721-
index >= vertices.length) {
2723+
if (vertices == null || index >= vertices.length) {
27222724
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getEmissive()");
27232725
return emissiveColor;
27242726
}

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ public PShapeOpenGL(PGraphicsOpenGL pg, int family) {
412412
// GROUP shapes are always marked as ended.
413413
shapeCreated = true;
414414
}
415+
416+
// OpenGL supports per-vertex coloring (unlike Java2D)
417+
perVertexStyles = true;
415418
}
416419

417420

0 commit comments

Comments
 (0)