Skip to content

Commit c05c47d

Browse files
committed
completed attrib setters in PShapeOpenGL
1 parent aab07e2 commit c05c47d

File tree

1 file changed

+90
-31
lines changed

1 file changed

+90
-31
lines changed

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ public void setNormal(int index, float nx, float ny, float nz) {
18301830
public PVector getAttribPosition(String name, int index, PVector vec) {
18311831
VertexAttribute attrib = polyAttribs.get(name);
18321832
if (attrib == null)
1833-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1833+
throw new RuntimeException("Trying to get values of non existing attribute");
18341834

18351835
if (vec == null) vec = new PVector();
18361836
if (root.tessUpdate) {
@@ -1854,7 +1854,7 @@ public PVector getAttribPosition(String name, int index, PVector vec) {
18541854
public float getAttribPositionX(String name, int index) {
18551855
VertexAttribute attrib = polyAttribs.get(name);
18561856
if (attrib == null)
1857-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1857+
throw new RuntimeException("Trying to get values of non existing attribute");
18581858

18591859
if (root.tessUpdate) {
18601860
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1870,7 +1870,7 @@ public float getAttribPositionX(String name, int index) {
18701870
public float getAttribPositionY(String name, int index) {
18711871
VertexAttribute attrib = polyAttribs.get(name);
18721872
if (attrib == null)
1873-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1873+
throw new RuntimeException("Trying to get values of non existing attribute");
18741874

18751875
if (root.tessUpdate) {
18761876
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1886,7 +1886,7 @@ public float getAttribPositionY(String name, int index) {
18861886
public float getAttribPositionZ(String name, int index) {
18871887
VertexAttribute attrib = polyAttribs.get(name);
18881888
if (attrib == null)
1889-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1889+
throw new RuntimeException("Trying to get values of non existing attribute");
18901890

18911891
if (root.tessUpdate) {
18921892
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1902,7 +1902,7 @@ public float getAttribPositionZ(String name, int index) {
19021902
public PVector getAttribNormal(String name, int index, PVector vec) {
19031903
VertexAttribute attrib = polyAttribs.get(name);
19041904
if (attrib == null)
1905-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1905+
throw new RuntimeException("Trying to get values of non existing attribute");
19061906

19071907
if (vec == null) vec = new PVector();
19081908
if (root.tessUpdate) {
@@ -1926,7 +1926,7 @@ public PVector getAttribNormal(String name, int index, PVector vec) {
19261926
public float getAttribNormalX(String name, int index) {
19271927
VertexAttribute attrib = polyAttribs.get(name);
19281928
if (attrib == null)
1929-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1929+
throw new RuntimeException("Trying to get values of non existing attribute");
19301930

19311931
if (root.tessUpdate) {
19321932
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1942,7 +1942,7 @@ public float getAttribNormalX(String name, int index) {
19421942
public float getAttribNormalY(String name, int index) {
19431943
VertexAttribute attrib = polyAttribs.get(name);
19441944
if (attrib == null)
1945-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1945+
throw new RuntimeException("Trying to get values of non existing attribute");
19461946

19471947
if (root.tessUpdate) {
19481948
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1958,7 +1958,7 @@ public float getAttribNormalY(String name, int index) {
19581958
public float getAttribNormalZ(String name, int index) {
19591959
VertexAttribute attrib = polyAttribs.get(name);
19601960
if (attrib == null)
1961-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1961+
throw new RuntimeException("Trying to get values of non existing attribute");
19621962

19631963
if (root.tessUpdate) {
19641964
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
@@ -1974,7 +1974,7 @@ public float getAttribNormalZ(String name, int index) {
19741974
public int getAttribColor(String name, int index) {
19751975
VertexAttribute attrib = polyAttribs.get(name);
19761976
if (attrib == null)
1977-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1977+
throw new RuntimeException("Trying to get values of non existing attribute");
19781978

19791979
if (root.tessUpdate) {
19801980
int[] tessAttrib = tessGeo.ipolyAttribs.get(name);
@@ -1991,7 +1991,7 @@ public int getAttribColor(String name, int index) {
19911991
public float[] getAttrib(String name, int index, float[] values) {
19921992
VertexAttribute attrib = polyAttribs.get(name);
19931993
if (attrib == null)
1994-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
1994+
throw new RuntimeException("Trying to get values of non existing attribute");
19951995

19961996
if (root.tessUpdate) {
19971997
if (values == null || values.length < attrib.tessSize) values = new float[attrib.tessSize];
@@ -2012,7 +2012,7 @@ public float[] getAttrib(String name, int index, float[] values) {
20122012
public int[] getAttrib(String name, int index, int[] values) {
20132013
VertexAttribute attrib = polyAttribs.get(name);
20142014
if (attrib == null)
2015-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
2015+
throw new RuntimeException("Trying to get values of non existing attribute");
20162016

20172017
if (root.tessUpdate) {
20182018
if (values == null || values.length < attrib.tessSize) values = new int[attrib.tessSize];
@@ -2033,7 +2033,7 @@ public int[] getAttrib(String name, int index, int[] values) {
20332033
public boolean[] getAttrib(String name, int index, boolean[] values) {
20342034
VertexAttribute attrib = polyAttribs.get(name);
20352035
if (attrib == null)
2036-
throw new RuntimeException("Trying to retrieve values of non existing attribute");
2036+
throw new RuntimeException("Trying to get values of non existing attribute");
20372037

20382038
if (root.tessUpdate) {
20392039
if (values == null || values.length < attrib.tessSize) values = new boolean[attrib.tessSize];
@@ -2062,7 +2062,16 @@ public void setAttribPosition(String name, int index, float x, float y, float z)
20622062
}
20632063

20642064
VertexAttribute attrib = attribImpl(name, VertexAttribute.POSITION, PGL.FLOAT, 3);
2065-
if (attrib != null) {
2065+
if (attrib == null)
2066+
throw new RuntimeException("Trying to set values of non existing attribute");
2067+
2068+
if (root.tessUpdate) {
2069+
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
2070+
int tessIdx = firstPolyVertex + index;
2071+
tessAttrib[4 * tessIdx + 0] = x;
2072+
tessAttrib[4 * tessIdx + 1] = y;
2073+
tessAttrib[4 * tessIdx + 2] = z;
2074+
} else {
20662075
float[] array = inGeo.fattribs.get(name);
20672076
array[3 * index + 0] = x;
20682077
array[3 * index + 1] = y;
@@ -2080,7 +2089,16 @@ public void setAttribNormal(String name, int index, float nx, float ny, float nz
20802089
}
20812090

20822091
VertexAttribute attrib = attribImpl(name, VertexAttribute.NORMAL, PGL.FLOAT, 3);
2083-
if (attrib != null) {
2092+
if (attrib == null)
2093+
throw new RuntimeException("Trying to set values of non existing attribute");
2094+
2095+
if (root.tessUpdate) {
2096+
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
2097+
int tessIdx = firstPolyVertex + index;
2098+
tessAttrib[3 * tessIdx + 0] = nx;
2099+
tessAttrib[3 * tessIdx + 1] = ny;
2100+
tessAttrib[3 * tessIdx + 2] = nz;
2101+
} else {
20842102
float[] array = inGeo.fattribs.get(name);
20852103
array[3 * index + 0] = nx;
20862104
array[3 * index + 1] = ny;
@@ -2098,7 +2116,13 @@ public void setAttribColor(String name, int index, int color) {
20982116
}
20992117

21002118
VertexAttribute attrib = attribImpl(name, VertexAttribute.COLOR, PGL.INT, 1);
2101-
if (attrib != null) {
2119+
if (attrib == null)
2120+
throw new RuntimeException("Trying to set values of non existing attribute");
2121+
2122+
if (root.tessUpdate) {
2123+
int[] tessAttrib = tessGeo.ipolyAttribs.get(name);
2124+
tessAttrib[firstPolyVertex + index] = PGL.javaToNativeARGB(color);
2125+
} else {
21022126
float[] array = inGeo.fattribs.get(name);
21032127
array[index] = PGL.javaToNativeARGB(color);
21042128
markForTessellation();
@@ -2114,11 +2138,22 @@ public void setAttrib(String name, int index, float... values) {
21142138
}
21152139

21162140
VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.FLOAT, values.length);
2117-
if (attrib.size != values.length)
2118-
throw new RuntimeException("Length of values array is different from attribute size");
2119-
float[] array = inGeo.fattribs.get(name);
2120-
PApplet.arrayCopy(values, 0, array, attrib.size * index, attrib.size);
2121-
markForTessellation();
2141+
if (attrib == null)
2142+
throw new RuntimeException("Trying to set values of non existing attribute");
2143+
2144+
if (root.tessUpdate) {
2145+
if (attrib.tessSize != values.length)
2146+
throw new RuntimeException("Length of values array is different from attribute tesselated size");
2147+
float[] tessAttrib = tessGeo.fpolyAttribs.get(name);
2148+
int tessIdx = firstPolyVertex + index;
2149+
PApplet.arrayCopy(values, 0, tessAttrib, attrib.tessSize * tessIdx, attrib.tessSize);
2150+
} else {
2151+
if (attrib.size != values.length)
2152+
throw new RuntimeException("Length of values array is different from attribute size");
2153+
float[] array = inGeo.fattribs.get(name);
2154+
PApplet.arrayCopy(values, 0, array, attrib.size * index, attrib.size);
2155+
markForTessellation();
2156+
}
21222157
}
21232158

21242159

@@ -2130,11 +2165,22 @@ public void setAttrib(String name, int index, int... values) {
21302165
}
21312166

21322167
VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.INT, values.length);
2133-
if (attrib.size != values.length)
2134-
throw new RuntimeException("Length of values array is different from attribute size");
2135-
int[] array = inGeo.iattribs.get(name);
2136-
PApplet.arrayCopy(values, 0, array, attrib.size * index, attrib.size);
2137-
markForTessellation();
2168+
if (attrib == null)
2169+
throw new RuntimeException("Trying to set values of non existing attribute");
2170+
2171+
if (root.tessUpdate) {
2172+
if (attrib.tessSize != values.length)
2173+
throw new RuntimeException("Length of values array is different from attribute tesselated size");
2174+
int[] tessAttrib = tessGeo.ipolyAttribs.get(name);
2175+
int tessIdx = firstPolyVertex + index;
2176+
PApplet.arrayCopy(values, 0, tessAttrib, attrib.tessSize * tessIdx, attrib.tessSize);
2177+
} else {
2178+
if (attrib.size != values.length)
2179+
throw new RuntimeException("Length of values array is different from attribute size");
2180+
int[] array = inGeo.iattribs.get(name);
2181+
PApplet.arrayCopy(values, 0, array, attrib.size * index, attrib.size);
2182+
markForTessellation();
2183+
}
21382184
}
21392185

21402186

@@ -2146,13 +2192,26 @@ public void setAttrib(String name, int index, boolean... values) {
21462192
}
21472193

21482194
VertexAttribute attrib = attribImpl(name, VertexAttribute.OTHER, PGL.BOOL, values.length);
2149-
if (attrib.size != values.length)
2150-
throw new RuntimeException("Length of values array is different from attribute size");
2151-
byte[] array = inGeo.battribs.get(name);
2152-
for (int i = 0; i < attrib.size; i++) {
2153-
array[attrib.size * index + i] = (byte)(values[i]?1:0);
2195+
if (attrib == null)
2196+
throw new RuntimeException("Trying to set values of non existing attribute");
2197+
2198+
if (root.tessUpdate) {
2199+
if (attrib.tessSize != values.length)
2200+
throw new RuntimeException("Length of values array is different from attribute tesselated size");
2201+
byte[] tessAttrib = tessGeo.bpolyAttribs.get(name);
2202+
int tessIdx = firstPolyVertex + index;
2203+
for (int i = 0; i < attrib.tessSize; i++) {
2204+
tessAttrib[attrib.tessSize * tessIdx + i] = (byte)(values[i]?1:0);
2205+
}
2206+
} else {
2207+
if (attrib.size != values.length)
2208+
throw new RuntimeException("Length of values array is different from attribute size");
2209+
byte[] array = inGeo.battribs.get(name);
2210+
for (int i = 0; i < attrib.size; i++) {
2211+
array[attrib.size * index + i] = (byte)(values[i]?1:0);
2212+
}
2213+
markForTessellation();
21542214
}
2155-
markForTessellation();
21562215
}
21572216

21582217

0 commit comments

Comments
 (0)