diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 3e8eb9626d..e19ced77dd 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -1239,6 +1239,21 @@ public void normal(float nx, float ny, float nz) { } + public void attribPosition(String name, float x, float y, float z) { + showMissingWarning("attrib"); + } + + + public void attribNormal(String name, float nx, float ny, float nz) { + showMissingWarning("attrib"); + } + + + public void attribColor(String name, int color) { + showMissingWarning("attrib"); + } + + public void attrib(String name, float... values) { showMissingWarning("attrib"); } diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 190aa00583..cdb78414b9 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -716,6 +716,17 @@ public void normal(float nx, float ny, float nz) { } + public void attribPosition(String name, float x, float y, float z) { + } + + public void attribNormal(String name, float nx, float ny, float nz) { + } + + + public void attribColor(String name, int color) { + } + + public void attrib(String name, float... values) { } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 0ba4c01d12..6a3692ae6d 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2625,39 +2625,73 @@ public void vertex(float x, float y, float z, float u, float v) { } + @Override + public void attribPosition(String name, float x, float y, float z) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.POSITION, + PGL.FLOAT, 3); + if (attrib != null) attrib.set(x, y, z); + } + + + @Override + public void attribNormal(String name, float nx, float ny, float nz) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.NORMAL, + PGL.FLOAT, 3); + if (attrib != null) attrib.set(nx, ny, nz); + } + + + @Override + public void attribColor(String name, int color) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.COLOR, PGL.INT, 1); + if (attrib != null) attrib.set(new int[] {color}); + } + + @Override public void attrib(String name, float... values) { - VertexAttribute attrib = attribImpl(name, PGL.FLOAT, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, + PGL.FLOAT, values.length); if (attrib != null) attrib.set(values); } @Override public void attrib(String name, int... values) { - VertexAttribute attrib = attribImpl(name, PGL.INT, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, + PGL.INT, values.length); if (attrib != null) attrib.set(values); } @Override public void attrib(String name, boolean... values) { - VertexAttribute attrib = attribImpl(name, PGL.BOOL, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, + PGL.BOOL, values.length); if (attrib != null) attrib.set(values); } - protected VertexAttribute attribImpl(String name, int type, int size) { + protected VertexAttribute attribImpl(String name, int kind, int type, int size) { if (4 < size) { PGraphics.showWarning("Vertex attributes cannot have more than 4 values"); return null; } VertexAttribute attrib = polyAttribs.get(name); if (attrib == null) { - attrib = new VertexAttribute(this, name, type, size); + attrib = new VertexAttribute(this, name, kind, type, size); polyAttribs.put(name, attrib); inGeo.initAttrib(attrib); tessGeo.initAttrib(attrib); } + if (attrib.kind != kind) { + PGraphics.showWarning("The attribute kind cannot be changed after creation"); + return null; + } + if (attrib.type != type) { + PGraphics.showWarning("The attribute type cannot be changed after creation"); + return null; + } if (attrib.size != size) { PGraphics.showWarning("New value for vertex attribute has wrong number of values"); return null; @@ -7398,23 +7432,17 @@ static protected class VertexAttribute { int lastModified; boolean active; - VertexAttribute(PGraphicsOpenGL pg, String name, int type, int size) { + VertexAttribute(PGraphicsOpenGL pg, String name, int kind, int type, int size) { this.pg = pg; this.name = name; + this.kind = kind; this.type = type; this.size = size; - tessSize = size; - - if (name.indexOf("pos") == 0 && type == PGL.FLOAT && size == 3) { - kind = POSITION; - tessSize = 4; - } else if (name.indexOf("norm") == 0 && type == PGL.FLOAT && size == 3) { - kind = NORMAL; - } else if (name.indexOf("color") == 0 && type == PGL.INT && size == 1) { - kind = COLOR; + if (kind == POSITION) { + tessSize = 4; // for w } else { - kind = OTHER; + tessSize = size; } if (type == PGL.FLOAT) { @@ -7520,6 +7548,16 @@ int sizeInBytes(int length) { return length * tessSize * elementSize; } + void set(float x, float y, float z) { + fvalues[0] = x; + fvalues[1] = y; + fvalues[2] = z; + } + + void set(int c) { + ivalues[0] = c; + } + void set(float[] values) { PApplet.arrayCopy(values, 0, fvalues, 0, size); } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index f3c1303839..a73319d37a 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1170,38 +1170,73 @@ public void normal(float nx, float ny, float nz) { } } + + @Override + public void attribPosition(String name, float x, float y, float z) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.POSITION, + PGL.FLOAT, 3); + if (attrib != null) attrib.set(x, y, z); + } + + + @Override + public void attribNormal(String name, float nx, float ny, float nz) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.NORMAL, + PGL.FLOAT, 3); + if (attrib != null) attrib.set(nx, ny, nz); + } + + + @Override + public void attribColor(String name, int color) { + VertexAttribute attrib = attribImpl(name, VertexAttribute.COLOR, PGL.INT, 1); + if (attrib != null) attrib.set(new int[] {color}); + } + + @Override public void attrib(String name, float... values) { - VertexAttribute attrib = attribImpl(name, PGL.FLOAT, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.FLOAT, + values.length); if (attrib != null) attrib.set(values); } @Override public void attrib(String name, int... values) { - VertexAttribute attrib = attribImpl(name, PGL.INT, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.INT, + values.length); if (attrib != null) attrib.set(values); } @Override public void attrib(String name, boolean... values) { - VertexAttribute attrib = attribImpl(name, PGL.BOOL, values.length); + VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.BOOL, + values.length); if (attrib != null) attrib.set(values); } - protected VertexAttribute attribImpl(String name, int type, int size) { + protected VertexAttribute attribImpl(String name, int kind, int type, int size) { if (4 < size) { PGraphics.showWarning("Vertex attributes cannot have more than 4 values"); return null; } VertexAttribute attrib = polyAttribs.get(name); if (attrib == null) { - attrib = new VertexAttribute(pg, name, type, size); + attrib = new VertexAttribute(pg, name, kind, type, size); polyAttribs.put(name, attrib); inGeo.initAttrib(attrib); } + if (attrib.kind != kind) { + PGraphics.showWarning("The attribute kind cannot be changed after creation"); + return null; + } + if (attrib.type != type) { + PGraphics.showWarning("The attribute type cannot be changed after creation"); + return null; + } if (attrib.size != size) { PGraphics.showWarning("New value for vertex attribute has wrong number of values"); return null;