catch issues with per-vertex coloring/styles (fixes #3677)

This commit is contained in:
Ben Fry
2015-08-21 10:57:00 -04:00
parent 0a62e9fc9c
commit facadfc9f5
2 changed files with 43 additions and 38 deletions

View File

@@ -116,13 +116,11 @@ public class PShape implements PConstants {
"getVertexCount() only works with PATH or GEOMETRY shapes";
public static final String NOT_A_SIMPLE_VERTEX =
"%1$s can not be called on quadratic or bezier vertices";
"%1$s can not be called on quadratic or bezier vertices";
static public final String PER_VERTEX_UNSUPPORTED =
"This renderer does not support %1$s for individual vertices";
// boundary box of this shape
//protected float x;
//protected float y;
//protected float width;
//protected float height;
/**
* ( begin auto-generated from PShape_width.xml )
*
@@ -239,6 +237,8 @@ public class PShape implements PConstants {
/** True if contains 3D data */
protected boolean is3D = false;
protected boolean perVertexStyles = false;
// should this be called vertices (consistent with PGraphics internals)
// or does that hurt flexibility?
@@ -704,8 +704,7 @@ public class PShape implements PConstants {
public void vertex(float x, float y, float z) {
// why not?
vertex(x, y);
vertex(x, y); // maybe? maybe not?
}
@@ -2388,8 +2387,8 @@ public class PShape implements PConstants {
this.fillColor = fill;
if (vertices != null) {
for (int i = 0; i < vertices.length; i++) {
if (vertices != null && perVertexStyles) {
for (int i = 0; i < vertexCount; i++) {
setFill(i, fill);
}
}
@@ -2402,13 +2401,16 @@ public class PShape implements PConstants {
return;
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getFill()");
if (!perVertexStyles) {
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setFill()");
return;
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getFill()");
return;
}
if (image == null) {
vertices[index][PGraphics.A] = ((fill >> 24) & 0xFF) / 255.0f;
@@ -2421,8 +2423,7 @@ public class PShape implements PConstants {
public int getTint(int index) {
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getTint()");
return this.tintColor;
}
@@ -2520,8 +2521,9 @@ public class PShape implements PConstants {
}
strokeColor = stroke;
if (vertices != null) {
for (int i = 0; i < vertices.length; i++) {
if (vertices != null && perVertexStyles) {
for (int i = 0; i < vertices.length; i++) {
setStroke(i, stroke);
}
}
@@ -2534,9 +2536,13 @@ public class PShape implements PConstants {
return;
}
if (!perVertexStyles) {
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStroke()");
return;
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStroke()");
return;
}
@@ -2550,13 +2556,11 @@ public class PShape implements PConstants {
public float getStrokeWeight(int index) {
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getStrokeWeight()");
return strokeWeight;
}
return vertices[index][PGraphics.SW];
}
@@ -2569,8 +2573,8 @@ public class PShape implements PConstants {
strokeWeight = weight;
if (vertices != null) {
for (int i = 0; i < vertices.length; i++) {
if (vertices != null && perVertexStyles) {
for (int i = 0; i < vertexCount; i++) {
setStrokeWeight(i, weight);
}
}
@@ -2583,9 +2587,13 @@ public class PShape implements PConstants {
return;
}
if (!perVertexStyles) {
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStrokeWeight()");
return;
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStrokeWeight()");
return;
}
@@ -2615,10 +2623,8 @@ public class PShape implements PConstants {
public int getAmbient(int index) {
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getAmbient()");
return ambientColor;
}
@@ -2653,8 +2659,7 @@ public class PShape implements PConstants {
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setAmbient()");
return;
}
@@ -2667,8 +2672,7 @@ public class PShape implements PConstants {
public int getSpecular(int index) {
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getSpecular()");
return specularColor;
}
@@ -2703,8 +2707,7 @@ public class PShape implements PConstants {
}
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setSpecular()");
return;
}
@@ -2717,8 +2720,7 @@ public class PShape implements PConstants {
public int getEmissive(int index) {
// make sure we allocated the vertices array and that vertex exists
if (vertices == null ||
index >= vertices.length) {
if (vertices == null || index >= vertices.length) {
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getEmissive()");
return emissiveColor;
}

View File

@@ -412,6 +412,9 @@ public class PShapeOpenGL extends PShape {
// GROUP shapes are always marked as ended.
shapeCreated = true;
}
// OpenGL supports per-vertex coloring (unlike Java2D)
perVertexStyles = true;
}