Making PShapeOpenGL to work with the PApplet recorder

This commit is contained in:
codeanticode
2012-06-15 19:26:46 +00:00
parent ca758aedb6
commit ff0ae29cb6
3 changed files with 129 additions and 51 deletions
@@ -6529,7 +6529,7 @@ public class PGraphicsOpenGL extends PGraphics {
InGeometry(int mode) {
renderMode = mode;
allocate();
}
}
// -----------------------------------------------------------------
//
@@ -7084,6 +7084,53 @@ public class PGraphicsOpenGL extends PGraphics {
curveVertexCount = savedCount;
}
// Returns the vertex data in the PGraphics double array format.
float[][] getVertexData() {
float[][] data = new float[vertexCount][VERTEX_FIELD_COUNT];
for (int i = 0; i < vertexCount; i++) {
float[] vert = data[i];
vert[X] = vertices[3 * i + 0];
vert[Y] = vertices[3 * i + 1];
vert[Z] = vertices[3 * i + 2];
vert[R] = ((colors[i] >> 16) & 0xFF) / 255.0f;
vert[G] = ((colors[i] >> 8) & 0xFF) / 255.0f;
vert[B] = ((colors[i] >> 0) & 0xFF) / 255.0f;
vert[A] = ((colors[i] >> 24) & 0xFF) / 255.0f;
vert[U] = texcoords[2 * i + 0];
vert[V] = texcoords[2 * i + 1];
vert[NX] = normals[3 * i + 0];
vert[NY] = normals[3 * i + 1];
vert[NZ] = normals[3 * i + 2];
vert[SR] = ((strokeColors[i] >> 16) & 0xFF) / 255.0f;
vert[SG] = ((strokeColors[i] >> 8) & 0xFF) / 255.0f;
vert[SB] = ((strokeColors[i] >> 0) & 0xFF) / 255.0f;
vert[SA] = ((strokeColors[i] >> 24) & 0xFF) / 255.0f;
vert[SW] = strokeWeights[i];
vert[AR] = ((ambient[i] >> 16) & 0xFF) / 255.0f;
vert[AG] = ((ambient[i] >> 8) & 0xFF) / 255.0f;
vert[AB] = ((ambient[i] >> 0) & 0xFF) / 255.0f;
vert[SPR] = ((specular[i] >> 16) & 0xFF) / 255.0f;
vert[SPG] = ((specular[i] >> 8) & 0xFF) / 255.0f;
vert[SPB] = ((specular[i] >> 0) & 0xFF) / 255.0f;
vert[ER] = ((emissive[i] >> 16) & 0xFF) / 255.0f;
vert[EG] = ((emissive[i] >> 8) & 0xFF) / 255.0f;
vert[EB] = ((emissive[i] >> 0) & 0xFF) / 255.0f;
vert[SHINE] = shininess[i];
}
return data;
}
// -----------------------------------------------------------------
//
// Edges
@@ -7873,7 +7920,7 @@ public class PGraphicsOpenGL extends PGraphics {
indCount += 3 * detailU;
return indices;
}
}
}
@@ -3744,31 +3744,35 @@ public class PShapeOpenGL extends PShape {
// Applies the styles of g.
protected void styles(PGraphics g) {
if (stroke) {
stroke(g.strokeColor);
strokeWeight(g.strokeWeight);
// These two don't to nothing probably:
strokeCap(g.strokeCap);
strokeJoin(g.strokeJoin);
} else {
noStroke();
}
if (g instanceof PGraphicsOpenGL) {
if (stroke) {
stroke(g.strokeColor);
strokeWeight(g.strokeWeight);
// These two don't to nothing probably:
strokeCap(g.strokeCap);
strokeJoin(g.strokeJoin);
} else {
noStroke();
}
if (fill) {
fill(g.fillColor);
if (fill) {
fill(g.fillColor);
} else {
noFill();
}
ambient(g.ambientColor);
specular(g.specularColor);
emissive(g.emissiveColor);
shininess(g.shininess);
// What about other style parameters, such as rectMode, etc?
// These should force a tessellation update, same as stroke
// cap and weight... right?
} else {
noFill();
}
ambient(g.ambientColor);
specular(g.specularColor);
emissive(g.emissiveColor);
shininess(g.shininess);
// What about other style parameters, such as rectMode, etc?
// These should force a tessellation update, same as stroke
// cap and weight... right?
super.styles(g);
}
}
@@ -3785,31 +3789,39 @@ public class PShapeOpenGL extends PShape {
public void draw(PGraphics g) {
if (visible) {
pre(g);
updateTessellation();
updateGeometry();
if (family == GROUP) {
if (fragmentedGroup(g)) {
for (int i = 0; i < childCount; i++) {
((PShapeOpenGL) children[i]).draw(g);
}
} else {
PImage tex = null;
if (textures != null && textures.size() == 1) {
tex = (PImage)textures.toArray()[0];
if (g instanceof PGraphicsOpenGL) {
if (visible) {
pre(g);
updateTessellation();
updateGeometry();
if (family == GROUP) {
if (fragmentedGroup(g)) {
for (int i = 0; i < childCount; i++) {
((PShapeOpenGL) children[i]).draw(g);
}
} else {
PImage tex = null;
if (textures != null && textures.size() == 1) {
tex = (PImage)textures.toArray()[0];
}
render((PGraphicsOpenGL)g, tex);
}
render((PGraphicsOpenGL)g, tex);
} else {
render((PGraphicsOpenGL)g, texture);
}
} else {
render((PGraphicsOpenGL)g, texture);
}
post(g);
}
post(g);
}
} else {
// The renderer is not PGraphicsOpenGL, which probably
// means that the draw() method is being called by the
// recorder. We just use the default drawing from the
// parent class.
super.draw(g);
}
}
@@ -3826,16 +3838,35 @@ public class PShapeOpenGL extends PShape {
protected void pre(PGraphics g) {
if (!style) {
styles(g);
if (g instanceof PGraphicsOpenGL) {
if (!style) {
styles(g);
}
} else {
super.pre(g);
}
}
public void post(PGraphics g) {
if (g instanceof PGraphicsOpenGL) {
} else {
super.post(g);
}
}
protected void drawGeometry(PGraphics g) {
vertexCount = inGeo.vertexCount;
vertices = inGeo.getVertexData();
super.drawGeometry(g);
vertexCount = 0;
vertices = null;
}
// Render the geometry stored in the root shape as VBOs, for the vertices
// corresponding to this shape. Sometimes we can have root == this.
protected void render(PGraphicsOpenGL g, PImage texture) {
@@ -51,7 +51,7 @@ public class Texture implements PConstants {
public static final int TEXRECT = 1;
/** Point sampling: both magnification and minification filtering are set to nearest */
//public static final int POINT = 2; // shared with shape feature
public static final int POINT = 2;
/** Linear sampling: magnification filtering is nearest, minification set to linear */
public static final int LINEAR = 3;
/** Bilinear sampling: both magnification filtering is set to linear and minification