mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
more work in PShape, same renaming
This commit is contained in:
@@ -96,7 +96,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
protected int pointBuffersContext;
|
||||
|
||||
// Generic vertex attributes (only for polys)
|
||||
protected AttributeMap attribs;
|
||||
protected AttributeMap polyAttribs;
|
||||
|
||||
static protected final int INIT_VERTEX_BUFFER_SIZE = 256;
|
||||
static protected final int INIT_INDEX_BUFFER_SIZE = 512;
|
||||
@@ -533,9 +533,9 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
viewport = PGL.allocateIntBuffer(4);
|
||||
|
||||
attribs = newAttributeMap();
|
||||
inGeo = newInGeometry(this, attribs, IMMEDIATE);
|
||||
tessGeo = newTessGeometry(this, attribs, IMMEDIATE);
|
||||
polyAttribs = newAttributeMap();
|
||||
inGeo = newInGeometry(this, polyAttribs, IMMEDIATE);
|
||||
tessGeo = newTessGeometry(this, polyAttribs, IMMEDIATE);
|
||||
texCache = newTexCache(this);
|
||||
|
||||
projection = new PMatrix3D();
|
||||
@@ -1298,8 +1298,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
boolean created = false;
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (!attrib.bufferCreated() || polyBuffersContextIsOutdated()) {
|
||||
attrib.createBuffer(pgl);
|
||||
created = true;
|
||||
@@ -1363,12 +1363,12 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
tessGeo.polyTexCoordsBuffer, PGL.STATIC_DRAW);
|
||||
}
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
tessGeo.updateAttribBuffer(name);
|
||||
pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.glName);
|
||||
pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size),
|
||||
tessGeo.attribBuffers.get(name), PGL.STATIC_DRAW);
|
||||
tessGeo.polyAttribBuffers.get(name), PGL.STATIC_DRAW);
|
||||
}
|
||||
|
||||
tessGeo.updatePolyIndicesBuffer();
|
||||
@@ -1431,8 +1431,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
glPolyShininess = 0;
|
||||
}
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.glName != 0) {
|
||||
PGraphicsOpenGL.finalizeVertexBufferObject(attrib.glName, polyBuffersContext);
|
||||
attrib.glName = 0;
|
||||
@@ -2291,10 +2291,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
PGraphics.showWarning("Vertex attributes cannot have more than 4 values");
|
||||
return null;
|
||||
}
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib == null) {
|
||||
attrib = new VertexAttribute(name, type, size);
|
||||
attribs.put(name, attrib);
|
||||
polyAttribs.put(name, attrib);
|
||||
inGeo.initAttrib(attrib);
|
||||
tessGeo.initAttrib(attrib);
|
||||
}
|
||||
@@ -2585,8 +2585,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
shader.setTexture(tex);
|
||||
}
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
attrib.updateLoc(shader);
|
||||
shader.setAttributeVBO(attrib.glLoc, attrib.glName,
|
||||
attrib.size, attrib.type,
|
||||
@@ -8884,7 +8884,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
static protected class TessGeometry {
|
||||
int renderMode;
|
||||
PGraphicsOpenGL pg;
|
||||
AttributeMap attribs;
|
||||
AttributeMap polyAttribs;
|
||||
|
||||
// Tessellated polygon data
|
||||
int polyVertexCount;
|
||||
@@ -8903,7 +8903,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
FloatBuffer polyShininessBuffer;
|
||||
|
||||
// Generic attributes
|
||||
HashMap<String, Buffer> attribBuffers = new HashMap<String, Buffer>();
|
||||
HashMap<String, Buffer> polyAttribBuffers = new HashMap<String, Buffer>();
|
||||
|
||||
int polyIndexCount;
|
||||
int firstPolyIndex;
|
||||
@@ -8958,13 +8958,13 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
float[] pointOffsets;
|
||||
short[] pointIndices;
|
||||
|
||||
HashMap<String, float[]> fattribs = new HashMap<String, float[]>();
|
||||
HashMap<String, int[]> iattribs = new HashMap<String, int[]>();
|
||||
HashMap<String, byte[]> battribs = new HashMap<String, byte[]>();
|
||||
HashMap<String, float[]> fpolyAttribs = new HashMap<String, float[]>();
|
||||
HashMap<String, int[]> ipolyAttribs = new HashMap<String, int[]>();
|
||||
HashMap<String, byte[]> bpolyAttribs = new HashMap<String, byte[]>();
|
||||
|
||||
TessGeometry(PGraphicsOpenGL pg, AttributeMap attr, int mode) {
|
||||
this.pg = pg;
|
||||
this.attribs = attr;
|
||||
this.polyAttribs = attr;
|
||||
renderMode = mode;
|
||||
allocate();
|
||||
}
|
||||
@@ -9020,16 +9020,16 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
void initAttrib(VertexAttribute attrib) {
|
||||
if (attrib.type == PGL.FLOAT) {
|
||||
float[] temp = new float[attrib.tessSize * PGL.DEFAULT_TESS_VERTICES];
|
||||
fattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
fpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
} else if (attrib.type == PGL.INT) {
|
||||
int[] temp = new int[attrib.tessSize * PGL.DEFAULT_TESS_VERTICES];
|
||||
iattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
ipolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
} else if (attrib.type == PGL.BOOL) {
|
||||
byte[] temp = new byte[attrib.tessSize * PGL.DEFAULT_TESS_VERTICES];
|
||||
battribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
bpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9340,20 +9340,20 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
protected void updateAttribBuffer(String name, int offset, int size) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.type == PGL.FLOAT) {
|
||||
FloatBuffer buffer = (FloatBuffer)attribBuffers.get(name);
|
||||
float[] array = fattribs.get(name);
|
||||
FloatBuffer buffer = (FloatBuffer)polyAttribBuffers.get(name);
|
||||
float[] array = fpolyAttribs.get(name);
|
||||
PGL.updateFloatBuffer(buffer, array,
|
||||
attrib.tessSize * offset, attrib.tessSize * size);
|
||||
} else if (attrib.type == PGL.INT) {
|
||||
IntBuffer buffer = (IntBuffer)attribBuffers.get(name);
|
||||
int[] array = iattribs.get(name);
|
||||
IntBuffer buffer = (IntBuffer)polyAttribBuffers.get(name);
|
||||
int[] array = ipolyAttribs.get(name);
|
||||
PGL.updateIntBuffer(buffer, array,
|
||||
attrib.tessSize * offset, attrib.tessSize * size);
|
||||
} else if (attrib.type == PGL.BOOL) {
|
||||
ByteBuffer buffer = (ByteBuffer)attribBuffers.get(name);
|
||||
byte[] array = battribs.get(name);
|
||||
ByteBuffer buffer = (ByteBuffer)polyAttribBuffers.get(name);
|
||||
byte[] array = bpolyAttribs.get(name);
|
||||
PGL.updateByteBuffer(buffer, array,
|
||||
attrib.tessSize * offset, attrib.tessSize * size);
|
||||
}
|
||||
@@ -9496,8 +9496,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
void expandAttributes(int n) {
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.type == PGL.FLOAT) {
|
||||
expandFloatAttribute(attrib, n);
|
||||
} else if (attrib.type == PGL.INT) {
|
||||
@@ -9509,27 +9509,27 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
void expandFloatAttribute(VertexAttribute attrib, int n) {
|
||||
float[] array = fattribs.get(attrib.name);
|
||||
float[] array = fpolyAttribs.get(attrib.name);
|
||||
float temp[] = new float[attrib.tessSize * n];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
fattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
fpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
}
|
||||
|
||||
void expandIntAttribute(VertexAttribute attrib, int n) {
|
||||
int[] array = iattribs.get(attrib.name);
|
||||
int[] array = ipolyAttribs.get(attrib.name);
|
||||
int temp[] = new int[attrib.tessSize * n];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
iattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
ipolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
}
|
||||
|
||||
void expandBoolAttribute(VertexAttribute attrib, int n) {
|
||||
byte[] array = battribs.get(attrib.name);
|
||||
byte[] array = bpolyAttribs.get(attrib.name);
|
||||
byte temp[] = new byte[attrib.tessSize * n];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
battribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
bpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
}
|
||||
|
||||
void expandPolyIndices(int n) {
|
||||
@@ -9694,8 +9694,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
void trimAttributes() {
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.type == PGL.FLOAT) {
|
||||
trimFloatAttribute(attrib);
|
||||
} else if (attrib.type == PGL.INT) {
|
||||
@@ -9707,27 +9707,27 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
void trimFloatAttribute(VertexAttribute attrib) {
|
||||
float[] array = fattribs.get(attrib.name);
|
||||
float[] array = fpolyAttribs.get(attrib.name);
|
||||
float temp[] = new float[attrib.tessSize * polyVertexCount];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
fattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
fpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateFloatBuffer(temp));
|
||||
}
|
||||
|
||||
void trimIntAttribute(VertexAttribute attrib) {
|
||||
int[] array = iattribs.get(attrib.name);
|
||||
int[] array = ipolyAttribs.get(attrib.name);
|
||||
int temp[] = new int[attrib.tessSize * polyVertexCount];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
iattribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
ipolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateIntBuffer(temp));
|
||||
}
|
||||
|
||||
void trimBoolAttribute(VertexAttribute attrib) {
|
||||
byte[] array = battribs.get(attrib.name);
|
||||
byte[] array = bpolyAttribs.get(attrib.name);
|
||||
byte temp[] = new byte[attrib.tessSize * polyVertexCount];
|
||||
PApplet.arrayCopy(array, 0, temp, 0, attrib.tessSize * polyVertexCount);
|
||||
battribs.put(attrib.name, temp);
|
||||
attribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
bpolyAttribs.put(attrib.name, temp);
|
||||
polyAttribBuffers.put(attrib.name, PGL.allocateByteBuffer(temp));
|
||||
}
|
||||
|
||||
void trimPolyIndices() {
|
||||
@@ -10017,18 +10017,18 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
int tessIdx = polyVertexCount - 1;
|
||||
int index;
|
||||
int pos = 25;
|
||||
for (int i = 0; i < attribs.size(); i++) {
|
||||
VertexAttribute attrib = attribs.get(i);
|
||||
for (int i = 0; i < polyAttribs.size(); i++) {
|
||||
VertexAttribute attrib = polyAttribs.get(i);
|
||||
String name = attrib.name;
|
||||
index = attrib.tessSize * tessIdx;
|
||||
if (attrib.isColor()) {
|
||||
// Reconstruct color from ARGB components
|
||||
int color = (int)d[pos + 0]<<24 | (int)d[pos + 1]<<24 | ((int)d[pos + 2]<<8) | ((int)d[pos + 3]);
|
||||
int[] tessValues = iattribs.get(name);
|
||||
int[] tessValues = ipolyAttribs.get(name);
|
||||
tessValues[index] = color;
|
||||
pos += 4;
|
||||
} else if (attrib.isPosition()) {
|
||||
float[] farray = fattribs.get(name);
|
||||
float[] farray = fpolyAttribs.get(name);
|
||||
float x = (float)d[pos++];
|
||||
float y = (float)d[pos++];
|
||||
float z = (float)d[pos++];
|
||||
@@ -10052,7 +10052,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
farray[index ] = 1;
|
||||
}
|
||||
} else if (attrib.isNormal()) {
|
||||
float[] farray = fattribs.get(name);
|
||||
float[] farray = fpolyAttribs.get(name);
|
||||
float x = (float)d[pos + 0];
|
||||
float y = (float)d[pos + 1];
|
||||
float z = (float)d[pos + 2];
|
||||
@@ -10068,17 +10068,17 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
pos += 3;
|
||||
} else {
|
||||
if (attrib.isFloat()) {
|
||||
float[] farray = fattribs.get(name);
|
||||
float[] farray = fpolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
farray[index++] = (float)d[pos++];
|
||||
}
|
||||
} else if (attrib.isInt()) {
|
||||
int[] iarray = iattribs.get(name);
|
||||
int[] iarray = ipolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
iarray[index++] = (int)d[pos++];
|
||||
}
|
||||
} else if (attrib.isBool()) {
|
||||
byte[] barray = battribs.get(name);
|
||||
byte[] barray = bpolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
barray[index++] = (byte)d[pos++];
|
||||
}
|
||||
@@ -10219,8 +10219,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyNormals[index++] = nx*nm.m01 + ny*nm.m11 + nz*nm.m21;
|
||||
polyNormals[index ] = nx*nm.m02 + ny*nm.m12 + nz*nm.m22;
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isColor() || attrib.isOther()) continue;
|
||||
|
||||
float[] inValues = in.fattribs.get(name);
|
||||
@@ -10229,7 +10229,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
y = inValues[index++];
|
||||
z = inValues[index ];
|
||||
|
||||
float[] tessValues = fattribs.get(name);
|
||||
float[] tessValues = fpolyAttribs.get(name);
|
||||
if (attrib.isPosition()) {
|
||||
index = 4 * tessIdx;
|
||||
if (clampXY) {
|
||||
@@ -10281,8 +10281,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyNormals[index++] = ny;
|
||||
polyNormals[index ] = nz;
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isColor() || attrib.isOther()) continue;
|
||||
|
||||
float[] inValues = in.fattribs.get(name);
|
||||
@@ -10291,7 +10291,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
y = inValues[index++];
|
||||
z = inValues[index ];
|
||||
|
||||
float[] tessValues = fattribs.get(name);
|
||||
float[] tessValues = fpolyAttribs.get(name);
|
||||
if (attrib.isPosition()) {
|
||||
index = 4 * tessIdx;
|
||||
tessValues[index++] = x;
|
||||
@@ -10314,11 +10314,11 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyVertices, 4 * tessIdx, 3);
|
||||
polyVertices[4 * tessIdx + 3] = 1;
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (!attrib.isPosition()) continue;
|
||||
float[] inValues = in.fattribs.get(name);
|
||||
float[] tessValues = fattribs.get(name);
|
||||
float[] tessValues = fpolyAttribs.get(name);
|
||||
PApplet.arrayCopy(inValues, 3 * inIdx,
|
||||
tessValues, 4 * tessIdx, 3);
|
||||
tessValues[4 * tessIdx + 3] = 1;
|
||||
@@ -10326,11 +10326,11 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
PApplet.arrayCopy(in.normals, 3 * i0,
|
||||
polyNormals, 3 * firstPolyVertex, 3 * nvert);
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (!attrib.isPosition()) continue;
|
||||
float[] inValues = in.fattribs.get(name);
|
||||
float[] tessValues = fattribs.get(name);
|
||||
float[] tessValues = fpolyAttribs.get(name);
|
||||
PApplet.arrayCopy(inValues, 3 * i0,
|
||||
tessValues, 3 * firstPolyVertex, 3 * nvert);
|
||||
}
|
||||
@@ -10357,26 +10357,26 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyEmissive[tessIdx] = in.emissive[inIdx];
|
||||
polyShininess[tessIdx] = in.shininess[inIdx];
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isPosition() || attrib.isNormal()) continue;
|
||||
int index0 = attrib.size * inIdx;
|
||||
int index1 = attrib.size * tessIdx;
|
||||
if (attrib.isFloat()) {
|
||||
float[] inValues = in.fattribs.get(name);
|
||||
float[] tessValues = fattribs.get(name);
|
||||
float[] tessValues = fpolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
tessValues[index1++] = inValues[index0++];
|
||||
}
|
||||
} else if (attrib.isInt()) {
|
||||
int[] inValues = in.iattribs.get(name);
|
||||
int[] tessValues = iattribs.get(name);
|
||||
int[] tessValues = ipolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
tessValues[index1++] = inValues[index0++];
|
||||
}
|
||||
} else if (attrib.isBool()) {
|
||||
byte[] inValues = in.battribs.get(name);
|
||||
byte[] tessValues = battribs.get(name);
|
||||
byte[] tessValues = bpolyAttribs.get(name);
|
||||
for (int n = 0; n < attrib.size; n++) {
|
||||
tessValues[index1++] = inValues[index0++];
|
||||
}
|
||||
@@ -10397,20 +10397,20 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
PApplet.arrayCopy(in.shininess, i0,
|
||||
polyShininess, firstPolyVertex, nvert);
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isPosition() || attrib.isNormal()) continue;
|
||||
Object inValues = null;
|
||||
Object tessValues = null;
|
||||
if (attrib.isFloat()) {
|
||||
inValues = in.fattribs.get(name);
|
||||
tessValues = fattribs.get(name);
|
||||
tessValues = fpolyAttribs.get(name);
|
||||
} else if (attrib.isInt()) {
|
||||
inValues = in.iattribs.get(name);
|
||||
tessValues = iattribs.get(name);
|
||||
tessValues = ipolyAttribs.get(name);
|
||||
} else if (attrib.isBool()) {
|
||||
inValues = in.battribs.get(name);
|
||||
tessValues = battribs.get(name);
|
||||
tessValues = bpolyAttribs.get(name);
|
||||
PApplet.arrayCopy(inValues, attrib.size * i0,
|
||||
tessValues, attrib.size * firstPolyVertex,
|
||||
attrib.size * nvert);
|
||||
@@ -10471,10 +10471,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyNormals[index++] = nx*tr.m00 + ny*tr.m01;
|
||||
polyNormals[index ] = nx*tr.m10 + ny*tr.m11;
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isColor() || attrib.isOther()) continue;
|
||||
float[] values = fattribs.get(name);
|
||||
float[] values = fpolyAttribs.get(name);
|
||||
if (attrib.isPosition()) {
|
||||
index = 4 * i;
|
||||
x = values[index++];
|
||||
@@ -10565,10 +10565,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
polyNormals[index++] = nx*tr.m10 + ny*tr.m11 + nz*tr.m12;
|
||||
polyNormals[index ] = nx*tr.m20 + ny*tr.m21 + nz*tr.m22;
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.isColor() || attrib.isOther()) continue;
|
||||
float[] values = fattribs.get(name);
|
||||
float[] values = fpolyAttribs.get(name);
|
||||
if (attrib.isPosition()) {
|
||||
index = 4 * i;
|
||||
x = values[index++];
|
||||
@@ -10713,7 +10713,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
void initGluTess() {
|
||||
if (gluTess == null) {
|
||||
callback = new TessellatorCallback(tess.attribs);
|
||||
callback = new TessellatorCallback(tess.polyAttribs);
|
||||
gluTess = pg.pgl.createTessellator(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class PShapeOpenGL extends PShape {
|
||||
protected TessGeometry tessGeo;
|
||||
protected Tessellator tessellator;
|
||||
|
||||
protected AttributeMap attribs;
|
||||
protected AttributeMap polyAttribs;
|
||||
|
||||
// ........................................................
|
||||
|
||||
@@ -337,8 +337,8 @@ public class PShapeOpenGL extends PShape {
|
||||
this.tessellated = false;
|
||||
|
||||
if (family == GEOMETRY || family == PRIMITIVE || family == PATH) {
|
||||
attribs = PGraphicsOpenGL.newAttributeMap();
|
||||
inGeo = PGraphicsOpenGL.newInGeometry(pg, attribs, PGraphicsOpenGL.RETAINED);
|
||||
polyAttribs = PGraphicsOpenGL.newAttributeMap();
|
||||
inGeo = PGraphicsOpenGL.newInGeometry(pg, polyAttribs, PGraphicsOpenGL.RETAINED);
|
||||
}
|
||||
|
||||
// Style parameters are retrieved from the current values in the renderer.
|
||||
@@ -535,7 +535,7 @@ public class PShapeOpenGL extends PShape {
|
||||
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyShininess, context);
|
||||
}
|
||||
|
||||
for (VertexAttribute attrib: attribs.values()) {
|
||||
for (VertexAttribute attrib: polyAttribs.values()) {
|
||||
if (attrib.glName != 0) {
|
||||
PGraphicsOpenGL.finalizeVertexBufferObject(attrib.glName, context);
|
||||
}
|
||||
@@ -1160,10 +1160,10 @@ public class PShapeOpenGL extends PShape {
|
||||
PGraphics.showWarning("Vertex attributes cannot have more than 4 values");
|
||||
return null;
|
||||
}
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib == null) {
|
||||
attrib = new VertexAttribute(name, type, size);
|
||||
attribs.put(name, attrib);
|
||||
polyAttribs.put(name, attrib);
|
||||
inGeo.initAttrib(attrib);
|
||||
tessGeo.initAttrib(attrib);
|
||||
}
|
||||
@@ -1430,7 +1430,7 @@ public class PShapeOpenGL extends PShape {
|
||||
firstPolyVertex, lastPolyVertex);
|
||||
root.setModifiedPolyVertices(firstPolyVertex, lastPolyVertex);
|
||||
root.setModifiedPolyNormals(firstPolyVertex, lastPolyVertex);
|
||||
for (VertexAttribute attrib: attribs.values()) {
|
||||
for (VertexAttribute attrib: polyAttribs.values()) {
|
||||
if (attrib.isPosition() || attrib.isNormal()) {
|
||||
root.setModifiedPolyAttrib(attrib, firstPolyVertex, lastPolyVertex);
|
||||
}
|
||||
@@ -1500,14 +1500,6 @@ public class PShapeOpenGL extends PShape {
|
||||
inGeo.addBezierVertex(x2, y2, z2,
|
||||
x3, y3, z3,
|
||||
x4, y4, z4, vertexBreak());
|
||||
|
||||
// inGeo.addVertex(x2, y2, z2, BEZIER_VERTEX, vertexBreak());
|
||||
// inGeo.addVertex(x3, y3, z3, BEZIER_VERTEX, false);
|
||||
// inGeo.addVertex(x4, y4, z4, BEZIER_VERTEX, false);
|
||||
//// inGeo.addBezierVertex(x2, y2, z2,
|
||||
// x3, y3, z3,
|
||||
// x4, y4, z4,
|
||||
// fill, stroke, bezierDetail, vertexCode(), kind);
|
||||
}
|
||||
|
||||
|
||||
@@ -1534,11 +1526,6 @@ public class PShapeOpenGL extends PShape {
|
||||
inGeo.setNormal(normalX, normalY, normalZ);
|
||||
inGeo.addQuadraticVertex(cx, cy, cz,
|
||||
x3, y3, z3, vertexBreak());
|
||||
// inGeo.addVertex(cx, cy, cz, QUADRATIC_VERTEX, vertexBreak());
|
||||
// inGeo.addVertex(x3, y3, z3, QUADRATIC_VERTEX, false);
|
||||
// inGeo.addQuadraticVertex(cx, cy, cz,
|
||||
// x3, y3, z3,
|
||||
// fill, stroke, bezierDetail, vertexCode(), kind);
|
||||
}
|
||||
|
||||
|
||||
@@ -1586,9 +1573,6 @@ public class PShapeOpenGL extends PShape {
|
||||
ambientColor, specularColor, emissiveColor, shininess);
|
||||
inGeo.setNormal(normalX, normalY, normalZ);
|
||||
inGeo.addCurveVertex(x, y, z, vertexBreak());
|
||||
// inGeo.addVertex(x, y, z, CURVE_VERTEX, vertexBreak());
|
||||
// inGeo.addCurveVertex(x, y, z,
|
||||
// fill, stroke, curveDetail, vertexCode(), kind);
|
||||
}
|
||||
|
||||
|
||||
@@ -1658,7 +1642,9 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
// TODO: in certain cases (kind = TRIANGLE, etc) the correspondence between
|
||||
// input and tessellated vertices is 1-1, so in those cases re-tessellation
|
||||
// wouldn't be necessary.
|
||||
// wouldn't be necessary. But in order to reasonable take care of that
|
||||
// situation, we would need a complete rethinking of the rendering architecture
|
||||
// in Processing :-)
|
||||
inGeo.vertices[3 * index + 0] = x;
|
||||
inGeo.vertices[3 * index + 1] = y;
|
||||
inGeo.vertices[3 * index + 2] = z;
|
||||
@@ -1724,6 +1710,21 @@ public class PShapeOpenGL extends PShape {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAttrib(String name, int index, float... values) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAttrib(String name, int index, int... values) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAttrib(String name, int index, boolean... values) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getTextureU(int index) {
|
||||
return inGeo.texcoords[2 * index + 0];
|
||||
@@ -2736,7 +2737,7 @@ public class PShapeOpenGL extends PShape {
|
||||
protected void tessellate() {
|
||||
if (root == this && parent == null) {
|
||||
if (tessGeo == null) {
|
||||
tessGeo = PGraphicsOpenGL.newTessGeometry(pg, attribs, PGraphicsOpenGL.RETAINED);
|
||||
tessGeo = PGraphicsOpenGL.newTessGeometry(pg, polyAttribs, PGraphicsOpenGL.RETAINED);
|
||||
}
|
||||
tessGeo.clear();
|
||||
|
||||
@@ -3838,13 +3839,13 @@ public class PShapeOpenGL extends PShape {
|
||||
pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
|
||||
tessGeo.polyShininessBuffer, glUsage);
|
||||
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
tessGeo.updateAttribBuffer(attrib.name);
|
||||
if (!attrib.bufferCreated()) attrib.createBuffer(pgl);
|
||||
pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.glName);
|
||||
pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size),
|
||||
tessGeo.attribBuffers.get(name), PGL.STATIC_DRAW);
|
||||
tessGeo.polyAttribBuffers.get(name), PGL.STATIC_DRAW);
|
||||
}
|
||||
|
||||
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
|
||||
@@ -3956,7 +3957,7 @@ public class PShapeOpenGL extends PShape {
|
||||
PGraphicsOpenGL.removeVertexBufferObject(glPolySpecular, context);
|
||||
PGraphicsOpenGL.removeVertexBufferObject(glPolyEmissive, context);
|
||||
PGraphicsOpenGL.removeVertexBufferObject(glPolyShininess, context);
|
||||
for (VertexAttribute attrib: attribs.values()) {
|
||||
for (VertexAttribute attrib: polyAttribs.values()) {
|
||||
PGraphicsOpenGL.removeVertexBufferObject(attrib.glName, context);
|
||||
}
|
||||
PGraphicsOpenGL.removeVertexBufferObject(glPolyIndex, context);
|
||||
@@ -3983,7 +3984,7 @@ public class PShapeOpenGL extends PShape {
|
||||
glPolySpecular = 0;
|
||||
glPolyEmissive = 0;
|
||||
glPolyShininess = 0;
|
||||
for (VertexAttribute attrib: attribs.values()) attrib.glName = 0;
|
||||
for (VertexAttribute attrib: polyAttribs.values()) attrib.glName = 0;
|
||||
glPolyIndex = 0;
|
||||
|
||||
glLineVertex = 0;
|
||||
@@ -4055,7 +4056,7 @@ public class PShapeOpenGL extends PShape {
|
||||
glPolyShininess = 0;
|
||||
}
|
||||
|
||||
for (VertexAttribute attrib: attribs.values()) {
|
||||
for (VertexAttribute attrib: polyAttribs.values()) {
|
||||
attrib.deleteBuffer(pgl);
|
||||
}
|
||||
|
||||
@@ -4192,8 +4193,8 @@ public class PShapeOpenGL extends PShape {
|
||||
firstModifiedPolyShininess = PConstants.MAX_INT;
|
||||
lastModifiedPolyShininess = PConstants.MIN_INT;
|
||||
}
|
||||
for (String name: attribs.keySet()) {
|
||||
VertexAttribute attrib = attribs.get(name);
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
if (attrib.modified) {
|
||||
int offset = firstModifiedPolyVertex;
|
||||
int size = lastModifiedPolyVertex - offset + 1;
|
||||
@@ -4349,7 +4350,7 @@ public class PShapeOpenGL extends PShape {
|
||||
protected void copyPolyAttrib(VertexAttribute attrib, int offset, int size) {
|
||||
tessGeo.updateAttribBuffer(attrib.name, offset, size);
|
||||
pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.glName);
|
||||
Buffer buf = tessGeo.attribBuffers.get(attrib.name);
|
||||
Buffer buf = tessGeo.polyAttribBuffers.get(attrib.name);
|
||||
buf.position(attrib.size * offset);
|
||||
pgl.bufferSubData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(offset),
|
||||
attrib.sizeInBytes(size), buf);
|
||||
@@ -4868,6 +4869,14 @@ public class PShapeOpenGL extends PShape {
|
||||
shader.setTexture(tex);
|
||||
}
|
||||
|
||||
for (String name: polyAttribs.keySet()) {
|
||||
VertexAttribute attrib = polyAttribs.get(name);
|
||||
attrib.updateLoc(shader);
|
||||
shader.setAttributeVBO(attrib.glLoc, attrib.glName,
|
||||
attrib.size, attrib.type,
|
||||
attrib.isColor(), 0, attrib.sizeInBytes(voffset));
|
||||
}
|
||||
|
||||
shader.draw(root.glPolyIndex, icount, ioffset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user