@@ -1664,17 +1664,17 @@ public class PImage implements PConstants, Cloneable {
/**
* ( begin auto-generated from PImage_blend.xml )
- *
- * Blends a region of pixels into the image specified by the img
- * parameter. These copies utilize full alpha channel support and a choice
- * of the following modes to blend the colors of source pixels (A) with the
+ *
+ * Blends a region of pixels into the image specified by the img
+ * parameter. These copies utilize full alpha channel support and a choice
+ * of the following modes to blend the colors of source pixels (A) with the
* ones of pixels in the destination image (B):
*
* BLEND - linear interpolation of colours: C = A*factor + B
*
* ADD - additive blending with white clip: C = min(A*factor + B, 255)
*
- * SUBTRACT - subtractive blending with black clip: C = max(B - A*factor,
+ * SUBTRACT - subtractive blending with black clip: C = max(B - A*factor,
* 0)
*
* DARKEST - only the darkest colour succeeds: C = min(A*factor, B)
@@ -1694,7 +1694,7 @@ public class PImage implements PConstants, Cloneable {
*
* HARD_LIGHT - SCREEN when greater than 50% gray, MULTIPLY when lower.
*
- * SOFT_LIGHT - Mix of DARKEST and LIGHTEST.
+ * SOFT_LIGHT - Mix of DARKEST and LIGHTEST.
* Works like OVERLAY, but not as harsh.
*
* DODGE - Lightens light tones and increases contrast, ignores darks.
@@ -1703,14 +1703,14 @@ public class PImage implements PConstants, Cloneable {
* BURN - Darker areas are applied, increasing contrast, ignores lights.
* Called "Color Burn" in Illustrator and Photoshop.
*
- * All modes use the alpha information (highest byte) of source image
- * pixels as the blending factor. If the source and destination regions are
- * different sizes, the image will be automatically resized to match the
- * destination size. If the srcImg parameter is not used, the
+ * All modes use the alpha information (highest byte) of source image
+ * pixels as the blending factor. If the source and destination regions are
+ * different sizes, the image will be automatically resized to match the
+ * destination size. If the srcImg parameter is not used, the
* display window is used as the source image.
*
* As of release 0149, this function ignores imageMode().
- *
+ *
* ( end auto-generated )
*
* @webref image:pixels
@@ -2962,7 +2962,7 @@ public class PImage implements PConstants, Cloneable {
try {
int outputFormat = (format == ARGB) ?
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
-
+
// JPEG and BMP images that have an alpha channel set get pretty unhappy.
// BMP just doesn't write, and JPEG writes it as a CMYK image.
// http://code.google.com/p/processing/issues/detail?id=415
@@ -2970,7 +2970,7 @@ public class PImage implements PConstants, Cloneable {
if (lower.endsWith("bmp") || lower.endsWith("jpg") || lower.endsWith("jpeg")) {
outputFormat = BufferedImage.TYPE_INT_RGB;
}
-
+
BufferedImage bimage = new BufferedImage(width, height, outputFormat);
bimage.setRGB(0, 0, width, height, pixels, 0, width);
@@ -2990,21 +2990,21 @@ public class PImage implements PConstants, Cloneable {
/**
* ( begin auto-generated from PImage_save.xml )
- *
- * Saves the image into a file. Images are saved in TIFF, TARGA, JPEG, and
- * PNG format depending on the extension within the filename
- * parameter. For example, "image.tif" will have a TIFF image and
- * "image.png" will save a PNG image. If no extension is included in the
- * filename, the image will save in TIFF format and .tif will be
- * added to the name. These files are saved to the sketch's folder, which
- * may be opened by selecting "Show sketch folder" from the "Sketch" menu.
- * It is not possible to use save() while running the program in a
- * web browser.
To save an image created within the code, rather
- * than through loading, it's necessary to make the image with the
- * createImage() function so it is aware of the location of the
- * program and can therefore save the file to the right place. See the
+ *
+ * Saves the image into a file. Images are saved in TIFF, TARGA, JPEG, and
+ * PNG format depending on the extension within the filename
+ * parameter. For example, "image.tif" will have a TIFF image and
+ * "image.png" will save a PNG image. If no extension is included in the
+ * filename, the image will save in TIFF format and .tif will be
+ * added to the name. These files are saved to the sketch's folder, which
+ * may be opened by selecting "Show sketch folder" from the "Sketch" menu.
+ * It is not possible to use save() while running the program in a
+ * web browser.
To save an image created within the code, rather
+ * than through loading, it's necessary to make the image with the
+ * createImage() function so it is aware of the location of the
+ * program and can therefore save the file to the right place. See the
* createImage() reference for more information.
- *
+ *
* ( end auto-generated )
* Advanced
* Save this image to disk.
@@ -3042,14 +3042,14 @@ public class PImage implements PConstants, Cloneable {
if (parent != null) {
// use savePath(), so that the intermediate directories are created
filename = parent.savePath(filename);
-
+
} else {
File file = new File(filename);
if (file.isAbsolute()) {
// make sure that the intermediate folders have been created
PApplet.createPath(file);
} else {
- String msg =
+ String msg =
"PImage.save() requires an absolute path. " +
"Use createImage(), or pass savePath() to save().";
PGraphics.showException(msg);
diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java
index 07a5a6890..98a985e4e 100644
--- a/core/src/processing/core/PShape.java
+++ b/core/src/processing/core/PShape.java
@@ -245,8 +245,8 @@ public class PShape implements PConstants {
public PShape() {
this.family = GROUP;
}
-
-
+
+
/**
* @nowebref
*/
@@ -254,12 +254,12 @@ public class PShape implements PConstants {
this.family = family;
}
-
+
public void setKind(int kind) {
this.kind = kind;
}
-
-
+
+
public void setName(String name) {
this.name = name;
}
@@ -395,15 +395,15 @@ public class PShape implements PConstants {
//checkBounds();
return depth;
}
-
-
-
+
+
+
// TODO: need to discuss about these two (four).
public PVector getTop() {
return getTop(null);
- }
-
-
+ }
+
+
public PVector getTop(PVector top) {
if (top == null) {
top = new PVector();
@@ -411,28 +411,28 @@ public class PShape implements PConstants {
return top;
}
-
+
public PVector getBottom() {
return getBottom(null);
- }
-
-
+ }
+
+
public PVector getBottom(PVector bottom) {
if (bottom == null) {
bottom = new PVector();
- }
+ }
return bottom;
- }
-
+ }
+
/**
* Return true if this shape is 2D. Defaults to true.
- */
+ */
public boolean is2D() {
return true;
}
-
-
+
+
/**
* Return true if this shape is 3D. Defaults to false.
*/
@@ -440,14 +440,14 @@ public class PShape implements PConstants {
return false;
}
-
+
/**
* Return true if this shape requires rendering through OpenGL. Defaults to false.
- */
+ */
public boolean isGL() {
return false;
}
-
+
///////////////////////////////////////////////////////////
@@ -584,50 +584,50 @@ public class PShape implements PConstants {
//////////////////////////////////////////////////////////////
// Ambient set/update
-
- public void ambient(int rgb) {
+
+ public void ambient(int rgb) {
}
-
- public void ambient(float gray) {
+
+ public void ambient(float gray) {
}
-
+
public void ambient(float x, float y, float z) {
}
-
+
//////////////////////////////////////////////////////////////
// Specular set/update
-
- public void specular(int rgb) {
+
+ public void specular(int rgb) {
}
-
- public void specular(float gray) {
+
+ public void specular(float gray) {
}
-
+
public void specular(float x, float y, float z) {
- }
-
-
+ }
+
+
//////////////////////////////////////////////////////////////
- // Emissive set/update
+ // Emissive set/update
- public void emissive(int rgb) {
+ public void emissive(int rgb) {
}
-
- public void emissive(float gray) {
+
+ public void emissive(float gray) {
}
-
+
public void emissive(float x, float y, float z) {
- }
-
+ }
+
//////////////////////////////////////////////////////////////
- // Shininess set/update
-
- public void shininess(float shine) {
- }
-
+ // Shininess set/update
+
+ public void shininess(float shine) {
+ }
+
///////////////////////////////////////////////////////////
//
@@ -744,7 +744,7 @@ public class PShape implements PConstants {
}
- public void post(PGraphics g) {
+ protected void post(PGraphics g) {
// for (int i = 0; i < childCount; i++) {
// children[i].draw(g);
// }
@@ -771,18 +771,18 @@ public class PShape implements PConstants {
g.popStyle();
}
}
-
-
+
+
////////////////////////////////////////////////////////////////////////
//
// Shape copy
-
-
+
+
static public PShape createShape(PApplet parent, PShape src) {
PShape dest = null;
if (src.family == GROUP) {
dest = parent.createShape(GROUP);
- PShape.copyGroup(parent, src, dest);
+ PShape.copyGroup(parent, src, dest);
} else if (src.family == PRIMITIVE) {
dest = parent.createShape(src.kind, src.params);
PShape.copyPrimitive(src, dest);
@@ -797,7 +797,7 @@ public class PShape implements PConstants {
return dest;
}
-
+
static public void copyGroup(PApplet parent, PShape src, PShape dest) {
copyMatrix(src, dest);
copyStyles(src, dest);
@@ -807,32 +807,32 @@ public class PShape implements PConstants {
dest.addChild(c);
}
}
-
-
+
+
static public void copyPrimitive(PShape src, PShape dest) {
- copyMatrix(src, dest);
+ copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
}
-
-
+
+
static public void copyGeometry(PShape src, PShape dest) {
- copyMatrix(src, dest);
+ copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
-
+
if (src.style) {
for (int i = 0; i < src.vertexCount; i++) {
float[] vert = src.vertices[i];
-
+
// Do we need to copy these as well?
// s.ambient(vert[AR] * 255, vert[AG] * 255, vert[AB] * 255);
// s.specular(vert[SPR] * 255, vert[SPG] * 255, vert[SPB] * 255);
// s.emissive(vert[ER] * 255, vert[EG] * 255, vert[EB] * 255);
// s.shininess(vert[SHINE]);
-
+
dest.normal(vert[NX], vert[NY], vert[NZ]);
- dest.vertex(vert[X], vert[Y], vert[Z], vert[U], vert[V]);
+ dest.vertex(vert[X], vert[Y], vert[Z], vert[U], vert[V]);
}
} else {
for (int i = 0; i < src.vertexCount; i++) {
@@ -844,26 +844,26 @@ public class PShape implements PConstants {
}
}
}
-
- dest.end();
+
+ dest.end();
}
-
-
+
+
static public void copyPath(PShape src, PShape dest) {
- copyMatrix(src, dest);
+ copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
dest.close = src.close;
- dest.setPath(src.vertexCount, src.vertices, src.vertexCodeCount, src.vertexCodes);
+ dest.setPath(src.vertexCount, src.vertices, src.vertexCodeCount, src.vertexCodes);
}
-
-
+
+
static public void copyMatrix(PShape src, PShape dest) {
if (src.matrix != null) {
- dest.applyMatrix(src.matrix);
- }
+ dest.applyMatrix(src.matrix);
+ }
}
-
+
static public void copyStyles(PShape src, PShape dest) {
if (src.stroke) {
dest.stroke = true;
@@ -881,18 +881,18 @@ public class PShape implements PConstants {
} else {
dest.fill = false;
}
- }
-
-
+ }
+
+
static public void copyImage(PShape src, PShape dest) {
if (src.image != null) {
dest.texture(src.image);
- }
+ }
}
-
-
+
+
////////////////////////////////////////////////////////////////////////
-
+
/**
* Called by the following (the shape() command adds the g)
@@ -1178,8 +1178,8 @@ public class PShape implements PConstants {
}
g.endShape(close ? CLOSE : OPEN);
}
-
-
+
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -1335,15 +1335,11 @@ public class PShape implements PConstants {
}
- public void updateRoot(PShape root) {
- }
-
-
public PShape getTessellation() {
return null;
}
-
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -1392,38 +1388,38 @@ public class PShape implements PConstants {
public void setPath(int vcount, float[][] verts) {
setPath(vcount, verts, 0, null);
}
-
-
+
+
public void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
if (verts == null || verts.length < vcount) return;
if (0 < ccount && (codes == null || codes.length < ccount)) return;
-
+
int ndim = verts[0].length;
vertexCount = vcount;
vertices = new float[vertexCount][ndim];
for (int i = 0; i < vertexCount; i++) {
PApplet.arrayCopy(verts[i], vertices[i]);
- }
-
+ }
+
vertexCodeCount = ccount;
if (0 < vertexCodeCount) {
vertexCodes = new int[vertexCodeCount];
PApplet.arrayCopy(codes, vertexCodes, vertexCodeCount);
- }
+ }
}
-
-
+
+
public int getVertexCount() {
return vertexCount;
}
-
+
public PVector getVertex(int index) {
return getVertex(index, null);
- }
-
-
+ }
+
+
public PVector getVertex(int index, PVector vec) {
if (vec == null) {
vec = new PVector();
@@ -1434,7 +1430,7 @@ public class PShape implements PConstants {
return vec;
}
-
+
public float getVertexX(int index) {
return vertices[index][X];
}
@@ -1449,31 +1445,31 @@ public class PShape implements PConstants {
return vertices[index][Z];
}
-
+
public void setVertex(int index, float x, float y) {
setVertex(index, x, y, 0);
}
-
-
+
+
public void setVertex(int index, float x, float y, float z) {
vertices[index][X] = x;
vertices[index][Y] = y;
vertices[index][Z] = z;
}
-
-
+
+
public void setVertex(int index, PVector vec) {
vertices[index][X] = vec.x;
vertices[index][Y] = vec.y;
- vertices[index][Z] = vec.z;
+ vertices[index][Z] = vec.z;
}
-
-
+
+
public PVector getNormal(int index) {
return getNormal(index, null);
}
-
-
+
+
public PVector getNormal(int index, PVector vec) {
if (vec == null) {
vec = new PVector();
@@ -1481,92 +1477,92 @@ public class PShape implements PConstants {
vec.x = vertices[index][NX];
vec.y = vertices[index][NY];
vec.z = vertices[index][NZ];
- return vec;
+ return vec;
}
-
-
+
+
public float getNormalX(int index) {
return vertices[index][NX];
}
-
+
public float getNormalY(int index) {
return vertices[index][NY];
}
-
-
+
+
public float getNormalZ(int index) {
- return vertices[index][NZ];
- }
-
+ return vertices[index][NZ];
+ }
+
public void setNormal(int index, float nx, float ny, float nz) {
vertices[index][NX] = nx;
vertices[index][NY] = ny;
- vertices[index][NZ] = nz;
+ vertices[index][NZ] = nz;
}
-
-
+
+
public float getTextureU(int index) {
return vertices[index][U];
}
-
-
+
+
public float getTextureV(int index) {
return vertices[index][V];
- }
-
-
+ }
+
+
public void setTextureUV(int index, float u, float v) {
vertices[index][U] = u;
vertices[index][V] = v;
}
-
-
+
+
public int getFill(int index) {
int a = (int) (vertices[index][A] * 255);
int r = (int) (vertices[index][R] * 255);
int g = (int) (vertices[index][G] * 255);
- int b = (int) (vertices[index][B] * 255);
+ int b = (int) (vertices[index][B] * 255);
return (a << 24) | (r << 16) | (g << 8) | b;
}
-
+
public void setFill(int index, int fill) {
- vertices[index][A] = ((fill >> 24) & 0xFF) / 255.0f;
+ vertices[index][A] = ((fill >> 24) & 0xFF) / 255.0f;
vertices[index][R] = ((fill >> 16) & 0xFF) / 255.0f;
vertices[index][G] = ((fill >> 8) & 0xFF) / 255.0f;
- vertices[index][B] = ((fill >> 0) & 0xFF) / 255.0f;
- }
+ vertices[index][B] = ((fill >> 0) & 0xFF) / 255.0f;
+ }
+
-
public int getStroke(int index) {
int a = (int) (vertices[index][SA] * 255);
int r = (int) (vertices[index][SR] * 255);
int g = (int) (vertices[index][SG] * 255);
- int b = (int) (vertices[index][SB] * 255);
+ int b = (int) (vertices[index][SB] * 255);
return (a << 24) | (r << 16) | (g << 8) | b;
}
-
+
public void setStroke(int index, int stroke) {
- vertices[index][SA] = ((stroke >> 24) & 0xFF) / 255.0f;
+ vertices[index][SA] = ((stroke >> 24) & 0xFF) / 255.0f;
vertices[index][SR] = ((stroke >> 16) & 0xFF) / 255.0f;
vertices[index][SG] = ((stroke >> 8) & 0xFF) / 255.0f;
- vertices[index][SB] = ((stroke >> 0) & 0xFF) / 255.0f;
- }
-
-
+ vertices[index][SB] = ((stroke >> 0) & 0xFF) / 255.0f;
+ }
+
+
public float getStrokeWeight(int index) {
return vertices[index][SW];
}
-
+
public void setStrokeWeight(int index, float weight) {
vertices[index][SW] = weight;
- }
-
-
+ }
+
+
public int getAmbient(int index) {
int r = (int) (vertices[index][AR] * 255);
int g = (int) (vertices[index][AG] * 255);
@@ -1574,13 +1570,13 @@ public class PShape implements PConstants {
return 0xff000000 | (r << 16) | (g << 8) | b;
}
-
+
public void setAmbient(int index, int ambient) {
vertices[index][AR] = ((ambient >> 16) & 0xFF) / 255.0f;
vertices[index][AG] = ((ambient >> 8) & 0xFF) / 255.0f;
- vertices[index][AB] = ((ambient >> 0) & 0xFF) / 255.0f;
- }
-
+ vertices[index][AB] = ((ambient >> 0) & 0xFF) / 255.0f;
+ }
+
public int getSpecular(int index) {
int r = (int) (vertices[index][SPR] * 255);
int g = (int) (vertices[index][SPG] * 255);
@@ -1588,14 +1584,14 @@ public class PShape implements PConstants {
return 0xff000000 | (r << 16) | (g << 8) | b;
}
-
+
public void setSpecular(int index, int specular) {
vertices[index][SPR] = ((specular >> 16) & 0xFF) / 255.0f;
vertices[index][SPG] = ((specular >> 8) & 0xFF) / 255.0f;
- vertices[index][SPB] = ((specular >> 0) & 0xFF) / 255.0f;
- }
-
-
+ vertices[index][SPB] = ((specular >> 0) & 0xFF) / 255.0f;
+ }
+
+
public int getEmissive(int index) {
int r = (int) (vertices[index][ER] * 255);
int g = (int) (vertices[index][EG] * 255);
@@ -1603,24 +1599,24 @@ public class PShape implements PConstants {
return 0xff000000 | (r << 16) | (g << 8) | b;
}
-
+
public void setEmissive(int index, int emissive) {
vertices[index][ER] = ((emissive >> 16) & 0xFF) / 255.0f;
vertices[index][EG] = ((emissive >> 8) & 0xFF) / 255.0f;
- vertices[index][EB] = ((emissive >> 0) & 0xFF) / 255.0f;
- }
-
-
+ vertices[index][EB] = ((emissive >> 0) & 0xFF) / 255.0f;
+ }
+
+
public float getShininess(int index) {
return vertices[index][SHINE];
}
-
+
public void setShininess(int index, float shine) {
vertices[index][SHINE] = shine;
}
-
-
+
+
public int[] getVertexCodes() {
if (vertexCodes == null) {
return null;
@@ -1630,12 +1626,12 @@ public class PShape implements PConstants {
}
return vertexCodes;
}
-
-
+
+
public int getVertexCodeCount() {
return vertexCodeCount;
}
-
+
/**
* One of VERTEX, BEZIER_VERTEX, CURVE_VERTEX, or BREAK.
@@ -1842,7 +1838,7 @@ public class PShape implements PConstants {
v0 /= norm;
v1 /= norm;
v2 /= norm;
- }
+ }
matrix.rotate(angle, v0, v1, v2);
}
diff --git a/core/src/processing/core/PShapeSVG.java b/core/src/processing/core/PShapeSVG.java
index 6df9757d8..cb420f649 100644
--- a/core/src/processing/core/PShapeSVG.java
+++ b/core/src/processing/core/PShapeSVG.java
@@ -1599,6 +1599,7 @@ public class PShapeSVG extends PShape {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
+ @Override
protected void styles(PGraphics g) {
super.styles(g);
@@ -1834,6 +1835,7 @@ public class PShapeSVG extends PShape {
* PShape layer3 = svg.getChild("Layer 3");
*
*/
+ @Override
public PShape getChild(String name) {
PShape found = super.getChild(name);
if (found == null) {
diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java
index 3f68004ff..a66c3997e 100644
--- a/core/src/processing/core/PVector.java
+++ b/core/src/processing/core/PVector.java
@@ -30,28 +30,28 @@ import processing.core.PConstants;
/**
* ( begin auto-generated from PVector.xml )
- *
- * A class to describe a two or three dimensional vector. This datatype
- * stores two or three variables that are commonly used as a position,
- * velocity, and/or acceleration. Technically, position is a point
- * and velocity and acceleration are vectors, but this is
- * often simplified to consider all three as vectors. For example, if you
- * consider a rectangle moving across the screen, at any given instant it
- * has a position (the object's location, expressed as a point.), a
- * velocity (the rate at which the object's position changes per time unit,
- * expressed as a vector), and acceleration (the rate at which the object's
- * velocity changes per time unit, expressed as a vector). Since vectors
- * represent groupings of values, we cannot simply use traditional
- * addition/multiplication/etc. Instead, we'll need to do some "vector"
- * math, which is made easy by the methods inside the PVector
+ *
+ * A class to describe a two or three dimensional vector. This datatype
+ * stores two or three variables that are commonly used as a position,
+ * velocity, and/or acceleration. Technically, position is a point
+ * and velocity and acceleration are vectors, but this is
+ * often simplified to consider all three as vectors. For example, if you
+ * consider a rectangle moving across the screen, at any given instant it
+ * has a position (the object's location, expressed as a point.), a
+ * velocity (the rate at which the object's position changes per time unit,
+ * expressed as a vector), and acceleration (the rate at which the object's
+ * velocity changes per time unit, expressed as a vector). Since vectors
+ * represent groupings of values, we cannot simply use traditional
+ * addition/multiplication/etc. Instead, we'll need to do some "vector"
+ * math, which is made easy by the methods inside the PVector
* class.
*
- * The methods for this class are extensive. For a complete list, visit the
- * developer's reference.
- *
+ *
* ( end auto-generated )
- *
+ *
* A class to describe a two or three dimensional vector.
*
* The result of all functions are applied to the vector itself, with the
@@ -64,7 +64,7 @@ import processing.core.PConstants;
* new PVector object is not created with each operation.
*
* Initially based on the Vector3D class by Dan Shiffman.
- *
+ *
* @webref math
*/
public class PVector implements Serializable {
@@ -74,42 +74,42 @@ public class PVector implements Serializable {
*/
private static final long serialVersionUID = -6717872085945400694L;
- /**
+ /**
* ( begin auto-generated from PVector_x.xml )
- *
- * The x component of the vector. This field (variable) can be used to both
+ *
+ * The x component of the vector. This field (variable) can be used to both
* get and set the value (see above example.)
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:field
* @usage web_application
* @brief The x component of the vector
*/
public float x;
- /**
+ /**
* ( begin auto-generated from PVector_y.xml )
- *
- * The y component of the vector. This field (variable) can be used to both
+ *
+ * The y component of the vector. This field (variable) can be used to both
* get and set the value (see above example.)
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:field
* @usage web_application
* @brief The y component of the vector
*/
public float y;
- /**
+ /**
* ( begin auto-generated from PVector_z.xml )
- *
- * The z component of the vector. This field (variable) can be used to both
+ *
+ * The z component of the vector. This field (variable) can be used to both
* get and set the value (see above example.)
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:field
* @usage web_application
* @brief The z component of the vector
@@ -152,12 +152,12 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_set.xml )
- *
- * Sets the x, y, and z component of the vector using three separate
+ *
+ * Sets the x, y, and z component of the vector using three separate
* variables, the data from a PVector, or the values from a float array.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @param x the x component of the vector
* @param y the y component of the vector
@@ -198,11 +198,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_random2D.xml )
- *
+ *
* Make a new 2D unit vector with a random direction. If you pass in "this"
* as an argument, it will use the PApplet's random number generator. You can
* also pass in a target PVector to fill.
- *
+ *
* @webref pvector:method
* @usage web_application
* @return the random PVector
@@ -238,17 +238,17 @@ public class PVector implements Serializable {
* @return the random PVector
*/
static public PVector random2D(PVector target, PApplet parent) {
- if (parent == null) return fromAngle((float)(Math.random()*Math.PI*2),target);
+ if (parent == null) return fromAngle((float)(Math.random()*Math.PI*2),target);
else return fromAngle(parent.random(PConstants.TWO_PI),target);
}
/**
* ( begin auto-generated from PVector_random3D.xml )
- *
+ *
* Make a new 3D unit vector with a random direction. If you pass in "this"
* as an argument, it will use the PApplet's random number generator. You can
* also pass in a target PVector to fill.
- *
+ *
* @webref pvector:method
* @usage web_application
* @return the random PVector
@@ -306,11 +306,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_sub.xml )
- *
+ *
* Make a new 2D unit vector from an angle.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Make a new 2D unit vector from an angle
@@ -339,11 +339,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_get.xml )
- *
+ *
* Gets a copy of the vector, returns a PVector object.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Get a copy of the vector
@@ -372,12 +372,12 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_mag.xml )
- *
- * Calculates the magnitude (length) of the vector and returns the result
+ *
+ * Calculates the magnitude (length) of the vector and returns the result
* as a float (this is simply the equation sqrt(x*x + y*y + z*z).)
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Calculate the magnitude of the vector
@@ -389,14 +389,14 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_mag.xml )
- *
- * Calculates the squared magnitude of the vector and returns the result
+ *
+ * Calculates the squared magnitude of the vector and returns the result
* as a float (this is simply the equation (x*x + y*y + z*z).)
- * Faster if the real length is not required in the
+ * Faster if the real length is not required in the
* case of comparing vectors, etc.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Calculate the magnitude of the vector
@@ -409,15 +409,15 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_add.xml )
- *
- * Adds x, y, and z components to a vector, adds one vector to another, or
- * adds two independent vectors together. The version of the method that
- * adds two vectors together is a static method and returns a PVector, the
- * others have no return value -- they act directly on the vector. See the
+ *
+ * Adds x, y, and z components to a vector, adds one vector to another, or
+ * adds two independent vectors together. The version of the method that
+ * adds two vectors together is a static method and returns a PVector, the
+ * others have no return value -- they act directly on the vector. See the
* examples for more context.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param v the vector to be added
@@ -467,15 +467,15 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_sub.xml )
- *
- * Subtracts x, y, and z components from a vector, subtracts one vector
- * from another, or subtracts two independent vectors. The version of the
- * method that subtracts two vectors is a static method and returns a
- * PVector, the others have no return value -- they act directly on the
+ *
+ * Subtracts x, y, and z components from a vector, subtracts one vector
+ * from another, or subtracts two independent vectors. The version of the
+ * method that subtracts two vectors is a static method and returns a
+ * PVector, the others have no return value -- they act directly on the
* vector. See the examples for more context.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param v any variable of type PVector
@@ -526,11 +526,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_mult.xml )
- *
+ *
* Multiplies a vector by a scalar or multiplies one vector by another.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param n the number to multiply with the vector
@@ -572,8 +572,8 @@ public class PVector implements Serializable {
/**
- * @param v1 the x, y, and z components of a PVector
- * @param v2 the x, y, and z components of a PVector
+ * @param v1 the x, y, and z components of a PVector
+ * @param v2 the x, y, and z components of a PVector
*/
static public PVector mult(PVector v1, PVector v2) {
return mult(v1, v2, null);
@@ -592,11 +592,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_div.xml )
- *
+ *
* Divides a vector by a scalar or divides one vector by another.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param n the value to divide by
@@ -665,12 +665,12 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_dist.xml )
- *
- * Calculates the Euclidean distance between two points (considering a
+ *
+ * Calculates the Euclidean distance between two points (considering a
* point as a vector object).
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param v the x, y, and z coordinates of a PVector
@@ -699,11 +699,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_dot.xml )
- *
+ *
* Calculates the dot product of two vectors.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param v any variable of type PVector
@@ -734,12 +734,12 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_cross.xml )
- *
- * Calculates and returns a vector composed of the cross product between
+ *
+ * Calculates and returns a vector composed of the cross product between
* two vectors.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @param v the vector to calculate the cross product
* @brief Calculate and return the cross product
@@ -787,11 +787,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_normalize.xml )
- *
+ *
* Normalize the vector to length 1 (make it a unit vector).
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Normalize the vector to a length of 1
@@ -824,11 +824,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_limit.xml )
- *
+ *
* Limit the magnitude of this vector to the value used for the max parameter.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param max the maximum magnitude for the vector
@@ -843,11 +843,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_setMag.xml )
- *
+ *
* Set the magnitude of this vector to the value used for the len parameter.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param len the new length for this vector
@@ -855,7 +855,7 @@ public class PVector implements Serializable {
*/
public void setMag(float len) {
normalize();
- mult(len);
+ mult(len);
}
/**
@@ -872,11 +872,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_setMag.xml )
- *
+ *
* Calculate the angle of rotation for this vector (only 2D vectors)
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @return the angle of rotation
@@ -889,11 +889,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_rotate.xml )
- *
+ *
* Rotate the vector by an angle (only 2D vectors), magnitude remains the same
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Rotate the vector by an angle (2D only)
@@ -906,14 +906,14 @@ public class PVector implements Serializable {
y = xTemp*PApplet.sin(theta) + y*PApplet.cos(theta);
}
-
+
/**
* ( begin auto-generated from PVector_rotate.xml )
- *
+ *
* Linear interpolate the vector to another vector
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @brief Linear interpolate the vector to another vector
@@ -957,11 +957,11 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_angleBetween.xml )
- *
+ *
* Calculates and returns the angle (in radians) between two vectors.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage web_application
* @param v1 the x, y, and z components of a PVector
@@ -988,6 +988,7 @@ public class PVector implements Serializable {
}
+ @Override
public String toString() {
return "[ " + x + ", " + y + ", " + z + " ]";
}
@@ -995,13 +996,13 @@ public class PVector implements Serializable {
/**
* ( begin auto-generated from PVector_array.xml )
- *
- * Return a representation of this vector as a float array. This is only
- * for temporary use. If used in any other fashion, the contents should be
+ *
+ * Return a representation of this vector as a float array. This is only
+ * for temporary use. If used in any other fashion, the contents should be
* copied by using the PVector.get() method to copy into your own array.
- *
+ *
* ( end auto-generated )
- *
+ *
* @webref pvector:method
* @usage: web_application
* @brief Return a representation of the vector as a float array
diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java
index 9f2d681ce..7c5a5874b 100644
--- a/core/src/processing/data/XML.java
+++ b/core/src/processing/data/XML.java
@@ -589,6 +589,7 @@ public class XML implements Serializable {
}
+ @Override
public String toString() {
return toString(2);
}
diff --git a/core/src/processing/opengl/FrameBuffer.java b/core/src/processing/opengl/FrameBuffer.java
index f6732edde..bdd6d4a85 100644
--- a/core/src/processing/opengl/FrameBuffer.java
+++ b/core/src/processing/opengl/FrameBuffer.java
@@ -35,16 +35,16 @@ import java.nio.IntBuffer;
* to onscreen rendering after a sequence of pushFramebuffer calls.
* It transparently handles the situations when the FBO extension is
* not available.
- *
+ *
* By Andres Colubri.
*/
-public class FrameBuffer implements PConstants {
+public class FrameBuffer implements PConstants {
protected PApplet parent;
protected PGraphicsOpenGL pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this framebuffer.
-
+
public int glFbo;
public int glDepth;
public int glStencil;
@@ -56,100 +56,101 @@ public class FrameBuffer implements PConstants {
protected int depthBits;
protected int stencilBits;
protected boolean packedDepthStencil;
-
+
protected boolean multisample;
protected int nsamples;
-
+
protected int numColorBuffers;
protected Texture[] colorBufferTex;
protected boolean screenFb;
- protected boolean noDepth;
-
+ protected boolean noDepth;
+
protected IntBuffer pixelBuffer;
FrameBuffer(PApplet parent, int w, int h) {
this(parent, w, h, 1, 1, 0, 0, false, false);
- }
-
- FrameBuffer(PApplet parent, int w, int h, boolean screen) {
+ }
+
+ FrameBuffer(PApplet parent, int w, int h, boolean screen) {
this(parent, w, h, 1, 1, 0, 0, false, screen);
}
- FrameBuffer(PApplet parent, int w, int h, int samples, int colorBuffers,
- int depthBits, int stencilBits, boolean packedDepthStencil,
+ FrameBuffer(PApplet parent, int w, int h, int samples, int colorBuffers,
+ int depthBits, int stencilBits, boolean packedDepthStencil,
boolean screen) {
this.parent = parent;
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
context = pgl.createEmptyContext();
-
+
glFbo = 0;
glDepth = 0;
glStencil = 0;
- glDepthStencil = 0;
+ glDepthStencil = 0;
glMultisample = 0;
-
+
if (screen) {
// If this framebuffer is used to represent a on-screen buffer,
// then it doesn't make it sense for it to have multisampling,
// color, depth or stencil buffers.
- depthBits = stencilBits = samples = colorBuffers = 0;
+ depthBits = stencilBits = samples = colorBuffers = 0;
}
-
+
width = w;
height = h;
-
+
if (1 < samples) {
multisample = true;
- nsamples = samples;
+ nsamples = samples;
} else {
multisample = false;
- nsamples = 1;
+ nsamples = 1;
}
-
+
numColorBuffers = colorBuffers;
colorBufferTex = new Texture[numColorBuffers];
for (int i = 0; i < numColorBuffers; i++) {
colorBufferTex[i] = null;
- }
-
+ }
+
if (depthBits < 1 && stencilBits < 1) {
this.depthBits = 0;
this.stencilBits = 0;
this.packedDepthStencil = false;
} else {
if (packedDepthStencil) {
- // When combined depth/stencil format is required, the depth and stencil
- // bits are overriden and the 24/8 combination for a 32 bits surface is
+ // When combined depth/stencil format is required, the depth and stencil
+ // bits are overriden and the 24/8 combination for a 32 bits surface is
// used.
this.depthBits = 24;
this.stencilBits = 8;
- this.packedDepthStencil = true;
+ this.packedDepthStencil = true;
} else {
this.depthBits = depthBits;
this.stencilBits = stencilBits;
- this.packedDepthStencil = false;
+ this.packedDepthStencil = false;
}
}
-
+
screenFb = screen;
-
+
allocate();
noDepth = false;
-
+
pixelBuffer = null;
}
-
+
+ @Override
protected void finalize() throws Throwable {
try {
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context.code());
- }
+ }
if (glDepth != 0) {
pg.finalizeRenderBufferObject(glDepth, context.code());
- }
+ }
if (glStencil != 0) {
pg.finalizeRenderBufferObject(glStencil, context.code());
}
@@ -158,69 +159,69 @@ public class FrameBuffer implements PConstants {
}
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
- }
+ }
} finally {
super.finalize();
}
- }
-
+ }
+
public void clear() {
pg.pushFramebuffer();
pg.setFramebuffer(this);
pgl.clearDepth(1);
pgl.clearStencil(0);
pgl.clearColor(0, 0, 0, 0);
- pgl.clear(PGL.DEPTH_BUFFER_BIT |
- PGL.STENCIL_BUFFER_BIT |
+ pgl.clear(PGL.DEPTH_BUFFER_BIT |
+ PGL.STENCIL_BUFFER_BIT |
PGL.COLOR_BUFFER_BIT);
- pg.popFramebuffer();
+ pg.popFramebuffer();
}
-
+
public void copy(FrameBuffer dest) {
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, this.glFbo);
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
pgl.blitFramebuffer(0, 0, this.width, this.height,
- 0, 0, dest.width, dest.height,
+ 0, 0, dest.width, dest.height,
PGL.COLOR_BUFFER_BIT, PGL.NEAREST);
}
-
+
public void bind() {
pgl.bindFramebuffer(PGL.FRAMEBUFFER, glFbo);
}
-
+
public void disableDepthTest() {
- noDepth = true;
+ noDepth = true;
}
-
+
public void finish() {
if (noDepth) {
// No need to clear depth buffer because depth testing was disabled.
if (pg.hintEnabled(ENABLE_DEPTH_TEST)) {
- pgl.enable(PGL.DEPTH_TEST);
+ pgl.enable(PGL.DEPTH_TEST);
} else {
pgl.disable(PGL.DEPTH_TEST);
- }
+ }
}
}
-
+
public void readPixels() {
if (pixelBuffer == null) createPixelBuffer();
pixelBuffer.rewind();
- pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
pixelBuffer);
}
-
+
public void getPixels(int[] pixels) {
if (pixelBuffer != null) {
pixelBuffer.get(pixels, 0, pixels.length);
- pixelBuffer.rewind();
+ pixelBuffer.rewind();
}
}
-
+
public IntBuffer getPixelBuffer() {
return pixelBuffer;
}
-
+
public boolean hasDepthBuffer() {
return 0 < depthBits;
}
@@ -228,76 +229,76 @@ public class FrameBuffer implements PConstants {
public boolean hasStencilBuffer() {
return 0 < stencilBits;
}
-
- ///////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////
// Color buffer setters.
-
-
+
+
public void setColorBuffer(Texture tex) {
setColorBuffers(new Texture[] { tex }, 1);
}
-
+
public void setColorBuffers(Texture[] textures) {
setColorBuffers(textures, textures.length);
}
-
-
+
+
public void setColorBuffers(Texture[] textures, int n) {
if (screenFb) return;
if (numColorBuffers != PApplet.min(n, textures.length)) {
- throw new RuntimeException("Wrong number of textures to set the color " +
+ throw new RuntimeException("Wrong number of textures to set the color " +
"buffers.");
}
-
+
for (int i = 0; i < numColorBuffers; i++) {
colorBufferTex[i] = textures[i];
}
-
+
pg.pushFramebuffer();
pg.setFramebuffer(this);
// Making sure nothing is attached.
for (int i = 0; i < numColorBuffers; i++) {
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
+ pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
PGL.TEXTURE_2D, 0, 0);
}
for (int i = 0; i < numColorBuffers; i++) {
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
- colorBufferTex[i].glTarget,
+ pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
+ colorBufferTex[i].glTarget,
colorBufferTex[i].glName, 0);
}
pgl.validateFramebuffer();
pg.popFramebuffer();
- }
-
-
- ///////////////////////////////////////////////////////////
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
+ // Allocate/release framebuffer.
+
- // Allocate/release framebuffer.
-
-
protected void allocate() {
- release(); // Just in the case this object is being re-allocated.
-
+ release(); // Just in the case this object is being re-allocated.
+
context = pgl.getCurrentContext();
-
+
if (screenFb) {
glFbo = 0;
- } else {
+ } else {
glFbo = pg.createFrameBufferObject(context.code());
}
-
+
// create the rest of the stuff...
if (multisample) {
createColorBufferMultisample();
}
-
+
if (packedDepthStencil) {
createPackedDepthStencilBuffer();
} else {
@@ -306,11 +307,11 @@ public class FrameBuffer implements PConstants {
}
if (0 < stencilBits) {
createStencilBuffer();
- }
- }
+ }
+ }
}
-
-
+
+
protected void release() {
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context.code());
@@ -331,10 +332,10 @@ public class FrameBuffer implements PConstants {
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
glDepthStencil = 0;
- }
+ }
}
-
-
+
+
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
@@ -343,75 +344,75 @@ public class FrameBuffer implements PConstants {
pg.removeRenderBufferObject(glStencil, context.code());
pg.removeRenderBufferObject(glDepthStencil, context.code());
pg.removeRenderBufferObject(glMultisample, context.code());
-
+
glFbo = 0;
glDepth = 0;
glStencil = 0;
- glDepthStencil = 0;
+ glDepthStencil = 0;
glMultisample = 0;
-
+
for (int i = 0; i < numColorBuffers; i++) {
colorBufferTex[i] = null;
}
}
return outdated;
- }
-
-
+ }
+
+
protected void createColorBufferMultisample() {
if (screenFb) return;
-
- pg.pushFramebuffer();
- pg.setFramebuffer(this);
- glMultisample = pg.createRenderBufferObject(context.code());
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
- PGL.RGBA8, width, height);
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
- PGL.RENDERBUFFER, glMultisample);
-
- pg.popFramebuffer();
- }
-
-
- protected void createPackedDepthStencilBuffer() {
- if (screenFb) return;
-
- if (width == 0 || height == 0) {
- throw new RuntimeException("PFramebuffer: size undefined.");
- }
-
pg.pushFramebuffer();
pg.setFramebuffer(this);
-
- glDepthStencil = pg.createRenderBufferObject(context.code());
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
-
- if (multisample) {
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
- PGL.DEPTH24_STENCIL8, width, height);
- } else {
- pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
- width, height);
- }
-
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
- PGL.RENDERBUFFER, glDepthStencil);
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
- PGL.RENDERBUFFER, glDepthStencil);
-
- pg.popFramebuffer();
+
+ glMultisample = pg.createRenderBufferObject(context.code());
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
+ PGL.RGBA8, width, height);
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
+ PGL.RENDERBUFFER, glMultisample);
+
+ pg.popFramebuffer();
}
-
-
- protected void createDepthBuffer() {
+
+
+ protected void createPackedDepthStencilBuffer() {
if (screenFb) return;
-
+
if (width == 0 || height == 0) {
throw new RuntimeException("PFramebuffer: size undefined.");
}
-
+
+ pg.pushFramebuffer();
+ pg.setFramebuffer(this);
+
+ glDepthStencil = pg.createRenderBufferObject(context.code());
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
+
+ if (multisample) {
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
+ PGL.DEPTH24_STENCIL8, width, height);
+ } else {
+ pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
+ width, height);
+ }
+
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
+ PGL.RENDERBUFFER, glDepthStencil);
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
+ PGL.RENDERBUFFER, glDepthStencil);
+
+ pg.popFramebuffer();
+ }
+
+
+ protected void createDepthBuffer() {
+ if (screenFb) return;
+
+ if (width == 0 || height == 0) {
+ throw new RuntimeException("PFramebuffer: size undefined.");
+ }
+
pg.pushFramebuffer();
pg.setFramebuffer(this);
@@ -420,30 +421,30 @@ public class FrameBuffer implements PConstants {
int glConst = PGL.DEPTH_COMPONENT16;
if (depthBits == 16) {
- glConst = PGL.DEPTH_COMPONENT16;
+ glConst = PGL.DEPTH_COMPONENT16;
} else if (depthBits == 24) {
glConst = PGL.DEPTH_COMPONENT24;
} else if (depthBits == 32) {
- glConst = PGL.DEPTH_COMPONENT32;
+ glConst = PGL.DEPTH_COMPONENT32;
}
-
- if (multisample) {
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
+
+ if (multisample) {
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
width, height);
} else {
pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
- }
+ }
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
PGL.RENDERBUFFER, glDepth);
pg.popFramebuffer();
}
-
-
+
+
protected void createStencilBuffer() {
if (screenFb) return;
-
+
if (width == 0 || height == 0) {
throw new RuntimeException("PFramebuffer: size undefined.");
}
@@ -456,28 +457,28 @@ public class FrameBuffer implements PConstants {
int glConst = PGL.STENCIL_INDEX1;
if (stencilBits == 1) {
- glConst = PGL.STENCIL_INDEX1;
+ glConst = PGL.STENCIL_INDEX1;
} else if (stencilBits == 4) {
glConst = PGL.STENCIL_INDEX4;
} else if (stencilBits == 8) {
- glConst = PGL.STENCIL_INDEX8;
+ glConst = PGL.STENCIL_INDEX8;
}
- if (multisample) {
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
+ if (multisample) {
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
width, height);
- } else {
+ } else {
pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
}
-
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
+
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
PGL.RENDERBUFFER, glStencil);
pg.popFramebuffer();
- }
-
-
+ }
+
+
protected void createPixelBuffer() {
pixelBuffer = IntBuffer.allocate(width * height);
- pixelBuffer.rewind();
- }
+ pixelBuffer.rewind();
+ }
}
diff --git a/core/src/processing/opengl/LinePath.java b/core/src/processing/opengl/LinePath.java
index fc7f8b55b..49d853812 100644
--- a/core/src/processing/opengl/LinePath.java
+++ b/core/src/processing/opengl/LinePath.java
@@ -31,9 +31,9 @@ import processing.core.PMatrix2D;
/**
* The {@code LinePath} class allows to represent polygonal paths,
- * potentially composed by several disjoint polygonal segments.
- * It can be iterated by the {@link PathIterator} class including all
- * of its segment types and winding rules
+ * potentially composed by several disjoint polygonal segments.
+ * It can be iterated by the {@link PathIterator} class including all
+ * of its segment types and winding rules
*
*/
public class LinePath {
@@ -56,12 +56,12 @@ public class LinePath {
* clockwise direction.
*/
public static final int WIND_NON_ZERO = 1;
-
+
/**
* Starts segment at a given position.
- */
+ */
public static final byte SEG_MOVETO = 0;
-
+
/**
* Extends segment by adding a line to a given position.
*/
@@ -110,7 +110,7 @@ public class LinePath {
private static PMatrix2D identity = new PMatrix2D();
private static float defaultMiterlimit = 10.0f;
-
+
static final int INIT_SIZE = 20;
static final int EXPAND_MAX = 500;
@@ -124,8 +124,8 @@ public class LinePath {
protected int numCoords;
protected int windingRule;
-
-
+
+
/**
* Constructs a new empty single precision {@code LinePath} object with a
* default winding rule of {@link #WIND_NON_ZERO}.
@@ -134,12 +134,12 @@ public class LinePath {
this(WIND_NON_ZERO, INIT_SIZE);
}
-
+
/**
* Constructs a new empty single precision {@code LinePath} object with the
* specified winding rule to control operations that require the interior of
* the path to be defined.
- *
+ *
* @param rule
* the winding rule
* @see #WIND_EVEN_ODD
@@ -147,14 +147,14 @@ public class LinePath {
*/
public LinePath(int rule) {
this(rule, INIT_SIZE);
- }
+ }
+
-
/**
* Constructs a new {@code LinePath} object from the given specified initial
* values. This method is only intended for internal use and should not be
* made public if the other constructors for this class are ever exposed.
- *
+ *
* @param rule
* the winding rule
* @param initialTypes
@@ -165,7 +165,7 @@ public class LinePath {
this.pointTypes = new byte[initialCapacity];
floatCoords = new float[initialCapacity * 2];
}
-
+
void needRoom(boolean needMove, int newCoords) {
if (needMove && numTypes == 0) {
@@ -200,7 +200,7 @@ public class LinePath {
*
* This method provides a single precision variant of the double precision
* {@code moveTo()} method on the base {@code LinePath} class.
- *
+ *
* @param x
* the specified X coordinate
* @param y
@@ -226,7 +226,7 @@ public class LinePath {
*
* This method provides a single precision variant of the double precision
* {@code lineTo()} method on the base {@code LinePath} class.
- *
+ *
* @param x
* the specified X coordinate
* @param y
@@ -240,7 +240,7 @@ public class LinePath {
floatCoords[numCoords++] = y;
}
-
+
/**
* The iterator for this class is not multi-threaded safe, which means that
* the {@code LinePath} class does not guarantee that modifications to the
@@ -251,7 +251,7 @@ public class LinePath {
return new PathIterator(this);
}
-
+
/**
* Closes the current subpath by drawing a straight line back to the
* coordinates of the last {@code moveTo}. If the path is already closed then
@@ -264,10 +264,10 @@ public class LinePath {
}
}
-
+
/**
* Returns the fill style winding rule.
- *
+ *
* @return an integer representing the current winding rule.
* @see #WIND_EVEN_ODD
* @see #WIND_NON_ZERO
@@ -277,10 +277,10 @@ public class LinePath {
return windingRule;
}
-
+
/**
* Sets the winding rule for this path to the specified value.
- *
+ *
* @param rule
* an integer representing the specified winding rule
* @exception IllegalArgumentException
@@ -295,7 +295,7 @@ public class LinePath {
}
windingRule = rule;
}
-
+
/**
* Resets the path to empty. The append position is set back to the beginning
@@ -305,7 +305,7 @@ public class LinePath {
numTypes = numCoords = 0;
}
-
+
static public class PathIterator {
float floatCoords[];
@@ -356,27 +356,27 @@ public class LinePath {
}
}
-
+
/////////////////////////////////////////////////////////////////////////////
//
// Stroked path methods
-
+
static public LinePath createStrokedPath(LinePath src, float weight,
int caps, int join) {
return createStrokedPath(src, weight, caps, join, defaultMiterlimit, null);
}
-
+
static public LinePath createStrokedPath(LinePath src, float weight,
int caps, int join, float miterlimit) {
return createStrokedPath(src, weight, caps, join, miterlimit, null);
}
-
-
+
+
/**
* Constructs a solid LinePath with the specified attributes.
- *
+ *
* @param src
* the original path to be stroked
* @param weight
@@ -387,7 +387,7 @@ public class LinePath {
* the decoration applied where path segments meet
* @param miterlimit
* @param transform
- *
+ *
*/
static public LinePath createStrokedPath(LinePath src, float weight,
int caps, int join,
@@ -395,29 +395,34 @@ public class LinePath {
final LinePath dest = new LinePath();
strokeTo(src, weight, caps, join, miterlimit, transform, new LineStroker() {
+ @Override
public void moveTo(int x0, int y0) {
dest.moveTo(S15_16ToFloat(x0), S15_16ToFloat(y0));
}
+ @Override
public void lineJoin() {
}
+ @Override
public void lineTo(int x1, int y1) {
dest.lineTo(S15_16ToFloat(x1), S15_16ToFloat(y1));
}
+ @Override
public void close() {
dest.closePath();
}
+ @Override
public void end() {
}
});
return dest;
}
-
-
+
+
private static void strokeTo(LinePath src, float width, int caps, int join,
float miterlimit, PMatrix2D transform,
LineStroker lsink) {
@@ -428,8 +433,8 @@ public class LinePath {
PathIterator pi = src.getPathIterator();
pathTo(pi, lsink);
}
-
-
+
+
private static void pathTo(PathIterator pi, LineStroker lsink) {
float coords[] = new float[2];
while (!pi.isDone()) {
@@ -451,14 +456,14 @@ public class LinePath {
pi.next();
}
lsink.end();
- }
-
-
+ }
+
+
/////////////////////////////////////////////////////////////////////////////
- //
+ //
// Utility methods
-
+
public static float[] copyOf(float[] source, int length) {
float[] target = new float[length];
for (int i = 0; i < target.length; i++) {
@@ -470,7 +475,7 @@ public class LinePath {
return target;
}
-
+
public static byte[] copyOf(byte[] source, int length) {
byte[] target = new byte[length];
for (int i = 0; i < target.length; i++) {
@@ -481,7 +486,7 @@ public class LinePath {
}
return target;
}
-
+
// From Ken Turkowski, _Fixed-Point Square Root_, In Graphics Gems V
public static int isqrt(int x) {
@@ -506,7 +511,7 @@ public class LinePath {
return root;
}
-
+
public static long lsqrt(long x) {
int fracbits = 16;
@@ -529,22 +534,22 @@ public class LinePath {
return root;
}
-
+
public static double hypot(double x, double y) {
return Math.sqrt(x * x + y * y);
}
-
+
public static int hypot(int x, int y) {
return (int) ((lsqrt((long) x * x + (long) y * y) + 128) >> 8);
}
-
+
public static long hypot(long x, long y) {
return (lsqrt(x * x + y * y) + 128) >> 8;
}
-
+
static int FloatToS15_16(float flt) {
flt = flt * 65536f + 0.5f;
if (flt <= -(65536f * 65536f)) {
@@ -556,8 +561,8 @@ public class LinePath {
}
}
-
+
static float S15_16ToFloat(int fix) {
return (fix / 65536f);
- }
+ }
}
diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java
index d7227ac5b..58c64f52d 100644
--- a/core/src/processing/opengl/PGL.java
+++ b/core/src/processing/opengl/PGL.java
@@ -144,10 +144,10 @@ public class PGL {
* Set to true if the host system is big endian (PowerPC, MIPS, SPARC), false
* if little endian (x86 Intel for Mac or PC).
*/
- protected static boolean BIG_ENDIAN =
+ protected static boolean BIG_ENDIAN =
ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
- protected static final String SHADER_PREPROCESSOR_DIRECTIVE =
+ protected static final String SHADER_PREPROCESSOR_DIRECTIVE =
"#ifdef GL_ES\n" +
"precision mediump float;\n" +
"precision mediump int;\n" +
@@ -188,9 +188,9 @@ public class PGL {
public static final int TEXTURE_2D = GL.GL_TEXTURE_2D;
public static final int TEXTURE_RECTANGLE = GL2.GL_TEXTURE_RECTANGLE;
-
+
public static final int TEXTURE_BINDING_2D = GL.GL_TEXTURE_BINDING_2D;
- public static final int TEXTURE_BINDING_RECTANGLE =
+ public static final int TEXTURE_BINDING_RECTANGLE =
GL2.GL_TEXTURE_BINDING_RECTANGLE;
public static final int RGB = GL.GL_RGB;
@@ -200,7 +200,7 @@ public class PGL {
public static final int UNSIGNED_BYTE = GL.GL_UNSIGNED_BYTE;
public static final int UNSIGNED_SHORT = GL.GL_UNSIGNED_SHORT;
public static final int FLOAT = GL.GL_FLOAT;
-
+
public static final int NEAREST = GL.GL_NEAREST;
public static final int LINEAR = GL.GL_LINEAR;
public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST;
@@ -227,21 +227,21 @@ public class PGL {
public static final int SAMPLES = GL.GL_SAMPLES;
- public static final int FRAMEBUFFER_COMPLETE =
+ public static final int FRAMEBUFFER_COMPLETE =
GL.GL_FRAMEBUFFER_COMPLETE;
- public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT =
+ public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT =
GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
- public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT =
+ public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT =
GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
- public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS =
+ public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS =
GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
- public static final int FRAMEBUFFER_INCOMPLETE_FORMATS =
+ public static final int FRAMEBUFFER_INCOMPLETE_FORMATS =
GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS;
- public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER =
+ public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER =
GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER;
- public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER =
+ public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER =
GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER;
- public static final int FRAMEBUFFER_UNSUPPORTED =
+ public static final int FRAMEBUFFER_UNSUPPORTED =
GL.GL_FRAMEBUFFER_UNSUPPORTED;
public static final int STATIC_DRAW = GL.GL_STATIC_DRAW;
@@ -260,14 +260,14 @@ public class PGL {
public static final int RENDERER = GL.GL_RENDERER;
public static final int VERSION = GL.GL_VERSION;
public static final int EXTENSIONS = GL.GL_EXTENSIONS;
- public static final int SHADING_LANGUAGE_VERSION =
+ public static final int SHADING_LANGUAGE_VERSION =
GL2ES2.GL_SHADING_LANGUAGE_VERSION;
public static final int MAX_TEXTURE_SIZE = GL.GL_MAX_TEXTURE_SIZE;
public static final int MAX_SAMPLES = GL2.GL_MAX_SAMPLES;
- public static final int ALIASED_LINE_WIDTH_RANGE =
+ public static final int ALIASED_LINE_WIDTH_RANGE =
GL.GL_ALIASED_LINE_WIDTH_RANGE;
- public static final int ALIASED_POINT_SIZE_RANGE =
+ public static final int ALIASED_POINT_SIZE_RANGE =
GL.GL_ALIASED_POINT_SIZE_RANGE;
public static final int DEPTH_BITS = GL.GL_DEPTH_BITS;
public static final int STENCIL_BITS = GL.GL_STENCIL_BITS;
@@ -323,18 +323,18 @@ public class PGL {
public GL gl;
/** GLU interface **/
- public GLU glu;
-
+ public GLU glu;
+
/** The rendering context (holds rendering state info) */
public GLContext context;
/** The AWT canvas where OpenGL rendering takes place */
public Canvas canvas;
-
+
/** GLES2 functionality (shaders, etc) */
protected GL2ES2 gl2;
- /** GL2 desktop functionality (blit framebuffer, map buffer range,
+ /** GL2 desktop functionality (blit framebuffer, map buffer range,
* multisampled renerbuffers) */
protected GL2 gl2x;
@@ -377,10 +377,10 @@ public class PGL {
/** Which texturing targets are enabled */
protected static boolean[] texturingTargets = { false, false };
-
+
/** Which textures are bound to each target */
protected static int[] boundTextures = { 0, 0 };
-
+
///////////////////////////////////////////////////////////
// FBO for anti-aliased rendering
@@ -431,7 +431,7 @@ public class PGL {
};
protected FloatBuffer texData;
- protected String texVertShaderSource =
+ protected String texVertShaderSource =
"attribute vec2 inVertex;" +
"attribute vec2 inTexcoord;" +
"varying vec2 vertTexcoord;" +
@@ -440,7 +440,7 @@ public class PGL {
" vertTexcoord = inTexcoord;" +
"}";
- protected String tex2DFragShaderSource =
+ protected String tex2DFragShaderSource =
SHADER_PREPROCESSOR_DIRECTIVE +
"uniform sampler2D textureSampler;" +
"varying vec2 vertTexcoord;" +
@@ -448,7 +448,7 @@ public class PGL {
" gl_FragColor = texture2D(textureSampler, vertTexcoord.st);" +
"}";
- protected String texRectFragShaderSource =
+ protected String texRectFragShaderSource =
SHADER_PREPROCESSOR_DIRECTIVE +
"uniform sampler2DRect textureSampler;" +
"varying vec2 vertTexcoord;" +
@@ -464,7 +464,7 @@ public class PGL {
protected FloatBuffer depthBuffer;
protected ByteBuffer stencilBuffer;
-
+
///////////////////////////////////////////////////////////
// Initialization, finalization
@@ -528,7 +528,7 @@ public class PGL {
} else {
// Restarting...
if (canvasAWT != null) {
- // TODO: Even if the GLCanvas is put inside an animator, the rendering
+ // TODO: Even if the GLCanvas is put inside an animator, the rendering
// runs inside the EDT, ask the JOGL guys about this.
// animator.stop();
// animator.remove(canvasAWT);
@@ -625,7 +625,7 @@ public class PGL {
}
multisample = 1 < numSamples;
if (multisample && gl2x == null) {
- throw new RuntimeException("Doesn't have the OpenGL extensions " +
+ throw new RuntimeException("Doesn't have the OpenGL extensions " +
"necessary for multisampling.");
}
packedDepthStencil = ext.indexOf("packed_depth_stencil") != -1;
@@ -635,22 +635,22 @@ public class PGL {
// Create the color texture...
gl.glGenTextures(1, glColorTex, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, glColorTex[0]);
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
GL.GL_NEAREST);
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
GL.GL_NEAREST);
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S,
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S,
GL.GL_CLAMP_TO_EDGE);
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T,
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T,
GL.GL_CLAMP_TO_EDGE);
- gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, fboWidth, fboHeight,
+ gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, fboWidth, fboHeight,
0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
// ...and attach to the color framebuffer.
gl.glGenFramebuffers(1, glColorFbo, 0);
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]);
- gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0,
+ gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0,
GL.GL_TEXTURE_2D, glColorTex[0], 0);
// Clear the color buffer in the color FBO
@@ -669,36 +669,36 @@ public class PGL {
// color render buffer...
gl.glGenRenderbuffers(1, glColorRenderBuffer, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glColorRenderBuffer[0]);
- gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
+ gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
GL.GL_RGBA8, fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0,
GL.GL_RENDERBUFFER, glColorRenderBuffer[0]);
if (packedDepthStencil) {
// packed depth+stencil buffer...
gl.glGenRenderbuffers(1, glPackedDepthStencil, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glPackedDepthStencil[0]);
- gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
- GL.GL_DEPTH24_STENCIL8,
+ gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
+ GL.GL_DEPTH24_STENCIL8,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_DEPTH_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_DEPTH_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glPackedDepthStencil[0]);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_STENCIL_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_STENCIL_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glPackedDepthStencil[0]);
} else {
// Separate depth and stencil buffers...
gl.glGenRenderbuffers(1, glDepthBuffer, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthBuffer[0]);
- gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
- GL.GL_DEPTH_COMPONENT24,
+ gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
+ GL.GL_DEPTH_COMPONENT24,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_DEPTH_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_DEPTH_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glDepthBuffer[0]);
// Some hardware doesn't support distinct depth and stencil buffers:
@@ -706,12 +706,12 @@ public class PGL {
// which just results in an unsupported framebuffer error.
gl.glGenRenderbuffers(1, glStencilBuffer, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glStencilBuffer[0]);
- gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
- GL.GL_STENCIL_INDEX8,
+ gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, numSamples,
+ GL.GL_STENCIL_INDEX8,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_STENCIL_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_STENCIL_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glStencilBuffer[0]);
}
@@ -719,8 +719,8 @@ public class PGL {
gl.glClearDepth(1);
gl.glClearStencil(0);
gl.glClearColor(0, 0, 0, 0);
- gl.glClear(GL.GL_DEPTH_BUFFER_BIT |
- GL.GL_STENCIL_BUFFER_BIT |
+ gl.glClear(GL.GL_DEPTH_BUFFER_BIT |
+ GL.GL_STENCIL_BUFFER_BIT |
GL.GL_COLOR_BUFFER_BIT);
// All set with multisampled FBO!
@@ -730,33 +730,33 @@ public class PGL {
// packed depth+stencil buffer...
gl.glGenRenderbuffers(1, glPackedDepthStencil, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glPackedDepthStencil[0]);
- gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8,
+ gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_DEPTH_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_DEPTH_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glPackedDepthStencil[0]);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_STENCIL_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_STENCIL_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glPackedDepthStencil[0]);
} else {
// Separate depth and stencil buffers...
gl.glGenRenderbuffers(1, glDepthBuffer, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthBuffer[0]);
- gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT24,
+ gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT24,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_DEPTH_ATTACHMENT,
- GL.GL_RENDERBUFFER,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_DEPTH_ATTACHMENT,
+ GL.GL_RENDERBUFFER,
glDepthBuffer[0]);
gl.glGenRenderbuffers(1, glStencilBuffer, 0);
gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, glStencilBuffer[0]);
- gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_STENCIL_INDEX8,
+ gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_STENCIL_INDEX8,
fboWidth, fboHeight);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_STENCIL_ATTACHMENT,
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_STENCIL_ATTACHMENT,
GL.GL_RENDERBUFFER, glStencilBuffer[0]);
}
@@ -919,7 +919,7 @@ public class PGL {
gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
gl.glDisable(GL.GL_BLEND);
- drawTexture(GL.GL_TEXTURE_2D, glColorTex[0], fboWidth, fboHeight,
+ drawTexture(GL.GL_TEXTURE_2D, glColorTex[0], fboWidth, fboHeight,
0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height);
// Leaving the color FBO currently bound as the screen FB.
@@ -950,11 +950,11 @@ public class PGL {
canvasAWT.display();
} else if (toolkit == NEWT) {
animator.requestDisplay();
- }
+ }
} catch (GLException e) {
- // Unwrap GLException so that only the causing exception
+ // Unwrap GLException so that only the causing exception
// is shown.
- Throwable tr = e.getCause();
+ Throwable tr = e.getCause();
throw (RuntimeException)tr;
}
}
@@ -1037,7 +1037,7 @@ public class PGL {
return glu.gluErrorString(err);
}
-
+
///////////////////////////////////////////////////////////
// Rendering options
@@ -1093,18 +1093,18 @@ public class PGL {
}
- public void texImage2D(int target, int level, int internalFormat,
- int width, int height, int border, int format,
+ public void texImage2D(int target, int level, int internalFormat,
+ int width, int height, int border, int format,
int type, Buffer data) {
- gl.glTexImage2D(target, level, internalFormat,
+ gl.glTexImage2D(target, level, internalFormat,
width, height, border, format, type, data);
}
- public void texSubImage2D(int target, int level, int xOffset, int yOffset,
- int width, int height, int format,
+ public void texSubImage2D(int target, int level, int xOffset, int yOffset,
+ int width, int height, int format,
int type, Buffer data) {
- gl.glTexSubImage2D(target, level, xOffset, yOffset,
+ gl.glTexSubImage2D(target, level, xOffset, yOffset,
width, height, format, type, data);
}
@@ -1114,7 +1114,7 @@ public class PGL {
}
- public void getTexParameteriv(int target, int param, int[] values,
+ public void getTexParameteriv(int target, int param, int[] values,
int offset) {
gl.glGetTexParameteriv(target, param, values, offset);
}
@@ -1175,13 +1175,13 @@ public class PGL {
}
- public void vertexAttribPointer(int loc, int size, int type,
+ public void vertexAttribPointer(int loc, int size, int type,
boolean normalized, int stride, int offset) {
gl2.glVertexAttribPointer(loc, size, type, normalized, stride, offset);
}
- public void vertexAttribPointer(int loc, int size, int type,
+ public void vertexAttribPointer(int loc, int size, int type,
boolean normalized, int stride, Buffer data) {
gl2.glVertexAttribPointer(loc, size, type, normalized, stride, data);
}
@@ -1192,7 +1192,7 @@ public class PGL {
}
- public ByteBuffer mapBufferRange(int target, int offset, int length,
+ public ByteBuffer mapBufferRange(int target, int offset, int length,
int access) {
if (gl2x != null) {
return gl2x.glMapBufferRange(target, offset, length, access);
@@ -1237,17 +1237,17 @@ public class PGL {
}
- public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1,
- int dstX0, int dstY0, int dstX1, int dstY1,
+ public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1,
+ int dstX0, int dstY0, int dstX1, int dstY1,
int mask, int filter) {
if (gl2x != null) {
- gl2x.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
+ gl2x.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1, mask, filter);
}
}
- public void framebufferTexture2D(int target, int attachment, int texTarget,
+ public void framebufferTexture2D(int target, int attachment, int texTarget,
int texId, int level) {
gl.glFramebufferTexture2D(target, attachment, texTarget, texId, level);
}
@@ -1258,22 +1258,22 @@ public class PGL {
}
- public void renderbufferStorageMultisample(int target, int samples,
+ public void renderbufferStorageMultisample(int target, int samples,
int format, int width, int height){
if (gl2x != null) {
- gl2x.glRenderbufferStorageMultisample(target, samples, format,
+ gl2x.glRenderbufferStorageMultisample(target, samples, format,
width, height);
}
}
- public void renderbufferStorage(int target, int format,
+ public void renderbufferStorage(int target, int format,
int width, int height) {
gl.glRenderbufferStorage(target, format, width, height);
}
- public void framebufferRenderbuffer(int target, int attachment,
+ public void framebufferRenderbuffer(int target, int attachment,
int rendbufTarget, int rendbufId) {
gl.glFramebufferRenderbuffer(target, attachment, rendbufTarget, rendbufId);
}
@@ -1349,7 +1349,7 @@ public class PGL {
}
- public void uniform4i(int loc, int value0, int value1, int value2,
+ public void uniform4i(int loc, int value0, int value1, int value2,
int value3) {
gl2.glUniform4i(loc, value0, value1, value2, value3);
}
@@ -1370,7 +1370,7 @@ public class PGL {
}
- public void uniform4f(int loc, float value0, float value1, float value2,
+ public void uniform4f(int loc, float value0, float value1, float value2,
float value3) {
gl2.glUniform4f(loc, value0, value1, value2, value3);
}
@@ -1416,19 +1416,19 @@ public class PGL {
}
- public void uniformMatrix2fv(int loc, int count, boolean transpose,
+ public void uniformMatrix2fv(int loc, int count, boolean transpose,
float[] mat, int offset) {
gl2.glUniformMatrix2fv(loc, count, transpose, mat, offset);
}
- public void uniformMatrix3fv(int loc, int count, boolean transpose,
+ public void uniformMatrix3fv(int loc, int count, boolean transpose,
float[] mat, int offset) {
gl2.glUniformMatrix3fv(loc, count, transpose, mat, offset);
}
- public void uniformMatrix4fv(int loc, int count, boolean transpose,
+ public void uniformMatrix4fv(int loc, int count, boolean transpose,
float[] mat, int offset) {
gl2.glUniformMatrix4fv(loc, count, transpose, mat, offset);
}
@@ -1449,7 +1449,7 @@ public class PGL {
}
- public void vertexAttrib4f(int loc, float value0, float value1, float value2,
+ public void vertexAttrib4f(int loc, float value0, float value1, float value2,
float value3) {
gl2.glVertexAttrib4f(loc, value0, value1, value2, value3);
}
@@ -1569,7 +1569,7 @@ public class PGL {
}
- public void readPixels(int x, int y, int width, int height, int format,
+ public void readPixels(int x, int y, int width, int height, int format,
int type, Buffer buffer) {
gl.glReadPixels(x, y, width, height, format, type, buffer);
}
@@ -1707,25 +1707,30 @@ public class PGL {
public void addVertex(double[] v) {
GLU.gluTessVertex(tess, v, 0, v);
}
-
+
protected class GLUCallback extends GLUtessellatorCallbackAdapter {
+ @Override
public void begin(int type) {
callback.begin(type);
}
+ @Override
public void end() {
callback.end();
}
+ @Override
public void vertex(Object data) {
callback.vertex(data);
}
+ @Override
public void combine(double[] coords, Object[] data,
float[] weight, Object[] outData) {
callback.combine(coords, data, weight, outData);
}
+ @Override
public void error(int errnum) {
callback.error(errnum);
}
@@ -1733,8 +1738,8 @@ public class PGL {
}
protected String tessError(int err) {
- return glu.gluErrorString(err);
- }
+ return glu.gluErrorString(err);
+ }
protected interface TessellatorCallback {
public void begin(int type);
@@ -1772,10 +1777,10 @@ public class PGL {
texturingTargets[0] = false;
} else if (target == TEXTURE_RECTANGLE) {
texturingTargets[1] = false;
- }
+ }
}
-
-
+
+
protected boolean texturingIsEnabled(int target) {
if (target == TEXTURE_2D) {
return texturingTargets[0];
@@ -1785,8 +1790,8 @@ public class PGL {
return false;
}
}
-
-
+
+
protected boolean textureIsBound(int target, int id) {
if (target == TEXTURE_2D) {
return boundTextures[0] == id;
@@ -1794,18 +1799,18 @@ public class PGL {
return boundTextures[1] == id;
} else {
return false;
- }
+ }
}
-
-
+
+
protected void initTexture(int target, int format, int width, int height) {
int[] texels = new int[width * height];
- texSubImage2D(target, 0, 0, 0, width, height, format, UNSIGNED_BYTE,
+ texSubImage2D(target, 0, 0, 0, width, height, format, UNSIGNED_BYTE,
IntBuffer.wrap(texels));
}
- protected void copyToTexture(int target, int format, int id, int x, int y,
+ protected void copyToTexture(int target, int format, int id, int x, int y,
int w, int h, IntBuffer buffer) {
activeTexture(TEXTURE0);
boolean enabledTex = false;
@@ -1826,7 +1831,7 @@ public class PGL {
int X0, int Y0, int X1, int Y1) {
drawTexture(target, id, width, height, X0, Y0, X1, Y1, X0, Y0, X1, Y1);
}
-
+
protected void drawTexture(int target, int id, int width, int height,
int texX0, int texY0, int texX1, int texY1,
@@ -1841,12 +1846,12 @@ public class PGL {
scrX0, scrY0, scrX1, scrY1);
}
}
-
+
protected void drawTexture2D(int id, int width, int height,
int texX0, int texY0, int texX1, int texY1,
int scrX0, int scrY0, int scrX1, int scrY1) {
- if (!loadedTex2DShader ||
+ if (!loadedTex2DShader ||
tex2DShaderContext.hashCode() != context.hashCode()) {
tex2DVertShader = createShader(VERTEX_SHADER, texVertShaderSource);
tex2DFragShader = createShader(FRAGMENT_SHADER, tex2DFragShaderSource);
@@ -1915,16 +1920,16 @@ public class PGL {
if (!texturingIsEnabled(TEXTURE_2D)) {
enableTexturing(TEXTURE_2D);
enabledTex = true;
- }
+ }
bindTexture(TEXTURE_2D, id);
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
texData.position(0);
- vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
+ vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
texData);
texData.position(2);
- vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
+ vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
texData);
drawArrays(TRIANGLE_STRIP, 0, 4);
@@ -1932,7 +1937,7 @@ public class PGL {
bindTexture(TEXTURE_2D, 0);
if (enabledTex) {
disableTexturing(TEXTURE_2D);
- }
+ }
disableVertexAttribArray(tex2DVertLoc);
disableVertexAttribArray(tex2DTCoordLoc);
@@ -1952,12 +1957,12 @@ public class PGL {
protected void drawTextureRect(int id, int width, int height,
int texX0, int texY0, int texX1, int texY1,
int scrX0, int scrY0, int scrX1, int scrY1) {
- if (!loadedTexRectShader ||
+ if (!loadedTexRectShader ||
texRectShaderContext.hashCode() != context.hashCode()) {
texRectVertShader = createShader(VERTEX_SHADER, texVertShaderSource);
texRectFragShader = createShader(FRAGMENT_SHADER, texRectFragShaderSource);
if (0 < texRectVertShader && 0 < texRectFragShader) {
- texRectShaderProgram = createProgram(texRectVertShader,
+ texRectShaderProgram = createProgram(texRectVertShader,
texRectFragShader);
}
if (0 < texRectShaderProgram) {
@@ -2028,10 +2033,10 @@ public class PGL {
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
texData.position(0);
- vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
+ vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
texData);
texData.position(2);
- vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
+ vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
texData);
drawArrays(TRIANGLE_STRIP, 0, 4);
@@ -2040,7 +2045,7 @@ public class PGL {
if (enabledTex) {
disableTexturing(TEXTURE_RECTANGLE);
}
-
+
disableVertexAttribArray(texRectVertLoc);
disableVertexAttribArray(texRectTCoordLoc);
@@ -2061,7 +2066,7 @@ public class PGL {
colorBuffer = IntBuffer.allocate(1);
}
colorBuffer.rewind();
- readPixels(scrX, pg.height - scrY - 1, 1, 1, RGBA, UNSIGNED_BYTE,
+ readPixels(scrX, pg.height - scrY - 1, 1, 1, RGBA, UNSIGNED_BYTE,
colorBuffer);
return colorBuffer.get();
}
@@ -2072,7 +2077,7 @@ public class PGL {
depthBuffer = FloatBuffer.allocate(1);
}
depthBuffer.rewind();
- readPixels(scrX, pg.height - scrY - 1, 1, 1, DEPTH_COMPONENT, FLOAT,
+ readPixels(scrX, pg.height - scrY - 1, 1, 1, DEPTH_COMPONENT, FLOAT,
depthBuffer);
return depthBuffer.get(0);
}
@@ -2082,7 +2087,7 @@ public class PGL {
if (stencilBuffer == null) {
stencilBuffer = ByteBuffer.allocate(1);
}
- readPixels(scrX, pg.height - scrY - 1, 1, 1, STENCIL_INDEX,
+ readPixels(scrX, pg.height - scrY - 1, 1, 1, STENCIL_INDEX,
GL.GL_UNSIGNED_BYTE, stencilBuffer);
return stencilBuffer.get(0);
}
@@ -2116,9 +2121,9 @@ public class PGL {
/**
- * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
- * little endian) representing an image of width x height resolution to Java
- * ARGB. It also rearranges the elements in the array so that the image is
+ * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
+ * little endian) representing an image of width x height resolution to Java
+ * ARGB. It also rearranges the elements in the array so that the image is
* flipped vertically.
*/
protected static void nativeToJavaARGB(int[] pixels, int width, int height) {
@@ -2192,10 +2197,10 @@ public class PGL {
/**
- * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
- * little endian) representing an image of width x height resolution to Java
- * RGB, so that the alpha component of all pixels is set to opaque (255). It
- * also rearranges the elements in the array so that the image is flipped
+ * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
+ * little endian) representing an image of width x height resolution to Java
+ * RGB, so that the alpha component of all pixels is set to opaque (255). It
+ * also rearranges the elements in the array so that the image is flipped
* vertically.
*/
protected static void nativeToJavaRGB(int[] pixels, int width, int height) {
@@ -2264,9 +2269,9 @@ public class PGL {
/**
- * Converts input array of Java ARGB values representing an image of width x
- * height resolution to native OpenGL format (RGBA on big endian, BGRA on
- * little endian). It also rearranges the elements in the array so that the
+ * Converts input array of Java ARGB values representing an image of width x
+ * height resolution to native OpenGL format (RGBA on big endian, BGRA on
+ * little endian). It also rearranges the elements in the array so that the
* image is flipped vertically.
*/
protected static void javaToNativeARGB(int[] pixels, int width, int height) {
@@ -2340,10 +2345,10 @@ public class PGL {
/**
- * Converts input array of Java ARGB values representing an image of width x
- * height resolution to native OpenGL format (RGBA on big endian, BGRA on
- * little endian), while setting alpha component of all pixels to opaque
- * (255). It also rearranges the elements in the array so that the image is
+ * Converts input array of Java ARGB values representing an image of width x
+ * height resolution to native OpenGL format (RGBA on big endian, BGRA on
+ * little endian), while setting alpha component of all pixels to opaque
+ * (255). It also rearranges the elements in the array so that the image is
* flipped vertically.
*/
protected static void javaToNativeRGB(int[] pixels, int width, int height) {
@@ -2438,23 +2443,23 @@ public class PGL {
return true;
} else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
throw new RuntimeException(
- "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" +
+ "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" +
Integer.toHexString(status) + ")");
} else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
throw new RuntimeException(
- "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" +
+ "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" +
Integer.toHexString(status) + ")");
} else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
- throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" +
+ throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" +
Integer.toHexString(status) + ")");
} else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) {
- throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" +
+ throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" +
Integer.toHexString(status) + ")");
} else if (status == FRAMEBUFFER_UNSUPPORTED) {
- throw new RuntimeException("GL_FRAMEBUFFER_UNSUPPORTED" +
+ throw new RuntimeException("GL_FRAMEBUFFER_UNSUPPORTED" +
Integer.toHexString(status));
} else {
- throw new RuntimeException("unknown framebuffer error (" +
+ throw new RuntimeException("unknown framebuffer error (" +
Integer.toHexString(status) + ")");
}
}
@@ -2507,21 +2512,21 @@ public class PGL {
public void init(GLAutoDrawable adrawable) {
drawable = adrawable;
context = adrawable.getContext();
-
+
gl = context.getGL();
String extensions = gl.glGetString(GL.GL_EXTENSIONS);
if (-1 == extensions.indexOf("_framebuffer_object")) {
throw new RuntimeException("No framebuffer objects available");
- }
+ }
if (-1 == extensions.indexOf("_vertex_buffer_object")) {
throw new RuntimeException("No vertex buffer objects available");
- }
+ }
if (-1 == extensions.indexOf("_vertex_shader")) {
throw new RuntimeException("No vertex shaders available");
- }
+ }
if (-1 == extensions.indexOf("_fragment_shader")) {
throw new RuntimeException("No fragment shaders available");
- }
+ }
}
@Override
@@ -2546,6 +2551,7 @@ public class PGL {
private TimerTask task = null;
private volatile boolean shouldRun;
+ @Override
protected String getBaseName(String prefix) {
return prefix + "PGLAnimator";
}
@@ -2588,6 +2594,7 @@ public class PGL {
task = new TimerTask() {
private boolean firstRun = true;
+ @Override
public void run() {
if (firstRun) {
Thread.currentThread().setName("PGL-RenderQueue-" + count);
diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java
index 44d704a1c..7522cf5d8 100644
--- a/core/src/processing/opengl/PGraphics2D.java
+++ b/core/src/processing/opengl/PGraphics2D.java
@@ -45,11 +45,13 @@ public class PGraphics2D extends PGraphicsOpenGL {
// RENDERER SUPPORT QUERIES
+ @Override
public boolean is2D() {
return true;
}
+ @Override
public boolean is3D() {
return false;
}
@@ -60,6 +62,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// HINTS
+ @Override
public void hint(int which) {
if (which == ENABLE_STROKE_PERSPECTIVE) {
showWarning("2D lines cannot be perspective-corrected.");
@@ -74,17 +77,20 @@ public class PGraphics2D extends PGraphicsOpenGL {
// PROJECTION
+ @Override
public void ortho() {
showMethodWarning("ortho");
}
+ @Override
public void ortho(float left, float right,
float bottom, float top) {
showMethodWarning("ortho");
}
+ @Override
public void ortho(float left, float right,
float bottom, float top,
float near, float far) {
@@ -92,22 +98,26 @@ public class PGraphics2D extends PGraphicsOpenGL {
}
+ @Override
public void perspective() {
showMethodWarning("perspective");
}
+ @Override
public void perspective(float fov, float aspect, float zNear, float zFar) {
showMethodWarning("perspective");
}
+ @Override
public void frustum(float left, float right, float bottom, float top,
float znear, float zfar) {
showMethodWarning("frustum");
}
+ @Override
protected void defaultPerspective() {
super.ortho(-width/2, +width/2, -height/2, +height/2, -1, +1);
}
@@ -118,21 +128,25 @@ public class PGraphics2D extends PGraphicsOpenGL {
// CAMERA
+ @Override
public void beginCamera() {
showMethodWarning("beginCamera");
}
+ @Override
public void endCamera() {
showMethodWarning("endCamera");
}
+ @Override
public void camera() {
showMethodWarning("camera");
}
+ @Override
public void camera(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ) {
@@ -140,6 +154,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
}
+ @Override
protected void defaultCamera() {
super.camera(width/2, height/2);
}
@@ -150,6 +165,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// MATRIX MORE!
+ @Override
protected void begin2D() {
pushProjection();
defaultPerspective();
@@ -158,6 +174,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
}
+ @Override
protected void end2D() {
popMatrix();
popProjection();
@@ -169,42 +186,47 @@ public class PGraphics2D extends PGraphicsOpenGL {
// SHAPE
+ @Override
public void shape(PShape shape) {
if (shape.is2D()) {
super.shape(shape);
} else {
- showWarning("The shape object is not 2D, cannot be displayed with " +
+ showWarning("The shape object is not 2D, cannot be displayed with " +
"this renderer");
}
}
+ @Override
public void shape(PShape shape, float x, float y) {
if (shape.is2D()) {
super.shape(shape, x, y);
} else {
- showWarning("The shape object is not 2D, cannot be displayed with " +
+ showWarning("The shape object is not 2D, cannot be displayed with " +
"this renderer");
}
}
+ @Override
public void shape(PShape shape, float a, float b, float c, float d) {
if (shape.is2D()) {
super.shape(shape, a, b, c, d);
} else {
- showWarning("The shape object is not 2D, cannot be displayed with " +
+ showWarning("The shape object is not 2D, cannot be displayed with " +
"this renderer");
}
}
+ @Override
public void shape(PShape shape, float x, float y, float z) {
showDepthWarningXYZ("shape");
}
- public void shape(PShape shape, float x, float y, float z,
+ @Override
+ public void shape(PShape shape, float x, float y, float z,
float c, float d, float e) {
showDepthWarningXYZ("shape");
}
@@ -220,7 +242,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
}
- static protected PShape2D loadShapeImpl(PGraphics pg, String filename,
+ static protected PShape2D loadShapeImpl(PGraphics pg, String filename,
String extension) {
PShapeSVG svg = null;
@@ -229,7 +251,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
} else if (extension.equals("svgz")) {
try {
- InputStream input =
+ InputStream input =
new GZIPInputStream(pg.parent.createInput(filename));
XML xml = new XML(PApplet.createReader(input));
svg = new PShapeSVG(xml);
@@ -252,21 +274,25 @@ public class PGraphics2D extends PGraphicsOpenGL {
// SHAPE CREATION
+ @Override
public PShape createShape(PShape source) {
return PShape2D.createShape(parent, source);
}
+ @Override
public PShape createShape() {
return createShape(POLYGON);
}
+ @Override
public PShape createShape(int type) {
return createShapeImpl(parent, type);
}
+ @Override
public PShape createShape(int kind, float... p) {
return createShapeImpl(parent, kind, p);
}
@@ -307,7 +333,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
}
- static protected PShape2D createShapeImpl(PApplet parent, int kind,
+ static protected PShape2D createShapeImpl(PApplet parent, int kind,
float... p) {
PShape2D shape = null;
int len = p.length;
@@ -382,6 +408,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// BEZIER VERTICES
+ @Override
public void bezierVertex(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
@@ -394,6 +421,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// QUADRATIC BEZIER VERTICES
+ @Override
public void quadraticVertex(float x2, float y2, float z2,
float x4, float y4, float z4) {
showDepthWarningXYZ("quadVertex");
@@ -405,6 +433,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// CURVE VERTICES
+ @Override
public void curveVertex(float x, float y, float z) {
showDepthWarningXYZ("curveVertex");
}
@@ -415,6 +444,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// BOX
+ @Override
public void box(float w, float h, float d) {
showMethodWarning("box");
}
@@ -425,6 +455,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
// SPHERE
+ @Override
public void sphere(float r) {
showMethodWarning("sphere");
}
@@ -435,10 +466,12 @@ public class PGraphics2D extends PGraphicsOpenGL {
// VERTEX SHAPES
+ @Override
public void vertex(float x, float y, float z) {
showDepthWarningXYZ("vertex");
}
+ @Override
public void vertex(float x, float y, float z, float u, float v) {
showDepthWarningXYZ("vertex");
}
@@ -447,30 +480,37 @@ public class PGraphics2D extends PGraphicsOpenGL {
// MATRIX TRANSFORMATIONS
+ @Override
public void translate(float tx, float ty, float tz) {
showDepthWarningXYZ("translate");
}
+ @Override
public void rotateX(float angle) {
showDepthWarning("rotateX");
}
+ @Override
public void rotateY(float angle) {
showDepthWarning("rotateY");
}
+ @Override
public void rotateZ(float angle) {
showDepthWarning("rotateZ");
}
+ @Override
public void rotate(float angle, float vx, float vy, float vz) {
showVariationWarning("rotate");
}
+ @Override
public void applyMatrix(PMatrix3D source) {
showVariationWarning("applyMatrix");
}
+ @Override
public void applyMatrix(float n00, float n01, float n02, float n03,
float n10, float n11, float n12, float n13,
float n20, float n21, float n22, float n23,
@@ -478,6 +518,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
showVariationWarning("applyMatrix");
}
+ @Override
public void scale(float sx, float sy, float sz) {
showDepthWarningXYZ("scale");
}
@@ -486,26 +527,31 @@ public class PGraphics2D extends PGraphicsOpenGL {
// SCREEN AND MODEL COORDS
+ @Override
public float screenX(float x, float y, float z) {
showDepthWarningXYZ("screenX");
return 0;
}
+ @Override
public float screenY(float x, float y, float z) {
showDepthWarningXYZ("screenY");
return 0;
}
+ @Override
public float screenZ(float x, float y, float z) {
showDepthWarningXYZ("screenZ");
return 0;
}
+ @Override
public PMatrix3D getMatrix(PMatrix3D target) {
showVariationWarning("getMatrix");
return target;
}
+ @Override
public void setMatrix(PMatrix3D source) {
showVariationWarning("setMatrix");
}
@@ -514,33 +560,40 @@ public class PGraphics2D extends PGraphicsOpenGL {
// LIGHTS
+ @Override
public void lights() {
showMethodWarning("lights");
}
+ @Override
public void noLights() {
showMethodWarning("noLights");
}
+ @Override
public void ambientLight(float red, float green, float blue) {
showMethodWarning("ambientLight");
}
+ @Override
public void ambientLight(float red, float green, float blue,
float x, float y, float z) {
showMethodWarning("ambientLight");
}
+ @Override
public void directionalLight(float red, float green, float blue,
float nx, float ny, float nz) {
showMethodWarning("directionalLight");
}
+ @Override
public void pointLight(float red, float green, float blue,
float x, float y, float z) {
showMethodWarning("pointLight");
}
+ @Override
public void spotLight(float red, float green, float blue,
float x, float y, float z,
float nx, float ny, float nz,
@@ -548,10 +601,12 @@ public class PGraphics2D extends PGraphicsOpenGL {
showMethodWarning("spotLight");
}
+ @Override
public void lightFalloff(float constant, float linear, float quadratic) {
showMethodWarning("lightFalloff");
}
+ @Override
public void lightSpecular(float v1, float v2, float v3) {
showMethodWarning("lightSpecular");
}
diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java
index c85847fb2..4dad25e78 100644
--- a/core/src/processing/opengl/PGraphics3D.java
+++ b/core/src/processing/opengl/PGraphics3D.java
@@ -38,106 +38,112 @@ public class PGraphics3D extends PGraphicsOpenGL {
super();
hints[ENABLE_STROKE_PERSPECTIVE] = true;
}
-
+
//////////////////////////////////////////////////////////////
// RENDERER SUPPORT QUERIES
-
-
+
+
+ @Override
public boolean is2D() {
return false;
}
-
+
+ @Override
public boolean is3D() {
return true;
- }
-
-
+ }
+
+
//////////////////////////////////////////////////////////////
// PROJECTION
-
-
- protected void defaultPerspective() {
+
+
+ @Override
+ protected void defaultPerspective() {
perspective();
}
-
-
+
+
//////////////////////////////////////////////////////////////
// CAMERA
-
-
- protected void defaultCamera() {
- camera();
- }
-
+
+ @Override
+ protected void defaultCamera() {
+ camera();
+ }
+
+
//////////////////////////////////////////////////////////////
// MATRIX MORE!
-
-
+
+
+ @Override
protected void begin2D() {
pushProjection();
ortho(-width/2, +width/2, -height/2, +height/2, -1, +1);
pushMatrix();
- camera(width/2, height/2);
+ camera(width/2, height/2);
}
-
+
+ @Override
protected void end2D() {
popMatrix();
- popProjection();
- }
-
-
+ popProjection();
+ }
+
+
//////////////////////////////////////////////////////////////
// SHAPE I/O
-
+
static protected boolean isSupportedExtension(String extension) {
return extension.equals("obj");
}
- static protected PShape loadShapeImpl(PGraphics pg, String filename,
+ static protected PShape loadShapeImpl(PGraphics pg, String filename,
String ext) {
- ArrayList vertices = new ArrayList();
+ ArrayList vertices = new ArrayList();
ArrayList normals = new ArrayList();
ArrayList textures = new ArrayList();
ArrayList faces = new ArrayList();
- ArrayList materials = new ArrayList();
-
+ ArrayList materials = new ArrayList();
+
BufferedReader reader = pg.parent.createReader(filename);
parseOBJ(pg.parent, reader, vertices, normals, textures, faces, materials);
int prevColorMode = pg.colorMode;
- float prevColorModeX = pg.colorModeX;
- float prevColorModeY = pg.colorModeY;
+ float prevColorModeX = pg.colorModeX;
+ float prevColorModeY = pg.colorModeY;
float prevColorModeZ = pg.colorModeZ;
float prevColorModeA = pg.colorModeA;
boolean prevStroke = pg.stroke;
int prevTextureMode = pg.textureMode;
pg.colorMode(RGB, 1);
- pg.stroke = false;
- pg.textureMode = NORMAL;
-
- // The OBJ geometry is stored in a group shape,
+ pg.stroke = false;
+ pg.textureMode = NORMAL;
+
+ // The OBJ geometry is stored in a group shape,
// with each face in a separate child geometry
// shape.
PShape root = createShapeImpl(pg.parent, GROUP);
-
+
int mtlIdxCur = -1;
- OBJMaterial mtl = null;
+ OBJMaterial mtl = null;
for (int i = 0; i < faces.size(); i++) {
OBJFace face = faces.get(i);
-
+
// Getting current material.
if (mtlIdxCur != face.matIdx) {
- mtlIdxCur = PApplet.max(0, face.matIdx); // To make sure that at least we get the default material.
+ mtlIdxCur = PApplet.max(0, face.matIdx); // To make sure that at least we get the default material.
mtl = materials.get(mtlIdxCur);
}
@@ -149,52 +155,52 @@ public class PGraphics3D extends PGraphicsOpenGL {
child = createShapeImpl(pg.parent, QUADS); // Face is a quad, so using appropriate shape kind.
} else {
child = createShapeImpl(pg.parent, POLYGON); // Face is a general polygon
- }
-
+ }
+
// Setting material properties for the new face
child.fill(mtl.kd.x, mtl.kd.y, mtl.kd.z);
child.ambient(mtl.ka.x, mtl.ka.y, mtl.ka.z);
child.specular(mtl.ks.x, mtl.ks.y, mtl.ks.z);
- child.shininess(mtl.ns);
+ child.shininess(mtl.ns);
if (mtl.kdMap != null) {
// If current material is textured, then tinting the texture using the diffuse color.
child.tint(mtl.kd.x, mtl.kd.y, mtl.kd.z, mtl.d);
}
-
+
for (int j = 0; j < face.vertIdx.size(); j++){
int vertIdx, normIdx;
PVector vert, norms;
vert = norms = null;
-
+
vertIdx = face.vertIdx.get(j).intValue() - 1;
vert = vertices.get(vertIdx);
-
+
if (j < face.normIdx.size()) {
normIdx = face.normIdx.get(j).intValue() - 1;
if (-1 < normIdx) {
- norms = normals.get(normIdx);
+ norms = normals.get(normIdx);
}
}
-
+
if (mtl != null && mtl.kdMap != null) {
// This face is textured.
int texIdx;
- PVector tex = null;
-
+ PVector tex = null;
+
if (j < face.texIdx.size()) {
texIdx = face.texIdx.get(j).intValue() - 1;
if (-1 < texIdx) {
- tex = textures.get(texIdx);
+ tex = textures.get(texIdx);
}
}
-
+
child.texture(mtl.kdMap);
if (norms != null) {
child.normal(norms.x, norms.y, norms.z);
}
if (tex != null) {
- child.vertex(vert.x, vert.y, vert.z, tex.x, tex.y);
+ child.vertex(vert.x, vert.y, vert.z, tex.x, tex.y);
} else {
child.vertex(vert.x, vert.y, vert.z);
}
@@ -203,47 +209,51 @@ public class PGraphics3D extends PGraphicsOpenGL {
if (norms != null) {
child.normal(norms.x, norms.y, norms.z);
}
- child.vertex(vert.x, vert.y, vert.z);
+ child.vertex(vert.x, vert.y, vert.z);
}
- }
-
+ }
+
child.end(CLOSE);
- root.addChild(child);
+ root.addChild(child);
}
-
- pg.colorMode(prevColorMode, prevColorModeX, prevColorModeY, prevColorModeZ,
- prevColorModeA);
+
+ pg.colorMode(prevColorMode, prevColorModeX, prevColorModeY, prevColorModeZ,
+ prevColorModeA);
pg.stroke = prevStroke;
- pg.textureMode = prevTextureMode;
-
+ pg.textureMode = prevTextureMode;
+
return root;
- }
-
-
+ }
+
+
//////////////////////////////////////////////////////////////
// SHAPE CREATION
-
- public PShape createShape(PShape source) {
- return PShape3D.createShape(parent, source);
- }
-
+ @Override
+ public PShape createShape(PShape source) {
+ return PShape3D.createShape(parent, source);
+ }
+
+
+ @Override
public PShape createShape() {
return createShape(POLYGON);
}
+ @Override
public PShape createShape(int type) {
return createShapeImpl(parent, type);
}
-
+
+ @Override
public PShape createShape(int kind, float... p) {
return createShapeImpl(parent, kind, p);
- }
-
+ }
+
static protected PShape3D createShapeImpl(PApplet parent, int type) {
PShape3D shape = null;
@@ -278,8 +288,8 @@ public class PGraphics3D extends PGraphicsOpenGL {
}
return shape;
}
-
-
+
+
static protected PShape3D createShapeImpl(PApplet parent, int kind, float... p) {
PShape3D shape = null;
int len = p.length;
@@ -357,34 +367,34 @@ public class PGraphics3D extends PGraphicsOpenGL {
return shape;
}
-
-
+
+
//////////////////////////////////////////////////////////////
- // OBJ LOADING
+ // OBJ LOADING
+
-
static protected void parseOBJ(PApplet parent,
- BufferedReader reader,
- ArrayList vertices,
- ArrayList normals,
- ArrayList textures,
- ArrayList faces,
+ BufferedReader reader,
+ ArrayList vertices,
+ ArrayList normals,
+ ArrayList textures,
+ ArrayList faces,
ArrayList materials) {
Hashtable mtlTable = new Hashtable();
int mtlIdxCur = -1;
boolean readv, readvn, readvt;
try {
-
+
readv = readvn = readvt = false;
String line;
String gname = "object";
while ((line = reader.readLine()) != null) {
// Parse the line.
-
+
// The below patch/hack comes from Carlos Tomas Marti and is a
// fix for single backslashes in Rhino obj files
-
+
// BEGINNING OF RHINO OBJ FILES HACK
// Statements can be broken in multiple lines using '\' at the
// end of a line.
@@ -400,28 +410,28 @@ public class PGraphics3D extends PGraphicsOpenGL {
line += s;
}
// END OF RHINO OBJ FILES HACK
-
- String[] elements = line.split("\\s+");
+
+ String[] elements = line.split("\\s+");
// if not a blank line, process the line.
if (elements.length > 0) {
if (elements[0].equals("v")) {
// vertex
- PVector tempv = new PVector(Float.valueOf(elements[1]).floatValue(),
- Float.valueOf(elements[2]).floatValue(),
+ PVector tempv = new PVector(Float.valueOf(elements[1]).floatValue(),
+ Float.valueOf(elements[2]).floatValue(),
Float.valueOf(elements[3]).floatValue());
vertices.add(tempv);
readv = true;
} else if (elements[0].equals("vn")) {
// normal
- PVector tempn = new PVector(Float.valueOf(elements[1]).floatValue(),
- Float.valueOf(elements[2]).floatValue(),
+ PVector tempn = new PVector(Float.valueOf(elements[1]).floatValue(),
+ Float.valueOf(elements[2]).floatValue(),
Float.valueOf(elements[3]).floatValue());
normals.add(tempn);
readvn = true;
} else if (elements[0].equals("vt")) {
- // uv, inverting v to take into account Processing's invertex Y axis
+ // uv, inverting v to take into account Processing's invertex Y axis
// with respect to OpenGL.
- PVector tempv = new PVector(Float.valueOf(elements[1]).floatValue(),
+ PVector tempv = new PVector(Float.valueOf(elements[1]).floatValue(),
1 - Float.valueOf(elements[2]).
floatValue());
textures.add(tempv);
@@ -435,7 +445,7 @@ public class PGraphics3D extends PGraphicsOpenGL {
parseMTL(parent, mreader, materials, mtlTable);
}
}
- } else if (elements[0].equals("g")) {
+ } else if (elements[0].equals("g")) {
gname = 1 < elements.length ? elements[1] : "";
} else if (elements[0].equals("usemtl")) {
// Getting index of current active material (will be applied on all subsequent faces).
@@ -445,15 +455,15 @@ public class PGraphics3D extends PGraphicsOpenGL {
Integer tempInt = mtlTable.get(mtlname);
mtlIdxCur = tempInt.intValue();
} else {
- mtlIdxCur = -1;
+ mtlIdxCur = -1;
}
}
} else if (elements[0].equals("f")) {
// Face setting
OBJFace face = new OBJFace();
- face.matIdx = mtlIdxCur;
+ face.matIdx = mtlIdxCur;
face.name = gname;
-
+
for (int i = 1; i < elements.length; i++) {
String seg = elements[i];
@@ -478,16 +488,16 @@ public class PGraphics3D extends PGraphicsOpenGL {
if (forder[0].length() > 0 && readv) {
face.vertIdx.add(Integer.valueOf(forder[0]));
}
-
+
if (forder[1].length() > 0) {
if (readvt) {
- face.texIdx.add(Integer.valueOf(forder[1]));
+ face.texIdx.add(Integer.valueOf(forder[1]));
} else if (readvn) {
face.normIdx.add(Integer.valueOf(forder[1]));
}
-
+
}
-
+
} else if (forder.length > 0) {
// Getting vertex index only.
if (forder[0].length() > 0 && readv) {
@@ -501,27 +511,27 @@ public class PGraphics3D extends PGraphicsOpenGL {
}
}
}
-
- faces.add(face);
+
+ faces.add(face);
}
}
}
if (materials.size() == 0) {
// No materials definition so far. Adding one default material.
- OBJMaterial defMtl = new OBJMaterial();
+ OBJMaterial defMtl = new OBJMaterial();
materials.add(defMtl);
- }
-
+ }
+
} catch (Exception e) {
e.printStackTrace();
}
}
-
-
+
+
static protected void parseMTL(PApplet parent,
- BufferedReader reader,
- ArrayList materials,
+ BufferedReader reader,
+ ArrayList materials,
Hashtable materialsHash) {
try {
String line;
@@ -560,22 +570,22 @@ public class PGraphics3D extends PGraphicsOpenGL {
currentMtl.ks.x = Float.valueOf(elements[1]).floatValue();
currentMtl.ks.y = Float.valueOf(elements[2]).floatValue();
currentMtl.ks.z = Float.valueOf(elements[3]).floatValue();
- } else if ((elements[0].equals("d") ||
+ } else if ((elements[0].equals("d") ||
elements[0].equals("Tr")) && elements.length > 1) {
// Reading the alpha transparency.
currentMtl.d = Float.valueOf(elements[1]).floatValue();
} else if (elements[0].equals("Ns") && elements.length > 1) {
// The specular component of the Phong shading model
currentMtl.ns = Float.valueOf(elements[1]).floatValue();
- }
+ }
}
}
} catch (Exception e) {
e.printStackTrace();
- }
+ }
}
-
-
+
+
// Stores a face from an OBJ file
static protected class OBJFace {
ArrayList vertIdx;
@@ -583,7 +593,7 @@ public class PGraphics3D extends PGraphicsOpenGL {
ArrayList normIdx;
int matIdx;
String name;
-
+
OBJFace() {
vertIdx = new ArrayList();
texIdx = new ArrayList();
@@ -591,9 +601,9 @@ public class PGraphics3D extends PGraphicsOpenGL {
matIdx = -1;
name = "";
}
- }
-
-
+ }
+
+
// Stores a material defined in an MTL file.
static protected class OBJMaterial {
String name;
@@ -603,11 +613,11 @@ public class PGraphics3D extends PGraphicsOpenGL {
float d;
float ns;
PImage kdMap;
-
+
OBJMaterial() {
this("default");
}
-
+
OBJMaterial(String name) {
this.name = name;
ka = new PVector(0.5f, 0.5f, 0.5f);
@@ -616,6 +626,6 @@ public class PGraphics3D extends PGraphicsOpenGL {
d = 1.0f;
ns = 0.0f;
kdMap = null;
- }
+ }
}
}
\ No newline at end of file
diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java
index c39d7dc0a..c8563f74c 100644
--- a/core/src/processing/opengl/PGraphicsOpenGL.java
+++ b/core/src/processing/opengl/PGraphicsOpenGL.java
@@ -139,46 +139,46 @@ public class PGraphicsOpenGL extends PGraphics {
// GL objects:
- static protected HashMap glTextureObjects =
+ static protected HashMap glTextureObjects =
new HashMap();
- static protected HashMap glVertexBuffers =
+ static protected HashMap glVertexBuffers =
new HashMap();
- static protected HashMap glFrameBuffers =
+ static protected HashMap glFrameBuffers =
new HashMap();
- static protected HashMap glRenderBuffers =
+ static protected HashMap glRenderBuffers =
new HashMap();
- static protected HashMap glslPrograms =
+ static protected HashMap glslPrograms =
new HashMap();
- static protected HashMap glslVertexShaders =
+ static protected HashMap glslVertexShaders =
new HashMap();
- static protected HashMap glslFragmentShaders =
+ static protected HashMap glslFragmentShaders =
new HashMap();
// ........................................................
// Shaders
- static protected URL defPolyColorShaderVertURL =
+ static protected URL defPolyColorShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyColorShaderVert.glsl");
- static protected URL defPolyTexShaderVertURL =
+ static protected URL defPolyTexShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyTexShaderVert.glsl");
- static protected URL defPolyLightShaderVertURL =
+ static protected URL defPolyLightShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyLightShaderVert.glsl");
- static protected URL defPolyTexlightShaderVertURL =
+ static protected URL defPolyTexlightShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyTexlightShaderVert.glsl");
- static protected URL defPolyNoTexShaderFragURL =
+ static protected URL defPolyNoTexShaderFragURL =
PGraphicsOpenGL.class.getResource("PolyNoTexShaderFrag.glsl");
- static protected URL defPolyTexShaderFragURL =
+ static protected URL defPolyTexShaderFragURL =
PGraphicsOpenGL.class.getResource("PolyTexShaderFrag.glsl");
- static protected URL defLineShaderVertURL =
+ static protected URL defLineShaderVertURL =
PGraphicsOpenGL.class.getResource("LineShaderVert.glsl");
- static protected URL defLineShaderFragURL =
+ static protected URL defLineShaderFragURL =
PGraphicsOpenGL.class.getResource("LineShaderFrag.glsl");
- static protected URL defPointShaderVertURL =
+ static protected URL defPointShaderVertURL =
PGraphicsOpenGL.class.getResource("PointShaderVert.glsl");
- static protected URL defPointShaderFragURL =
+ static protected URL defPointShaderFragURL =
PGraphicsOpenGL.class.getResource("PointShaderFrag.glsl");
-
+
static protected PolyColorShader defPolyColorShader;
static protected PolyTexShader defPolyTexShader;
static protected PolyLightShader defPolyLightShader;
@@ -186,10 +186,10 @@ public class PGraphicsOpenGL extends PGraphics {
static protected LineShader defLineShader;
static protected PointShader defPointShader;
- static protected URL maskShaderFragURL =
- PGraphicsOpenGL.class.getResource("MaskShaderFrag.glsl");
- static protected PolyTexShader maskShader;
-
+ static protected URL maskShaderFragURL =
+ PGraphicsOpenGL.class.getResource("MaskShaderFrag.glsl");
+ static protected PolyTexShader maskShader;
+
protected PolyColorShader polyColorShader;
protected PolyTexShader polyTexShader;
protected PolyLightShader polyLightShader;
@@ -198,13 +198,13 @@ public class PGraphicsOpenGL extends PGraphics {
protected PointShader pointShader;
// When shader warnings are enabled, the renderer is strict in regards to the
- // use of the polygon shaders. For instance, if a light shader is set to
- // render lit geometry, but the geometry is mixed with some pieces of unlit or
- // textured geometry, then it will warn that the set shader cannot be used for
- // that other type of geometry, even though Processing will use the correct,
+ // use of the polygon shaders. For instance, if a light shader is set to
+ // render lit geometry, but the geometry is mixed with some pieces of unlit or
+ // textured geometry, then it will warn that the set shader cannot be used for
+ // that other type of geometry, even though Processing will use the correct,
// built-in shaders to handle it.
protected boolean shaderWarningsEnabled = true;
-
+
// ........................................................
// Tessellator, geometry
@@ -466,7 +466,7 @@ public class PGraphicsOpenGL extends PGraphics {
final static protected float POINT_ACCURACY_FACTOR = 10.0f;
/** Used in quad point tessellation. */
- final protected float[][] QUAD_POINT_SIGNS =
+ final protected float[][] QUAD_POINT_SIGNS =
{ {-1, +1}, {-1, -1}, {+1, -1}, {+1, +1} };
@@ -516,6 +516,7 @@ public class PGraphicsOpenGL extends PGraphics {
// }
+ @Override
public void setPrimary(boolean primary) {
super.setPrimary(primary);
format = ARGB;
@@ -528,13 +529,15 @@ public class PGraphicsOpenGL extends PGraphics {
//public void setAntiAlias(int samples) // PGraphics
+ @Override
public void setFrameRate(float frameRate) {
pgl.setFrameRate(frameRate);
}
+ @Override
public void setSize(int iwidth, int iheight) {
- resized = (0 < width && width != iwidth) ||
+ resized = (0 < width && width != iwidth) ||
(0 < height && height != iwidth);
width = iwidth;
@@ -571,6 +574,7 @@ public class PGraphicsOpenGL extends PGraphics {
* There is no pixel array to allocate for an OpenGL canvas
* because OpenGL's pixel buffer is all handled internally.
*/
+ @Override
protected void allocate() {
super.allocate();
@@ -599,6 +603,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void dispose() { // PGraphics
super.dispose();
deleteFinalizedGLResources();
@@ -621,15 +626,25 @@ public class PGraphicsOpenGL extends PGraphics {
protected class GLResource {
int id;
int context;
+
GLResource(int id, int context) {
this.id = id;
this.context = context;
}
+ @Override
public boolean equals(Object obj) {
GLResource other = (GLResource)obj;
return other.id == id && other.context == context;
}
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31 * result + id;
+ result = 31 * result + context;
+ return result;
+ }
}
@@ -1002,7 +1017,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
- synchronized protected void finalizeGLSLVertShaderObject(int id,
+ synchronized protected void finalizeGLSLVertShaderObject(int id,
int context) {
GLResource res = new GLResource(id, context);
if (glslVertexShaders.containsKey(res)) {
@@ -1066,7 +1081,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
- synchronized protected void finalizeGLSLFragShaderObject(int id,
+ synchronized protected void finalizeGLSLFragShaderObject(int id,
int context) {
GLResource res = new GLResource(id, context);
if (glslFragmentShaders.containsKey(res)) {
@@ -1114,7 +1129,7 @@ public class PGraphicsOpenGL extends PGraphics {
// FRAMEBUFFERS
- public void pushFramebuffer() {
+ protected void pushFramebuffer() {
if (fbStackDepth == FB_STACK_DEPTH) {
throw new RuntimeException("Too many pushFramebuffer calls");
}
@@ -1123,13 +1138,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
- public void setFramebuffer(FrameBuffer fbo) {
+ protected void setFramebuffer(FrameBuffer fbo) {
currentFramebuffer = fbo;
currentFramebuffer.bind();
}
- public void popFramebuffer() {
+ protected void popFramebuffer() {
if (fbStackDepth == 0) {
throw new RuntimeException("popFramebuffer call is unbalanced.");
}
@@ -1210,45 +1225,45 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = size * PGL.SIZEOF_INT;
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.STATIC_DRAW);
if (lit) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
- pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.STATIC_DRAW);
}
if (tex) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
- pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.STATIC_DRAW);
}
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.polyIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount),
+ ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount),
PGL.STATIC_DRAW);
}
@@ -1340,21 +1355,21 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = size * PGL.SIZEOF_INT;
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.lineIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount),
+ ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount),
PGL.STATIC_DRAW);
}
@@ -1430,21 +1445,21 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = size * PGL.SIZEOF_INT;
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
- pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
+ pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.pointIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount),
+ ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount),
PGL.STATIC_DRAW);
}
@@ -1483,11 +1498,13 @@ public class PGraphicsOpenGL extends PGraphics {
* OpenGL cannot draw until a proper native peer is available, so this
* returns the value of PApplet.isDisplayable() (inherited from Component).
*/
+ @Override
public boolean canDraw() {
return pgl.canDraw();
}
+ @Override
public void requestDraw() {
if (primarySurface) {
if (pgl.initialized) {
@@ -1499,18 +1516,19 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void beginDraw() {
if (drawing) {
showWarning("Already called beginDraw().");
return;
}
- if (pgCurrent != null && !pgCurrent.primarySurface &&
+ if (pgCurrent != null && !pgCurrent.primarySurface &&
!this.primarySurface) {
- // It seems that the user is trying to start another beginDraw()/endDraw()
- // block for an offscreen surface, still drawing on another offscreen
+ // It seems that the user is trying to start another beginDraw()/endDraw()
+ // block for an offscreen surface, still drawing on another offscreen
// surface.
- showWarning("Already called beginDraw() for another " +
+ showWarning("Already called beginDraw() for another " +
"PGraphicsOpenGL object.");
return;
}
@@ -1533,9 +1551,9 @@ public class PGraphicsOpenGL extends PGraphics {
if (!pgl.initialized) {
initOffscreen();
} else {
- boolean outdated = offscreenFramebuffer != null &&
+ boolean outdated = offscreenFramebuffer != null &&
offscreenFramebuffer.contextIsOutdated();
- boolean outdatedMulti = offscreenFramebufferMultisample != null &&
+ boolean outdatedMulti = offscreenFramebufferMultisample != null &&
offscreenFramebufferMultisample.contextIsOutdated();
if (outdated || outdatedMulti) {
pgl.initialized = false;
@@ -1707,6 +1725,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void endDraw() {
report("top endDraw()");
@@ -1738,7 +1757,7 @@ public class PGraphicsOpenGL extends PGraphics {
offscreenFramebufferMultisample.copy(offscreenFramebuffer);
}
- if (!pgl.initialized || !pgPrimary.pgl.initialized ||
+ if (!pgl.initialized || !pgPrimary.pgl.initialized ||
parent.frameCount == 0) {
// If the primary surface is re-initialized, this offscreen
// surface needs to save its contents into the pixels array
@@ -1777,12 +1796,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public PGL beginPGL() {
flush();
return pgl;
}
+ @Override
public void endPGL() {
restoreGL();
}
@@ -1881,7 +1902,7 @@ public class PGraphicsOpenGL extends PGraphics {
// We can write directly to the color FBO, or to the multisample FBO
// if multisampling is enabled.
if (offscreenMultisample) {
- offscreenNotCurrent = offscreenFramebufferMultisample !=
+ offscreenNotCurrent = offscreenFramebufferMultisample !=
currentFramebuffer;
} else {
offscreenNotCurrent = offscreenFramebuffer != currentFramebuffer;
@@ -2036,6 +2057,7 @@ public class PGraphicsOpenGL extends PGraphics {
// protected void checkSettings()
+ @Override
protected void defaultSettings() {
super.defaultSettings();
@@ -2064,6 +2086,7 @@ public class PGraphicsOpenGL extends PGraphics {
// HINTS
+ @Override
public void hint(int which) {
boolean oldValue = hints[PApplet.abs(which)];
super.hint(which);
@@ -2112,6 +2135,7 @@ public class PGraphicsOpenGL extends PGraphics {
// VERTEX SHAPES
+ @Override
public void beginShape(int kind) {
shape = kind;
@@ -2128,10 +2152,11 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void endShape(int mode) {
if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] &&
textureImage0 != null && textureImage == null) {
- // The previous shape had a texture and this one doesn't. So we need to
+ // The previous shape had a texture and this one doesn't. So we need to
// flush the textured geometry.
textureImage = textureImage0;
flush();
@@ -2146,19 +2171,21 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
+
protected void endShape(int[] indices) {
endShape(indices, null);
}
+
protected void endShape(int[] indices, int[] edges) {
if (shape != TRIANGLE && shape != TRIANGLES) {
- throw new RuntimeException("Indices and edges can only be set for " +
+ throw new RuntimeException("Indices and edges can only be set for " +
"TRIANGLE shapes");
}
if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] &&
textureImage0 != null && textureImage == null) {
- // The previous shape had a texture and this one doesn't. So we need to
+ // The previous shape had a texture and this one doesn't. So we need to
// flush the textured geometry.
textureImage = textureImage0;
flush();
@@ -2174,6 +2201,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void textureWrap(int wrap) {
this.textureWrap = wrap;
}
@@ -2184,6 +2212,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void texture(PImage image) {
if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] &&
image != textureImage0) {
@@ -2197,6 +2226,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void noTexture() {
if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] &&
null != textureImage0) {
@@ -2210,6 +2240,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void beginContour() {
if (openContour) {
showWarning("Already called beginContour().");
@@ -2220,6 +2251,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void endContour() {
if (!openContour) {
showWarning("Need to call beginContour() first.");
@@ -2229,21 +2261,25 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void vertex(float x, float y) {
vertexImpl(x, y, 0, 0, 0);
}
+ @Override
public void vertex(float x, float y, float u, float v) {
vertexImpl(x, y, 0, u, v);
}
+ @Override
public void vertex(float x, float y, float z) {
vertexImpl(x, y, z, 0, 0);
}
+ @Override
public void vertex(float x, float y, float z, float u, float v) {
vertexImpl(x, y, z, u, v);
}
@@ -2296,6 +2332,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void clip(float a, float b, float c, float d) {
if (imageMode == CORNER) {
if (c < 0) { // reset a negative width
@@ -2344,6 +2381,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void noClip() {
if (clip) {
flush();
@@ -2405,7 +2443,7 @@ public class PGraphicsOpenGL extends PGraphics {
tessellator.tessellateQuadStrip();
} else if (shape == POLYGON) {
if (stroke && defaultEdges) inGeo.addPolygonEdges(mode == CLOSE);
- tessellator.tessellatePolygon(false, mode == CLOSE,
+ tessellator.tessellatePolygon(false, mode == CLOSE,
normalMode == NORMAL_MODE_AUTO);
}
}
@@ -2438,12 +2476,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void flush() {
- boolean hasPolys = 0 < tessGeo.polyVertexCount &&
+ boolean hasPolys = 0 < tessGeo.polyVertexCount &&
0 < tessGeo.polyIndexCount;
- boolean hasLines = 0 < tessGeo.lineVertexCount &&
+ boolean hasLines = 0 < tessGeo.lineVertexCount &&
0 < tessGeo.lineIndexCount;
- boolean hasPoints = 0 < tessGeo.pointVertexCount &&
+ boolean hasPoints = 0 < tessGeo.pointVertexCount &&
0 < tessGeo.pointIndexCount;
boolean hasPixels = modified && pixels != null;
@@ -2464,7 +2503,7 @@ public class PGraphicsOpenGL extends PGraphics {
// tessellated vertices, so we set the OpenGL modelview matrix as
// the identity to avoid applying the model transformations twice.
// We save the modelview objects and temporarily use the identity
- // static matrix to avoid calling pushMatrix(), resetMatrix(),
+ // static matrix to avoid calling pushMatrix(), resetMatrix(),
// popMatrix().
modelview0 = modelview;
modelviewInv0 = modelviewInv;
@@ -2535,32 +2574,32 @@ public class PGraphicsOpenGL extends PGraphics {
cache.indexOffset[n] + cache.indexCount[n] - ioffset;
int voffset = cache.vertexOffset[n];
- shader.setVertexAttribute(glPolyVertex, 4, PGL.FLOAT, 0,
+ shader.setVertexAttribute(glPolyVertex, 4, PGL.FLOAT, 0,
4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(glPolyColor, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setColorAttribute(glPolyColor, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
if (lights) {
- shader.setNormalAttribute(glPolyNormal, 3, PGL.FLOAT, 0,
+ shader.setNormalAttribute(glPolyNormal, 3, PGL.FLOAT, 0,
3 * voffset * PGL.SIZEOF_FLOAT);
- shader.setAmbientAttribute(glPolyAmbient, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setAmbientAttribute(glPolyAmbient, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
- shader.setSpecularAttribute(glPolySpecular, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setSpecularAttribute(glPolySpecular, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
- shader.setEmissiveAttribute(glPolyEmissive, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setEmissiveAttribute(glPolyEmissive, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
- shader.setShininessAttribute(glPolyShininess, 1, PGL.FLOAT, 0,
+ shader.setShininessAttribute(glPolyShininess, 1, PGL.FLOAT, 0,
voffset * PGL.SIZEOF_FLOAT);
}
if (tex != null) {
- shader.setTexcoordAttribute(glPolyTexcoord, 2, PGL.FLOAT, 0,
+ shader.setTexcoordAttribute(glPolyTexcoord, 2, PGL.FLOAT, 0,
2 * voffset * PGL.SIZEOF_FLOAT);
shader.setTexture(tex);
}
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
ioffset * PGL.SIZEOF_INDEX);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
}
@@ -2589,10 +2628,10 @@ public class PGraphicsOpenGL extends PGraphics {
int last = texCache.lastCache[i];
IndexCache cache = tessGeo.polyIndexCache;
for (int n = first; n <= last; n++) {
- int ioffset = n == first ? texCache.firstIndex[i] :
+ int ioffset = n == first ? texCache.firstIndex[i] :
cache.indexOffset[n];
int icount = n == last ? texCache.lastIndex[i] - ioffset + 1 :
- cache.indexOffset[n] + cache.indexCount[n] -
+ cache.indexOffset[n] + cache.indexCount[n] -
ioffset;
int voffset = cache.vertexOffset[n];
@@ -2608,7 +2647,7 @@ public class PGraphicsOpenGL extends PGraphics {
int argb1 = PGL.nativeToJavaARGB(color[i1]);
int argb2 = PGL.nativeToJavaARGB(color[i2]);
- if (flushMode == FLUSH_CONTINUOUSLY ||
+ if (flushMode == FLUSH_CONTINUOUSLY ||
hints[DISABLE_TRANSFORM_CACHE]) {
float[] src0 = {0, 0, 0, 0};
float[] src1 = {0, 0, 0, 0};
@@ -2635,9 +2674,9 @@ public class PGraphicsOpenGL extends PGraphics {
raw.fill(argb2);
raw.vertex(pt2[X], pt2[Y], pt2[Z], uv[2 * i2 + 0], uv[2 * i2 + 1]);
} else if (raw.is2D()) {
- float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sx2 = screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
float sy2 = screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
@@ -2657,11 +2696,11 @@ public class PGraphicsOpenGL extends PGraphics {
raw.fill(argb2);
raw.vertex(pt2[X], pt2[Y], pt2[Z]);
} else if (raw.is2D()) {
- float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
- float sx2 = screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
+ float sx2 = screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
float sy2 = screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
raw.fill(argb0);
raw.vertex(sx0, sy0);
@@ -2691,15 +2730,15 @@ public class PGraphicsOpenGL extends PGraphics {
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
- shader.setVertexAttribute(glLineVertex, 4, PGL.FLOAT, 0,
+ shader.setVertexAttribute(glLineVertex, 4, PGL.FLOAT, 0,
4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(glLineColor, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setColorAttribute(glLineColor, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
- shader.setLineAttribute(glLineAttrib, 4, PGL.FLOAT, 0,
+ shader.setLineAttribute(glLineAttrib, 4, PGL.FLOAT, 0,
4 * voffset * PGL.SIZEOF_FLOAT);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
ioffset * PGL.SIZEOF_INDEX);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
}
@@ -2765,9 +2804,9 @@ public class PGraphicsOpenGL extends PGraphics {
raw.stroke(argb1);
raw.vertex(pt1[X], pt1[Y], pt1[Z]);
} else if (raw.is2D()) {
- float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
raw.strokeWeight(sw0);
raw.stroke(argb0);
@@ -2795,15 +2834,15 @@ public class PGraphicsOpenGL extends PGraphics {
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
- shader.setVertexAttribute(glPointVertex, 4, PGL.FLOAT, 0,
+ shader.setVertexAttribute(glPointVertex, 4, PGL.FLOAT, 0,
4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(glPointColor, 4, PGL.UNSIGNED_BYTE, 0,
+ shader.setColorAttribute(glPointColor, 4, PGL.UNSIGNED_BYTE, 0,
4 * voffset * PGL.SIZEOF_BYTE);
- shader.setPointAttribute(glPointAttrib, 2, PGL.FLOAT, 0,
+ shader.setPointAttribute(glPointAttrib, 2, PGL.FLOAT, 0,
2 * voffset * PGL.SIZEOF_FLOAT);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
ioffset * PGL.SIZEOF_INDEX);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
}
@@ -2861,7 +2900,7 @@ public class PGraphicsOpenGL extends PGraphics {
raw.stroke(argb0);
raw.vertex(pt0[X], pt0[Y], pt0[Z]);
} else if (raw.is2D()) {
- float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
raw.strokeWeight(weight);
raw.stroke(argb0);
@@ -2881,6 +2920,7 @@ public class PGraphicsOpenGL extends PGraphics {
// BEZIER CURVE VERTICES
+ @Override
public void bezierVertex(float x2, float y2,
float x3, float y3,
float x4, float y4) {
@@ -2890,6 +2930,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void bezierVertex(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
@@ -2913,6 +2954,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void quadraticVertex(float cx, float cy,
float x3, float y3) {
quadraticVertexImpl(cx, cy, 0,
@@ -2920,6 +2962,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void quadraticVertex(float cx, float cy, float cz,
float x3, float y3, float z3) {
quadraticVertexImpl(cx, cy, cz,
@@ -2943,11 +2986,13 @@ public class PGraphicsOpenGL extends PGraphics {
// CATMULL-ROM CURVE VERTICES
+ @Override
public void curveVertex(float x, float y) {
curveVertexImpl(x, y, 0);
}
+ @Override
public void curveVertex(float x, float y, float z) {
curveVertexImpl(x, y, z);
}
@@ -2967,11 +3012,13 @@ public class PGraphicsOpenGL extends PGraphics {
// POINT, LINE, TRIANGLE, QUAD
+ @Override
public void point(float x, float y) {
pointImpl(x, y, 0);
}
+ @Override
public void point(float x, float y, float z) {
pointImpl(x, y, z);
}
@@ -2989,11 +3036,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void line(float x1, float y1, float x2, float y2) {
lineImpl(x1, y1, 0, x2, y2, 0);
}
+ @Override
public void line(float x1, float y1, float z1,
float x2, float y2, float z2) {
lineImpl(x1, y1, z1, x2, y2, z2);
@@ -3015,6 +3064,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void triangle(float x1, float y1, float x2, float y2,
float x3, float y3) {
beginShape(TRIANGLES);
@@ -3031,6 +3081,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void quad(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4) {
beginShape(QUADS);
@@ -3053,6 +3104,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void rectMode(int mode)
+ @Override
public void rect(float a, float b, float c, float d) {
beginShape(QUADS);
defaultEdges = false;
@@ -3066,6 +3118,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void rect(float a, float b, float c, float d,
float tl, float tr, float br, float bl) {
beginShape(POLYGON);
@@ -3089,6 +3142,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void ellipseMode(int mode)
+ @Override
public void ellipse(float a, float b, float c, float d) {
beginShape(TRIANGLE_FAN);
defaultEdges = false;
@@ -3103,6 +3157,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void ellipse(float a, float b, float c, float d)
+ @Override
public void arc(float a, float b, float c, float d,
float start, float stop) {
beginShape(TRIANGLE_FAN);
@@ -3122,6 +3177,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void box(float size)
+ @Override
public void box(float w, float h, float d) {
beginShape(QUADS);
defaultEdges = false;
@@ -3140,13 +3196,14 @@ public class PGraphicsOpenGL extends PGraphics {
// public void sphereDetail(int ures, int vres)
+ @Override
public void sphere(float r) {
beginShape(TRIANGLES);
defaultEdges = false;
normalMode = NORMAL_MODE_VERTEX;
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
- int[] indices = inGeo.addSphere(r, sphereDetailU, sphereDetailV,
+ int[] indices = inGeo.addSphere(r, sphereDetailU, sphereDetailV,
fill, stroke);
endShape(indices);
}
@@ -3216,11 +3273,13 @@ public class PGraphicsOpenGL extends PGraphics {
// SMOOTH
+ @Override
public void smooth() {
smooth(2);
}
+ @Override
public void smooth(int level) {
if (smoothDisabled) return;
@@ -3237,9 +3296,9 @@ public class PGraphicsOpenGL extends PGraphics {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
- PGraphics.showWarning("The smooth/noSmooth functions are being " +
+ PGraphics.showWarning("The smooth/noSmooth functions are being " +
"called too often.\n" +
- "This results in screen flickering, so they " +
+ "This results in screen flickering, so they " +
"will be disabled\n" +
"for the rest of the sketch's execution.");
}
@@ -3256,6 +3315,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void noSmooth() {
if (smoothDisabled) return;
@@ -3265,9 +3325,9 @@ public class PGraphicsOpenGL extends PGraphics {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
- PGraphics.showWarning("The smooth/noSmooth functions are being " +
+ PGraphics.showWarning("The smooth/noSmooth functions are being " +
"called too often.\n" +
- "This results in screen flickering, so they " +
+ "This results in screen flickering, so they " +
"will be disabled\n" +
"for the rest of the sketch's execution.");
}
@@ -3308,7 +3368,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
- public void shape(PShape shape, float x, float y, float z, float c, float d,
+ public void shape(PShape shape, float x, float y, float z, float c, float d,
float e) {
if (shape.isVisible()) { // don't do expensive matrix ops if invisible
flush();
@@ -3318,14 +3378,14 @@ public class PGraphicsOpenGL extends PGraphics {
if (shapeMode == CENTER) {
// x, y and z are center, c, d and e refer to a diameter
translate(x - c / 2f, y - d / 2f, z - e / 2f);
- scale(c / shape.getWidth(),
- d / shape.getHeight(),
+ scale(c / shape.getWidth(),
+ d / shape.getHeight(),
e / shape.getDepth());
} else if (shapeMode == CORNER) {
translate(x, y, z);
- scale(c / shape.getWidth(),
- d / shape.getHeight(),
+ scale(c / shape.getWidth(),
+ d / shape.getHeight(),
e / shape.getDepth());
} else if (shapeMode == CORNERS) {
@@ -3335,8 +3395,8 @@ public class PGraphicsOpenGL extends PGraphics {
e -= z;
// then same as above
translate(x, y, z);
- scale(c / shape.getWidth(),
- d / shape.getHeight(),
+ scale(c / shape.getWidth(),
+ d / shape.getHeight(),
e / shape.getDepth());
}
shape.draw(this);
@@ -3351,6 +3411,7 @@ public class PGraphicsOpenGL extends PGraphics {
// SHAPE I/O
+ @Override
public PShape loadShape(String filename) {
String ext = PApplet.getExtension(filename);
if (PGraphics2D.isSupportedExtension(ext)) {
@@ -3384,6 +3445,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void textMode(int mode)
+ @Override
protected boolean textModeCheck(int mode) {
return mode == MODEL;
}
@@ -3408,16 +3470,17 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Implementation of actual drawing for a line of text.
*/
- protected void textLineImpl(char buffer[], int start, int stop,
+ @Override
+ protected void textLineImpl(char buffer[], int start, int stop,
float x, float y) {
textTex = (PFontTexture)textFont.getCache(pgPrimary);
if (textTex == null) {
- textTex = new PFontTexture(parent, textFont, maxTextureSize,
+ textTex = new PFontTexture(parent, textFont, maxTextureSize,
maxTextureSize, is3D());
textFont.setCache(pgPrimary, textTex);
} else {
if (textTex.contextIsOutdated()) {
- textTex = new PFontTexture(parent, textFont,
+ textTex = new PFontTexture(parent, textFont,
PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize),
PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D());
textFont.setCache(pgPrimary, textTex);
@@ -3467,6 +3530,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
protected void textCharImpl(char ch, float x, float y) {
PFont.Glyph glyph = textFont.getGlyph(ch);
@@ -3495,8 +3559,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
- protected void textCharModelImpl(PFontTexture.TextureInfo info,
- float x0, float y0,
+ protected void textCharModelImpl(PFontTexture.TextureInfo info,
+ float x0, float y0,
float x1, float y1) {
if (textTex.currentTex != info.texIndex) {
textTex.setTexture(info.texIndex);
@@ -3518,6 +3582,7 @@ public class PGraphicsOpenGL extends PGraphics {
// MATRIX STACK
+ @Override
public void pushMatrix() {
if (modelviewStackDepth == MATRIX_STACK_DEPTH) {
throw new RuntimeException(ERROR_PUSHMATRIX_OVERFLOW);
@@ -3530,6 +3595,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void popMatrix() {
if (hints[DISABLE_TRANSFORM_CACHE]) {
flush();
@@ -3552,11 +3618,13 @@ public class PGraphicsOpenGL extends PGraphics {
// MATRIX TRANSFORMATIONS
+ @Override
public void translate(float tx, float ty) {
translateImpl(tx, ty, 0);
}
+ @Override
public void translate(float tx, float ty, float tz) {
translateImpl(tx, ty, tz);
}
@@ -3573,7 +3641,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
- static protected void invTranslate(PMatrix3D matrix,
+ static protected void invTranslate(PMatrix3D matrix,
float tx, float ty, float tz) {
matrix.preApply(1, 0, 0, -tx,
0, 1, 0, -ty,
@@ -3588,21 +3656,25 @@ public class PGraphicsOpenGL extends PGraphics {
* people drawing 2D graphics to be using rotateZ. And they might kick our a--
* for the confusion.
*/
+ @Override
public void rotate(float angle) {
rotateImpl(angle, 0, 0, 1);
}
+ @Override
public void rotateX(float angle) {
rotateImpl(angle, 1, 0, 0);
}
+ @Override
public void rotateY(float angle) {
rotateImpl(angle, 0, 1, 0);
}
+ @Override
public void rotateZ(float angle) {
rotateImpl(angle, 0, 0, 1);
}
@@ -3612,6 +3684,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Rotate around an arbitrary vector, similar to glRotate(), except that it
* takes radians (instead of degrees).
*/
+ @Override
public void rotate(float angle, float v0, float v1, float v2) {
rotateImpl(angle, v0, v1, v2);
}
@@ -3642,7 +3715,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
- static private void invRotate(PMatrix3D matrix, float angle,
+ static private void invRotate(PMatrix3D matrix, float angle,
float v0, float v1, float v2) {
float c = PApplet.cos(-angle);
float s = PApplet.sin(-angle);
@@ -3658,6 +3731,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Same as scale(s, s, s).
*/
+ @Override
public void scale(float s) {
scaleImpl(s, s, s);
}
@@ -3666,6 +3740,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Same as scale(sx, sy, 1).
*/
+ @Override
public void scale(float sx, float sy) {
scaleImpl(sx, sy, 1);
}
@@ -3674,6 +3749,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Scale in three dimensions.
*/
+ @Override
public void scale(float sx, float sy, float sz) {
scaleImpl(sx, sy, sz);
}
@@ -3697,6 +3773,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void shearX(float angle) {
float t = (float) Math.tan(angle);
applyMatrixImpl(1, t, 0, 0,
@@ -3706,6 +3783,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void shearY(float angle) {
float t = (float) Math.tan(angle);
applyMatrixImpl(1, 0, 0, 0,
@@ -3720,6 +3798,7 @@ public class PGraphicsOpenGL extends PGraphics {
// MATRIX MORE!
+ @Override
public void resetMatrix() {
if (hints[DISABLE_TRANSFORM_CACHE]) {
flush();
@@ -3736,6 +3815,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void applyMatrix(PMatrix2D source) {
applyMatrixImpl(source.m00, source.m01, 0, source.m02,
source.m10, source.m11, 0, source.m12,
@@ -3744,6 +3824,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void applyMatrix(float n00, float n01, float n02,
float n10, float n11, float n12) {
applyMatrixImpl(n00, n01, 0, n02,
@@ -3753,6 +3834,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void applyMatrix(PMatrix3D source) {
applyMatrixImpl(source.m00, source.m01, source.m02, source.m03,
source.m10, source.m11, source.m12, source.m13,
@@ -3764,6 +3846,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Apply a 4x4 transformation matrix to the modelview stack.
*/
+ @Override
public void applyMatrix(float n00, float n01, float n02, float n03,
float n10, float n11, float n12, float n13,
float n20, float n21, float n22, float n23,
@@ -3809,6 +3892,7 @@ public class PGraphicsOpenGL extends PGraphics {
// MATRIX GET/SET/PRINT
+ @Override
public PMatrix getMatrix() {
return modelview.get();
}
@@ -3817,6 +3901,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public PMatrix2D getMatrix(PMatrix2D target)
+ @Override
public PMatrix3D getMatrix(PMatrix3D target) {
if (target == null) {
target = new PMatrix3D();
@@ -3829,6 +3914,7 @@ public class PGraphicsOpenGL extends PGraphics {
// public void setMatrix(PMatrix source)
+ @Override
public void setMatrix(PMatrix2D source) {
resetMatrix();
applyMatrix(source);
@@ -3838,6 +3924,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Set the current transformation to the contents of the specified source.
*/
+ @Override
public void setMatrix(PMatrix3D source) {
resetMatrix();
applyMatrix(source);
@@ -3847,6 +3934,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Print the current model (or "transformation") matrix.
*/
+ @Override
public void printMatrix() {
modelview.print();
}
@@ -3984,6 +4072,7 @@ public class PGraphicsOpenGL extends PGraphics {
* endCamera();
*
*/
+ @Override
public void beginCamera() {
if (manipulatingCamera) {
throw new RuntimeException("beginCamera() cannot be called again "
@@ -4002,6 +4091,7 @@ public class PGraphicsOpenGL extends PGraphics {
* whatever, because the final camera matrix will be copied (not multiplied)
* into the modelview.
*/
+ @Override
public void endCamera() {
if (!manipulatingCamera) {
throw new RuntimeException("Cannot call endCamera() "
@@ -4050,6 +4140,7 @@ public class PGraphicsOpenGL extends PGraphics {
* with beginCamera(), endCamera() to indicate that they should apply (in
* inverse), to the camera transformation matrix.
*/
+ @Override
public void camera() {
camera(cameraX, cameraY, cameraZ, cameraX, cameraY, 0, 0, 1, 0);
}
@@ -4111,6 +4202,7 @@ public class PGraphicsOpenGL extends PGraphics {
* cz, ux, uy, uz) as naked calls because they do all the matrix resetting
* automatically.
*/
+ @Override
public void camera(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ) {
@@ -4201,6 +4293,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Print the current camera matrix.
*/
+ @Override
public void printCamera() {
camera.print();
}
@@ -4220,6 +4313,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Calls ortho() with the proper parameters for Processing's standard
* orthographic projection.
*/
+ @Override
public void ortho() {
ortho(-width/2, +width/2, -height/2, +height/2, cameraNear, cameraFar);
}
@@ -4229,6 +4323,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Calls ortho() with the specified size of the viewing volume along
* the X and Z directions.
*/
+ @Override
public void ortho(float left, float right,
float bottom, float top) {
ortho(left, right, bottom, top, cameraNear, cameraFar);
@@ -4244,6 +4339,7 @@ public class PGraphicsOpenGL extends PGraphics {
* camera position.
*
*/
+ @Override
public void ortho(float left, float right,
float bottom, float top,
float near, float far) {
@@ -4290,6 +4386,7 @@ public class PGraphicsOpenGL extends PGraphics {
* replace matrices, rather than multiplying against the previous.
*
*/
+ @Override
public void perspective() {
perspective(cameraFOV, cameraAspect, cameraNear, cameraFar);
}
@@ -4298,6 +4395,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Similar to gluPerspective(). Implementation based on Mesa's glu.c
*/
+ @Override
public void perspective(float fov, float aspect, float zNear, float zFar) {
float ymax = zNear * (float) Math.tan(fov / 2);
float ymin = -ymax;
@@ -4313,6 +4411,7 @@ public class PGraphicsOpenGL extends PGraphics {
*
* Implementation based on the explanation in the OpenGL blue book.
*/
+ @Override
public void frustum(float left, float right, float bottom, float top,
float znear, float zfar) {
// Flushing geometry with a different perspective configuration.
@@ -4337,6 +4436,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Print the current projection matrix.
*/
+ @Override
public void printProjection() {
projection.print();
}
@@ -4352,48 +4452,53 @@ public class PGraphicsOpenGL extends PGraphics {
// SCREEN AND MODEL COORDS
+ @Override
public float screenX(float x, float y) {
return screenXImpl(x, y, 0);
}
+ @Override
public float screenY(float x, float y) {
return screenYImpl(x, y, 0);
}
+ @Override
public float screenX(float x, float y, float z) {
return screenXImpl(x, y, z);
}
+ @Override
public float screenY(float x, float y, float z) {
return screenYImpl(x, y, z);
}
+ @Override
public float screenZ(float x, float y, float z) {
return screenZImpl(x, y, z);
}
protected float screenXImpl(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
return screenXImpl(ax, ay, az, aw);
}
protected float screenXImpl(float x, float y, float z, float w) {
- float ox =
+ float ox =
projection.m00*x + projection.m01*y + projection.m02*z + projection.m03*w;
- float ow =
+ float ow =
projection.m30*x + projection.m31*y + projection.m32*z + projection.m33*w;
if (nonZero(ow)) {
@@ -4405,22 +4510,22 @@ public class PGraphicsOpenGL extends PGraphics {
protected float screenYImpl(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
return screenYImpl(ax, ay, az, aw);
}
protected float screenYImpl(float x, float y, float z, float w) {
- float oy =
+ float oy =
projection.m10*x + projection.m11*y + projection.m12*z + projection.m13*w;
- float ow =
+ float ow =
projection.m30*x + projection.m31*y + projection.m32*z + projection.m33*w;
if (nonZero(ow)) {
@@ -4434,22 +4539,22 @@ public class PGraphicsOpenGL extends PGraphics {
protected float screenZImpl(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
return screenZImpl(ax, ay, az, aw);
}
protected float screenZImpl(float x, float y, float z, float w) {
- float oz =
+ float oz =
projection.m20*x + projection.m21*y + projection.m22*z + projection.m23*w;
- float ow =
+ float ow =
projection.m30*x + projection.m31*y + projection.m32*z + projection.m33*w;
if (nonZero(ow)) {
@@ -4460,57 +4565,60 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public float modelX(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
- float ox =
+ float ox =
cameraInv.m00*ax + cameraInv.m01*ay + cameraInv.m02*az + cameraInv.m03*aw;
- float ow =
+ float ow =
cameraInv.m30*ax + cameraInv.m31*ay + cameraInv.m32*az + cameraInv.m33*aw;
return nonZero(ow) ? ox / ow : ox;
}
+ @Override
public float modelY(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
- float oy =
+ float oy =
cameraInv.m10*ax + cameraInv.m11*ay + cameraInv.m12*az + cameraInv.m13*aw;
- float ow =
+ float ow =
cameraInv.m30*ax + cameraInv.m31*ay + cameraInv.m32*az + cameraInv.m33*aw;
return nonZero(ow) ? oy / ow : oy;
}
+ @Override
public float modelZ(float x, float y, float z) {
- float ax =
+ float ax =
modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03;
- float ay =
+ float ay =
modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13;
- float az =
+ float az =
modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23;
- float aw =
+ float aw =
modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33;
- float oz =
+ float oz =
cameraInv.m20*ax + cameraInv.m21*ay + cameraInv.m22*az + cameraInv.m23*aw;
- float ow =
+ float ow =
cameraInv.m30*ax + cameraInv.m31*ay + cameraInv.m32*az + cameraInv.m33*aw;
return nonZero(ow) ? oz / ow : oz;
@@ -4550,16 +4658,19 @@ public class PGraphicsOpenGL extends PGraphics {
// STROKE CAP/JOIN/WEIGHT
+ @Override
public void strokeWeight(float weight) {
this.strokeWeight = weight;
}
+ @Override
public void strokeJoin(int join) {
this.strokeJoin = join;
}
+ @Override
public void strokeCap(int cap) {
this.strokeCap = cap;
}
@@ -4570,6 +4681,7 @@ public class PGraphicsOpenGL extends PGraphics {
// FILL COLOR
+ @Override
protected void fillFromCalc() {
super.fillFromCalc();
@@ -4687,6 +4799,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Simon Greenwold, April 2005
*
*/
+ @Override
public void lights() {
enableLighting();
@@ -4698,7 +4811,7 @@ public class PGraphicsOpenGL extends PGraphics {
lightSpecular(0, 0, 0);
ambientLight(colorModeX * 0.5f, colorModeY * 0.5f, colorModeZ * 0.5f);
- directionalLight(colorModeX * 0.5f, colorModeY * 0.5f, colorModeZ * 0.5f,
+ directionalLight(colorModeX * 0.5f, colorModeY * 0.5f, colorModeZ * 0.5f,
0, 0, -1);
colorMode = colorModeSaved;
@@ -4708,6 +4821,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Disables lighting.
*/
+ @Override
public void noLights() {
disableLighting();
lightCount = 0;
@@ -4717,6 +4831,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Add an ambient light based on the current color mode.
*/
+ @Override
public void ambientLight(float r, float g, float b) {
ambientLight(r, g, b, 0, 0, 0);
}
@@ -4726,11 +4841,12 @@ public class PGraphicsOpenGL extends PGraphics {
* Add an ambient light based on the current color mode. This version includes
* an (x, y, z) position for situations where the falloff distance is used.
*/
- public void ambientLight(float r, float g, float b,
+ @Override
+ public void ambientLight(float r, float g, float b,
float x, float y, float z) {
enableLighting();
if (lightCount == PGL.MAX_LIGHTS) {
- throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
+ throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
" lights");
}
@@ -4751,11 +4867,12 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void directionalLight(float r, float g, float b,
float dx, float dy, float dz) {
enableLighting();
if (lightCount == PGL.MAX_LIGHTS) {
- throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
+ throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
" lights");
}
@@ -4776,11 +4893,12 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void pointLight(float r, float g, float b,
float x, float y, float z) {
enableLighting();
if (lightCount == PGL.MAX_LIGHTS) {
- throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
+ throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
" lights");
}
@@ -4803,13 +4921,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void spotLight(float r, float g, float b,
float x, float y, float z,
float dx, float dy, float dz,
float angle, float concentration) {
enableLighting();
if (lightCount == PGL.MAX_LIGHTS) {
- throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
+ throw new RuntimeException("can only create " + PGL.MAX_LIGHTS +
" lights");
}
@@ -4836,6 +4955,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Set the light falloff rates for the last light that was created. Default is
* lightFalloff(1, 0, 0).
*/
+ @Override
public void lightFalloff(float constant, float linear, float quadratic) {
currentLightFalloffConstant = constant;
currentLightFalloffLinear = linear;
@@ -4846,6 +4966,7 @@ public class PGraphicsOpenGL extends PGraphics {
/**
* Set the specular color of the last light created.
*/
+ @Override
public void lightSpecular(float x, float y, float z) {
colorCalc(x, y, z);
currentLightSpecular[0] = calcR;
@@ -4870,13 +4991,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
- protected void lightPosition(int num, float x, float y, float z,
+ protected void lightPosition(int num, float x, float y, float z,
boolean dir) {
- lightPosition[4 * num + 0] =
+ lightPosition[4 * num + 0] =
x*modelview.m00 + y*modelview.m01 + z*modelview.m02 + modelview.m03;
- lightPosition[4 * num + 1] =
+ lightPosition[4 * num + 1] =
x*modelview.m10 + y*modelview.m11 + z*modelview.m12 + modelview.m13;
- lightPosition[4 * num + 2] =
+ lightPosition[4 * num + 2] =
x*modelview.m20 + y*modelview.m21 + z*modelview.m22 + modelview.m23;
// Used to inicate if the light is directional or not.
@@ -4885,13 +5006,13 @@ public class PGraphicsOpenGL extends PGraphics {
protected void lightNormal(int num, float dx, float dy, float dz) {
- // Applying normal matrix to the light direction vector, which is the
+ // Applying normal matrix to the light direction vector, which is the
// transpose of the inverse of the modelview.
- float nx =
+ float nx =
dx*modelviewInv.m00 + dy*modelviewInv.m10 + dz*modelviewInv.m20;
- float ny =
+ float ny =
dx*modelviewInv.m01 + dy*modelviewInv.m11 + dz*modelviewInv.m21;
- float nz =
+ float nz =
dx*modelviewInv.m02 + dy*modelviewInv.m12 + dz*modelviewInv.m22;
float invn = 1.0f / PApplet.dist(0, 0, 0, nx, ny, nz);
@@ -4976,6 +5097,7 @@ public class PGraphicsOpenGL extends PGraphics {
// BACKGROUND
+ @Override
protected void backgroundImpl(PImage image) {
backgroundImpl();
set(0, 0, image);
@@ -4985,6 +5107,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
protected void backgroundImpl() {
flush();
@@ -5061,6 +5184,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+
//////////////////////////////////////////////////////////////
// RENDERER SUPPORT QUERIES
@@ -5068,11 +5192,13 @@ public class PGraphicsOpenGL extends PGraphics {
// public boolean displayable()
+ @Override
public boolean isGL() {
return true;
}
+
//////////////////////////////////////////////////////////////
// PIMAGE METHODS
@@ -5089,6 +5215,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Initializes the pixels array, copying the current contents of the
// color buffer into it.
+ @Override
public void loadPixels() {
boolean needEndDraw = false;
if (!drawing) {
@@ -5136,7 +5263,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected void readPixels() {
beginPixelsOp(OP_READ);
pixelBuffer.rewind();
- pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
pixelBuffer);
endPixelsOp();
@@ -5182,6 +5309,7 @@ public class PGraphicsOpenGL extends PGraphics {
// GET/SET PIXELS
+ @Override
public int get(int x, int y) {
loadPixels();
setgetPixels = true;
@@ -5189,6 +5317,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
protected PImage getImpl(int x, int y, int w, int h) {
loadPixels();
setgetPixels = true;
@@ -5196,6 +5325,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void set(int x, int y, int argb) {
loadPixels();
setgetPixels = true;
@@ -5203,6 +5333,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
PImage src) {
loadPixels();
@@ -5232,15 +5363,15 @@ public class PGraphicsOpenGL extends PGraphics {
if (pgl.primaryIsFboBacked()) {
pgl.bindPrimaryColorFBO();
- // Copy the contents of the FBO used by the primary surface into
- // texture, this copy operation is very fast because it is resolved
+ // Copy the contents of the FBO used by the primary surface into
+ // texture, this copy operation is very fast because it is resolved
// in the GPU.
- texture.set(pgl.getFboTexTarget(), pgl.getFboTexName(),
+ texture.set(pgl.getFboTexTarget(), pgl.getFboTexName(),
pgl.getFboWidth(), pgl.getFboHeight(), width, height);
pgl.bindPrimaryMultiFBO();
} else {
- // Here we go the slow route: we first copy the contents of the color
- // buffer into a pixels array (but we keep it in native format) and
+ // Here we go the slow route: we first copy the contents of the color
+ // buffer into a pixels array (but we keep it in native format) and
// then copy this array into the texture.
if (nativePixels == null || nativePixels.length < width * height) {
nativePixels = new int[width * height];
@@ -5248,7 +5379,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
beginPixelsOp(OP_READ);
- pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
nativePixelBuffer);
endPixelsOp();
@@ -5307,7 +5438,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Uses the texture in img as the color buffer for this surface.
public void setTexture(PImage img) {
if (width != img.width || height != img.height) {
- PGraphics.showWarning("Resolution of image is different from PGraphics " +
+ PGraphics.showWarning("Resolution of image is different from PGraphics " +
"object");
return;
}
@@ -5351,17 +5482,17 @@ public class PGraphicsOpenGL extends PGraphics {
int texX0, int texY0, int texX1, int texY1,
int scrX0, int scrY0, int scrX1, int scrY1) {
beginPGL();
- pgl.drawTexture(target, id, width, height,
- texX0, texY0, texX1, texY1,
+ pgl.drawTexture(target, id, width, height,
+ texX0, texY0, texX1, texY1,
scrX0, scrY0, scrX1, scrY1);
endPGL();
}
-
-
+
+
protected void loadTextureImpl(int sampling, boolean mipmap) {
if (width == 0 || height == 0) return;
if (texture == null || texture.contextIsOutdated()) {
- Texture.Parameters params = new Texture.Parameters(ARGB,
+ Texture.Parameters params = new Texture.Parameters(ARGB,
sampling, mipmap);
texture = new Texture(parent, width, height, params);
texture.setFlippedY(true);
@@ -5395,11 +5526,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
+
//////////////////////////////////////////////////////////////
// IMAGE CONVERSION
+ /*
static public void nativeToJavaRGB(PImage image) {
if (image.pixels != null) {
PGL.nativeToJavaRGB(image.pixels, image.width, image.height);
@@ -5426,13 +5559,16 @@ public class PGraphicsOpenGL extends PGraphics {
PGL.javaToNativeARGB(image.pixels, image.width, image.height);
}
}
+ */
+
+
-
//////////////////////////////////////////////////////////////
// MASK
+ @Override
public void mask(int alpha[]) {
PImage temp = get();
temp.mask(alpha);
@@ -5440,20 +5576,22 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void mask(PImage alpha) {
if (alpha.width != width || alpha.height != height) {
throw new RuntimeException("The PImage used with mask() must be " +
- "the same size as the applet.");
+ "the same size as the applet.");
}
-
+
if (maskShader == null) {
- maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL,
+ maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL,
maskShaderFragURL);
}
maskShader.set("maskSampler", alpha);
filter(maskShader);
}
-
+
+
//////////////////////////////////////////////////////////////
@@ -5465,6 +5603,7 @@ public class PGraphicsOpenGL extends PGraphics {
* set() with a smaller image area, or call the filter on an image instead,
* and then draw that.
*/
+ @Override
public void filter(int kind) {
PImage temp = get();
temp.filter(kind);
@@ -5477,6 +5616,7 @@ public class PGraphicsOpenGL extends PGraphics {
* set() with a smaller image area, or call the filter on an image instead,
* and then draw that.
*/
+ @Override
public void filter(int kind, float param) {
PImage temp = get();
temp.filter(kind, param);
@@ -5484,6 +5624,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ @Override
public void filter(PShader shader) {
if (!(shader instanceof PolyTexShader)) {
PGraphics.showWarning("Object is not a valid shader");
@@ -5492,21 +5633,21 @@ public class PGraphicsOpenGL extends PGraphics {
loadTexture();
- if (textureCopy == null || textureCopy.width != width ||
+ if (textureCopy == null || textureCopy.width != width ||
textureCopy.height != height) {
- Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT,
+ Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT,
false);
textureCopy = new Texture(parent, width, height, params);
textureCopy.setFlippedY(true);
imageCopy = wrapTexture(textureCopy);
}
- textureCopy.set(texture.glTarget, texture.glName,
+ textureCopy.set(texture.glTarget, texture.glName,
texture.glWidth, texture.glHeight, width, height);
- // Disable writing to the depth buffer, so that after applying the filter we
+ // Disable writing to the depth buffer, so that after applying the filter we
// can still use the depth information to keep adding geometry to the scene.
pgl.depthMask(false);
- // Also disabling depth testing so the texture is drawn on top of everything
+ // Also disabling depth testing so the texture is drawn on top of everything
// that has been drawn before.
pgl.disable(PGL.DEPTH_TEST);
@@ -5603,6 +5744,7 @@ public class PGraphicsOpenGL extends PGraphics {
* Reference article about blending modes:
* http://www.pegtop.net/delphi/articles/blendmodes/
*/
+ @Override
public void blendMode(int mode) {
if (blendMode != mode) {
// Flushing any remaining geometry that uses a different blending
@@ -5672,8 +5814,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
pgl.blendFunc(PGL.ONE_MINUS_DST_COLOR, PGL.ONE);
}
- // HARD_LIGHT, SOFT_LIGHT, OVERLAY, DODGE, BURN modes cannot be
- // implemented in fixed-function pipeline because they require conditional
+ // HARD_LIGHT, SOFT_LIGHT, OVERLAY, DODGE, BURN modes cannot be
+ // implemented in fixed-function pipeline because they require conditional
// blending and non-linear blending equations.
}
}
@@ -5721,7 +5863,7 @@ public class PGraphicsOpenGL extends PGraphics {
public Texture getTexture(PImage img) {
Texture tex = (Texture)initCache(img);
if (tex == null) return null;
-
+
if (img.isModified()) {
if (img.width != tex.width || img.height != tex.height) {
tex.init(img.width, img.height);
@@ -5732,13 +5874,14 @@ public class PGraphicsOpenGL extends PGraphics {
if (tex.hasBuffers()) {
tex.bufferUpdate();
}
-
+
checkTexture(tex);
-
+
return tex;
}
+ @Override
public Object initCache(PImage img) {
Texture tex = (Texture)img.getCache(pgPrimary);
if (tex == null || tex.contextIsOutdated()) {
@@ -5781,7 +5924,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (img.width == 0 || img.height == 0) {
// Cannot add textures of size 0
return null;
- }
+ }
if (img.parent == null) {
img.parent = parent;
}
@@ -5798,9 +5941,9 @@ public class PGraphicsOpenGL extends PGraphics {
tex.usingMipmaps(false, textureSampling);
} else {
tex.usingMipmaps(true, textureSampling);
- }
+ }
}
-
+
if ((tex.usingRepeat && textureWrap == CLAMP) ||
(!tex.usingRepeat && textureWrap == REPEAT)) {
if (textureWrap == CLAMP) {
@@ -5810,8 +5953,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
}
-
-
+
+
protected PImage wrapTexture(Texture tex) {
// We don't use the PImage(int width, int height, int mode) constructor to
// avoid initializing the pixels array.
@@ -5843,6 +5986,7 @@ public class PGraphicsOpenGL extends PGraphics {
// RESIZE
+ @Override
public void resize(int wide, int high) {
PGraphics.showMethodWarning("resize");
}
@@ -5879,26 +6023,26 @@ public class PGraphicsOpenGL extends PGraphics {
offscreenFramebufferMultisample.release();
}
- boolean packed = depthBits == 24 && stencilBits == 8 &&
+ boolean packed = depthBits == 24 && stencilBits == 8 &&
packedDepthStencilSupported;
- if (PGraphicsOpenGL.fboMultisampleSupported && 1 < quality) {
- offscreenFramebufferMultisample =
+ if (PGraphicsOpenGL.fboMultisampleSupported && 1 < quality) {
+ offscreenFramebufferMultisample =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, quality, 0,
depthBits, stencilBits, packed, false);
offscreenFramebufferMultisample.clear();
offscreenMultisample = true;
- // The offscreen framebuffer where the multisampled image is finally drawn
- // to doesn't need depth and stencil buffers since they are part of the
+ // The offscreen framebuffer where the multisampled image is finally drawn
+ // to doesn't need depth and stencil buffers since they are part of the
// multisampled framebuffer.
- offscreenFramebuffer =
+ offscreenFramebuffer =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, 1, 1, 0, 0,
false, false);
} else {
quality = 0;
- offscreenFramebuffer =
+ offscreenFramebuffer =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, 1, 1,
depthBits, stencilBits, packed, false);
offscreenMultisample = false;
@@ -5915,14 +6059,14 @@ public class PGraphicsOpenGL extends PGraphics {
OPENGL_VERSION = pgl.getString(PGL.VERSION);
OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS);
GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION);
-
- npotTexSupported =
+
+ npotTexSupported =
-1 < OPENGL_EXTENSIONS.indexOf("_texture_non_power_of_two");
- autoMipmapGenSupported =
+ autoMipmapGenSupported =
-1 < OPENGL_EXTENSIONS.indexOf("_generate_mipmap");
- fboMultisampleSupported =
+ fboMultisampleSupported =
-1 < OPENGL_EXTENSIONS.indexOf("_framebuffer_multisample");
- packedDepthStencilSupported =
+ packedDepthStencilSupported =
-1 < OPENGL_EXTENSIONS.indexOf("_packed_depth_stencil");
try {
@@ -5961,18 +6105,19 @@ public class PGraphicsOpenGL extends PGraphics {
// SHADER HANDLING
+ @Override
public PShader loadShader(String fragFilename) {
- int shaderType = getTypeFromFragmentShader(fragFilename);
+ int shaderType = getTypeFromFragmentShader(fragFilename);
PShader shader = null;
if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent);
shader.setVertexShader(defPolyTexShaderVertURL);
} else if (shaderType == PShader.COLOR) {
shader = new PolyColorShader(parent);
- shader.setVertexShader(defPolyColorShaderVertURL);
- }
+ shader.setVertexShader(defPolyColorShaderVertURL);
+ }
if (shader == null){
- PGraphics.showWarning("The GLSL code doesn't seem to contain a valid " +
+ PGraphics.showWarning("The GLSL code doesn't seem to contain a valid " +
"shader to use in Processing.");
} else {
shader.setFragmentShader(fragFilename);
@@ -5981,23 +6126,24 @@ public class PGraphicsOpenGL extends PGraphics {
}
- public PShader loadShader(String fragFilename, String vertFilename) {
+ @Override
+ public PShader loadShader(String fragFilename, String vertFilename) {
int shaderType = getTypeFromVertexShader(vertFilename);
PShader shader = null;
if (fragFilename == null || fragFilename.equals("")) {
if (shaderType == PShader.POINT) {
shader = new PointShader(parent);
- shader.setFragmentShader(defPointShaderFragURL);
+ shader.setFragmentShader(defPointShaderFragURL);
} else if (shaderType == PShader.LINE) {
shader = new LineShader(parent);
- shader.setFragmentShader(defLineShaderFragURL);
+ shader.setFragmentShader(defLineShaderFragURL);
} else if (shaderType == PShader.TEXLIGHT) {
shader = new PolyTexlightShader(parent);
- shader.setFragmentShader(defPolyTexShaderFragURL);
+ shader.setFragmentShader(defPolyTexShaderFragURL);
} else if (shaderType == PShader.LIGHT) {
shader = new PolyLightShader(parent);
- shader.setFragmentShader(defPolyNoTexShaderFragURL);
- } else if (shaderType == PShader.TEXTURE) {
+ shader.setFragmentShader(defPolyNoTexShaderFragURL);
+ } else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent);
shader.setFragmentShader(defPolyTexShaderFragURL);
} else if (shaderType == PShader.COLOR) {
@@ -6009,13 +6155,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
} else {
if (shaderType == PShader.POINT) {
- shader = new PointShader(parent, vertFilename, fragFilename);
+ shader = new PointShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.LINE) {
shader = new LineShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.TEXLIGHT) {
shader = new PolyTexlightShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.LIGHT) {
- shader = new PolyLightShader(parent, vertFilename, fragFilename);
+ shader = new PolyLightShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.COLOR) {
@@ -6023,18 +6169,20 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
if (shader == null) {
- PGraphics.showWarning("The GLSL code doesn't seem to contain a valid " +
- "shader to use in Processing.");
+ PGraphics.showWarning("The GLSL code doesn't seem to contain a valid " +
+ "shader to use in Processing.");
}
return shader;
}
+ @Override
public void shader(PShader shader) {
shader(shader, POLYGON);
}
-
-
+
+
+ @Override
public void shader(PShader shader, int kind) {
flush(); // Flushing geometry drawn with a different shader.
@@ -6055,52 +6203,54 @@ public class PGraphicsOpenGL extends PGraphics {
lineShader = (LineShader)shader;
} else {
showWarning("shader() called with a wrong shader object");
- }
- } else if (kind == POINTS) {
+ }
+ } else if (kind == POINTS) {
if (shader instanceof PointShader) {
pointShader = (PointShader)shader;
} else {
showWarning("shader() called with a wrong shader object");
- }
+ }
} else {
showWarning("shader() called with an unknown shader type");
}
}
-
+
+ @Override
public void resetShader() {
resetShader(POLYGON);
}
-
+
+ @Override
public void resetShader(int kind) {
flush(); // Flushing geometry drawn with a different shader.
-
+
if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) {
polyTexShader = null;
polyColorShader = null;
polyTexlightShader = null;
polyLightShader = null;
- } else if (kind == LINES) {
+ } else if (kind == LINES) {
lineShader = null;
- } else if (kind == POINTS) {
+ } else if (kind == POINTS) {
pointShader = null;
} else {
PGraphics.showWarning("Wrong shader type");
}
}
-
+
public void shaderWarnings(boolean enable) {
shaderWarningsEnabled = enable;
}
-
+
protected int getTypeFromFragmentShader(String filename) {
String[] source = parent.loadStrings(filename);
-
+
Pattern pattern = Pattern.compile("uniform *sampler2D *textureSampler");
-
+
int type = PShader.COLOR;
for (int i = 0; i < source.length; i++) {
Matcher matcher = pattern.matcher(source[i]);
@@ -6111,17 +6261,17 @@ public class PGraphicsOpenGL extends PGraphics {
}
return type;
}
-
-
+
+
protected int getTypeFromVertexShader(String filename) {
String[] source = parent.loadStrings(filename);
-
+
Pattern pointPattern = Pattern.compile("attribute *vec2 *inPoint");
Pattern linePattern = Pattern.compile("attribute *vec4 *inLine");
Pattern lightPattern1 = Pattern.compile("uniform *vec4 *lightPosition");
- Pattern lightPattern2 = Pattern.compile("uniform *vec3 *lightNormal");
+ Pattern lightPattern2 = Pattern.compile("uniform *vec3 *lightNormal");
Pattern texPattern = Pattern.compile("attribute vec2 inTexcoord");
-
+
int type = PShader.COLOR;
for (int i = 0; i < source.length; i++) {
boolean foundPoint = pointPattern.matcher(source[i]).find();
@@ -6129,7 +6279,7 @@ public class PGraphicsOpenGL extends PGraphics {
boolean foundLight = lightPattern1.matcher(source[i]).find() ||
lightPattern2.matcher(source[i]).find();
boolean foundTex = texPattern.matcher(source[i]).find();
-
+
if (foundPoint) {
type = PShader.POINT;
} else if (foundLine) {
@@ -6140,21 +6290,21 @@ public class PGraphicsOpenGL extends PGraphics {
type = PShader.LIGHT;
} else if (foundTex) {
type = PShader.TEXTURE;
- }
+ }
if (type != PShader.COLOR) break;
- }
+ }
return type;
}
-
-
+
+
protected PolyShader getPolyShader(boolean lit, boolean tex) {
PolyShader shader;
if (lit) {
if (tex) {
if (polyTexlightShader == null) {
if (defPolyTexlightShader == null) {
- defPolyTexlightShader = new PolyTexlightShader(parent,
- defPolyTexlightShaderVertURL,
+ defPolyTexlightShader = new PolyTexlightShader(parent,
+ defPolyTexlightShaderVertURL,
defPolyTexShaderFragURL);
}
shader = defPolyTexlightShader;
@@ -6165,12 +6315,12 @@ public class PGraphicsOpenGL extends PGraphics {
} else {
if (polyLightShader == null) {
if (defPolyLightShader == null) {
- defPolyLightShader = new PolyLightShader(parent,
- defPolyLightShaderVertURL,
+ defPolyLightShader = new PolyLightShader(parent,
+ defPolyLightShaderVertURL,
defPolyNoTexShaderFragURL);
}
shader = defPolyLightShader;
- lightShaderCheck();
+ lightShaderCheck();
} else {
shader = polyLightShader;
}
@@ -6179,8 +6329,8 @@ public class PGraphicsOpenGL extends PGraphics {
if (tex) {
if (polyTexShader == null) {
if (defPolyTexShader == null) {
- defPolyTexShader = new PolyTexShader(parent,
- defPolyTexShaderVertURL,
+ defPolyTexShader = new PolyTexShader(parent,
+ defPolyTexShaderVertURL,
defPolyTexShaderFragURL);
}
shader = defPolyTexShader;
@@ -6191,8 +6341,8 @@ public class PGraphicsOpenGL extends PGraphics {
} else {
if (polyColorShader == null) {
if (defPolyColorShader == null) {
- defPolyColorShader = new PolyColorShader(parent,
- defPolyColorShaderVertURL,
+ defPolyColorShader = new PolyColorShader(parent,
+ defPolyColorShaderVertURL,
defPolyNoTexShaderFragURL);
}
shader = defPolyColorShader;
@@ -6204,60 +6354,60 @@ public class PGraphicsOpenGL extends PGraphics {
}
shader.setRenderer(this);
shader.loadAttributes();
- shader.loadUniforms();
+ shader.loadUniforms();
return shader;
}
protected void texlightShaderCheck() {
- if (shaderWarningsEnabled &&
- (polyLightShader != null ||
- polyTexShader != null ||
+ if (shaderWarningsEnabled &&
+ (polyLightShader != null ||
+ polyTexShader != null ||
polyColorShader != null)) {
- PGraphics.showWarning("Your shader cannot be used to render textured " +
+ PGraphics.showWarning("Your shader cannot be used to render textured " +
"and lit geometry, using default shader instead.");
}
}
-
-
+
+
protected void lightShaderCheck() {
if (shaderWarningsEnabled &&
- (polyTexlightShader != null ||
- polyTexShader != null ||
+ (polyTexlightShader != null ||
+ polyTexShader != null ||
polyColorShader != null)) {
- PGraphics.showWarning("Your shader cannot be used to render lit " +
+ PGraphics.showWarning("Your shader cannot be used to render lit " +
"geometry, using default shader instead.");
}
}
-
+
protected void texShaderCheck() {
if (shaderWarningsEnabled &&
- (polyTexlightShader != null ||
- polyLightShader != null ||
+ (polyTexlightShader != null ||
+ polyLightShader != null ||
polyColorShader != null)) {
- PGraphics.showWarning("Your shader cannot be used to render textured " +
+ PGraphics.showWarning("Your shader cannot be used to render textured " +
"geometry, using default shader instead.");
- }
+ }
}
protected void colorShaderCheck() {
if (shaderWarningsEnabled &&
- (polyTexlightShader != null ||
- polyLightShader != null ||
+ (polyTexlightShader != null ||
+ polyLightShader != null ||
polyTexShader != null)) {
- PGraphics.showWarning("Your shader cannot be used to render colored " +
+ PGraphics.showWarning("Your shader cannot be used to render colored " +
"geometry, using default shader instead.");
- }
+ }
}
-
-
+
+
protected LineShader getLineShader() {
LineShader shader;
if (lineShader == null) {
if (defLineShader == null) {
- defLineShader = new LineShader(parent, defLineShaderVertURL,
+ defLineShader = new LineShader(parent, defLineShaderVertURL,
defLineShaderFragURL);
}
shader = defLineShader;
@@ -6266,7 +6416,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
shader.setRenderer(this);
shader.loadAttributes();
- shader.loadUniforms();
+ shader.loadUniforms();
return shader;
}
@@ -6275,7 +6425,7 @@ public class PGraphicsOpenGL extends PGraphics {
PointShader shader;
if (pointShader == null) {
if (defPointShader == null) {
- defPointShader = new PointShader(parent, defPointShaderVertURL,
+ defPointShader = new PointShader(parent, defPointShaderVertURL,
defPointShaderFragURL);
}
shader = defPointShader;
@@ -6284,7 +6434,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
shader.setRenderer(this);
shader.loadAttributes();
- shader.loadUniforms();
+ shader.loadUniforms();
return shader;
}
@@ -6302,21 +6452,21 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
- public void setVertexAttribute(int vboId, int size, int type,
+ public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setColorAttribute(int vboId, int size, int type,
+ public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setNormalAttribute(int vboId, int size, int type,
+ public void setNormalAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setAmbientAttribute(int vboId, int size, int type,
+ public void setAmbientAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setSpecularAttribute(int vboId, int size, int type,
+ public void setSpecularAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setEmissiveAttribute(int vboId, int size, int type,
+ public void setEmissiveAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setShininessAttribute(int vboId, int size, int type,
+ public void setShininessAttribute(int vboId, int size, int type,
int stride, int offset) { }
- public void setTexcoordAttribute(int vboId, int size, int type,
+ public void setTexcoordAttribute(int vboId, int size, int type,
int stride, int offset) { }
public void setTexture(Texture tex) { }
}
@@ -6334,7 +6484,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public PolyColorShader(PApplet parent, String vertFilename,
+ public PolyColorShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6343,35 +6493,40 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
}
+ @Override
public void loadUniforms() {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
projectionMatrixLoc = getUniformLoc("projectionMatrix");
}
- public void setVertexAttribute(int vboId, int size, int type,
+ @Override
+ public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
}
- public void setColorAttribute(int vboId, int size, int type,
+ @Override
+ public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
}
+ @Override
public void bind() {
super.bind();
if (pgCurrent == null) {
setRenderer(PGraphicsOpenGL.pgCurrent);
loadAttributes();
- loadUniforms();
+ loadUniforms();
}
-
+
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
@@ -6391,6 +6546,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
+ @Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
@@ -6430,7 +6586,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public PolyLightShader(PApplet parent, String vertFilename,
+ public PolyLightShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6439,6 +6595,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
@@ -6450,6 +6607,7 @@ public class PGraphicsOpenGL extends PGraphics {
inShineLoc = getAttributeLoc("inShine");
}
+ @Override
public void loadUniforms() {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
@@ -6466,49 +6624,57 @@ public class PGraphicsOpenGL extends PGraphics {
lightSpotParametersLoc = getUniformLoc("lightSpotParameters");
}
- public void setVertexAttribute(int vboId, int size, int type,
+ @Override
+ public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
}
- public void setColorAttribute(int vboId, int size, int type,
+ @Override
+ public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
}
- public void setNormalAttribute(int vboId, int size, int type,
+ @Override
+ public void setNormalAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inNormalLoc, vboId, size, type, false, stride, offset);
}
- public void setAmbientAttribute(int vboId, int size, int type,
+ @Override
+ public void setAmbientAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inAmbientLoc, vboId, size, type, true, stride, offset);
}
- public void setSpecularAttribute(int vboId, int size, int type,
+ @Override
+ public void setSpecularAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inSpecularLoc, vboId, size, type, true, stride, offset);
}
- public void setEmissiveAttribute(int vboId, int size, int type,
+ @Override
+ public void setEmissiveAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inEmissiveLoc, vboId, size, type, true, stride, offset);
}
- public void setShininessAttribute(int vboId, int size, int type,
+ @Override
+ public void setShininessAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inShineLoc, vboId, size, type, false, stride, offset);
}
+ @Override
public void bind() {
super.bind();
if (pgCurrent == null) {
setRenderer(PGraphicsOpenGL.pgCurrent);
loadAttributes();
- loadUniforms();
+ loadUniforms();
}
-
+
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
if (-1 < inNormalLoc) pgl.enableVertexAttribArray(inNormalLoc);
@@ -6539,17 +6705,18 @@ public class PGraphicsOpenGL extends PGraphics {
}
setUniformValue(lightCountLoc, pgCurrent.lightCount);
- setUniformVector(lightPositionLoc, pgCurrent.lightPosition, 4);
- setUniformVector(lightNormalLoc, pgCurrent.lightNormal, 3);
- setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3);
- setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3);
- setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3);
- setUniformVector(lightFalloffCoefficientsLoc,
- pgCurrent.lightFalloffCoefficients, 3);
- setUniformVector(lightSpotParametersLoc,
+ setUniformVector(lightPositionLoc, pgCurrent.lightPosition, 4);
+ setUniformVector(lightNormalLoc, pgCurrent.lightNormal, 3);
+ setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3);
+ setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3);
+ setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3);
+ setUniformVector(lightFalloffCoefficientsLoc,
+ pgCurrent.lightFalloffCoefficients, 3);
+ setUniformVector(lightSpotParametersLoc,
pgCurrent.lightSpotParameters, 2);
}
+ @Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
@@ -6580,7 +6747,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public PolyTexShader(PApplet parent, String vertFilename,
+ public PolyTexShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6589,6 +6756,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadUniforms() {
super.loadUniforms();
@@ -6597,17 +6765,20 @@ public class PGraphicsOpenGL extends PGraphics {
texcoordOffsetLoc = getUniformLoc("texcoordOffset");
}
+ @Override
public void loadAttributes() {
super.loadAttributes();
inTexcoordLoc = getAttributeLoc("inTexcoord");
}
- public void setTexcoordAttribute(int vboId, int size, int type,
+ @Override
+ public void setTexcoordAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset);
}
+ @Override
public void setTexture(Texture tex) {
float scaleu = 1;
float scalev = 1;
@@ -6639,20 +6810,22 @@ public class PGraphicsOpenGL extends PGraphics {
tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
setUniformMatrix(texcoordMatrixLoc, tcmat);
}
-
+
setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
-
- setUniformValue(textureSamplerLoc, 0);
+
+ setUniformValue(textureSamplerLoc, 0);
}
+ @Override
public void bind() {
firstTexUnit = 1; // 0 will be used by the textureSampler
-
+
super.bind();
if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc);
}
+ @Override
public void unbind() {
if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc);
@@ -6674,7 +6847,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public PolyTexlightShader(PApplet parent, String vertFilename,
+ public PolyTexlightShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6683,6 +6856,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadUniforms() {
super.loadUniforms();
@@ -6691,17 +6865,20 @@ public class PGraphicsOpenGL extends PGraphics {
texcoordOffsetLoc = getUniformLoc("texcoordOffset");
}
+ @Override
public void loadAttributes() {
super.loadAttributes();
inTexcoordLoc = getAttributeLoc("inTexcoord");
}
- public void setTexcoordAttribute(int vboId, int size, int type,
+ @Override
+ public void setTexcoordAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset);
}
+ @Override
public void setTexture(Texture tex) {
float scaleu = 1;
float scalev = 1;
@@ -6735,18 +6912,20 @@ public class PGraphicsOpenGL extends PGraphics {
}
setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
-
+
setUniformValue(textureSamplerLoc, 0);
}
+ @Override
public void bind() {
firstTexUnit = 1; // 0 will be used by the textureSampler
-
- super.bind();
+
+ super.bind();
if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc);
}
+ @Override
public void unbind() {
if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc);
@@ -6772,7 +6951,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public LineShader(PApplet parent, String vertFilename,
+ public LineShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6781,12 +6960,14 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
inAttribLoc = getAttributeLoc("inLine");
}
+ @Override
public void loadUniforms() {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
@@ -6797,28 +6978,29 @@ public class PGraphicsOpenGL extends PGraphics {
scaleLoc = getUniformLoc("scale");
}
- public void setVertexAttribute(int vboId, int size, int type,
+ public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
}
- public void setColorAttribute(int vboId, int size, int type,
+ public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
}
- public void setLineAttribute(int vboId, int size, int type,
+ public void setLineAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inAttribLoc, vboId, size, type, false, stride, offset);
}
+ @Override
public void bind() {
super.bind();
if (pgCurrent == null) {
setRenderer(PGraphicsOpenGL.pgCurrent);
loadAttributes();
- loadUniforms();
- }
+ loadUniforms();
+ }
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
@@ -6862,6 +7044,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
+ @Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
@@ -6881,7 +7064,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected int viewportLoc;
protected int perspectiveLoc;
-
+
protected int inVertexLoc;
protected int inColorLoc;
protected int inPointLoc;
@@ -6890,7 +7073,7 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent);
}
- public PointShader(PApplet parent, String vertFilename,
+ public PointShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
@@ -6899,43 +7082,46 @@ public class PGraphicsOpenGL extends PGraphics {
super(parent, vertURL, fragURL);
}
+ @Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
inPointLoc = getAttributeLoc("inPoint");
}
+ @Override
public void loadUniforms() {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
projectionMatrixLoc = getUniformLoc("projectionMatrix");
-
+
viewportLoc = getUniformLoc("viewport");
- perspectiveLoc = getUniformLoc("perspective");
+ perspectiveLoc = getUniformLoc("perspective");
}
- public void setVertexAttribute(int vboId, int size, int type,
+ public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
}
- public void setColorAttribute(int vboId, int size, int type,
+ public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
}
- public void setPointAttribute(int vboId, int size, int type,
+ public void setPointAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inPointLoc, vboId, size, type, false, stride, offset);
}
+ @Override
public void bind() {
super.bind();
if (pgCurrent == null) {
setRenderer(PGraphicsOpenGL.pgCurrent);
loadAttributes();
- loadUniforms();
- }
+ loadUniforms();
+ }
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
@@ -6955,7 +7141,7 @@ public class PGraphicsOpenGL extends PGraphics {
pgCurrent.updateGLProjection();
setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection);
}
-
+
float x = pgCurrent.viewport[0];
float y = pgCurrent.viewport[1];
float w = pgCurrent.viewport[2];
@@ -6966,9 +7152,10 @@ public class PGraphicsOpenGL extends PGraphics {
setUniformValue(perspectiveLoc, 1);
} else {
setUniformValue(perspectiveLoc, 0);
- }
+ }
}
+ @Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
@@ -7065,7 +7252,7 @@ public class PGraphicsOpenGL extends PGraphics {
PImage img = textures[i];
Texture tex = null;
- if (img != null) {
+ if (img != null) {
tex = pgPrimary.getTexture(img);
if (tex != null) {
tex.bind();
@@ -7658,7 +7845,7 @@ public class PGraphicsOpenGL extends PGraphics {
normalX, normalY, normalZ,
0, 0,
strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor,
+ ambientColor, specularColor, emissiveColor,
shininessFactor,
code);
}
@@ -7671,7 +7858,7 @@ public class PGraphicsOpenGL extends PGraphics {
normalX, normalY, normalZ,
u, v,
strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor,
+ ambientColor, specularColor, emissiveColor,
shininessFactor,
code);
}
@@ -7683,7 +7870,7 @@ public class PGraphicsOpenGL extends PGraphics {
normalX, normalY, normalZ,
0, 0,
strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor,
+ ambientColor, specularColor, emissiveColor,
shininessFactor,
code);
}
@@ -7696,7 +7883,7 @@ public class PGraphicsOpenGL extends PGraphics {
normalX, normalY, normalZ,
u, v,
strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor,
+ ambientColor, specularColor, emissiveColor,
shininessFactor,
code);
}
@@ -7758,7 +7945,7 @@ public class PGraphicsOpenGL extends PGraphics {
void addBezierVertex(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4,
- boolean fill, boolean stroke, int detail, int code,
+ boolean fill, boolean stroke, int detail, int code,
int shape) {
bezierInitCheck();
bezierVertexCheck(shape, vertexCount);
@@ -7791,7 +7978,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void addQuadraticVertex(float cx, float cy, float cz,
float x3, float y3, float z3,
- boolean fill, boolean stroke, int detail,
+ boolean fill, boolean stroke, int detail,
int code) {
addQuadraticVertex(cx, cy, cz,
x3, y3, z3,
@@ -7800,7 +7987,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void addQuadraticVertex(float cx, float cy, float cz,
float x3, float y3, float z3,
- boolean fill, boolean stroke, int detail,
+ boolean fill, boolean stroke, int detail,
int code, int shape) {
float x1 = getLastVertexX();
float y1 = getLastVertexY();
@@ -7819,7 +8006,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
void addCurveVertex(float x, float y, float z,
- boolean fill, boolean stroke, int detail, int code,
+ boolean fill, boolean stroke, int detail, int code,
int shape) {
curveVertexCheck(shape);
float[] vertex = curveVertices[curveVertexCount];
@@ -8190,7 +8377,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Primitives
void setMaterial(int fillColor, int strokeColor, float strokeWeight,
- int ambientColor, int specularColor, int emissiveColor,
+ int ambientColor, int specularColor, int emissiveColor,
float shininessFactor) {
this.fillColor = fillColor;
this.strokeColor = strokeColor;
@@ -8408,9 +8595,9 @@ public class PGraphicsOpenGL extends PGraphics {
float sx2 = pgCurrent.screenX(x + w, y + h);
float sy2 = pgCurrent.screenY(x + w, y + h);
- int accuracy =
+ int accuracy =
PApplet.max(MIN_POINT_ACCURACY,
- (int) (TWO_PI * PApplet.dist(sx1, sy1, sx2, sy2) /
+ (int) (TWO_PI * PApplet.dist(sx1, sy1, sx2, sy2) /
POINT_ACCURACY_FACTOR));
float inc = (float) PGraphicsOpenGL.SINCOS_LENGTH / accuracy;
@@ -8653,14 +8840,14 @@ public class PGraphicsOpenGL extends PGraphics {
for (int i = 0; i < detailU; i++) {
int ioff = offset + i;
setNormal(sphereX[ioff], sphereY[ioff], sphereZ[ioff]);
- addVertex(r * sphereX[ioff], r *sphereY[ioff], r * sphereZ[ioff],
+ addVertex(r * sphereX[ioff], r *sphereY[ioff], r * sphereZ[ioff],
u , v, VERTEX);
u -= du;
}
vertCount += detailU;
vert1 = vertCount;
setNormal(sphereX[offset], sphereY[offset], sphereZ[offset]);
- addVertex(r * sphereX[offset], r * sphereY[offset], r * sphereZ[offset],
+ addVertex(r * sphereX[offset], r * sphereY[offset], r * sphereZ[offset],
u, v, VERTEX);
vertCount++;
@@ -9387,7 +9574,7 @@ public class PGraphicsOpenGL extends PGraphics {
//
// Add point geometry
- // Sets point vertex with index tessIdx using the data from input vertex
+ // Sets point vertex with index tessIdx using the data from input vertex
// inIdx.
void setPointVertex(int tessIdx, InGeometry in, int inIdx) {
int index;
@@ -9397,7 +9584,7 @@ public class PGraphicsOpenGL extends PGraphics {
float y = in.vertices[index++];
float z = in.vertices[index ];
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
@@ -9429,7 +9616,7 @@ public class PGraphicsOpenGL extends PGraphics {
float y0 = in.vertices[index++];
float z0 = in.vertices[index ];
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
@@ -9454,9 +9641,9 @@ public class PGraphicsOpenGL extends PGraphics {
lineAttribs[index ] = 0;
}
- // Sets line vertex with index tessIdx using the data from input vertices
+ // Sets line vertex with index tessIdx using the data from input vertices
//inIdx0 and inIdx1.
- void setLineVertex(int tessIdx, InGeometry in, int inIdx0, int inIdx1,
+ void setLineVertex(int tessIdx, InGeometry in, int inIdx0, int inIdx1,
int rgba, float weight) {
int index;
@@ -9470,7 +9657,7 @@ public class PGraphicsOpenGL extends PGraphics {
float y1 = in.vertices[index++];
float z1 = in.vertices[index ];
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
@@ -9520,7 +9707,7 @@ public class PGraphicsOpenGL extends PGraphics {
int am, int sp, int em, float shine) {
int index;
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
PMatrix3D nm = modelviewInv;
@@ -9569,7 +9756,7 @@ public class PGraphicsOpenGL extends PGraphics {
int index;
int count = polyVertexCount - 1;
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
PMatrix3D nm = modelviewInv;
@@ -9623,7 +9810,7 @@ public class PGraphicsOpenGL extends PGraphics {
polyVertexCheck(nvert);
- if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
+ if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL &&
!hints[DISABLE_TRANSFORM_CACHE]) {
PMatrix3D mm = modelview;
PMatrix3D nm = modelviewInv;
@@ -9655,7 +9842,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
} else {
if (nvert <= PGL.MIN_ARRAYCOPY_SIZE) {
- // Copying elements one by one instead of using arrayCopy is more
+ // Copying elements one by one instead of using arrayCopy is more
// efficient for few vertices...
for (int i = 0; i < nvert; i++) {
int inIdx = i0 + i;
@@ -9686,11 +9873,11 @@ public class PGraphicsOpenGL extends PGraphics {
for (int i = 0; i < nvert; i++) {
int inIdx = i0 + i;
int tessIdx = firstPolyVertex + i;
- PApplet.arrayCopy(in.vertices, 3 * inIdx,
+ PApplet.arrayCopy(in.vertices, 3 * inIdx,
polyVertices, 4 * tessIdx, 3);
polyVertices[4 * tessIdx + 3] = 1;
}
- PApplet.arrayCopy(in.normals, 3 * i0,
+ PApplet.arrayCopy(in.normals, 3 * i0,
polyNormals, 3 * firstPolyVertex, 3 * nvert);
}
}
@@ -9716,17 +9903,17 @@ public class PGraphicsOpenGL extends PGraphics {
polyShininess[tessIdx] = in.shininess[inIdx];
}
} else {
- PApplet.arrayCopy(in.colors, i0,
+ PApplet.arrayCopy(in.colors, i0,
polyColors, firstPolyVertex, nvert);
- PApplet.arrayCopy(in.texcoords, 2 * i0,
+ PApplet.arrayCopy(in.texcoords, 2 * i0,
polyTexcoords, 2 * firstPolyVertex, 2 * nvert);
- PApplet.arrayCopy(in.ambient, i0,
+ PApplet.arrayCopy(in.ambient, i0,
polyAmbient, firstPolyVertex, nvert);
- PApplet.arrayCopy(in.specular, i0,
+ PApplet.arrayCopy(in.specular, i0,
polySpecular, firstPolyVertex, nvert);
- PApplet.arrayCopy(in.emissive, i0,
+ PApplet.arrayCopy(in.emissive, i0,
polyEmissive, firstPolyVertex, nvert);
- PApplet.arrayCopy(in.shininess, i0,
+ PApplet.arrayCopy(in.shininess, i0,
polyShininess, firstPolyVertex, nvert);
}
}
@@ -9993,7 +10180,7 @@ public class PGraphicsOpenGL extends PGraphics {
this.accurate2DStrokes = accurate;
}
- void setTexCache(TexCache texCache, PImage prevTexImage,
+ void setTexCache(TexCache texCache, PImage prevTexImage,
PImage newTexImage) {
this.texCache = texCache;
this.prevTexImage = prevTexImage;
@@ -10032,9 +10219,9 @@ public class PGraphicsOpenGL extends PGraphics {
// Each point generates a separate triangle fan.
// The number of triangles of each fan depends on the
// stroke weight of the point.
- int nPtVert =
+ int nPtVert =
PApplet.max(MIN_POINT_ACCURACY,
- (int) (TWO_PI * strokeWeight /
+ (int) (TWO_PI * strokeWeight /
POINT_ACCURACY_FACTOR)) + 1;
if (PGL.MAX_VERTEX_INDEX1 <= nPtVert) {
throw new RuntimeException("Error in point tessellation.");
@@ -10088,9 +10275,9 @@ public class PGraphicsOpenGL extends PGraphics {
float val = 0;
float inc = (float) SINCOS_LENGTH / perim;
for (int k = 0; k < perim; k++) {
- tess.pointAttribs[2 * attribIdx + 0] =
+ tess.pointAttribs[2 * attribIdx + 0] =
0.5f * cosLUT[(int) val] * strokeWeight;
- tess.pointAttribs[2 * attribIdx + 1] =
+ tess.pointAttribs[2 * attribIdx + 1] =
0.5f * sinLUT[(int) val] * strokeWeight;
val = (val + inc) % SINCOS_LENGTH;
attribIdx++;
@@ -10139,9 +10326,9 @@ public class PGraphicsOpenGL extends PGraphics {
tess.setPolyVertex(vertIdx, x0, y0, 0, rgba);
vertIdx++;
for (int k = 0; k < perim; k++) {
- tess.setPolyVertex(vertIdx,
+ tess.setPolyVertex(vertIdx,
x0 + 0.5f * cosLUT[(int) val] * strokeWeight,
- y0 + 0.5f * sinLUT[(int) val] * strokeWeight,
+ y0 + 0.5f * sinLUT[(int) val] * strokeWeight,
0, rgba);
vertIdx++;
val = (val + inc) % SINCOS_LENGTH;
@@ -10217,9 +10404,9 @@ public class PGraphicsOpenGL extends PGraphics {
tess.pointAttribs[2 * attribIdx + 1] = 0;
attribIdx++;
for (int k = 0; k < 4; k++) {
- tess.pointAttribs[2 * attribIdx + 0] =
+ tess.pointAttribs[2 * attribIdx + 0] =
0.5f * QUAD_POINT_SIGNS[k][0] * strokeWeight;
- tess.pointAttribs[2 * attribIdx + 1] =
+ tess.pointAttribs[2 * attribIdx + 1] =
0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight;
attribIdx++;
}
@@ -10265,9 +10452,9 @@ public class PGraphicsOpenGL extends PGraphics {
tess.setPolyVertex(vertIdx, x0, y0, 0, rgba);
vertIdx++;
for (int k = 0; k < nvert - 1; k++) {
- tess.setPolyVertex(vertIdx,
+ tess.setPolyVertex(vertIdx,
x0 + 0.5f * QUAD_POINT_SIGNS[k][0] * strokeWeight,
- y0 + 0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight,
+ y0 + 0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight,
0, rgba);
vertIdx++;
}
@@ -10316,7 +10503,7 @@ public class PGraphicsOpenGL extends PGraphics {
int first = in.firstVertex;
tess.lineVertexCheck(nvert);
tess.lineIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
tess.lineIndexCache.getLast();
firstLineIndexCache = index;
for (int ln = 0; ln < lineCount; ln++) {
@@ -10335,7 +10522,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (noCapsJoins(nvert)) {
tess.polyVertexCheck(nvert);
tess.polyIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
tess.polyIndexCache.getLast();
firstLineIndexCache = index;
if (firstPolyIndexCache == -1) firstPolyIndexCache = index; // If the geometry has no fill, needs the first poly index.
@@ -10373,13 +10560,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
void tessellateLineStrip3D(int lineCount) {
- int nBevelTr = noCapsJoins() ? 0 : (lineCount - 1);
+ int nBevelTr = noCapsJoins() ? 0 : (lineCount - 1);
int nvert = lineCount * 4 + nBevelTr;
int nind = lineCount * 2 * 3 + nBevelTr * 2 * 3;
tess.lineVertexCheck(nvert);
tess.lineIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
tess.lineIndexCache.getLast();
firstLineIndexCache = index;
int i0 = in.firstVertex;
@@ -10403,7 +10590,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (noCapsJoins(nvert)) {
tess.polyVertexCheck(nvert);
tess.polyIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
tess.polyIndexCache.getLast();
firstLineIndexCache = index;
if (firstPolyIndexCache == -1) firstPolyIndexCache = index; // If the geometry has no fill, needs the first poly index.
@@ -10441,16 +10628,16 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
- void tessellateLineLoop3D(int lineCount) {
+ void tessellateLineLoop3D(int lineCount) {
// TODO: This calculation doesn't add the bevel join between
// the first and last vertex, need to fix.
- int nBevelTr = noCapsJoins() ? 0 : (lineCount - 1);
+ int nBevelTr = noCapsJoins() ? 0 : (lineCount - 1);
int nvert = lineCount * 4 + nBevelTr;
int nind = lineCount * 2 * 3 + nBevelTr * 2 * 3;
tess.lineVertexCheck(nvert);
tess.lineIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
tess.lineIndexCache.getLast();
firstLineIndexCache = index;
int i0 = in.firstVertex;
@@ -10475,7 +10662,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (noCapsJoins(nvert)) {
tess.polyVertexCheck(nvert);
tess.polyIndexCheck(nind);
- int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
tess.polyIndexCache.getLast();
firstLineIndexCache = index;
if (firstPolyIndexCache == -1) firstPolyIndexCache = index; // If the geometry has no fill, needs the first poly index.
@@ -10521,7 +10708,7 @@ public class PGraphicsOpenGL extends PGraphics {
tess.lineVertexCheck(nInVert);
tess.lineIndexCheck(nInInd);
- int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.lineIndexCache.addNew() :
tess.lineIndexCache.getLast();
firstLineIndexCache = index;
short[] lastInd = {-1, -1};
@@ -10549,7 +10736,7 @@ public class PGraphicsOpenGL extends PGraphics {
tess.polyVertexCheck(nInVert);
tess.polyIndexCheck(nInInd);
- int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
+ int index = in.renderMode == RETAINED ? tess.polyIndexCache.addNew() :
tess.polyIndexCache.getLast();
firstLineIndexCache = index;
if (firstPolyIndexCache == -1) firstPolyIndexCache = index; // If the geometry has no fill, needs the first poly index.
@@ -10591,7 +10778,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Adding the data that defines a quad starting at vertex i0 and
// ending at i1.
- int addLine3D(int i0, int i1, int index, short[] lastInd,
+ int addLine3D(int i0, int i1, int index, short[] lastInd,
boolean constStroke) {
IndexCache cache = tess.lineIndexCache;
int count = cache.vertexCount[index];
@@ -10638,10 +10825,10 @@ public class PGraphicsOpenGL extends PGraphics {
tess.setLineVertex(vidx, in, i0, color0);
if (newCache) {
- PGraphics.showWarning("Stroke path is too long, some bevel " +
+ PGraphics.showWarning("Stroke path is too long, some bevel " +
"triangles won't be added.");
- // TODO: Fix this situation, the vertices from the previous cache
+ // TODO: Fix this situation, the vertices from the previous cache
// block should be copied in the newly created one.
tess.lineIndices[iidx++] = (short) (count + 4);
tess.lineIndices[iidx++] = (short) (count + 0);
@@ -10703,11 +10890,11 @@ public class PGraphicsOpenGL extends PGraphics {
normy = +dirx / llen;
}
- tess.setPolyVertex(vidx++, x0 + normx * weight/2, y0 + normy * weight/2,
+ tess.setPolyVertex(vidx++, x0 + normx * weight/2, y0 + normy * weight/2,
0, color);
tess.polyIndices[iidx++] = (short) (count + 0);
- tess.setPolyVertex(vidx++, x0 - normx * weight/2, y0 - normy * weight/2,
+ tess.setPolyVertex(vidx++, x0 - normx * weight/2, y0 - normy * weight/2,
0, color);
tess.polyIndices[iidx++] = (short) (count + 1);
@@ -10716,7 +10903,7 @@ public class PGraphicsOpenGL extends PGraphics {
weight = in.strokeWeights[i1];
}
- tess.setPolyVertex(vidx++, x1 - normx * weight/2, y1 - normy * weight/2,
+ tess.setPolyVertex(vidx++, x1 - normx * weight/2, y1 - normy * weight/2,
0, color);
tess.polyIndices[iidx++] = (short) (count + 2);
@@ -10724,7 +10911,7 @@ public class PGraphicsOpenGL extends PGraphics {
tess.polyIndices[iidx++] = (short) (count + 2);
tess.polyIndices[iidx++] = (short) (count + 0);
- tess.setPolyVertex(vidx++, x1 + normx * weight/2, y1 + normy * weight/2,
+ tess.setPolyVertex(vidx++, x1 + normx * weight/2, y1 + normy * weight/2,
0, color);
tess.polyIndices[iidx++] = (short) (count + 3);
@@ -10743,7 +10930,7 @@ public class PGraphicsOpenGL extends PGraphics {
return noCapsJoins();
}
}
-
+
boolean noCapsJoins() {
// We first calculate the (volumetric) scaling factor that is associated
// to the current transformation matrix, which is given by the absolute
@@ -10757,7 +10944,7 @@ public class PGraphicsOpenGL extends PGraphics {
scaleFactor = (float) Math.sqrt(areaScaleFactor);
} else if (transform instanceof PMatrix3D) {
PMatrix3D tr = (PMatrix3D)transform;
- float volumeScaleFactor =
+ float volumeScaleFactor =
Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) +
tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) +
tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20));
@@ -10767,9 +10954,9 @@ public class PGraphicsOpenGL extends PGraphics {
// The stroke weight is scaled so it correspons to the current
// "zoom level" being applied on the geometry due to scaling:
- return scaleFactor * strokeWeight < PGL.MIN_CAPS_JOINS_WEIGHT;
+ return scaleFactor * strokeWeight < PGL.MIN_CAPS_JOINS_WEIGHT;
}
-
+
// -----------------------------------------------------------------
//
// Polygon primitives tessellation
@@ -10975,7 +11162,7 @@ public class PGraphicsOpenGL extends PGraphics {
inMaxVertRel = PApplet.max(inMaxVertRel, PApplet.max(ri0, ri1, ri2));
- if ((PGL.MAX_VERTEX_INDEX1 - 3 <= inMaxVertRel + dupCount &&
+ if ((PGL.MAX_VERTEX_INDEX1 - 3 <= inMaxVertRel + dupCount &&
inMaxVertRel + dupCount < PGL.MAX_VERTEX_INDEX1) ||
(tr == trCount - 1)) {
// The vertex indices of the current group are about to
@@ -10984,12 +11171,12 @@ public class PGraphicsOpenGL extends PGraphics {
int nondupCount = 0;
if (0 < dupCount) {
- // Adjusting the negative indices so they correspond to vertices
+ // Adjusting the negative indices so they correspond to vertices
// added at the end of the block.
for (int i = inInd0; i <= inInd1; i++) {
int ri = tess.polyIndices[offset + i];
if (ri < 0) {
- tess.polyIndices[offset + i] =
+ tess.polyIndices[offset + i] =
(short) (inMaxVertRel + 1 + dupIndexPos(ri));
}
}
@@ -11118,7 +11305,7 @@ public class PGraphicsOpenGL extends PGraphics {
void setLastTexIndex(int lastIndex, int lastCache) {
if (texCache != null) {
if (prevTexImage != newTexImage || texCache.size == 0) {
- texCache.addTexture(newTexImage, firstTexIndex, firstTexCache,
+ texCache.addTexture(newTexImage, firstTexIndex, firstTexCache,
lastIndex, lastCache);
} else {
texCache.setLastIndex(lastIndex, lastCache);
@@ -11181,9 +11368,9 @@ public class PGraphicsOpenGL extends PGraphics {
int eg = (in.emissive[i] >> 8) & 0xFF;
int eb = (in.emissive[i] >> 0) & 0xFF;
- // Vertex data includes coordinates, colors, normals, texture
+ // Vertex data includes coordinates, colors, normals, texture
// coordinates, and material properties.
- double[] vertex = new double[] {
+ double[] vertex = new double[] {
in.vertices [3*i + 0], in.vertices [3*i + 1], in.vertices[3*i + 2],
fa, fr, fg, fb,
in.normals [3*i + 0], in.normals [3*i + 1], in.normals [3*i + 2],
@@ -11215,7 +11402,7 @@ public class PGraphicsOpenGL extends PGraphics {
LinePath.JOIN_MITER;
// Make the outline of the stroke from the path
- LinePath strokedPath = LinePath.createStrokedPath(path, strokeWeight,
+ LinePath strokedPath = LinePath.createStrokedPath(path, strokeWeight,
cap, join);
gluTess.beginPolygon();
@@ -11251,7 +11438,7 @@ public class PGraphicsOpenGL extends PGraphics {
sg = (strokeColor >> 8) & 0xFF;
sb = (strokeColor >> 0) & 0xFF;
- // Vertex data includes coordinates, colors, normals, texture
+ // Vertex data includes coordinates, colors, normals, texture
// coordinates, and material properties.
vertex = new double[] { coords[0], coords[1], 0,
sa, sr, sg, sb,
@@ -11273,14 +11460,14 @@ public class PGraphicsOpenGL extends PGraphics {
/////////////////////////////////////////
- // Interenting notes about using the GLU tessellator to render thick
+ // Interenting notes about using the GLU tessellator to render thick
// polylines:
// http://stackoverflow.com/questions/687173/how-do-i-render-thick-2d-lines-as-polygons
//
- // "...Since I disliked the tesselator API I lifted the tesselation code
- // from the free SGI OpenGL reference implementation, rewrote the entire
- // front-end and added memory pools to get the number of allocations down.
- // It took two days to do this, but it was well worth it (like factor five
+ // "...Since I disliked the tesselator API I lifted the tesselation code
+ // from the free SGI OpenGL reference implementation, rewrote the entire
+ // front-end and added memory pools to get the number of allocations down.
+ // It took two days to do this, but it was well worth it (like factor five
// performance improvement)..."
//
// This C implementation of GLU could be useful:
@@ -11394,12 +11581,12 @@ public class PGraphicsOpenGL extends PGraphics {
protected void addIndex(int tessIdx) {
tess.polyIndexCheck();
- tess.polyIndices[tess.polyIndexCount - 1] =
+ tess.polyIndices[tess.polyIndexCount - 1] =
(short) (vertFirst + tessIdx);
}
protected void calcTriNormal(int tessIdx0, int tessIdx1, int tessIdx2) {
- tess.calcPolyNormal(vertFirst + tessIdx0, vertFirst + tessIdx1,
+ tess.calcPolyNormal(vertFirst + tessIdx0, vertFirst + tessIdx1,
vertFirst + tessIdx2);
}
@@ -11408,19 +11595,19 @@ public class PGraphicsOpenGL extends PGraphics {
double[] d = (double[]) data;
int l = d.length;
if (l < 25) {
- throw new RuntimeException("TessCallback vertex() data is not " +
+ throw new RuntimeException("TessCallback vertex() data is not " +
"of length 25");
}
if (vertCount < PGL.MAX_VERTEX_INDEX1) {
// Combining individual rgba components back into int color values
- int fcolor =
+ int fcolor =
((int)d[ 3]<<24) | ((int)d[ 4]<<16) | ((int)d[ 5]<<8) | (int)d[ 6];
- int acolor =
+ int acolor =
((int)d[12]<<24) | ((int)d[13]<<16) | ((int)d[14]<<8) | (int)d[15];
- int scolor =
+ int scolor =
((int)d[16]<<24) | ((int)d[17]<<16) | ((int)d[18]<<8) | (int)d[19];
- int ecolor =
+ int ecolor =
((int)d[20]<<24) | ((int)d[21]<<16) | ((int)d[22]<<8) | (int)d[23];
tess.addPolyVertex((float) d[ 0], (float) d[ 1], (float) d[ 2],
@@ -11432,13 +11619,13 @@ public class PGraphicsOpenGL extends PGraphics {
vertCount++;
} else {
- throw new RuntimeException("The tessellator is generating too " +
- "many vertices, reduce complexity of " +
+ throw new RuntimeException("The tessellator is generating too " +
+ "many vertices, reduce complexity of " +
"shape.");
}
} else {
- throw new RuntimeException("TessCallback vertex() data not " +
+ throw new RuntimeException("TessCallback vertex() data not " +
"understood");
}
}
diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java
index f440cb623..98a60ad5c 100644
--- a/core/src/processing/opengl/PShader.java
+++ b/core/src/processing/opengl/PShader.java
@@ -30,10 +30,10 @@ import java.net.URL;
import java.util.HashMap;
/**
- * This class encapsulates a GLSL shader program, including a vertex
+ * This class encapsulates a GLSL shader program, including a vertex
* and a fragment shader. Based on the GLSLShader class from GLGraphics, which
* in turn was originally based in the code by JohnG:
- * http://processing.org/discourse/beta/num_1159494801.html
+ * http://processing.org/discourse/beta/num_1159494801.html
*/
public class PShader {
// shaders constants
@@ -43,111 +43,112 @@ public class PShader {
static protected final int TEXLIGHT = 3;
static protected final int LINE = 4;
static protected final int POINT = 5;
-
+
protected PApplet parent;
// The main renderer associated to the parent PApplet.
- protected PGraphicsOpenGL pgMain;
+ protected PGraphicsOpenGL pgMain;
// We need a reference to the renderer since a shader might
// be called by different renderers within a single application
// (the one corresponding to the main surface, or other offscreen
// renderers).
protected PGraphicsOpenGL pgCurrent;
-
+
protected PGL pgl;
protected PGL.Context context; // The context that created this shader.
public int glProgram;
public int glVertex;
- public int glFragment;
-
+ public int glFragment;
+
protected URL vertexURL;
protected URL fragmentURL;
-
+
protected String vertexFilename;
protected String fragmentFilename;
protected String vertexShaderSource;
protected String fragmentShaderSource;
-
+
protected boolean bound;
-
+
protected HashMap uniformValues = null;
-
+
protected HashMap textures;
protected int firstTexUnit;
-
+
public PShader() {
parent = null;
pgMain = null;
pgl = null;
context = null;
-
+
this.vertexURL = null;
this.fragmentURL = null;
this.vertexFilename = null;
- this.fragmentFilename = null;
-
+ this.fragmentFilename = null;
+
glProgram = 0;
glVertex = 0;
glFragment = 0;
-
+
firstTexUnit = 0;
-
+
bound = false;
}
-
-
+
+
public PShader(PApplet parent) {
this();
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
pgl = pgMain.pgl;
context = pgl.createEmptyContext();
- }
-
-
+ }
+
+
/**
* Creates a shader program using the specified vertex and fragment
* shaders.
- *
+ *
* @param parent PApplet
* @param vertexFN String
- * @param fragmentFN String
+ * @param fragmentFN String
*/
public PShader(PApplet parent, String vertFilename, String fragFilename) {
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
- pgl = pgMain.pgl;
-
+ pgl = pgMain.pgl;
+
this.vertexURL = null;
this.fragmentURL = null;
this.vertexFilename = vertFilename;
- this.fragmentFilename = fragFilename;
-
+ this.fragmentFilename = fragFilename;
+
glProgram = 0;
glVertex = 0;
- glFragment = 0;
+ glFragment = 0;
}
-
-
+
+
public PShader(PApplet parent, URL vertURL, URL fragURL) {
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
- pgl = pgMain.pgl;
+ pgl = pgMain.pgl;
this.vertexURL = vertURL;
- this.fragmentURL = fragURL;
+ this.fragmentURL = fragURL;
this.vertexFilename = null;
this.fragmentFilename = null;
-
+
glProgram = 0;
glVertex = 0;
- glFragment = 0;
- }
-
-
+ glFragment = 0;
+ }
+
+
+ @Override
protected void finalize() throws Throwable {
try {
if (glVertex != 0) {
@@ -163,28 +164,28 @@ public class PShader {
super.finalize();
}
}
-
-
+
+
public void setVertexShader(String vertFilename) {
this.vertexFilename = vertFilename;
}
-
+
public void setVertexShader(URL vertURL) {
- this.vertexURL = vertURL;
- }
-
-
+ this.vertexURL = vertURL;
+ }
+
+
public void setFragmentShader(String fragFilename) {
- this.fragmentFilename = fragFilename;
+ this.fragmentFilename = fragFilename;
}
-
+
public void setFragmentShader(URL fragURL) {
- this.fragmentURL = fragURL;
+ this.fragmentURL = fragURL;
}
-
+
/**
* Initializes (if needed) and binds the shader program.
*/
@@ -196,7 +197,7 @@ public class PShader {
bindTextures();
}
-
+
/**
* Unbinds the shader program.
*/
@@ -205,8 +206,8 @@ public class PShader {
pgl.useProgram(0);
bound = false;
}
-
-
+
+
/**
* Returns true if the shader is bound, false otherwise.
*/
@@ -214,58 +215,58 @@ public class PShader {
return bound;
}
-
- public void set(String name, int x) {
+
+ public void set(String name, int x) {
setUniformImpl(name, UniformValue.INT1, new int[] { x });
}
-
-
+
+
public void set(String name, int x, int y) {
setUniformImpl(name, UniformValue.INT2, new int[] { x, y });
}
-
-
+
+
public void set(String name, int x, int y, int z) {
setUniformImpl(name, UniformValue.INT3, new int[] { x, y, z });
}
-
-
+
+
public void set(String name, int x, int y, int z, int w) {
setUniformImpl(name, UniformValue.INT4, new int[] { x, y, z });
}
-
-
+
+
public void set(String name, float x) {
setUniformImpl(name, UniformValue.FLOAT1, new float[] { x });
}
-
-
+
+
public void set(String name, float x, float y) {
setUniformImpl(name, UniformValue.FLOAT2, new float[] { x, y });
}
-
-
+
+
public void set(String name, float x, float y, float z) {
setUniformImpl(name, UniformValue.FLOAT3, new float[] { x, y, z });
}
-
-
+
+
public void set(String name, float x, float y, float z, float w) {
setUniformImpl(name, UniformValue.FLOAT4, new float[] { x, y, z, w });
}
-
-
+
+
public void set(String name, PVector vec) {
- setUniformImpl(name, UniformValue.FLOAT3,
+ setUniformImpl(name, UniformValue.FLOAT3,
new float[] { vec.x, vec.y, vec.z });
}
-
-
+
+
public void set(String name, int[] vec) {
set(name, vec, 1);
- }
+ }
+
-
public void set(String name, int[] vec, int ncoords) {
if (ncoords == 1) {
setUniformImpl(name, UniformValue.INT1VEC, vec);
@@ -276,20 +277,20 @@ public class PShader {
} else if (ncoords == 4) {
setUniformImpl(name, UniformValue.INT4VEC, vec);
} else if (4 < ncoords) {
- PGraphics.showWarning("Only up to 4 coordinates per element are " +
+ PGraphics.showWarning("Only up to 4 coordinates per element are " +
"supported.");
} else {
PGraphics.showWarning("Wrong number of coordinates: it is negative!");
}
- }
-
-
+ }
+
+
public void set(String name, float[] vec) {
set(name, vec, 1);
- }
-
-
- public void set(String name, float[] vec, int ncoords) {
+ }
+
+
+ public void set(String name, float[] vec, int ncoords) {
if (ncoords == 1) {
setUniformImpl(name, UniformValue.FLOAT1VEC, vec);
} else if (ncoords == 2) {
@@ -299,63 +300,63 @@ public class PShader {
} else if (ncoords == 4) {
setUniformImpl(name, UniformValue.FLOAT4VEC, vec);
} else if (4 < ncoords) {
- PGraphics.showWarning("Only up to 4 coordinates per element are " +
+ PGraphics.showWarning("Only up to 4 coordinates per element are " +
"supported.");
} else {
PGraphics.showWarning("Wrong number of coordinates: it is negative!");
}
}
-
-
+
+
public void set(String name, PMatrix2D mat) {
- float[] matv = { mat.m00, mat.m01,
+ float[] matv = { mat.m00, mat.m01,
mat.m10, mat.m11 };
setUniformImpl(name, UniformValue.MAT2, matv);
}
-
-
+
+
public void set(String name, PMatrix3D mat) {
set(name, mat, false);
}
-
-
+
+
public void set(String name, PMatrix3D mat, boolean use3x3) {
if (use3x3) {
- float[] matv = { mat.m00, mat.m01, mat.m02,
+ float[] matv = { mat.m00, mat.m01, mat.m02,
mat.m10, mat.m11, mat.m12,
mat.m20, mat.m21, mat.m22 };
setUniformImpl(name, UniformValue.MAT3, matv);
} else {
- float[] matv = { mat.m00, mat.m01, mat.m02, mat.m03,
+ float[] matv = { mat.m00, mat.m01, mat.m02, mat.m03,
mat.m10, mat.m11, mat.m12, mat.m13,
- mat.m20, mat.m21, mat.m22, mat.m23,
+ mat.m20, mat.m21, mat.m22, mat.m23,
mat.m30, mat.m31, mat.m32, mat.m33 };
setUniformImpl(name, UniformValue.MAT4, matv);
}
}
-
-
+
+
public void set(String name, PImage tex) {
setUniformImpl(name, UniformValue.SAMPLER2D, tex);
}
-
-
-
+
+
+
/**
* Returns the ID location of the attribute parameter given its name.
- *
+ *
* @param name String
* @return int
*/
protected int getAttributeLoc(String name) {
- init();
+ init();
return pgl.getAttribLocation(glProgram, name);
}
-
+
/**
* Returns the ID location of the uniform parameter given its name.
- *
+ *
* @param name String
* @return int
*/
@@ -364,101 +365,101 @@ public class PShader {
return pgl.getUniformLocation(glProgram, name);
}
-
- protected void setAttributeVBO(int loc, int vboId, int size, int type,
+
+ protected void setAttributeVBO(int loc, int vboId, int size, int type,
boolean normalized, int stride, int offset) {
if (-1 < loc) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboId);
pgl.vertexAttribPointer(loc, size, type, normalized, stride, offset);
}
- }
-
-
+ }
+
+
protected void setUniformValue(int loc, int x) {
if (-1 < loc) {
pgl.uniform1i(loc, x);
}
- }
+ }
+
-
protected void setUniformValue(int loc, int x, int y) {
if (-1 < loc) {
pgl.uniform2i(loc, x, y);
}
- }
+ }
+
-
protected void setUniformValue(int loc, int x, int y, int z) {
if (-1 < loc) {
pgl.uniform3i(loc, x, y, z);
}
- }
+ }
+
-
protected void setUniformValue(int loc, int x, int y, int z, int w) {
if (-1 < loc) {
pgl.uniform4i(loc, x, y, z, w);
}
- }
-
-
+ }
+
+
protected void setUniformValue(int loc, float x) {
if (-1 < loc) {
pgl.uniform1f(loc, x);
}
- }
-
+ }
+
protected void setUniformValue(int loc, float x, float y) {
if (-1 < loc) {
- pgl.uniform2f(loc, x, y);
+ pgl.uniform2f(loc, x, y);
}
- }
-
+ }
+
protected void setUniformValue(int loc, float x, float y, float z) {
if (-1 < loc) {
- pgl.uniform3f(loc, x, y, z);
- }
- }
+ pgl.uniform3f(loc, x, y, z);
+ }
+ }
+
-
protected void setUniformValue(int loc, float x, float y, float z, float w) {
if (-1 < loc) {
pgl.uniform4f(loc, x, y, z, w);
}
- }
-
-
+ }
+
+
protected void setUniformVector(int loc, int[] vec, int ncoords) {
if (-1 < loc) {
if (ncoords == 1) {
- pgl.uniform1iv(loc, vec.length, vec, 0);
+ pgl.uniform1iv(loc, vec.length, vec, 0);
} else if (ncoords == 2) {
pgl.uniform2iv(loc, vec.length / 2, vec, 0);
} else if (ncoords == 3) {
pgl.uniform3iv(loc, vec.length / 3, vec, 0);
} else if (ncoords == 4) {
pgl.uniform3iv(loc, vec.length / 4, vec, 0);
- }
+ }
}
- }
-
-
+ }
+
+
protected void setUniformVector(int loc, float[] vec, int ncoords) {
- if (-1 < loc) {
+ if (-1 < loc) {
if (ncoords == 1) {
- pgl.uniform1fv(loc, vec.length, vec, 0);
+ pgl.uniform1fv(loc, vec.length, vec, 0);
} else if (ncoords == 2) {
pgl.uniform2fv(loc, vec.length / 2, vec, 0);
} else if (ncoords == 3) {
pgl.uniform3fv(loc, vec.length / 3, vec, 0);
} else if (ncoords == 4) {
pgl.uniform4fv(loc, vec.length / 4, vec, 0);
- }
+ }
}
}
-
-
+
+
protected void setUniformMatrix(int loc, float[] mat) {
if (-1 < loc) {
if (mat.length == 4) {
@@ -469,10 +470,10 @@ public class PShader {
pgl.uniformMatrix4fv(loc, 1, false, mat, 0);
}
}
- }
+ }
+
-
/*
// The individual attribute setters are not really needed, read this:
// http://stackoverflow.com/questions/7718976/what-is-glvertexattrib-versus-glvertexattribpointer-used-for
@@ -481,114 +482,114 @@ public class PShader {
if (-1 < loc) {
pgl.glVertexAttrib1f(loc, x);
}
- }
-
+ }
+
public void set2FloatAttribute(int loc, float x, float y) {
if (-1 < loc) {
pgl.glVertexAttrib2f(loc, x, y);
}
- }
-
+ }
+
public void set3FloatAttribute(int loc, float x, float y, float z) {
if (-1 < loc) {
pgl.glVertexAttrib3f(loc, x, y, z);
}
- }
-
+ }
+
public void set4FloatAttribute(int loc, float x, float y, float z, float w) {
if (-1 < loc) {
pgl.glVertexAttrib4f(loc, x, y, z, w);
}
}
- */
-
-
+ */
+
+
protected void setUniformImpl(String name, int type, Object value) {
int loc = getUniformLoc(name);
if (-1 < loc) {
if (uniformValues == null) {
- uniformValues = new HashMap();
+ uniformValues = new HashMap();
}
- uniformValues.put(loc, new UniformValue(type, value));
+ uniformValues.put(loc, new UniformValue(type, value));
} else {
- PGraphics.showWarning("The shader doesn't have a uniform called \"" +
+ PGraphics.showWarning("The shader doesn't have a uniform called \"" +
name + "\"");
- }
- }
-
-
+ }
+ }
+
+
protected void consumeUniforms() {
if (uniformValues != null && 0 < uniformValues.size()) {
- int texUnit = firstTexUnit;
- for (Integer loc: uniformValues.keySet()) {
- UniformValue val = uniformValues.get(loc);
+ int texUnit = firstTexUnit;
+ for (Integer loc: uniformValues.keySet()) {
+ UniformValue val = uniformValues.get(loc);
if (val.type == UniformValue.INT1) {
int[] v = ((int[])val.value);
- pgl.uniform1i(loc, v[0]);
+ pgl.uniform1i(loc, v[0]);
} else if (val.type == UniformValue.INT2) {
int[] v = ((int[])val.value);
- pgl.uniform2i(loc, v[0], v[1]);
+ pgl.uniform2i(loc, v[0], v[1]);
} else if (val.type == UniformValue.INT3) {
int[] v = ((int[])val.value);
- pgl.uniform3i(loc, v[0], v[1], v[2]);
+ pgl.uniform3i(loc, v[0], v[1], v[2]);
} else if (val.type == UniformValue.INT4) {
int[] v = ((int[])val.value);
- pgl.uniform4i(loc, v[0], v[1], v[2], v[4]);
+ pgl.uniform4i(loc, v[0], v[1], v[2], v[4]);
} else if (val.type == UniformValue.FLOAT1) {
float[] v = ((float[])val.value);
- pgl.uniform1f(loc, v[0]);
+ pgl.uniform1f(loc, v[0]);
} else if (val.type == UniformValue.FLOAT2) {
float[] v = ((float[])val.value);
- pgl.uniform2f(loc, v[0], v[1]);
+ pgl.uniform2f(loc, v[0], v[1]);
} else if (val.type == UniformValue.FLOAT3) {
float[] v = ((float[])val.value);
- pgl.uniform3f(loc, v[0], v[1], v[2]);
+ pgl.uniform3f(loc, v[0], v[1], v[2]);
} else if (val.type == UniformValue.FLOAT4) {
float[] v = ((float[])val.value);
pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
} else if (val.type == UniformValue.INT1VEC) {
int[] v = ((int[])val.value);
- pgl.uniform1iv(loc, v.length, v, 0);
+ pgl.uniform1iv(loc, v.length, v, 0);
} else if (val.type == UniformValue.INT2VEC) {
int[] v = ((int[])val.value);
pgl.uniform2iv(loc, v.length / 2, v, 0);
} else if (val.type == UniformValue.INT3VEC) {
int[] v = ((int[])val.value);
- pgl.uniform3iv(loc, v.length / 3, v, 0);
+ pgl.uniform3iv(loc, v.length / 3, v, 0);
} else if (val.type == UniformValue.INT4VEC) {
int[] v = ((int[])val.value);
- pgl.uniform4iv(loc, v.length / 4, v, 0);
+ pgl.uniform4iv(loc, v.length / 4, v, 0);
} else if (val.type == UniformValue.FLOAT1VEC) {
float[] v = ((float[])val.value);
- pgl.uniform1fv(loc, v.length, v, 0);
+ pgl.uniform1fv(loc, v.length, v, 0);
} else if (val.type == UniformValue.FLOAT2VEC) {
float[] v = ((float[])val.value);
pgl.uniform2fv(loc, v.length / 2, v, 0);
} else if (val.type == UniformValue.FLOAT3VEC) {
float[] v = ((float[])val.value);
- pgl.uniform3fv(loc, v.length / 3, v, 0);
+ pgl.uniform3fv(loc, v.length / 3, v, 0);
} else if (val.type == UniformValue.FLOAT4VEC) {
float[] v = ((float[])val.value);
- pgl.uniform4fv(loc, v.length / 4, v, 0);
+ pgl.uniform4fv(loc, v.length / 4, v, 0);
} else if (val.type == UniformValue.MAT2) {
float[] v = ((float[])val.value);
- pgl.uniformMatrix2fv(loc, 1, false, v, 0);
+ pgl.uniformMatrix2fv(loc, 1, false, v, 0);
} else if (val.type == UniformValue.MAT3) {
float[] v = ((float[])val.value);
- pgl.uniformMatrix3fv(loc, 1, false, v, 0);
+ pgl.uniformMatrix3fv(loc, 1, false, v, 0);
} else if (val.type == UniformValue.MAT4) {
float[] v = ((float[])val.value);
- pgl.uniformMatrix4fv(loc, 1, false, v, 0);
+ pgl.uniformMatrix4fv(loc, 1, false, v, 0);
} else if (val.type == UniformValue.SAMPLER2D) {
PImage img = (PImage)val.value;
- Texture tex = pgMain.getTexture(img);
+ Texture tex = pgMain.getTexture(img);
pgl.uniform1i(loc, texUnit);
- if (textures == null) {
+ if (textures == null) {
textures = new HashMap();
- }
+ }
textures.put(texUnit, tex);
texUnit++;
}
@@ -596,57 +597,57 @@ public class PShader {
uniformValues.clear();
}
}
-
-
+
+
protected void bindTextures() {
- if (textures != null) {
+ if (textures != null) {
for (int unit: textures.keySet()) {
Texture tex = textures.get(unit);
pgl.activeTexture(PGL.TEXTURE0 + unit);
tex.bind();
- }
+ }
}
}
-
-
+
+
protected void unbindTextures() {
if (textures != null) {
for (int unit: textures.keySet()) {
Texture tex = textures.get(unit);
pgl.activeTexture(PGL.TEXTURE0 + unit);
tex.unbind();
- }
+ }
pgl.activeTexture(PGL.TEXTURE0);
- }
+ }
}
-
-
+
+
protected void init() {
if (glProgram == 0 || contextIsOutdated()) {
context = pgl.getCurrentContext();
glProgram = pgMain.createGLSLProgramObject(context.code());
-
- boolean hasVert = false;
+
+ boolean hasVert = false;
if (vertexFilename != null) {
- hasVert = loadVertexShader(vertexFilename);
+ hasVert = loadVertexShader(vertexFilename);
} else if (vertexURL != null) {
hasVert = loadVertexShader(vertexURL);
} else {
- PGraphics.showException("Vertex shader filenames and URLs are " +
+ PGraphics.showException("Vertex shader filenames and URLs are " +
"both null!");
}
-
- boolean hasFrag = false;
+
+ boolean hasFrag = false;
if (fragmentFilename != null) {
hasFrag = loadFragmentShader(fragmentFilename);
- } else if (fragmentURL != null) {
+ } else if (fragmentURL != null) {
hasFrag = loadFragmentShader(fragmentURL);
} else {
- PGraphics.showException("Fragment shader filenames and URLs are " +
+ PGraphics.showException("Fragment shader filenames and URLs are " +
"both null!");
}
-
- boolean vertRes = true;
+
+ boolean vertRes = true;
if (hasVert) {
vertRes = compileVertexShader();
}
@@ -655,7 +656,7 @@ public class PShader {
if (hasFrag) {
fragRes = compileFragmentShader();
}
-
+
if (vertRes && fragRes) {
if (hasVert) {
pgl.attachShader(glProgram, glVertex);
@@ -664,150 +665,150 @@ public class PShader {
pgl.attachShader(glProgram, glFragment);
}
pgl.linkProgram(glProgram);
-
+
int[] linked = new int[1];
- pgl.getProgramiv(glProgram, PGL.LINK_STATUS, linked, 0);
+ pgl.getProgramiv(glProgram, PGL.LINK_STATUS, linked, 0);
if (linked[0] == PGL.FALSE) {
- PGraphics.showException("Cannot link shader program:\n" +
+ PGraphics.showException("Cannot link shader program:\n" +
pgl.getProgramInfoLog(glProgram));
}
-
+
pgl.validateProgram(glProgram);
-
+
int[] validated = new int[1];
- pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, validated, 0);
+ pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, validated, 0);
if (validated[0] == PGL.FALSE) {
- PGraphics.showException("Cannot validate shader program:\n" +
+ PGraphics.showException("Cannot validate shader program:\n" +
pgl.getProgramInfoLog(glProgram));
- }
+ }
}
}
- }
-
-
+ }
+
+
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
pgMain.removeGLSLProgramObject(glProgram, context.code());
pgMain.removeGLSLVertShaderObject(glVertex, context.code());
pgMain.removeGLSLFragShaderObject(glFragment, context.code());
-
+
glProgram = 0;
glVertex = 0;
glFragment = 0;
}
return outdated;
}
-
-
+
+
/**
* Loads and compiles the vertex shader contained in file.
- *
+ *
* @param file String
*/
protected boolean loadVertexShader(String filename) {
vertexShaderSource = PApplet.join(parent.loadStrings(filename), "\n");
return vertexShaderSource != null;
}
-
+
/**
* Loads and compiles the vertex shader contained in the URL.
- *
+ *
* @param file String
*/
protected boolean loadVertexShader(URL url) {
try {
- vertexShaderSource = PApplet.join(PApplet.loadStrings(url.openStream()),
+ vertexShaderSource = PApplet.join(PApplet.loadStrings(url.openStream()),
"\n");
return vertexShaderSource != null;
} catch (IOException e) {
PGraphics.showException("Cannot load vertex shader " + url.getFile());
return false;
}
- }
-
-
+ }
+
+
/**
* Loads and compiles the fragment shader contained in file.
- *
+ *
* @param file String
*/
protected boolean loadFragmentShader(String filename) {
fragmentShaderSource = PApplet.join(parent.loadStrings(filename), "\n");
return fragmentShaderSource != null;
- }
-
-
+ }
+
+
/**
* Loads and compiles the fragment shader contained in the URL.
- *
+ *
* @param url URL
*/
protected boolean loadFragmentShader(URL url) {
try {
- fragmentShaderSource = PApplet.join(PApplet.loadStrings(url.openStream()),
+ fragmentShaderSource = PApplet.join(PApplet.loadStrings(url.openStream()),
"\n");
return fragmentShaderSource != null;
} catch (IOException e) {
PGraphics.showException("Cannot load fragment shader " + url.getFile());
return false;
}
- }
-
-
+ }
+
+
/**
* @param shaderSource a string containing the shader's code
*/
protected boolean compileVertexShader() {
glVertex = pgMain.createGLSLVertShaderObject(context.code());
-
+
pgl.shaderSource(glVertex, vertexShaderSource);
pgl.compileShader(glVertex);
-
+
int[] compiled = new int[1];
- pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, compiled, 0);
+ pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, compiled, 0);
if (compiled[0] == PGL.FALSE) {
- PGraphics.showException("Cannot compile vertex shader:\n" +
+ PGraphics.showException("Cannot compile vertex shader:\n" +
pgl.getShaderInfoLog(glVertex));
return false;
} else {
return true;
- }
- }
-
-
+ }
+ }
+
+
/**
* @param shaderSource a string containing the shader's code
*/
protected boolean compileFragmentShader() {
glFragment = pgMain.createGLSLFragShaderObject(context.code());
-
+
pgl.shaderSource(glFragment, fragmentShaderSource);
pgl.compileShader(glFragment);
-
+
int[] compiled = new int[1];
pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, compiled, 0);
if (compiled[0] == PGL.FALSE) {
- PGraphics.showException("Cannot compile fragment shader:\n" +
- pgl.getShaderInfoLog(glFragment));
+ PGraphics.showException("Cannot compile fragment shader:\n" +
+ pgl.getShaderInfoLog(glFragment));
return false;
} else {
return true;
- }
+ }
}
-
+
protected void setRenderer(PGraphicsOpenGL pg) {
pgCurrent = pg;
}
protected void loadAttributes() { }
-
-
- protected void loadUniforms() { }
-
-
+
+
+ protected void loadUniforms() { }
+
+
protected void release() {
if (glVertex != 0) {
pgMain.deleteGLSLVertShaderObject(glVertex, context.code());
@@ -833,26 +834,26 @@ public class PShader {
static final int FLOAT1 = 4;
static final int FLOAT2 = 5;
static final int FLOAT3 = 6;
- static final int FLOAT4 = 7;
- static final int INT1VEC = 8;
+ static final int FLOAT4 = 7;
+ static final int INT1VEC = 8;
static final int INT2VEC = 9;
static final int INT3VEC = 10;
- static final int INT4VEC = 11;
+ static final int INT4VEC = 11;
static final int FLOAT1VEC = 12;
static final int FLOAT2VEC = 13;
static final int FLOAT3VEC = 14;
- static final int FLOAT4VEC = 15;
+ static final int FLOAT4VEC = 15;
static final int MAT2 = 16;
static final int MAT3 = 17;
static final int MAT4 = 18;
static final int SAMPLER2D = 19;
-
+
int type;
Object value;
UniformValue(int type, Object value) {
this.type = type;
this.value = value;
- }
- }
+ }
+ }
}
diff --git a/core/src/processing/opengl/PShape2D.java b/core/src/processing/opengl/PShape2D.java
index e5fe07d7f..2b3e75055 100644
--- a/core/src/processing/opengl/PShape2D.java
+++ b/core/src/processing/opengl/PShape2D.java
@@ -27,32 +27,34 @@ import processing.core.PGraphics;
import processing.core.PShape;
public class PShape2D extends PShapeOpenGL {
-
+
public PShape2D(PApplet parent, int family) {
super(parent, family);
- }
-
+ }
+
+ @Override
public boolean is2D() {
return true;
}
+ @Override
public boolean is3D() {
return false;
}
-
+
////////////////////////////////////////////////////////////////////////
//
- // Shape copy
-
-
+ // Shape copy
+
+
static public PShape2D createShape(PApplet parent, PShape src) {
PShape2D dest = null;
if (src.getFamily() == GROUP) {
dest = PGraphics2D.createShapeImpl(parent, GROUP);
- PShape2D.copyGroup(parent, src, dest);
+ PShape2D.copyGroup(parent, src, dest);
} else if (src.getFamily() == PRIMITIVE) {
- dest = PGraphics2D.createShapeImpl(parent, src.getKind(),
+ dest = PGraphics2D.createShapeImpl(parent, src.getKind(),
src.getParams());
PShape.copyPrimitive(src, dest);
} else if (src.getFamily() == GEOMETRY) {
@@ -64,108 +66,123 @@ public class PShape2D extends PShapeOpenGL {
}
dest.setName(src.getName());
return dest;
- }
-
-
+ }
+
+
static public void copyGroup(PApplet parent, PShape src, PShape dest) {
copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
-
+
for (int i = 0; i < src.getChildCount(); i++) {
PShape c = PShape2D.createShape(parent, src.getChild(i));
dest.addChild(c);
}
- }
-
-
- ///////////////////////////////////////////////////////////
-
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Drawing methods
-
+
+ // Drawing methods
+
+ @Override
public void vertex(float x, float y, float z) {
PGraphics.showDepthWarningXYZ("vertex");
}
-
+
+ @Override
public void vertex(float x, float y, float z, float u, float v) {
PGraphics.showDepthWarningXYZ("vertex");
- }
-
- ///////////////////////////////////////////////////////////
-
+ }
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Bezier curves
-
+
+ // Bezier curves
+
+ @Override
public void bezierVertex(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
PGraphics.showDepthWarningXYZ("bezierVertex");
}
+ @Override
public void quadraticVertex(float x2, float y2, float z2,
float x4, float y4, float z4) {
PGraphics.showDepthWarningXYZ("quadVertex");
- }
+ }
+ @Override
public void curveVertex(float x, float y, float z) {
PGraphics.showDepthWarningXYZ("curveVertex");
- }
-
- ///////////////////////////////////////////////////////////
-
+ }
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Geometric transformations
-
+
+ // Geometric transformations
+
+ @Override
public void translate(float tx, float ty, float tz) {
PGraphics.showVariationWarning("translate");
- }
-
+ }
+
+ @Override
public void rotateX(float angle) {
PGraphics.showDepthWarning("rotateX");
}
+ @Override
public void rotateY(float angle) {
PGraphics.showDepthWarning("rotateY");
}
+ @Override
public void rotateZ(float angle) {
PGraphics.showDepthWarning("rotateZ");
}
+ @Override
public void rotate(float angle, float vx, float vy, float vz) {
PGraphics.showVariationWarning("rotate");
- }
-
+ }
+
+ @Override
public void applyMatrix(float n00, float n01, float n02, float n03,
float n10, float n11, float n12, float n13,
float n20, float n21, float n22, float n23,
float n30, float n31, float n32, float n33) {
PGraphics.showVariationWarning("applyMatrix");
- }
-
+ }
+
+ @Override
public void scale(float sx, float sy, float sz) {
PGraphics.showDepthWarningXYZ("scale");
}
-
- ///////////////////////////////////////////////////////////
-
- //
-
- // Setters/getters of individual vertices
+ ///////////////////////////////////////////////////////////
+
+ //
+
+ // Setters/getters of individual vertices
+
+ @Override
public float getVertexZ(int index) {
PGraphics.showDepthWarningXYZ("getVertexZ");
return 0;
- }
-
+ }
+
+ @Override
public void setVertex(int index, float x, float y) {
super.setVertex(index, x, y, 0);
}
-
+
+ @Override
public void setVertex(int index, float x, float y, float z) {
PGraphics.showDepthWarningXYZ("setVertex");
}
diff --git a/core/src/processing/opengl/PShape3D.java b/core/src/processing/opengl/PShape3D.java
index 4134e9559..df169eaa1 100644
--- a/core/src/processing/opengl/PShape3D.java
+++ b/core/src/processing/opengl/PShape3D.java
@@ -30,28 +30,30 @@ public class PShape3D extends PShapeOpenGL {
public PShape3D(PApplet parent, int family) {
super(parent, family);
}
-
+
+ @Override
public boolean is2D() {
return false;
}
+ @Override
public boolean is3D() {
return true;
}
-
-
+
+
////////////////////////////////////////////////////////////////////////
//
- // Shape copy
-
-
+ // Shape copy
+
+
static public PShape3D createShape(PApplet parent, PShape src) {
PShape3D dest = null;
if (src.getFamily() == GROUP) {
dest = PGraphics3D.createShapeImpl(parent, GROUP);
- PShape3D.copyGroup(parent, src, dest);
+ PShape3D.copyGroup(parent, src, dest);
} else if (src.getFamily() == PRIMITIVE) {
- dest = PGraphics3D.createShapeImpl(parent, src.getKind(),
+ dest = PGraphics3D.createShapeImpl(parent, src.getKind(),
src.getParams());
PShape.copyPrimitive(src, dest);
} else if (src.getFamily() == GEOMETRY) {
@@ -63,17 +65,17 @@ public class PShape3D extends PShapeOpenGL {
}
dest.setName(src.getName());
return dest;
- }
-
-
+ }
+
+
static public void copyGroup(PApplet parent, PShape src, PShape dest) {
copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
-
+
for (int i = 0; i < src.getChildCount(); i++) {
PShape c = PShape3D.createShape(parent, src.getChild(i));
dest.addChild(c);
}
- }
+ }
}
diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java
index e6ff94420..801cc53d4 100644
--- a/core/src/processing/opengl/PShapeOpenGL.java
+++ b/core/src/processing/opengl/PShapeOpenGL.java
@@ -46,16 +46,16 @@ import java.util.Arrays;
import java.util.HashSet;
/**
- * This class holds a 3D model composed of vertices, normals, colors
- * (per vertex) and texture coordinates (also per vertex). All this data is
+ * This class holds a 3D model composed of vertices, normals, colors
+ * (per vertex) and texture coordinates (also per vertex). All this data is
* stored in Vertex Buffer Objects (VBO) in GPU memory for very fast access.
* OBJ loading implemented using code from Saito's OBJLoader library:
* http://code.google.com/p/saitoobjloader/
- * and OBJReader from Ahmet Kizilay
- * http://www.openprocessing.org/visuals/?visualID=191
+ * and OBJReader from Ahmet Kizilay
+ * http://www.openprocessing.org/visuals/?visualID=191
* By Andres Colubri
- *
- *
+ *
+ *
* Other formats to consider:
* AMF: http://en.wikipedia.org/wiki/Additive_Manufacturing_File_Format
* STL: http://en.wikipedia.org/wiki/STL_(file_format)
@@ -67,33 +67,33 @@ public class PShapeOpenGL extends PShape {
static protected final int ROTATE = 1;
static protected final int SCALE = 2;
static protected final int MATRIX = 3;
-
+
protected PGraphicsOpenGL pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this shape.
- protected PShapeOpenGL root;
+ protected PShapeOpenGL root;
// ........................................................
-
- // Input, tessellated geometry
-
+
+ // Input, tessellated geometry
+
protected InGeometry inGeo;
protected TessGeometry tessGeo;
protected Tessellator tessellator;
// ........................................................
-
- // Texturing
-
+
+ // Texturing
+
protected HashSet textures;
- protected PImage texture;
+ protected PImage texture;
protected boolean strokedTexture;
-
+
// ........................................................
-
- // OpenGL buffers
-
+
+ // OpenGL buffers
+
public int glPolyVertex;
public int glPolyColor;
public int glPolyNormal;
@@ -103,21 +103,21 @@ public class PShapeOpenGL extends PShape {
public int glPolyEmissive;
public int glPolyShininess;
public int glPolyIndex;
-
+
public int glLineVertex;
public int glLineColor;
public int glLineAttrib;
- public int glLineIndex;
-
+ public int glLineIndex;
+
public int glPointVertex;
public int glPointColor;
public int glPointAttrib;
- public int glPointIndex;
+ public int glPointIndex;
// ........................................................
-
+
// Offsets for geometry aggregation and update.
-
+
protected int polyVertCopyOffset;
protected int polyIndCopyOffset;
protected int lineVertCopyOffset;
@@ -128,48 +128,48 @@ public class PShapeOpenGL extends PShape {
protected int polyIndexOffset;
protected int polyVertexOffset;
protected int polyVertexAbs;
- protected int polyVertexRel;
-
+ protected int polyVertexRel;
+
protected int lineIndexOffset;
protected int lineVertexOffset;
protected int lineVertexAbs;
protected int lineVertexRel;
-
+
protected int pointIndexOffset;
protected int pointVertexOffset;
protected int pointVertexAbs;
protected int pointVertexRel;
-
+
protected int firstPolyIndexCache;
- protected int lastPolyIndexCache;
+ protected int lastPolyIndexCache;
protected int firstLineIndexCache;
protected int lastLineIndexCache;
protected int firstPointIndexCache;
protected int lastPointIndexCache;
- protected int firstPolyVertex;
+ protected int firstPolyVertex;
protected int lastPolyVertex;
- protected int firstLineVertex;
+ protected int firstLineVertex;
protected int lastLineVertex;
- protected int firstPointVertex;
- protected int lastPointVertex;
-
+ protected int firstPointVertex;
+ protected int lastPointVertex;
+
// ........................................................
-
+
// Geometric transformations.
-
- protected PMatrix transform;
-
+
+ protected PMatrix transform;
+
// ........................................................
-
- // State/rendering flags
-
+
+ // State/rendering flags
+
protected boolean tessellated;
protected boolean needBufferInit;
-
+
protected boolean isSolid;
protected boolean isClosed;
-
+
protected boolean openContour = false;
protected boolean breakShape = false;
protected boolean shapeEnded = false;
@@ -179,16 +179,16 @@ public class PShapeOpenGL extends PShape {
// 3D shapes, poly geometry is coincident with the fill
// triangles, as the lines and points are stored separately.
// However, for 2D shapes the poly geometry contains all of
- // the three since the same rendering shader applies to
- // fill, line and point geometry.
+ // the three since the same rendering shader applies to
+ // fill, line and point geometry.
protected boolean hasPolys;
protected boolean hasLines;
protected boolean hasPoints;
-
+
// ........................................................
-
- // Modes inherited from renderer
-
+
+ // Modes inherited from renderer
+
protected int textureMode;
protected int rectMode;
protected int ellipseMode;
@@ -196,17 +196,17 @@ public class PShapeOpenGL extends PShape {
protected int imageMode;
// ........................................................
-
+
// Bezier and Catmull-Rom curves
-
+
protected int bezierDetail = 20;
protected int curveDetail = 20;
- protected float curveTightness = 0;
-
+ protected float curveTightness = 0;
+
// ........................................................
-
+
// Normals
-
+
protected float normalX, normalY, normalZ;
// normal calculated per triangle
@@ -217,72 +217,72 @@ public class PShapeOpenGL extends PShape {
static protected final int NORMAL_MODE_VERTEX = 2;
// Current mode for normals, one of AUTO, SHAPE, or VERTEX
- protected int normalMode;
-
+ protected int normalMode;
+
// ........................................................
-
- // Modification variables (used only by the root shape)
-
+
+ // Modification variables (used only by the root shape)
+
protected boolean modified;
-
+
protected boolean modifiedPolyVertices;
protected boolean modifiedPolyColors;
protected boolean modifiedPolyNormals;
- protected boolean modifiedPolyTexcoords;
+ protected boolean modifiedPolyTexcoords;
protected boolean modifiedPolyAmbient;
protected boolean modifiedPolySpecular;
protected boolean modifiedPolyEmissive;
protected boolean modifiedPolyShininess;
-
+
protected boolean modifiedLineVertices;
protected boolean modifiedLineColors;
- protected boolean modifiedLineAttributes;
+ protected boolean modifiedLineAttributes;
protected boolean modifiedPointVertices;
protected boolean modifiedPointColors;
- protected boolean modifiedPointAttributes;
-
+ protected boolean modifiedPointAttributes;
+
protected int firstModifiedPolyVertex;
protected int lastModifiedPolyVertex;
protected int firstModifiedPolyColor;
protected int lastModifiedPolyColor;
protected int firstModifiedPolyNormal;
- protected int lastModifiedPolyNormal;
+ protected int lastModifiedPolyNormal;
protected int firstModifiedPolyTexcoord;
- protected int lastModifiedPolyTexcoord;
+ protected int lastModifiedPolyTexcoord;
protected int firstModifiedPolyAmbient;
- protected int lastModifiedPolyAmbient;
+ protected int lastModifiedPolyAmbient;
protected int firstModifiedPolySpecular;
- protected int lastModifiedPolySpecular;
+ protected int lastModifiedPolySpecular;
protected int firstModifiedPolyEmissive;
- protected int lastModifiedPolyEmissive;
+ protected int lastModifiedPolyEmissive;
protected int firstModifiedPolyShininess;
- protected int lastModifiedPolyShininess;
-
+ protected int lastModifiedPolyShininess;
+
protected int firstModifiedLineVertex;
- protected int lastModifiedLineVertex;
+ protected int lastModifiedLineVertex;
protected int firstModifiedLineColor;
- protected int lastModifiedLineColor;
+ protected int lastModifiedLineColor;
protected int firstModifiedLineAttribute;
- protected int lastModifiedLineAttribute;
-
+ protected int lastModifiedLineAttribute;
+
protected int firstModifiedPointVertex;
- protected int lastModifiedPointVertex;
+ protected int lastModifiedPointVertex;
protected int firstModifiedPointColor;
- protected int lastModifiedPointColor;
+ protected int lastModifiedPointColor;
protected int firstModifiedPointAttribute;
- protected int lastModifiedPointAttribute;
-
-
- PShapeOpenGL() {
+ protected int lastModifiedPointAttribute;
+
+
+ PShapeOpenGL() {
}
-
-
+
+
public PShapeOpenGL(PApplet parent, int family) {
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
context = pgl.createEmptyContext();
-
+
glPolyVertex = 0;
glPolyColor = 0;
glPolyNormal = 0;
@@ -290,82 +290,83 @@ public class PShapeOpenGL extends PShape {
glPolyAmbient = 0;
glPolySpecular = 0;
glPolyEmissive = 0;
- glPolyShininess = 0;
+ glPolyShininess = 0;
glPolyIndex = 0;
-
+
glLineVertex = 0;
glLineColor = 0;
glLineAttrib = 0;
glLineIndex = 0;
-
+
glPointVertex = 0;
glPointColor = 0;
glPointAttrib = 0;
glPointIndex = 0;
-
+
this.tessellator = PGraphicsOpenGL.tessellator;
- this.family = family;
+ this.family = family;
this.root = this;
this.parent = null;
this.tessellated = false;
-
+
if (family == GEOMETRY || family == PRIMITIVE || family == PATH) {
- inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED);
+ inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED);
}
-
+
// Modes are retrieved from the current values in the renderer.
- textureMode = pg.textureMode;
+ textureMode = pg.textureMode;
rectMode = pg.rectMode;
ellipseMode = pg.ellipseMode;
shapeMode = pg.shapeMode;
imageMode = pg.imageMode;
-
- colorMode(pg.colorMode,
+
+ colorMode(pg.colorMode,
pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA);
-
- // Initial values for fill, stroke and tint colors are also imported from
- // the renderer. This is particular relevant for primitive shapes, since is
- // not possible to set their color separately when creating them, and their
- // input vertices are actually generated at rendering time, by which the
+
+ // Initial values for fill, stroke and tint colors are also imported from
+ // the renderer. This is particular relevant for primitive shapes, since is
+ // not possible to set their color separately when creating them, and their
+ // input vertices are actually generated at rendering time, by which the
// color configuration of the renderer might have changed.
fill = pg.fill;
fillColor = pg.fillColor;
-
- stroke = pg.stroke;
- strokeColor = pg.strokeColor;
- strokeWeight = pg.strokeWeight;
+
+ stroke = pg.stroke;
+ strokeColor = pg.strokeColor;
+ strokeWeight = pg.strokeWeight;
strokeCap = pg.strokeCap;
strokeJoin = pg.strokeJoin;
-
- tint = pg.tint;
+
+ tint = pg.tint;
tintColor = pg.tintColor;
- ambientColor = pg.ambientColor;
- specularColor = pg.specularColor;
+ ambientColor = pg.ambientColor;
+ specularColor = pg.specularColor;
emissiveColor = pg.emissiveColor;
shininess = pg.shininess;
-
- normalX = normalY = 0;
+
+ normalX = normalY = 0;
normalZ = 1;
-
+
normalMode = NORMAL_MODE_AUTO;
-
+
if (family == GROUP) {
// GROUP shapes are always marked as ended.
shapeEnded = true;
}
}
-
+
+ @Override
public void addChild(PShape child) {
if (child instanceof PShapeOpenGL) {
if (family == GROUP) {
PShapeOpenGL c3d = (PShapeOpenGL)child;
-
+
super.addChild(c3d);
c3d.updateRoot(root);
markForTessellation();
-
+
if (c3d.family == GROUP) {
if (c3d.textures != null) {
for (PImage tex: c3d.textures) {
@@ -381,9 +382,9 @@ public class PShapeOpenGL extends PShape {
if (c3d.stroke) {
strokedTexture(true);
}
- }
+ }
}
-
+
} else {
PGraphics.showWarning("Cannot add child shape to non-group shape.");
}
@@ -391,9 +392,9 @@ public class PShapeOpenGL extends PShape {
PGraphics.showWarning("Shape must be 3D to be added to the group.");
}
}
-
-
- public void updateRoot(PShape root) {
+
+
+ protected void updateRoot(PShape root) {
this.root = (PShapeOpenGL) root;
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
@@ -401,181 +402,187 @@ public class PShapeOpenGL extends PShape {
child.updateRoot(root);
}
}
- }
-
-
+ }
+
+
+ @Override
protected void finalize() throws Throwable {
try {
- finalizePolyBuffers();
+ finalizePolyBuffers();
finalizeLineBuffers();
finalizePointBuffers();
} finally {
super.finalize();
}
}
-
-
+
+
protected void finalizePolyBuffers() {
- if (glPolyVertex != 0) {
- pg.finalizeVertexBufferObject(glPolyVertex, context.code());
- }
-
- if (glPolyColor != 0) {
- pg.finalizeVertexBufferObject(glPolyColor, context.code());
- }
+ if (glPolyVertex != 0) {
+ pg.finalizeVertexBufferObject(glPolyVertex, context.code());
+ }
- if (glPolyNormal != 0) {
- pg.finalizeVertexBufferObject(glPolyNormal, context.code());
- }
+ if (glPolyColor != 0) {
+ pg.finalizeVertexBufferObject(glPolyColor, context.code());
+ }
- if (glPolyTexcoord != 0) {
- pg.finalizeVertexBufferObject(glPolyTexcoord, context.code());
- }
+ if (glPolyNormal != 0) {
+ pg.finalizeVertexBufferObject(glPolyNormal, context.code());
+ }
- if (glPolyAmbient != 0) {
- pg.finalizeVertexBufferObject(glPolyAmbient, context.code());
- }
-
- if (glPolySpecular != 0) {
- pg.finalizeVertexBufferObject(glPolySpecular, context.code());
- }
+ if (glPolyTexcoord != 0) {
+ pg.finalizeVertexBufferObject(glPolyTexcoord, context.code());
+ }
- if (glPolyEmissive != 0) {
- pg.finalizeVertexBufferObject(glPolyEmissive, context.code());
- }
+ if (glPolyAmbient != 0) {
+ pg.finalizeVertexBufferObject(glPolyAmbient, context.code());
+ }
- if (glPolyShininess != 0) {
- pg.finalizeVertexBufferObject(glPolyShininess, context.code());
- }
-
- if (glPolyIndex != 0) {
- pg.finalizeVertexBufferObject(glPolyIndex, context.code());
- }
+ if (glPolySpecular != 0) {
+ pg.finalizeVertexBufferObject(glPolySpecular, context.code());
+ }
+
+ if (glPolyEmissive != 0) {
+ pg.finalizeVertexBufferObject(glPolyEmissive, context.code());
+ }
+
+ if (glPolyShininess != 0) {
+ pg.finalizeVertexBufferObject(glPolyShininess, context.code());
+ }
+
+ if (glPolyIndex != 0) {
+ pg.finalizeVertexBufferObject(glPolyIndex, context.code());
+ }
}
-
-
+
+
protected void finalizeLineBuffers() {
- if (glLineVertex != 0) {
- pg.finalizeVertexBufferObject(glLineVertex, context.code());
- }
-
- if (glLineColor != 0) {
- pg.finalizeVertexBufferObject(glLineColor, context.code());
- }
+ if (glLineVertex != 0) {
+ pg.finalizeVertexBufferObject(glLineVertex, context.code());
+ }
- if (glLineAttrib != 0) {
- pg.finalizeVertexBufferObject(glLineAttrib, context.code());
- }
-
- if (glLineIndex != 0) {
- pg.finalizeVertexBufferObject(glLineIndex, context.code());
- }
- }
-
-
- protected void finalizePointBuffers() {
- if (glPointVertex != 0) {
- pg.finalizeVertexBufferObject(glPointVertex, context.code());
- }
-
- if (glPointColor != 0) {
- pg.finalizeVertexBufferObject(glPointColor, context.code());
- }
+ if (glLineColor != 0) {
+ pg.finalizeVertexBufferObject(glLineColor, context.code());
+ }
- if (glPointAttrib != 0) {
- pg.finalizeVertexBufferObject(glPointAttrib, context.code());
- }
-
- if (glPointIndex != 0) {
- pg.finalizeVertexBufferObject(glPointIndex, context.code());
- }
+ if (glLineAttrib != 0) {
+ pg.finalizeVertexBufferObject(glLineAttrib, context.code());
+ }
+
+ if (glLineIndex != 0) {
+ pg.finalizeVertexBufferObject(glLineIndex, context.code());
+ }
}
-
- ///////////////////////////////////////////////////////////
-
+
+ protected void finalizePointBuffers() {
+ if (glPointVertex != 0) {
+ pg.finalizeVertexBufferObject(glPointVertex, context.code());
+ }
+
+ if (glPointColor != 0) {
+ pg.finalizeVertexBufferObject(glPointColor, context.code());
+ }
+
+ if (glPointAttrib != 0) {
+ pg.finalizeVertexBufferObject(glPointAttrib, context.code());
+ }
+
+ if (glPointIndex != 0) {
+ pg.finalizeVertexBufferObject(glPointIndex, context.code());
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Query methods
-
-
+
+ // Query methods
+
+
+ @Override
public float getWidth() {
- PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
- Float.POSITIVE_INFINITY);
- PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
+ PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
+ Float.POSITIVE_INFINITY);
+ PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
if (shapeEnded) {
getVertexMin(min);
getVertexMax(max);
- }
+ }
width = max.x - min.x;
return width;
}
-
+
+ @Override
public float getHeight() {
- PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
- Float.POSITIVE_INFINITY);
- PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
+ PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
+ Float.POSITIVE_INFINITY);
+ PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
if (shapeEnded) {
getVertexMin(min);
getVertexMax(max);
- }
+ }
height = max.y - min.y;
return height;
}
-
+
+ @Override
public float getDepth() {
- PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
- Float.POSITIVE_INFINITY);
- PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
+ PVector min = new PVector(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
+ Float.POSITIVE_INFINITY);
+ PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
if (shapeEnded) {
getVertexMin(min);
getVertexMax(max);
- }
- depth = max.z - min.z;
+ }
+ depth = max.z - min.z;
return depth;
- }
-
-
+ }
+
+
+ @Override
public PVector getTop(PVector top) {
if (top == null) {
top = new PVector();
}
- top.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
+ top.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.POSITIVE_INFINITY);
getVertexMin(top);
return top;
}
-
+
+ @Override
public PVector getBottom(PVector bottom) {
if (bottom == null) {
bottom = new PVector();
}
- bottom.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
+ bottom.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
getVertexMax(bottom);
return bottom;
- }
-
-
+ }
+
+
protected void getVertexMin(PVector min) {
updateTessellation();
-
+
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.getVertexMin(min);
+ child.getVertexMin(min);
}
} else {
- if (hasPolys) {
+ if (hasPolys) {
tessGeo.getPolyVertexMin(min, firstPolyVertex, lastPolyVertex);
- }
- if (is3D()) {
+ }
+ if (is3D()) {
if (hasLines) {
tessGeo.getLineVertexMin(min, firstLineVertex, lastLineVertex);
}
@@ -586,16 +593,16 @@ public class PShapeOpenGL extends PShape {
}
}
-
+
protected void getVertexMax(PVector max) {
updateTessellation();
-
+
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.getVertexMax(max);
}
- } else {
+ } else {
if (hasPolys) {
tessGeo.getPolyVertexMax(max, firstPolyVertex, lastPolyVertex);
}
@@ -608,28 +615,28 @@ public class PShapeOpenGL extends PShape {
}
}
}
- }
-
-
+ }
+
+
protected int getVertexSum(PVector sum, int count) {
updateTessellation();
-
+
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
count += child.getVertexSum(sum, count);
}
- } else {
+ } else {
if (hasPolys) {
count += tessGeo.getPolyVertexSum(sum, firstPolyVertex, lastPolyVertex);
}
if (is3D()) {
if (hasLines) {
- count += tessGeo.getLineVertexSum(sum, firstLineVertex,
+ count += tessGeo.getLineVertexSum(sum, firstLineVertex,
lastLineVertex);
}
if (hasPoints) {
- count += tessGeo.getPointVertexSum(sum, firstPointVertex,
+ count += tessGeo.getPointVertexSum(sum, firstPointVertex,
lastPointVertex);
}
}
@@ -637,53 +644,55 @@ public class PShapeOpenGL extends PShape {
return count;
}
-
- ///////////////////////////////////////////////////////////
-
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Drawing methods
-
-
+
+ // Drawing methods
+
+
public void textureMode(int mode) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.textureMode(mode);
- }
- } else {
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.textureMode(mode);
+ }
+ } else {
textureMode = mode;
}
}
-
+
+ @Override
public void texture(PImage tex) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.texture(tex);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.texture(tex);
+ }
} else {
PImage tex0 = texture;
texture = tex;
if (tex0 != tex && parent != null) {
((PShapeOpenGL)parent).removeTexture(tex);
- }
+ }
if (parent != null) {
((PShapeOpenGL)parent).addTexture(texture);
if (is2D() && stroke) {
((PShapeOpenGL)parent).strokedTexture(true);
- }
+ }
}
- }
+ }
}
-
+
+ @Override
public void noTexture() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.noTexture();
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.noTexture();
}
} else {
PImage tex0 = texture;
@@ -692,37 +701,37 @@ public class PShapeOpenGL extends PShape {
((PShapeOpenGL)parent).removeTexture(tex0);
if (is2D()) {
((PShapeOpenGL)parent).strokedTexture(false);
- }
- }
+ }
+ }
}
- }
+ }
+
-
protected void addTexture(PImage tex) {
if (textures == null) {
- textures = new HashSet();
+ textures = new HashSet();
}
textures.add(tex);
if (parent != null) {
((PShapeOpenGL)parent).addTexture(tex);
- }
+ }
}
-
-
+
+
protected void removeTexture(PImage tex) {
if (textures == null || !textures.contains(tex)) return; // Nothing to remove.
-
+
// First check that none of the child shapes
// have texture tex...
boolean childHasTex = false;
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
if (child.hasTexture(tex)) {
childHasTex = true;
break;
}
}
-
+
if (!childHasTex) {
// ...if not, it is safe to remove from this shape.
textures.remove(tex);
@@ -735,21 +744,21 @@ public class PShapeOpenGL extends PShape {
// tex anymore, we now can remove it from the parent.
if (parent != null) {
((PShapeOpenGL)parent).removeTexture(tex);
- }
+ }
}
-
-
+
+
protected void strokedTexture(boolean newValue) {
if (strokedTexture == newValue) return; // Nothing to change.
-
+
if (newValue) {
- strokedTexture = true;
- } else {
+ strokedTexture = true;
+ } else {
// First check that none of the child shapes
// have have a stroked texture...
boolean childHasStrokedTex = false;
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
if (child.hasStrokedTexture()) {
childHasStrokedTex = true;
break;
@@ -759,98 +768,105 @@ public class PShapeOpenGL extends PShape {
if (!childHasStrokedTex) {
// ...if not, it is safe to mark this shape as without
// stroked texture.
- strokedTexture = false;
+ strokedTexture = false;
}
}
-
+
// Now we can update the parent shape.
if (parent != null) {
((PShapeOpenGL)parent).strokedTexture(newValue);
- }
+ }
}
-
-
+
+
protected boolean hasTexture(PImage tex) {
if (family == GROUP) {
- return textures != null && textures.contains(tex);
+ return textures != null && textures.contains(tex);
} else {
return texture == tex;
}
}
-
-
+
+
protected boolean hasStrokedTexture() {
if (family == GROUP) {
- return strokedTexture;
+ return strokedTexture;
} else {
return texture != null && stroke;
}
- }
-
-
+ }
+
+
+ @Override
public void solid(boolean solid) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
child.solid(solid);
}
} else {
- isSolid = solid;
- }
+ isSolid = solid;
+ }
}
-
-
+
+
+ @Override
public void beginContour() {
- if (family == GROUP) {
+ if (family == GROUP) {
PGraphics.showWarning("Cannot begin contour in GROUP shapes");
return;
}
-
+
if (openContour) {
PGraphics.showWarning("Already called beginContour().");
return;
- }
- openContour = true;
+ }
+ openContour = true;
}
-
-
+
+
+ @Override
public void endContour() {
- if (family == GROUP) {
+ if (family == GROUP) {
PGraphics.showWarning("Cannot end contour in GROUP shapes");
return;
}
-
+
if (!openContour) {
PGraphics.showWarning("Need to call beginContour() first.");
- return;
+ return;
}
- openContour = false;
- breakShape = true;
+ openContour = false;
+ breakShape = true;
}
-
+
+ @Override
public void vertex(float x, float y) {
- vertexImpl(x, y, 0, 0, 0);
+ vertexImpl(x, y, 0, 0, 0);
}
-
+
+ @Override
public void vertex(float x, float y, float u, float v) {
- vertexImpl(x, y, 0, u, v);
- }
-
-
- public void vertex(float x, float y, float z) {
- vertexImpl(x, y, z, 0, 0);
+ vertexImpl(x, y, 0, u, v);
}
-
+
+ @Override
+ public void vertex(float x, float y, float z) {
+ vertexImpl(x, y, z, 0, 0);
+ }
+
+
+ @Override
public void vertex(float x, float y, float z, float u, float v) {
- vertexImpl(x, y, z, u, v);
- }
-
-
+ vertexImpl(x, y, z, u, v);
+ }
+
+
protected void vertexImpl(float x, float y, float z, float u, float v) {
- if (family == GROUP) {
+ if (family == GROUP) {
PGraphics.showWarning("Cannot add vertices to GROUP shape");
return;
}
@@ -860,59 +876,60 @@ public class PShapeOpenGL extends PShape {
if (fill || textured) {
if (!textured) {
fcolor = fillColor;
- } else {
+ } else {
if (tint) {
fcolor = tintColor;
} else {
fcolor = 0xffFFFFFF;
}
}
- }
-
+ }
+
if (texture != null && textureMode == IMAGE) {
u = PApplet.min(1, u / texture.width);
v = PApplet.min(1, v / texture.height);
}
-
+
int scolor = 0x00;
float sweight = 0;
if (stroke) {
scolor = strokeColor;
sweight = strokeWeight;
- }
-
- inGeo.addVertex(x, y, z,
- fcolor,
+ }
+
+ inGeo.addVertex(x, y, z,
+ fcolor,
normalX, normalY, normalZ,
- u, v,
+ u, v,
scolor, sweight,
ambientColor, specularColor, emissiveColor, shininess,
- vertexCode());
-
+ vertexCode());
+
markForTessellation();
}
-
-
+
+
protected int vertexCode() {
int code = VERTEX;
if (breakShape) {
code = BREAK;
breakShape = false;
- }
+ }
return code;
}
-
-
+
+
+ @Override
public void normal(float nx, float ny, float nz) {
- if (family == GROUP) {
+ if (family == GROUP) {
PGraphics.showWarning("Cannot set normal in GROUP shape");
return;
}
-
+
normalX = nx;
normalY = ny;
normalZ = nz;
-
+
// if drawing a shape and the normal hasn't been set yet,
// then we need to set the normals for each vertex so far
if (normalMode == NORMAL_MODE_AUTO) {
@@ -921,91 +938,96 @@ public class PShapeOpenGL extends PShape {
} else if (normalMode == NORMAL_MODE_SHAPE) {
// a separate normal for each vertex
normalMode = NORMAL_MODE_VERTEX;
- }
+ }
}
-
+
+ @Override
public void end() {
end(OPEN);
- }
+ }
-
- public void end(int mode) {
- if (family == GROUP) {
+
+ @Override
+ public void end(int mode) {
+ if (family == GROUP) {
PGraphics.showWarning("Cannot end GROUP shape");
return;
}
-
- // Input arrays are trimmed since they are expanded by doubling their old
+
+ // Input arrays are trimmed since they are expanded by doubling their old
// size, which might lead to arrays larger than the vertex counts.
inGeo.trim();
-
- isClosed = mode == CLOSE;
+
+ isClosed = mode == CLOSE;
markForTessellation();
shapeEnded = true;
- }
-
-
+ }
+
+
+ @Override
public void setParams(float[] source) {
- if (family != PRIMITIVE) {
+ if (family != PRIMITIVE) {
PGraphics.showWarning("Parameters can only be set to PRIMITIVE shapes");
return;
}
-
+
super.setParams(source);
markForTessellation();
shapeEnded = true;
}
-
-
+
+
+ @Override
public void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
- if (family != PATH) {
+ if (family != PATH) {
PGraphics.showWarning("Vertex coordinates and codes can only be set to " +
"PATH shapes");
return;
}
-
+
super.setPath(vcount, verts, ccount, codes);
markForTessellation();
- shapeEnded = true;
+ shapeEnded = true;
}
-
+
//////////////////////////////////////////////////////////////
// Stroke cap/join/weight set/update
-
+
+ @Override
public void strokeWeight(float weight) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeWeight(weight);
}
- } else {
+ } else {
updateStrokeWeight(weight);
- }
+ }
}
-
-
+
+
protected void updateStrokeWeight(float newWeight) {
if (PGraphicsOpenGL.same(strokeWeight, newWeight)) return;
- float oldWeight = strokeWeight;
+ float oldWeight = strokeWeight;
strokeWeight = newWeight;
-
+
Arrays.fill(inGeo.strokeWeights, 0, inGeo.vertexCount, strokeWeight);
- if (shapeEnded && tessellated && (hasLines || hasPoints)) {
+ if (shapeEnded && tessellated && (hasLines || hasPoints)) {
float resizeFactor = newWeight / oldWeight;
- if (hasLines) {
+ if (hasLines) {
if (is3D()) {
for (int i = firstLineVertex; i <= lastLineVertex; i++) {
tessGeo.lineAttribs[4 * i + 3] *= resizeFactor;
- }
+ }
root.setModifiedLineAttributes(firstLineVertex, lastLineVertex);
} else if (is2D()) {
- // Changing the stroke weight on a 2D shape needs a
+ // Changing the stroke weight on a 2D shape needs a
// re-tesellation in order to replace the old line
- // geometry.
+ // geometry.
markForTessellation();
}
}
@@ -1014,193 +1036,203 @@ public class PShapeOpenGL extends PShape {
for (int i = firstPointVertex; i <= lastPointVertex; i++) {
tessGeo.pointAttribs[2 * i + 0] *= resizeFactor;
tessGeo.pointAttribs[2 * i + 1] *= resizeFactor;
- }
+ }
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
} else if (is2D()) {
- // Changing the stroke weight on a 2D shape needs a
+ // Changing the stroke weight on a 2D shape needs a
// re-tesellation in order to replace the old point
// geometry.
markForTessellation();
- }
- }
- }
+ }
+ }
+ }
}
+ @Override
public void strokeJoin(int join) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeJoin(join);
}
} else {
if (is2D() && strokeJoin != join) {
- // Changing the stroke join on a 2D shape needs a
+ // Changing the stroke join on a 2D shape needs a
// re-tesellation in order to replace the old join
// geometry.
- markForTessellation();
- }
+ markForTessellation();
+ }
strokeJoin = join;
- }
+ }
}
+ @Override
public void strokeCap(int cap) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeCap(cap);
}
} else {
if (is2D() && strokeCap != cap) {
- // Changing the stroke cap on a 2D shape needs a
- // re-tesellation in order to replace the old cap
+ // Changing the stroke cap on a 2D shape needs a
+ // re-tesellation in order to replace the old cap
// geometry.
- markForTessellation();
+ markForTessellation();
}
- strokeCap = cap;
- }
+ strokeCap = cap;
+ }
}
-
-
+
+
//////////////////////////////////////////////////////////////
// Fill set/update
-
+
+ @Override
public void noFill() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.noFill();
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.noFill();
+ }
} else {
fill = false;
updateFillColor(0x0);
}
}
-
+
+ @Override
public void fill(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(rgb);
+ }
} else {
colorCalc(rgb);
fillFromCalc();
}
}
-
+
+ @Override
public void fill(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(rgb, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(rgb, alpha);
+ }
} else {
colorCalc(rgb, alpha);
fillFromCalc();
- }
+ }
}
-
+
+ @Override
public void fill(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(gray);
+ }
} else {
colorCalc(gray);
fillFromCalc();
}
}
-
+
+ @Override
public void fill(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(gray, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(gray, alpha);
+ }
} else {
colorCalc(gray, alpha);
fillFromCalc();
- }
+ }
}
-
+
+ @Override
public void fill(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(x, y, z);
+ }
} else {
colorCalc(x, y, z);
fillFromCalc();
- }
+ }
}
-
+
+ @Override
public void fill(float x, float y, float z, float a) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.fill(x, y, z, a);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.fill(x, y, z, a);
+ }
} else {
colorCalc(x, y, z, a);
fillFromCalc();
- }
+ }
}
-
+
protected void fillFromCalc() {
fill = true;
updateFillColor(calcColor);
- }
-
-
+ }
+
+
protected void updateFillColor(int newFillColor) {
if (fillColor == newFillColor) return;
fillColor = newFillColor;
-
+
if (texture == null) {
- Arrays.fill(inGeo.colors, 0, inGeo.vertexCount,
+ Arrays.fill(inGeo.colors, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(fillColor));
- if (shapeEnded && tessellated && hasPolys) {
+ if (shapeEnded && tessellated && hasPolys) {
if (is3D()) {
- Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1,
- PGL.javaToNativeARGB(fillColor));
+ Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1,
+ PGL.javaToNativeARGB(fillColor));
root.setModifiedPolyColors(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polyColors, firstPolyVertex, last1,
- PGL.javaToNativeARGB(fillColor));
+ Arrays.fill(tessGeo.polyColors, firstPolyVertex, last1,
+ PGL.javaToNativeARGB(fillColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
- }
- }
+ }
+ }
}
-
-
+
+
//////////////////////////////////////////////////////////////
- // Stroke (color) set/update
-
-
+ // Stroke (color) set/update
+
+
+ @Override
public void noStroke() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.noStroke();
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.noStroke();
+ }
} else {
if (stroke) {
// Disabling stroke on a shape previously with
@@ -1208,93 +1240,99 @@ public class PShapeOpenGL extends PShape {
// the additional geometry of lines and/or points.
markForTessellation();
stroke = false;
- }
+ }
updateStrokeColor(0x0);
if (is2D() && parent != null) {
((PShapeOpenGL)parent).strokedTexture(false);
}
- }
+ }
}
-
-
+
+
+ @Override
public void stroke(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(rgb);
+ }
} else {
colorCalc(rgb);
- strokeFromCalc();
- }
+ strokeFromCalc();
+ }
}
-
-
+
+
+ @Override
public void stroke(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(rgb, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(rgb, alpha);
+ }
} else {
colorCalc(rgb, alpha);
- strokeFromCalc();
+ strokeFromCalc();
}
}
-
+
+ @Override
public void stroke(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(gray);
+ }
} else {
colorCalc(gray);
strokeFromCalc();
- }
+ }
}
-
+
+ @Override
public void stroke(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(gray, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(gray, alpha);
+ }
} else {
colorCalc(gray, alpha);
- strokeFromCalc();
+ strokeFromCalc();
}
}
-
+
+ @Override
public void stroke(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(x, y, z);
+ }
} else {
colorCalc(x, y, z);
- strokeFromCalc();
+ strokeFromCalc();
}
}
-
+
+ @Override
public void stroke(float x, float y, float z, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.stroke(x, y, z, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.stroke(x, y, z, alpha);
+ }
} else {
colorCalc(x, y, z, alpha);
- strokeFromCalc();
+ strokeFromCalc();
}
}
-
-
+
+
protected void strokeFromCalc() {
if (!stroke) {
// Enabling stroke on a shape previously without
@@ -1302,476 +1340,502 @@ public class PShapeOpenGL extends PShape {
// the additional geometry of lines and/or points.
markForTessellation();
stroke = true;
- }
+ }
updateStrokeColor(calcColor);
if (is2D() && texture != null && parent != null) {
((PShapeOpenGL)parent).strokedTexture(true);
}
}
-
- protected void updateStrokeColor(int newStrokeColor) {
+
+ protected void updateStrokeColor(int newStrokeColor) {
if (strokeColor == newStrokeColor) return;
strokeColor = newStrokeColor;
-
- Arrays.fill(inGeo.strokeColors, 0, inGeo.vertexCount,
+
+ Arrays.fill(inGeo.strokeColors, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(strokeColor));
if (shapeEnded && tessellated && (hasLines || hasPoints)) {
- if (hasLines) {
+ if (hasLines) {
if (is3D()) {
- Arrays.fill(tessGeo.lineColors, firstLineVertex, lastLineVertex + 1,
- PGL.javaToNativeARGB(strokeColor));
+ Arrays.fill(tessGeo.lineColors, firstLineVertex, lastLineVertex + 1,
+ PGL.javaToNativeARGB(strokeColor));
root.setModifiedLineColors(firstLineVertex, lastLineVertex);
} else if (is2D()) {
- Arrays.fill(tessGeo.polyColors, firstLineVertex, lastLineVertex + 1,
+ Arrays.fill(tessGeo.polyColors, firstLineVertex, lastLineVertex + 1,
PGL.javaToNativeARGB(strokeColor));
root.setModifiedPolyColors(firstLineVertex, lastLineVertex);
}
}
if (hasPoints) {
if (is3D()) {
- Arrays.fill(tessGeo.pointColors, firstPointVertex, lastPointVertex + 1,
+ Arrays.fill(tessGeo.pointColors, firstPointVertex, lastPointVertex + 1,
PGL.javaToNativeARGB(strokeColor));
root.setModifiedPointColors(firstPointVertex, lastPointVertex);
} else if (is2D()) {
- Arrays.fill(tessGeo.polyColors, firstPointVertex, lastPointVertex + 1,
+ Arrays.fill(tessGeo.polyColors, firstPointVertex, lastPointVertex + 1,
PGL.javaToNativeARGB(strokeColor));
- root.setModifiedPolyColors(firstPointVertex, lastPointVertex);
+ root.setModifiedPolyColors(firstPointVertex, lastPointVertex);
}
- }
- }
- }
+ }
+ }
+ }
+
-
//////////////////////////////////////////////////////////////
- // Tint set/update
-
-
+ // Tint set/update
+
+
+ @Override
public void noTint() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.noTint();
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.noTint();
+ }
} else {
tint = false;
- updateTintColor(0x0);
- }
- }
-
-
+ updateTintColor(0x0);
+ }
+ }
+
+
+ @Override
public void tint(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(rgb);
+ }
} else {
colorCalc(rgb);
- tintFromCalc();
+ tintFromCalc();
}
- }
-
-
+ }
+
+
+ @Override
public void tint(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(rgb, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(rgb, alpha);
+ }
} else {
colorCalc(rgb, alpha);
- tintFromCalc();
+ tintFromCalc();
}
}
-
-
+
+
+ @Override
public void tint(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(gray);
+ }
} else {
colorCalc(gray);
- tintFromCalc();
- }
+ tintFromCalc();
+ }
}
-
-
+
+
+ @Override
public void tint(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(gray, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(gray, alpha);
+ }
} else {
colorCalc(gray, alpha);
- tintFromCalc();
- }
+ tintFromCalc();
+ }
}
-
+
+ @Override
public void tint(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(x, y, z);
+ }
} else {
colorCalc(x, y, z);
- tintFromCalc();
- }
+ tintFromCalc();
+ }
}
-
-
+
+
+ @Override
public void tint(float x, float y, float z, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.tint(x, y, z, alpha);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.tint(x, y, z, alpha);
+ }
} else {
colorCalc(x, y, z, alpha);
- tintFromCalc();
- }
- }
-
-
+ tintFromCalc();
+ }
+ }
+
+
protected void tintFromCalc() {
tint = true;
- updateTintColor(calcColor);
- }
-
-
+ updateTintColor(calcColor);
+ }
+
+
protected void updateTintColor(int newTintColor) {
if (tintColor == newTintColor) return;
tintColor = newTintColor;
-
+
if (texture != null) {
- Arrays.fill(inGeo.colors, 0, inGeo.vertexCount,
+ Arrays.fill(inGeo.colors, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(tintColor));
- if (shapeEnded && tessellated && hasPolys) {
+ if (shapeEnded && tessellated && hasPolys) {
if (is3D()) {
- Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1,
- PGL.javaToNativeARGB(tintColor));
+ Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1,
+ PGL.javaToNativeARGB(tintColor));
root.setModifiedPolyColors(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polyColors, firstPolyVertex, last1,
- PGL.javaToNativeARGB(tintColor));
- root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
+ Arrays.fill(tessGeo.polyColors, firstPolyVertex, last1,
+ PGL.javaToNativeARGB(tintColor));
+ root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
- }
- }
+ }
+ }
}
-
-
+
+
//////////////////////////////////////////////////////////////
// Ambient set/update
-
-
+
+
+ @Override
public void ambient(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.ambient(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.ambient(rgb);
+ }
} else {
colorCalc(rgb);
- ambientFromCalc();
- }
+ ambientFromCalc();
+ }
}
+ @Override
public void ambient(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.ambient(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.ambient(gray);
+ }
} else {
colorCalc(gray);
- ambientFromCalc();
- }
+ ambientFromCalc();
+ }
}
+ @Override
public void ambient(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.ambient(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.ambient(x, y, z);
+ }
} else {
colorCalc(x, y, z);
- ambientFromCalc();
- }
+ ambientFromCalc();
+ }
}
-
-
- protected void ambientFromCalc() {
- updateAmbientColor(calcColor);
- }
-
- protected void updateAmbientColor(int newAmbientColor) {
+
+ protected void ambientFromCalc() {
+ updateAmbientColor(calcColor);
+ }
+
+
+ protected void updateAmbientColor(int newAmbientColor) {
if (ambientColor == newAmbientColor) return;
ambientColor = newAmbientColor;
-
- Arrays.fill(inGeo.ambient, 0, inGeo.vertexCount,
+
+ Arrays.fill(inGeo.ambient, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(ambientColor));
- if (shapeEnded && tessellated && hasPolys) {
+ if (shapeEnded && tessellated && hasPolys) {
if (is3D()) {
- Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, lastPolyVertex = 1,
- PGL.javaToNativeARGB(ambientColor));
+ Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, lastPolyVertex = 1,
+ PGL.javaToNativeARGB(ambientColor));
root.setModifiedPolyAmbient(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, last1,
- PGL.javaToNativeARGB(ambientColor));
- root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
+ Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, last1,
+ PGL.javaToNativeARGB(ambientColor));
+ root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
- }
+ }
}
-
-
+
+
//////////////////////////////////////////////////////////////
- // Specular set/update
-
+ // Specular set/update
+
+ @Override
public void specular(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.specular(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.specular(rgb);
+ }
} else {
colorCalc(rgb);
- specularFromCalc();
- }
+ specularFromCalc();
+ }
}
+ @Override
public void specular(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.specular(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.specular(gray);
+ }
} else {
colorCalc(gray);
- specularFromCalc();
- }
+ specularFromCalc();
+ }
}
+ @Override
public void specular(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.specular(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.specular(x, y, z);
+ }
} else {
colorCalc(x, y, z);
- specularFromCalc();
- }
- }
-
-
- protected void specularFromCalc() {
- updateSpecularColor(calcColor);
+ specularFromCalc();
+ }
}
-
+
+ protected void specularFromCalc() {
+ updateSpecularColor(calcColor);
+ }
+
+
protected void updateSpecularColor(int newSpecularColor) {
if (specularColor == newSpecularColor) return;
specularColor = newSpecularColor;
-
- Arrays.fill(inGeo.specular, 0, inGeo.vertexCount,
+
+ Arrays.fill(inGeo.specular, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(specularColor));
- if (shapeEnded && tessellated && hasPolys) {
+ if (shapeEnded && tessellated && hasPolys) {
if (is3D()) {
- Arrays.fill(tessGeo.polySpecular, firstPolyVertex, lastPolyVertex + 1,
- PGL.javaToNativeARGB(specularColor));
+ Arrays.fill(tessGeo.polySpecular, firstPolyVertex, lastPolyVertex + 1,
+ PGL.javaToNativeARGB(specularColor));
root.setModifiedPolySpecular(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polySpecular, firstPolyVertex, last1,
- PGL.javaToNativeARGB(specularColor));
+ Arrays.fill(tessGeo.polySpecular, firstPolyVertex, last1,
+ PGL.javaToNativeARGB(specularColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
- }
+ }
}
}
-
-
+
+
//////////////////////////////////////////////////////////////
// Emissive set/update
-
-
+
+
+ @Override
public void emissive(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.emissive(rgb);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.emissive(rgb);
+ }
} else {
colorCalc(rgb);
- emissiveFromCalc();
- }
+ emissiveFromCalc();
+ }
}
+ @Override
public void emissive(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.emissive(gray);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.emissive(gray);
+ }
} else {
colorCalc(gray);
- emissiveFromCalc();
- }
+ emissiveFromCalc();
+ }
}
+ @Override
public void emissive(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.emissive(x, y, z);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.emissive(x, y, z);
+ }
} else {
colorCalc(x, y, z);
- emissiveFromCalc();
- }
- }
-
-
- protected void emissiveFromCalc() {
- updateEmissiveColor(calcColor);
+ emissiveFromCalc();
+ }
}
-
- protected void updateEmissiveColor(int newEmissiveColor) {
+
+ protected void emissiveFromCalc() {
+ updateEmissiveColor(calcColor);
+ }
+
+
+ protected void updateEmissiveColor(int newEmissiveColor) {
if (emissiveColor == newEmissiveColor) return;
- emissiveColor = newEmissiveColor;
-
- Arrays.fill(inGeo.emissive, 0, inGeo.vertexCount,
+ emissiveColor = newEmissiveColor;
+
+ Arrays.fill(inGeo.emissive, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(emissiveColor));
- if (shapeEnded && tessellated && 0 < tessGeo.polyVertexCount) {
+ if (shapeEnded && tessellated && 0 < tessGeo.polyVertexCount) {
if (is3D()) {
- Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, lastPolyVertex + 1,
- PGL.javaToNativeARGB(emissiveColor));
+ Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, lastPolyVertex + 1,
+ PGL.javaToNativeARGB(emissiveColor));
root.setModifiedPolyEmissive(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, last1,
- PGL.javaToNativeARGB(emissiveColor));
+ Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, last1,
+ PGL.javaToNativeARGB(emissiveColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
- }
+ }
}
-
-
+
+
//////////////////////////////////////////////////////////////
- // Shininess set/update
-
-
+ // Shininess set/update
+
+
+ @Override
public void shininess(float shine) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
- PShapeOpenGL child = (PShapeOpenGL) children[i];
- child.shininess(shine);
- }
+ PShapeOpenGL child = (PShapeOpenGL) children[i];
+ child.shininess(shine);
+ }
} else {
- updateShininessFactor(shine);
- }
+ updateShininessFactor(shine);
+ }
}
-
-
+
+
protected void updateShininessFactor(float newShininess) {
if (PGraphicsOpenGL.same(shininess, newShininess)) return;
- shininess = newShininess;
-
+ shininess = newShininess;
+
Arrays.fill(inGeo.shininess, 0, inGeo.vertexCount, shininess);
- if (shapeEnded && tessellated && hasPolys) {
+ if (shapeEnded && tessellated && hasPolys) {
if (is3D()) {
- Arrays.fill(tessGeo.polyShininess, firstPolyVertex, lastPolyVertex + 1,
- shininess);
+ Arrays.fill(tessGeo.polyShininess, firstPolyVertex, lastPolyVertex + 1,
+ shininess);
root.setModifiedPolyShininess(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
- Arrays.fill(tessGeo.polyShininess, firstPolyVertex, last1, shininess);
+ Arrays.fill(tessGeo.polyShininess, firstPolyVertex, last1, shininess);
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Geometric transformations
-
-
+
+
+ @Override
public void translate(float tx, float ty) {
transform(TRANSLATE, tx, ty);
}
-
-
+
+
+ @Override
public void translate(float tx, float ty, float tz) {
transform(TRANSLATE, tx, ty, tz);
}
-
-
+
+
+ @Override
public void rotate(float angle) {
transform(ROTATE, angle);
}
-
-
+
+
+ @Override
public void rotate(float angle, float v0, float v1, float v2) {
transform(ROTATE, angle, v0, v1, v2);
}
-
-
+
+
+ @Override
public void scale(float s) {
transform(SCALE, s, s);
}
+ @Override
public void scale(float x, float y) {
transform(SCALE, x, y);
}
+ @Override
public void scale(float x, float y, float z) {
transform(SCALE, x, y, z);
- }
+ }
-
+
+ @Override
public void applyMatrix(PMatrix2D source) {
transform(MATRIX, source.m00, source.m01, source.m02,
- source.m10, source.m11, source.m12);
+ source.m10, source.m11, source.m12);
}
-
+
+ @Override
public void applyMatrix(float n00, float n01, float n02,
float n10, float n11, float n12) {
transform(MATRIX, n00, n01, n02,
@@ -1779,6 +1843,7 @@ public class PShapeOpenGL extends PShape {
}
+ @Override
public void applyMatrix(float n00, float n01, float n02, float n03,
float n10, float n11, float n12, float n13,
float n20, float n21, float n22, float n23,
@@ -1788,8 +1853,9 @@ public class PShapeOpenGL extends PShape {
n20, n21, n22, n23,
n30, n31, n32, n33);
}
-
-
+
+
+ @Override
public void resetMatrix() {
if (shapeEnded && matrix != null) {
if (family == GROUP) {
@@ -1806,8 +1872,8 @@ public class PShapeOpenGL extends PShape {
}
}
}
-
-
+
+
protected void transform(int type, float... args) {
int dimensions;
if (type == ROTATE) {
@@ -1816,20 +1882,20 @@ public class PShapeOpenGL extends PShape {
dimensions = args.length == 6 ? 2 : 3;
} else {
dimensions = args.length;
- }
+ }
transformImpl(type, dimensions, args);
}
-
-
+
+
protected void transformImpl(int type, int ncoords, float... args) {
checkMatrix(ncoords);
- calcTransform(type, ncoords, args);
+ calcTransform(type, ncoords, args);
if (tessellated) {
applyMatrixImpl(transform);
}
}
-
-
+
+
protected void calcTransform(int type, int dimensions, float... args) {
if (transform == null) {
if (dimensions == 2) {
@@ -1840,7 +1906,7 @@ public class PShapeOpenGL extends PShape {
} else {
transform.reset();
}
-
+
switch (type) {
case TRANSLATE:
if (dimensions == 3) {
@@ -1873,50 +1939,52 @@ public class PShapeOpenGL extends PShape {
transform.set(args[0], args[1], args[2],
args[3], args[4], args[5]);
}
- break;
- }
+ break;
+ }
matrix.apply(transform);
}
-
-
+
+
protected void applyMatrixImpl(PMatrix matrix) {
if (hasPolys) {
- tessGeo.applyMatrixOnPolyGeometry(matrix,
- firstPolyVertex, lastPolyVertex);
+ tessGeo.applyMatrixOnPolyGeometry(matrix,
+ firstPolyVertex, lastPolyVertex);
root.setModifiedPolyVertices(firstPolyVertex, lastPolyVertex);
root.setModifiedPolyNormals(firstPolyVertex, lastPolyVertex);
}
-
+
if (is3D()) {
if (hasLines) {
- tessGeo.applyMatrixOnLineGeometry(matrix,
- firstLineVertex, lastLineVertex);
+ tessGeo.applyMatrixOnLineGeometry(matrix,
+ firstLineVertex, lastLineVertex);
root.setModifiedLineVertices(firstLineVertex, lastLineVertex);
root.setModifiedLineAttributes(firstLineVertex, lastLineVertex);
- }
-
+ }
+
if (hasPoints) {
- tessGeo.applyMatrixOnPointGeometry(matrix,
- firstPointVertex, lastPointVertex);
+ tessGeo.applyMatrixOnPointGeometry(matrix,
+ firstPointVertex, lastPointVertex);
root.setModifiedPointVertices(firstPointVertex, lastPointVertex);
- }
+ }
}
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
- // Bezier curves
-
-
+
+ // Bezier curves
+
+
+ @Override
public void bezierDetail(int detail) {
bezierDetail = detail;
pg.bezierDetail(detail);
- }
-
-
+ }
+
+
+ @Override
public void bezierVertex(float x2, float y2,
float x3, float y3,
float x4, float y4) {
@@ -1924,8 +1992,9 @@ public class PShapeOpenGL extends PShape {
x3, y3, 0,
x4, y4, 0);
}
-
+
+ @Override
public void bezierVertex(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
@@ -1933,8 +2002,8 @@ public class PShapeOpenGL extends PShape {
x3, y3, z3,
x4, y4, z4);
}
-
-
+
+
protected void bezierVertexImpl(float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4) {
@@ -1944,85 +2013,93 @@ public class PShapeOpenGL extends PShape {
inGeo.addBezierVertex(x2, y2, z2,
x3, y3, z3,
x4, y4, z4,
- fill, stroke, bezierDetail, vertexCode(), kind);
+ fill, stroke, bezierDetail, vertexCode(), kind);
}
-
-
+
+
+ @Override
public void quadraticVertex(float cx, float cy,
float x3, float y3) {
quadraticVertexImpl(cx, cy, 0,
x3, y3, 0);
- }
+ }
-
+
+ @Override
public void quadraticVertex(float cx, float cy, float cz,
float x3, float y3, float z3) {
quadraticVertexImpl(cx, cy, cz,
- x3, y3, z3);
+ x3, y3, z3);
}
-
-
+
+
protected void quadraticVertexImpl(float cx, float cy, float cz,
float x3, float y3, float z3) {
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
- inGeo.setNormal(normalX, normalY, normalZ);
+ inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addQuadraticVertex(cx, cy, cz,
x3, y3, z3,
- fill, stroke, bezierDetail, vertexCode(), kind);
+ fill, stroke, bezierDetail, vertexCode(), kind);
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Catmull-Rom curves
-
+
+ @Override
public void curveDetail(int detail) {
curveDetail = detail;
pg.curveDetail(detail);
}
-
-
+
+
+ @Override
public void curveTightness(float tightness) {
curveTightness = tightness;
pg.curveTightness(tightness);
- }
-
-
+ }
+
+
+ @Override
public void curveVertex(float x, float y) {
curveVertexImpl(x, y, 0);
- }
+ }
-
+
+ @Override
public void curveVertex(float x, float y, float z) {
curveVertexImpl(x, y, z);
}
-
-
+
+
protected void curveVertexImpl(float x, float y, float z) {
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addCurveVertex(x, y, z,
- fill, stroke, curveDetail, vertexCode(), kind);
+ fill, stroke, curveDetail, vertexCode(), kind);
}
-
-
- ///////////////////////////////////////////////////////////
-
- //
-
- // Setters/getters of individual vertices
-
+
+ ///////////////////////////////////////////////////////////
+
+ //
+
+ // Setters/getters of individual vertices
+
+
+ @Override
public int getVertexCount() {
- return inGeo.vertexCount;
+ return inGeo.vertexCount;
}
-
-
+
+
+ @Override
public PVector getVertex(int index, PVector vec) {
if (vec == null) {
vec = new PVector();
@@ -2032,44 +2109,51 @@ public class PShapeOpenGL extends PShape {
vec.z = inGeo.vertices[3 * index + 2];
return vec;
}
-
-
+
+
+ @Override
public float getVertexX(int index) {
return inGeo.vertices[3 * index + 0];
}
-
-
+
+
+ @Override
public float getVertexY(int index) {
return inGeo.vertices[3 * index + 1];
}
-
-
+
+
+ @Override
public float getVertexZ(int index) {
return inGeo.vertices[3 * index + 2];
}
-
-
+
+
+ @Override
public void setVertex(int index, float x, float y) {
setVertex(index, x, y, 0);
}
-
-
- public void setVertex(int index, float x, float y, float z) {
+
+
+ @Override
+ public void setVertex(int index, float x, float y, float z) {
inGeo.vertices[3 * index + 0] = x;
inGeo.vertices[3 * index + 1] = y;
inGeo.vertices[3 * index + 2] = z;
markForTessellation();
}
-
-
+
+
+ @Override
public void setVertex(int index, PVector vec) {
inGeo.vertices[3 * index + 0] = vec.x;
inGeo.vertices[3 * index + 1] = vec.y;
inGeo.vertices[3 * index + 2] = vec.z;
- markForTessellation();
+ markForTessellation();
}
-
-
+
+
+ @Override
public PVector getNormal(int index, PVector vec) {
if (vec == null) {
vec = new PVector();
@@ -2079,133 +2163,155 @@ public class PShapeOpenGL extends PShape {
vec.z = inGeo.normals[3 * index + 2];
return vec;
}
-
-
+
+
+ @Override
public float getNormalX(int index) {
return inGeo.normals[3 * index + 0];
}
-
+
+ @Override
public float getNormalY(int index) {
return inGeo.normals[3 * index + 1];
- }
+ }
-
+
+ @Override
public float getNormalZ(int index) {
return inGeo.normals[3 * index + 2];
- }
-
-
- public void setNormal(int index, float nx, float ny, float nz) {
+ }
+
+
+ @Override
+ public void setNormal(int index, float nx, float ny, float nz) {
inGeo.normals[3 * index + 0] = nx;
inGeo.normals[3 * index + 1] = ny;
inGeo.normals[3 * index + 2] = nz;
markForTessellation();
}
-
-
+
+
+ @Override
public float getTextureU(int index) {
return inGeo.texcoords[2 * index + 0];
}
-
+
+ @Override
public float getTextureV(int index) {
return inGeo.texcoords[2 * index + 1];
- }
-
-
- public void setTextureUV(int index, float u, float v) {
+ }
+
+
+ @Override
+ public void setTextureUV(int index, float u, float v) {
inGeo.texcoords[2 * index + 0] = u;
inGeo.texcoords[2 * index + 1] = v;
markForTessellation();
}
-
-
+
+
+ @Override
public int getFill(int index) {
return PGL.nativeToJavaARGB(inGeo.colors[index]);
}
-
- public void setFill(int index, int fill) {
+
+ @Override
+ public void setFill(int index, int fill) {
inGeo.colors[index] = PGL.javaToNativeARGB(fill);
markForTessellation();
- }
-
-
+ }
+
+
+ @Override
public int getStroke(int index) {
return PGL.nativeToJavaARGB(inGeo.strokeColors[index]);
}
-
- public void setStroke(int index, int stroke) {
+
+ @Override
+ public void setStroke(int index, int stroke) {
inGeo.strokeColors[index] = PGL.javaToNativeARGB(stroke);
markForTessellation();
- }
-
-
+ }
+
+
+ @Override
public float getStrokeWeight(int index) {
return inGeo.strokeWeights[index];
}
-
- public void setStrokeWeight(int index, float weight) {
+
+ @Override
+ public void setStrokeWeight(int index, float weight) {
inGeo.strokeWeights[index] = weight;
markForTessellation();
- }
+ }
-
+
+ @Override
public int getAmbient(int index) {
return PGL.nativeToJavaARGB(inGeo.ambient[index]);
}
-
- public void setAmbient(int index, int ambient) {
+
+ @Override
+ public void setAmbient(int index, int ambient) {
inGeo.ambient[index] = PGL.javaToNativeARGB(ambient);
markForTessellation();
- }
-
+ }
+
+ @Override
public int getSpecular(int index) {
return PGL.nativeToJavaARGB(inGeo.specular[index]);
}
-
- public void setSpecular(int index, int specular) {
+
+ @Override
+ public void setSpecular(int index, int specular) {
inGeo.specular[index] = PGL.javaToNativeARGB(specular);
markForTessellation();
- }
-
-
- public int getEmissive(int index) {
+ }
+
+
+ @Override
+ public int getEmissive(int index) {
return PGL.nativeToJavaARGB(inGeo.emissive[index]);
}
-
- public void setEmissive(int index, int emissive) {
+
+ @Override
+ public void setEmissive(int index, int emissive) {
inGeo.emissive[index] = PGL.javaToNativeARGB(emissive);
markForTessellation();
- }
-
-
+ }
+
+
+ @Override
public float getShininess(int index) {
return inGeo.shininess[index];
}
-
- public void setShininess(int index, float shine) {
+
+ @Override
+ public void setShininess(int index, float shine) {
inGeo.shininess[index] = shine;
markForTessellation();
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Tessellated geometry getter.
-
+
+ @Override
public PShape getTessellation() {
updateTessellation();
-
+
float[] vertices = tessGeo.polyVertices;
float[] normals = tessGeo.polyNormals;
int[] color = tessGeo.polyColors;
@@ -2214,125 +2320,125 @@ public class PShapeOpenGL extends PShape {
PShape tess;
if (is3D()) {
- tess = PGraphics3D.createShapeImpl(pg.parent, TRIANGLES);
+ tess = PGraphics3D.createShapeImpl(pg.parent, TRIANGLES);
} else if (is2D()) {
tess = PGraphics2D.createShapeImpl(pg.parent, TRIANGLES);
} else {
PGraphics.showWarning("This shape is not either 2D or 3D!");
return null;
- }
+ }
tess.noStroke();
-
+
IndexCache cache = tessGeo.polyIndexCache;
- for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
+ for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
+
for (int tr = ioffset / 3; tr < (ioffset + icount) / 3; tr++) {
int i0 = voffset + indices[3 * tr + 0];
int i1 = voffset + indices[3 * tr + 1];
int i2 = voffset + indices[3 * tr + 2];
if (is3D()) {
- float x0 = vertices[4 * i0 + 0];
- float y0 = vertices[4 * i0 + 1];
+ float x0 = vertices[4 * i0 + 0];
+ float y0 = vertices[4 * i0 + 1];
float z0 = vertices[4 * i0 + 2];
- float x1 = vertices[4 * i1 + 0];
- float y1 = vertices[4 * i1 + 1];
+ float x1 = vertices[4 * i1 + 0];
+ float y1 = vertices[4 * i1 + 1];
float z1 = vertices[4 * i1 + 2];
- float x2 = vertices[4 * i2 + 0];
- float y2 = vertices[4 * i2 + 1];
+ float x2 = vertices[4 * i2 + 0];
+ float y2 = vertices[4 * i2 + 1];
float z2 = vertices[4 * i2 + 2];
-
- float nx0 = normals[3 * i0 + 0];
- float ny0 = normals[3 * i0 + 1];
+
+ float nx0 = normals[3 * i0 + 0];
+ float ny0 = normals[3 * i0 + 1];
float nz0 = normals[3 * i0 + 2];
- float nx1 = normals[3 * i1 + 0];
- float ny1 = normals[3 * i1 + 1];
+ float nx1 = normals[3 * i1 + 0];
+ float ny1 = normals[3 * i1 + 1];
float nz1 = normals[3 * i1 + 2];
- float nx2 = normals[3 * i2 + 0];
- float ny2 = normals[3 * i2 + 1];
+ float nx2 = normals[3 * i2 + 0];
+ float ny2 = normals[3 * i2 + 1];
float nz2 = normals[3 * i2 + 2];
-
+
int argb0 = PGL.nativeToJavaARGB(color[i0]);
int argb1 = PGL.nativeToJavaARGB(color[i1]);
- int argb2 = PGL.nativeToJavaARGB(color[i2]);
-
+ int argb2 = PGL.nativeToJavaARGB(color[i2]);
+
tess.fill(argb0);
tess.normal(nx0, ny0, nz0);
tess.vertex(x0, y0, z0, uv[2 * i0 + 0], uv[2 * i0 + 1]);
-
+
tess.fill(argb1);
tess.normal(nx1, ny1, nz1);
tess.vertex(x1, y1, z1, uv[2 * i1 + 0], uv[2 * i1 + 1]);
-
+
tess.fill(argb2);
tess.normal(nx2, ny2, nz2);
- tess.vertex(x2, y2, z2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
+ tess.vertex(x2, y2, z2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
} else if (is2D()) {
float x0 = vertices[4 * i0 + 0], y0 = vertices[4 * i0 + 1];
float x1 = vertices[4 * i1 + 0], y1 = vertices[4 * i1 + 1];
float x2 = vertices[4 * i2 + 0], y2 = vertices[4 * i2 + 1];
-
+
int argb0 = PGL.nativeToJavaARGB(color[i0]);
int argb1 = PGL.nativeToJavaARGB(color[i1]);
- int argb2 = PGL.nativeToJavaARGB(color[i2]);
-
+ int argb2 = PGL.nativeToJavaARGB(color[i2]);
+
tess.fill(argb0);
tess.vertex(x0, y0, uv[2 * i0 + 0], uv[2 * i0 + 1]);
-
+
tess.fill(argb1);
tess.vertex(x1, y1, uv[2 * i1 + 0], uv[2 * i1 + 1]);
-
+
tess.fill(argb2);
- tess.vertex(x2, y2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
+ tess.vertex(x2, y2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
}
}
}
tess.end();
-
+
return tess;
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Tessellation
-
-
+
+
protected void updateTessellation() {
if (!root.tessellated || root.contextIsOutdated()) {
root.tessellate();
root.aggregate();
}
}
-
-
+
+
protected void markForTessellation() {
root.tessellated = false;
tessellated = false;
}
-
+
protected void tessellate() {
- if (root == this && parent == null) {
+ if (root == this && parent == null) {
if (tessGeo == null) {
tessGeo = pg.newTessGeometry(PGraphicsOpenGL.RETAINED);
- }
+ }
tessGeo.clear();
-
+
tessellateImpl();
-
- // Tessellated arrays are trimmed since they are expanded
- // by doubling their old size, which might lead to arrays
- // larger than the vertex counts.
- tessGeo.trim();
-
+
+ // Tessellated arrays are trimmed since they are expanded
+ // by doubling their old size, which might lead to arrays
+ // larger than the vertex counts.
+ tessGeo.trim();
+
modified = false;
- needBufferInit = true;
-
+ needBufferInit = true;
+
modifiedPolyVertices = false;
modifiedPolyColors = false;
modifiedPolyNormals = false;
@@ -2341,16 +2447,16 @@ public class PShapeOpenGL extends PShape {
modifiedPolySpecular = false;
modifiedPolyEmissive = false;
modifiedPolyShininess = false;
-
+
modifiedLineVertices = false;
modifiedLineColors = false;
modifiedLineAttributes = false;
modifiedPointVertices = false;
modifiedPointColors = false;
- modifiedPointAttributes = false;
-
- firstModifiedPolyVertex = PConstants.MAX_INT;
+ modifiedPointAttributes = false;
+
+ firstModifiedPolyVertex = PConstants.MAX_INT;
lastModifiedPolyVertex = PConstants.MIN_INT;
firstModifiedPolyColor = PConstants.MAX_INT;
lastModifiedPolyColor = PConstants.MIN_INT;
@@ -2366,29 +2472,29 @@ public class PShapeOpenGL extends PShape {
lastModifiedPolyEmissive = PConstants.MIN_INT;
firstModifiedPolyShininess = PConstants.MAX_INT;
lastModifiedPolyShininess = PConstants.MIN_INT;
-
+
firstModifiedLineVertex = PConstants.MAX_INT;
lastModifiedLineVertex = PConstants.MIN_INT;
firstModifiedLineColor = PConstants.MAX_INT;
lastModifiedLineColor = PConstants.MIN_INT;
firstModifiedLineAttribute = PConstants.MAX_INT;
lastModifiedLineAttribute = PConstants.MIN_INT;
-
+
firstModifiedPointVertex = PConstants.MAX_INT;
lastModifiedPointVertex = PConstants.MIN_INT;
firstModifiedPointColor = PConstants.MAX_INT;
lastModifiedPointColor = PConstants.MIN_INT;
firstModifiedPointAttribute = PConstants.MAX_INT;
- lastModifiedPointAttribute = PConstants.MIN_INT;
- }
+ lastModifiedPointAttribute = PConstants.MIN_INT;
+ }
}
-
+
protected void tessellateImpl() {
tessGeo = root.tessGeo;
firstPolyIndexCache = -1;
- lastPolyIndexCache = -1;
+ lastPolyIndexCache = -1;
firstLineIndexCache = -1;
lastLineIndexCache = -1;
firstPointIndexCache = -1;
@@ -2399,14 +2505,14 @@ public class PShapeOpenGL extends PShape {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tessellateImpl();
}
- } else {
- if (shapeEnded) {
+ } else {
+ if (shapeEnded) {
// If the geometry was tessellated previously, then
// the edges information will still be stored in the
// input object, so it needs to be removed to avoid
// duplication.
inGeo.clearEdges();
-
+
tessellator.setInGeometry(inGeo);
tessellator.setTessGeometry(tessGeo);
tessellator.setFill(fill || texture != null);
@@ -2414,14 +2520,14 @@ public class PShapeOpenGL extends PShape {
tessellator.setStrokeColor(strokeColor);
tessellator.setStrokeWeight(strokeWeight);
tessellator.setStrokeCap(strokeCap);
- tessellator.setStrokeJoin(strokeJoin);
+ tessellator.setStrokeJoin(strokeJoin);
tessellator.setTexCache(null, null, null);
tessellator.setTransform(matrix);
- tessellator.set3D(is3D());
-
+ tessellator.set3D(is3D());
+
if (family == GEOMETRY) {
if (kind == POINTS) {
- tessellator.tessellatePoints();
+ tessellator.tessellatePoints();
} else if (kind == LINES) {
tessellator.tessellateLines();
} else if (kind == LINE_STRIP) {
@@ -2436,11 +2542,11 @@ public class PShapeOpenGL extends PShape {
if (stroke) inGeo.addTriangleFanEdges();
if (normalMode == NORMAL_MODE_AUTO) inGeo.calcTriangleFanNormals();
tessellator.tessellateTriangleFan();
- } else if (kind == TRIANGLE_STRIP) {
+ } else if (kind == TRIANGLE_STRIP) {
if (stroke) inGeo.addTriangleStripEdges();
if (normalMode == NORMAL_MODE_AUTO) inGeo.calcTriangleStripNormals();
tessellator.tessellateTriangleStrip();
- } else if (kind == QUAD || kind == QUADS) {
+ } else if (kind == QUAD || kind == QUADS) {
if (stroke) inGeo.addQuadsEdges();
if (normalMode == NORMAL_MODE_AUTO) inGeo.calcQuadsNormals();
tessellator.tessellateQuads();
@@ -2450,23 +2556,23 @@ public class PShapeOpenGL extends PShape {
tessellator.tessellateQuadStrip();
} else if (kind == POLYGON) {
if (stroke) inGeo.addPolygonEdges(isClosed);
- tessellator.tessellatePolygon(isSolid, isClosed,
+ tessellator.tessellatePolygon(isSolid, isClosed,
normalMode == NORMAL_MODE_AUTO);
}
- } else if (family == PRIMITIVE) {
+ } else if (family == PRIMITIVE) {
// The input geometry needs to be cleared because the geometry
// generation methods in InGeometry add the vertices of the
// new primitive to what is already stored.
inGeo.clear();
-
+
if (kind == POINT) {
tessellatePoint();
} else if (kind == LINE) {
- tessellateLine();
+ tessellateLine();
} else if (kind == TRIANGLE) {
- tessellateTriangle();
+ tessellateTriangle();
} else if (kind == QUAD) {
- tessellateQuad();
+ tessellateQuad();
} else if (kind == RECT) {
tessellateRect();
} else if (kind == ELLIPSE) {
@@ -2474,15 +2580,15 @@ public class PShapeOpenGL extends PShape {
} else if (kind == ARC) {
tessellateArc();
} else if (kind == BOX) {
- tessellateBox();
+ tessellateBox();
} else if (kind == SPHERE) {
tessellateSphere();
}
} else if (family == PATH) {
- inGeo.clear();
+ inGeo.clear();
tessellatePath();
}
-
+
if (texture != null && parent != null) {
((PShapeOpenGL)parent).addTexture(texture);
}
@@ -2490,20 +2596,20 @@ public class PShapeOpenGL extends PShape {
firstPolyIndexCache = tessellator.firstPolyIndexCache;
lastPolyIndexCache = tessellator.lastPolyIndexCache;
firstLineIndexCache = tessellator.firstLineIndexCache;
- lastLineIndexCache = tessellator.lastLineIndexCache;
+ lastLineIndexCache = tessellator.lastLineIndexCache;
firstPointIndexCache = tessellator.firstPointIndexCache;
lastPointIndexCache = tessellator.lastPointIndexCache;
}
}
-
+
firstPolyVertex = lastPolyVertex = -1;
firstLineVertex = lastLineVertex = -1;
firstPointVertex = lastPointVertex = -1;
-
+
tessellated = true;
}
-
-
+
+
protected void tessellatePoint() {
float x = 0, y = 0, z = 0;
if (params.length == 2) {
@@ -2515,15 +2621,15 @@ public class PShapeOpenGL extends PShape {
y = params[1];
z = params[2];
}
-
+
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
inGeo.setNormal(normalX, normalY, normalZ);
- inGeo.addPoint(x, y, z, fill, stroke);
- tessellator.tessellatePoints();
+ inGeo.addPoint(x, y, z, fill, stroke);
+ tessellator.tessellatePoints();
}
-
-
+
+
protected void tessellateLine() {
float x1 = 0, y1 = 0, z1 = 0;
float x2 = 0, y2 = 0, z2 = 0;
@@ -2531,26 +2637,26 @@ public class PShapeOpenGL extends PShape {
x1 = params[0];
y1 = params[1];
x2 = params[2];
- y2 = params[3];
+ y2 = params[3];
} else if (params.length == 6) {
x1 = params[0];
y1 = params[1];
z1 = params[2];
x2 = params[3];
y2 = params[4];
- z2 = params[5];
+ z2 = params[5];
}
-
+
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addLine(x1, y1, z1,
x2, y2, z2,
- fill, stroke);
- tessellator.tessellateLines();
+ fill, stroke);
+ tessellator.tessellateLines();
}
-
-
+
+
protected void tessellateTriangle() {
float x1 = 0, y1 = 0;
float x2 = 0, y2 = 0;
@@ -2561,34 +2667,34 @@ public class PShapeOpenGL extends PShape {
x2 = params[2];
y2 = params[3];
x3 = params[4];
- y3 = params[5];
+ y3 = params[5];
}
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor, shininess);
+ ambientColor, specularColor, emissiveColor, shininess);
inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addTriangle(x1, y1, 0,
x2, y2, 0,
x3, y3, 0,
- fill, stroke);
- tessellator.tessellateTriangles();
+ fill, stroke);
+ tessellator.tessellateTriangles();
}
-
-
+
+
protected void tessellateQuad() {
float x1 = 0, y1 = 0;
float x2 = 0, y2 = 0;
float x3 = 0, y3 = 0;
- float x4 = 0, y4 = 0;
+ float x4 = 0, y4 = 0;
if (params.length == 8) {
x1 = params[0];
y1 = params[1];
x2 = params[2];
y2 = params[3];
x3 = params[4];
- y3 = params[5];
+ y3 = params[5];
x4 = params[6];
- y4 = params[7];
+ y4 = params[7];
}
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
@@ -2599,10 +2705,10 @@ public class PShapeOpenGL extends PShape {
x3, y3, 0,
x4, y4, 0,
fill, stroke);
- tessellator.tessellateQuads();
- }
-
-
+ tessellator.tessellateQuads();
+ }
+
+
protected void tessellateRect() {
float a = 0, b = 0, c = 0, d = 0;
float tl = 0, tr = 0, br = 0, bl = 0;
@@ -2618,7 +2724,7 @@ public class PShapeOpenGL extends PShape {
b = params[1];
c = params[2];
d = params[3];
- tl = tr = br = bl = params[4];
+ tl = tr = br = bl = params[4];
rounded = true;
} else if (params.length == 8) {
a = params[0];
@@ -2628,7 +2734,7 @@ public class PShapeOpenGL extends PShape {
tl = params[4];
tr = params[5];
br = params[6];
- bl = params[7];
+ bl = params[7];
rounded = true;
}
@@ -2640,33 +2746,33 @@ public class PShapeOpenGL extends PShape {
inGeo.addRect(a, b, c, d,
tl, tr, br, bl,
fill, stroke, bezierDetail, rectMode);
- tessellator.tessellatePolygon(false, true, true);
+ tessellator.tessellatePolygon(false, true, true);
} else {
inGeo.addRect(a, b, c, d,
fill, stroke, rectMode);
- tessellator.tessellateQuads();
- }
+ tessellator.tessellateQuads();
+ }
}
-
-
+
+
protected void tessellateEllipse() {
float a = 0, b = 0, c = 0, d = 0;
if (params.length == 4) {
a = params[0];
b = params[1];
c = params[2];
- d = params[3];
+ d = params[3];
}
-
+
ellipseMode = CORNER;
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
- inGeo.setNormal(normalX, normalY, normalZ);
+ inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode);
- tessellator.tessellateTriangleFan();
+ tessellator.tessellateTriangleFan();
}
-
-
+
+
protected void tessellateArc() {
float a = 0, b = 0, c = 0, d = 0;
float start = 0, stop = 0;
@@ -2674,37 +2780,37 @@ public class PShapeOpenGL extends PShape {
a = params[0];
b = params[1];
c = params[2];
- d = params[3];
+ d = params[3];
start = params[4];
- stop = params[5];
- }
-
+ stop = params[5];
+ }
+
ellipseMode = CORNER;
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
inGeo.setNormal(normalX, normalY, normalZ);
inGeo.addArc(a, b, c, d, start, stop, fill, stroke, ellipseMode);
- tessellator.tessellateTriangleFan();
+ tessellator.tessellateTriangleFan();
}
-
-
+
+
protected void tessellateBox() {
float w = 0, h = 0, d = 0;
if (params.length == 1) {
- w = h = d = params[0];
+ w = h = d = params[0];
} else if (params.length == 3) {
w = params[0];
h = params[1];
d = params[2];
}
-
+
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor, shininess);
- inGeo.addBox(w, h, d, fill, stroke);
- tessellator.tessellateQuads();
+ ambientColor, specularColor, emissiveColor, shininess);
+ inGeo.addBox(w, h, d, fill, stroke);
+ tessellator.tessellateQuads();
}
-
-
+
+
protected void tessellateSphere() {
// Getting sphere detail from renderer. Is this correct?
int nu = pg.sphereDetailU;
@@ -2713,20 +2819,20 @@ public class PShapeOpenGL extends PShape {
if (params.length == 1) {
r = params[0];
}
-
- inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
- ambientColor, specularColor, emissiveColor, shininess);
- int[] indices = inGeo.addSphere(r, nu, nv, fill, stroke);
- tessellator.tessellateTriangles(indices);
- }
-
-
- protected void tessellatePath() {
- if (vertices == null) return;
-
+
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
ambientColor, specularColor, emissiveColor, shininess);
-
+ int[] indices = inGeo.addSphere(r, nu, nv, fill, stroke);
+ tessellator.tessellateTriangles(indices);
+ }
+
+
+ protected void tessellatePath() {
+ if (vertices == null) return;
+
+ inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
+ ambientColor, specularColor, emissiveColor, shininess);
+
if (vertexCodeCount == 0) { // each point is a simple vertex
if (vertices[0].length == 2) { // tesellating 2D vertices
for (int i = 0; i < vertexCount; i++) {
@@ -2740,7 +2846,7 @@ public class PShapeOpenGL extends PShape {
} else { // coded set of vertices
int idx = 0;
int code = BREAK;
-
+
if (vertices[0].length == 2) { // tessellating a 2D path
for (int j = 0; j < vertexCodeCount; j++) {
@@ -2748,12 +2854,12 @@ public class PShapeOpenGL extends PShape {
case VERTEX:
inGeo.addVertex(vertices[idx][X], vertices[idx][Y], code);
- code = VERTEX;
+ code = VERTEX;
idx++;
break;
case QUAD_BEZIER_VERTEX:
- inGeo.addQuadraticVertex(vertices[idx+0][X], vertices[idx+0][Y], 0,
+ inGeo.addQuadraticVertex(vertices[idx+0][X], vertices[idx+0][Y], 0,
vertices[idx+1][X], vertices[idx+1][Y], 0,
fill, stroke, bezierDetail, code);
code = VERTEX;
@@ -2784,18 +2890,18 @@ public class PShapeOpenGL extends PShape {
switch (vertexCodes[j]) {
case VERTEX:
- inGeo.addVertex(vertices[idx][X], vertices[idx][Y],
+ inGeo.addVertex(vertices[idx][X], vertices[idx][Y],
vertices[idx][Z], code);
code = VERTEX;
idx++;
break;
case QUAD_BEZIER_VERTEX:
- inGeo.addQuadraticVertex(vertices[idx+0][X],
- vertices[idx+0][Y],
+ inGeo.addQuadraticVertex(vertices[idx+0][X],
+ vertices[idx+0][Y],
vertices[idx+0][Z],
- vertices[idx+1][X],
- vertices[idx+1][Y],
+ vertices[idx+1][X],
+ vertices[idx+1][Y],
vertices[idx+0][Z],
fill, stroke, bezierDetail, code);
code = VERTEX;
@@ -2804,14 +2910,14 @@ public class PShapeOpenGL extends PShape {
case BEZIER_VERTEX:
- inGeo.addBezierVertex(vertices[idx+0][X],
- vertices[idx+0][Y],
+ inGeo.addBezierVertex(vertices[idx+0][X],
+ vertices[idx+0][Y],
vertices[idx+0][Z],
- vertices[idx+1][X],
- vertices[idx+1][Y],
+ vertices[idx+1][X],
+ vertices[idx+1][Y],
vertices[idx+1][Z],
- vertices[idx+2][X],
- vertices[idx+2][Y],
+ vertices[idx+2][X],
+ vertices[idx+2][Y],
vertices[idx+2][Z],
fill, stroke, bezierDetail, code);
code = VERTEX;
@@ -2819,8 +2925,8 @@ public class PShapeOpenGL extends PShape {
break;
case CURVE_VERTEX:
- inGeo.addCurveVertex(vertices[idx][X],
- vertices[idx][Y],
+ inGeo.addCurveVertex(vertices[idx][X],
+ vertices[idx][Y],
vertices[idx][Z],
fill, stroke, curveDetail, code);
code = VERTEX;
@@ -2832,68 +2938,68 @@ public class PShapeOpenGL extends PShape {
}
}
}
-
- if (stroke) inGeo.addPolygonEdges(isClosed);
- tessellator.tessellatePolygon(false, isClosed, true);
- }
-
-
- ///////////////////////////////////////////////////////////
-
+
+ if (stroke) inGeo.addPolygonEdges(isClosed);
+ tessellator.tessellatePolygon(false, isClosed, true);
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Aggregation
-
-
+
+
protected void aggregate() {
if (root == this && parent == null) {
// Initializing auxiliary variables in root node
// needed for aggregation.
polyIndexOffset = 0;
polyVertexOffset = 0;
- polyVertexAbs = 0;
- polyVertexRel = 0;
-
+ polyVertexAbs = 0;
+ polyVertexRel = 0;
+
lineIndexOffset = 0;
lineVertexOffset = 0;
- lineVertexAbs = 0;
- lineVertexRel = 0;
-
+ lineVertexAbs = 0;
+ lineVertexRel = 0;
+
pointIndexOffset = 0;
pointVertexOffset = 0;
- pointVertexAbs = 0;
+ pointVertexAbs = 0;
pointVertexRel = 0;
-
+
// Recursive aggregation.
aggregateImpl();
}
}
-
-
- // This method is very important, as it is responsible of generating the
+
+
+ // This method is very important, as it is responsible of generating the
// correct vertex and index offsets for each level of the shape hierarchy.
// This is the core of the recursive algorithm that calculates the indices
// for the vertices accumulated in a single VBO.
- // Basically, the algorithm traverses all the shapes in the hierarchy and
- // updates the index cache for each child shape holding geometry (those being
- // the leaf nodes in the hierarchy tree), and creates index caches for the
+ // Basically, the algorithm traverses all the shapes in the hierarchy and
+ // updates the index cache for each child shape holding geometry (those being
+ // the leaf nodes in the hierarchy tree), and creates index caches for the
// group shapes so that the draw() method can be called from any shape in the
- // hierarchy and the correct piece of geometry will be rendered.
+ // hierarchy and the correct piece of geometry will be rendered.
//
// For example, in the following hierarchy:
//
- // ROOT GROUP
+ // ROOT GROUP
// |
- // /-----------------0-----------------\
+ // /-----------------0-----------------\
// | |
- // CHILD GROUP 0 CHILD GROUP 1
+ // CHILD GROUP 0 CHILD GROUP 1
// | |
- // | /---------------0-----------------\
+ // | /---------------0-----------------\
// | | | |
// GEO SHAPE 0 GEO SHAPE 0 GEO SHAPE 1 GEO SHAPE 2
// 4 vertices 5 vertices 6 vertices 3 vertices
//
- // calling draw() from the root group should result in all the
+ // calling draw() from the root group should result in all the
// vertices (4 + 5 + 6 + 3 = 18) being rendered, while calling
// draw() from either child groups 0 or 1 should result in the first
// 4 vertices or the last 14 vertices being rendered, respectively.
@@ -2903,109 +3009,109 @@ public class PShapeOpenGL extends PShape {
hasPolys = false;
hasLines = false;
hasPoints = false;
- for (int i = 0; i < childCount; i++) {
+ for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.aggregateImpl();
hasPolys |= child.hasPolys;
- hasLines |= child.hasLines;
- hasPoints |= child.hasPoints;
- }
+ hasLines |= child.hasLines;
+ hasPoints |= child.hasPoints;
+ }
} else { // LEAF SHAPE (family either GEOMETRY, PATH or PRIMITIVE)
hasPolys = -1 < firstPolyIndexCache && -1 < lastPolyIndexCache;
- hasLines = -1 < firstLineIndexCache && -1 < lastLineIndexCache;
- hasPoints = -1 < firstPointIndexCache && -1 < lastPointIndexCache;
+ hasLines = -1 < firstLineIndexCache && -1 < lastLineIndexCache;
+ hasPoints = -1 < firstPointIndexCache && -1 < lastPointIndexCache;
}
-
+
if (hasPolys) {
updatePolyIndexCache();
}
if (is3D()) {
- if (hasLines) updateLineIndexCache();
+ if (hasLines) updateLineIndexCache();
if (hasPoints) updatePointIndexCache();
}
-
+
if (matrix != null) {
// Some geometric transformations were applied on
// this shape before tessellation, so they are applied now.
//applyMatrixImpl(matrix);
if (hasPolys) {
- tessGeo.applyMatrixOnPolyGeometry(matrix,
+ tessGeo.applyMatrixOnPolyGeometry(matrix,
firstPolyVertex, lastPolyVertex);
}
if (is3D()) {
if (hasLines) {
- tessGeo.applyMatrixOnLineGeometry(matrix,
+ tessGeo.applyMatrixOnLineGeometry(matrix,
firstLineVertex, lastLineVertex);
}
if (hasPoints) {
- tessGeo.applyMatrixOnPointGeometry(matrix,
+ tessGeo.applyMatrixOnPointGeometry(matrix,
firstPointVertex, lastPointVertex);
}
}
- }
+ }
}
-
-
+
+
// Updates the index cache for the range that corresponds to this shape.
protected void updatePolyIndexCache() {
IndexCache cache = tessGeo.polyIndexCache;
if (family == GROUP) {
- // Updates the index cache to include the elements corresponding to
- // a group shape, using the cache entries of the child shapes. The
+ // Updates the index cache to include the elements corresponding to
+ // a group shape, using the cache entries of the child shapes. The
// index cache has a pyramidal structure where the base is formed
- // by the entries corresponding to the leaf (geometry) shapes, and
+ // by the entries corresponding to the leaf (geometry) shapes, and
// each subsequent level is determined by the higher-level group shapes
// The index pyramid is flattened into arrays in order to use simple
// data structures, so each shape needs to store the positions in the
// cache that corresponds to itself.
-
+
// The index ranges of the child shapes that share the vertex offset
- // are unified into a single range in the parent level.
+ // are unified into a single range in the parent level.
firstPolyIndexCache = lastPolyIndexCache = -1;
- int gindex = -1;
-
- for (int i = 0; i < childCount; i++) {
+ int gindex = -1;
+
+ for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
-
+
int first = child.firstPolyIndexCache;
- int count = -1 < first ? child.lastPolyIndexCache - first + 1 : -1;
- for (int n = first; n < first + count; n++) {
+ int count = -1 < first ? child.lastPolyIndexCache - first + 1 : -1;
+ for (int n = first; n < first + count; n++) {
if (gindex == -1) {
gindex = cache.addNew(n);
firstPolyIndexCache = gindex;
} else {
if (cache.vertexOffset[gindex] == cache.vertexOffset[n]) {
- // When the vertex offsets are the same, this means that the
- // current index range in the group shape can be extended to
+ // When the vertex offsets are the same, this means that the
+ // current index range in the group shape can be extended to
// include the index range in the current child shape.
// This is a result of how the indices are updated for the
// leaf shapes.
- cache.incCounts(gindex,
+ cache.incCounts(gindex,
cache.indexCount[n], cache.vertexCount[n]);
} else {
gindex = cache.addNew(n);
}
}
}
-
+
// Updating the first and last poly vertices for this group shape.
if (-1 < child.firstPolyVertex) {
if (firstPolyVertex == -1) {
- firstPolyVertex = Integer.MAX_VALUE;
+ firstPolyVertex = Integer.MAX_VALUE;
}
firstPolyVertex = PApplet.min(firstPolyVertex, child.firstPolyVertex);
}
if (-1 < child.lastPolyVertex) {
- lastPolyVertex = PApplet.max(lastPolyVertex, child.lastPolyVertex);
+ lastPolyVertex = PApplet.max(lastPolyVertex, child.lastPolyVertex);
}
}
lastPolyIndexCache = gindex;
} else {
- // The index cache is updated in order to reflect the fact that all
+ // The index cache is updated in order to reflect the fact that all
// the vertices will be stored in a single VBO in the root shape.
// This update works as follows (the methodology is the same for
- // poly, line and point): the VertexAbs variable in the root shape
+ // poly, line and point): the VertexAbs variable in the root shape
// stores the index of the last vertex up to this shape (plus one)
// without taking into consideration the MAX_VERTEX_INDEX limit, so
// it effectively runs over the entire range.
@@ -3013,31 +3119,31 @@ public class PShapeOpenGL extends PShape {
// exceeded, therefore creating the start of a new index group in the
// root shape. When this happens, the indices in the child shape need
// to be restarted as well to reflect the new index offset.
-
- firstPolyVertex = lastPolyVertex =
+
+ firstPolyVertex = lastPolyVertex =
cache.vertexOffset[firstPolyIndexCache];
for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int vcount = cache.vertexCount[n];
- if (PGL.MAX_VERTEX_INDEX1 <= root.polyVertexRel + vcount || // Too many vertices already signal the start of a new cache...
- (is2D() && startStrokedTex(n))) { // ... or, in 2D, the beginning of line or points.
+ if (PGL.MAX_VERTEX_INDEX1 <= root.polyVertexRel + vcount || // Too many vertices already signal the start of a new cache...
+ (is2D() && startStrokedTex(n))) { // ... or, in 2D, the beginning of line or points.
root.polyVertexRel = 0;
root.polyVertexOffset = root.polyVertexAbs;
- cache.indexOffset[n] = root.polyIndexOffset;
+ cache.indexOffset[n] = root.polyIndexOffset;
} else {
- tessGeo.incPolyIndices(ioffset, ioffset + icount - 1,
+ tessGeo.incPolyIndices(ioffset, ioffset + icount - 1,
root.polyVertexRel);
}
cache.vertexOffset[n] = root.polyVertexOffset;
if (is2D()) {
- setFirstStrokeVertex(n, lastPolyVertex);
+ setFirstStrokeVertex(n, lastPolyVertex);
}
-
- root.polyIndexOffset += icount;
+
+ root.polyIndexOffset += icount;
root.polyVertexAbs += vcount;
- root.polyVertexRel += vcount;
+ root.polyVertexRel += vcount;
lastPolyVertex += vcount;
}
lastPolyVertex--;
@@ -3046,336 +3152,336 @@ public class PShapeOpenGL extends PShape {
}
}
}
-
-
- protected boolean startStrokedTex(int n) {
- return texture != null && (n == firstLineIndexCache ||
+
+
+ protected boolean startStrokedTex(int n) {
+ return texture != null && (n == firstLineIndexCache ||
n == firstPointIndexCache);
}
-
+
protected void setFirstStrokeVertex(int n, int vert) {
if (n == firstLineIndexCache && firstLineVertex == -1) {
firstLineVertex = lastLineVertex = vert;
}
if (n == firstPointIndexCache && firstPointVertex == -1) {
firstPointVertex = lastPointVertex = vert;
- }
+ }
}
-
+
protected void setLastStrokeVertex(int vert) {
if (-1 < lastLineVertex) {
lastLineVertex = vert;
- }
- if (-1 < lastPointVertex) {
- lastPointVertex += vert;
}
- }
-
+ if (-1 < lastPointVertex) {
+ lastPointVertex += vert;
+ }
+ }
+
protected void updateLineIndexCache() {
IndexCache cache = tessGeo.lineIndexCache;
if (family == GROUP) {
firstLineIndexCache = lastLineIndexCache = -1;
- int gindex = -1;
-
- for (int i = 0; i < childCount; i++) {
+ int gindex = -1;
+
+ for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
-
+
int first = child.firstLineIndexCache;
- int count = -1 < first ? child.lastLineIndexCache - first + 1 : -1;
- for (int n = first; n < first + count; n++) {
+ int count = -1 < first ? child.lastLineIndexCache - first + 1 : -1;
+ for (int n = first; n < first + count; n++) {
if (gindex == -1) {
gindex = cache.addNew(n);
firstLineIndexCache = gindex;
} else {
if (cache.vertexOffset[gindex] == cache.vertexOffset[n]) {
- cache.incCounts(gindex, cache.indexCount[n],
+ cache.incCounts(gindex, cache.indexCount[n],
cache.vertexCount[n]);
} else {
gindex = cache.addNew(n);
}
}
}
-
+
// Updating the first and last line vertices for this group shape.
if (-1 < child.firstLineVertex) {
- if (firstLineVertex == -1) firstLineVertex = Integer.MAX_VALUE;
+ if (firstLineVertex == -1) firstLineVertex = Integer.MAX_VALUE;
firstLineVertex = PApplet.min(firstLineVertex, child.firstLineVertex);
}
if (-1 < child.lastLineVertex) {
- lastLineVertex = PApplet.max(lastLineVertex, child.lastLineVertex);
+ lastLineVertex = PApplet.max(lastLineVertex, child.lastLineVertex);
}
}
lastLineIndexCache = gindex;
- } else {
- firstLineVertex = lastLineVertex =
+ } else {
+ firstLineVertex = lastLineVertex =
cache.vertexOffset[firstLineIndexCache];
for (int n = firstLineIndexCache; n <= lastLineIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int vcount = cache.vertexCount[n];
- if (PGL.MAX_VERTEX_INDEX1 <= root.lineVertexRel + vcount) {
+ if (PGL.MAX_VERTEX_INDEX1 <= root.lineVertexRel + vcount) {
root.lineVertexRel = 0;
root.lineVertexOffset = root.lineVertexAbs;
cache.indexOffset[n] = root.lineIndexOffset;
} else {
- tessGeo.incLineIndices(ioffset, ioffset + icount - 1,
+ tessGeo.incLineIndices(ioffset, ioffset + icount - 1,
root.lineVertexRel);
}
cache.vertexOffset[n] = root.lineVertexOffset;
-
- root.lineIndexOffset += icount;
+
+ root.lineIndexOffset += icount;
root.lineVertexAbs += vcount;
- root.lineVertexRel += vcount;
+ root.lineVertexRel += vcount;
lastLineVertex += vcount;
}
- lastLineVertex--;
+ lastLineVertex--;
}
}
-
-
+
+
protected void updatePointIndexCache() {
IndexCache cache = tessGeo.pointIndexCache;
- if (family == GROUP) {
+ if (family == GROUP) {
firstPointIndexCache = lastPointIndexCache = -1;
- int gindex = -1;
-
- for (int i = 0; i < childCount; i++) {
+ int gindex = -1;
+
+ for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
-
+
int first = child.firstPointIndexCache;
- int count = -1 < first ? child.lastPointIndexCache - first + 1 : -1;
- for (int n = first; n < first + count; n++) {
+ int count = -1 < first ? child.lastPointIndexCache - first + 1 : -1;
+ for (int n = first; n < first + count; n++) {
if (gindex == -1) {
gindex = cache.addNew(n);
firstPointIndexCache = gindex;
} else {
if (cache.vertexOffset[gindex] == cache.vertexOffset[n]) {
- // When the vertex offsets are the same, this means that the
- // current index range in the group shape can be extended to
+ // When the vertex offsets are the same, this means that the
+ // current index range in the group shape can be extended to
// include either the index range in the current child shape.
// This is a result of how the indices are updated for the
// leaf shapes in aggregateImpl().
- cache.incCounts(gindex, cache.indexCount[n],
+ cache.incCounts(gindex, cache.indexCount[n],
cache.vertexCount[n]);
} else {
gindex = cache.addNew(n);
}
}
}
-
- // Updating the first and last point vertices for this group shape.
+
+ // Updating the first and last point vertices for this group shape.
if (-1 < child.firstPointVertex) {
- if (firstPointVertex == -1) firstPointVertex = Integer.MAX_VALUE;
- firstPointVertex = PApplet.min(firstPointVertex,
+ if (firstPointVertex == -1) firstPointVertex = Integer.MAX_VALUE;
+ firstPointVertex = PApplet.min(firstPointVertex,
child.firstPointVertex);
}
if (-1 < child.lastPointVertex) {
- lastPointVertex = PApplet.max(lastPointVertex, child.lastPointVertex);
- }
+ lastPointVertex = PApplet.max(lastPointVertex, child.lastPointVertex);
+ }
}
- lastPointIndexCache = gindex;
+ lastPointIndexCache = gindex;
} else {
- firstPointVertex = lastPointVertex =
+ firstPointVertex = lastPointVertex =
cache.vertexOffset[firstPointIndexCache];
for (int n = firstPointIndexCache; n <= lastPointIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int vcount = cache.vertexCount[n];
- if (PGL.MAX_VERTEX_INDEX1 <= root.pointVertexRel + vcount) {
+ if (PGL.MAX_VERTEX_INDEX1 <= root.pointVertexRel + vcount) {
root.pointVertexRel = 0;
root.pointVertexOffset = root.pointVertexAbs;
cache.indexOffset[n] = root.pointIndexOffset;
} else {
- tessGeo.incPointIndices(ioffset, ioffset + icount - 1,
+ tessGeo.incPointIndices(ioffset, ioffset + icount - 1,
root.pointVertexRel);
}
cache.vertexOffset[n] = root.pointVertexOffset;
-
- root.pointIndexOffset += icount;
+
+ root.pointIndexOffset += icount;
root.pointVertexAbs += vcount;
- root.pointVertexRel += vcount;
+ root.pointVertexRel += vcount;
lastPointVertex += vcount;
}
- lastPointVertex--;
+ lastPointVertex--;
}
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Buffer initialization
-
-
+
+
protected void initBuffers() {
if (needBufferInit) {
context = pgl.getCurrentContext();
-
- if (0 < tessGeo.polyVertexCount && 0 < tessGeo.polyIndexCount) {
+
+ if (0 < tessGeo.polyVertexCount && 0 < tessGeo.polyIndexCount) {
initPolyBuffers();
- }
-
- if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
+ }
+
+ if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
initLineBuffers();
- }
-
- if (0 < tessGeo.pointVertexCount && 0 < tessGeo.pointIndexCount) {
+ }
+
+ if (0 < tessGeo.pointVertexCount && 0 < tessGeo.pointIndexCount) {
initPointBuffers();
}
-
+
needBufferInit = false;
}
}
-
-
- protected void initPolyBuffers() {
+
+
+ protected void initPolyBuffers() {
int size = tessGeo.polyVertexCount;
int sizef = size * PGL.SIZEOF_FLOAT;
int sizei = size * PGL.SIZEOF_INT;
-
- glPolyVertex = pg.createVertexBufferObject(context.code());
+
+ glPolyVertex = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
- FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size),
- PGL.STATIC_DRAW);
-
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size),
+ PGL.STATIC_DRAW);
+
glPolyColor = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.polyColors, 0, size),
- PGL.STATIC_DRAW);
-
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.polyColors, 0, size),
+ PGL.STATIC_DRAW);
+
glPolyNormal = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
- pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
- FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size),
- PGL.STATIC_DRAW);
-
+ pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
+ FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size),
+ PGL.STATIC_DRAW);
+
glPolyTexcoord = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
- pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
- FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size),
- PGL.STATIC_DRAW);
-
- glPolyAmbient = pg.createVertexBufferObject(context.code());
- pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.polyAmbient, 0, size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
+ FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size),
PGL.STATIC_DRAW);
-
+
+ glPolyAmbient = pg.createVertexBufferObject(context.code());
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.polyAmbient, 0, size),
+ PGL.STATIC_DRAW);
+
glPolySpecular = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.polySpecular, 0, size),
- PGL.STATIC_DRAW);
-
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.polySpecular, 0, size),
+ PGL.STATIC_DRAW);
+
glPolyEmissive = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.polyEmissive, 0, size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.polyEmissive, 0, size),
PGL.STATIC_DRAW);
-
+
glPolyShininess = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
- FloatBuffer.wrap(tessGeo.polyShininess, 0, size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
+ FloatBuffer.wrap(tessGeo.polyShininess, 0, size),
PGL.STATIC_DRAW);
-
+
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
-
- glPolyIndex = pg.createVertexBufferObject(context.code());
+
+ glPolyIndex = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.polyIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.polyIndices, 0,
+ ShortBuffer.wrap(tessGeo.polyIndices, 0,
tessGeo.polyIndexCount), PGL.STATIC_DRAW);
-
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
- }
-
-
+
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+
protected void initLineBuffers() {
int size = tessGeo.lineVertexCount;
int sizef = size * PGL.SIZEOF_FLOAT;
- int sizei = size * PGL.SIZEOF_INT;
-
- glLineVertex = pg.createVertexBufferObject(context.code());
- pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
- FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size),
+ int sizei = size * PGL.SIZEOF_INT;
+
+ glLineVertex = pg.createVertexBufferObject(context.code());
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size),
PGL.STATIC_DRAW);
-
+
glLineColor = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.lineColors, 0, size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.lineColors, 0, size),
PGL.STATIC_DRAW);
glLineAttrib = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
- FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size),
PGL.STATIC_DRAW);
-
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
-
- glLineIndex = pg.createVertexBufferObject(context.code());
+
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+
+ glLineIndex = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.lineIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.lineIndices, 0,
+ ShortBuffer.wrap(tessGeo.lineIndices, 0,
tessGeo.lineIndexCount), PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
}
-
-
+
+
protected void initPointBuffers() {
int size = tessGeo.pointVertexCount;
int sizef = size * PGL.SIZEOF_FLOAT;
int sizei = size * PGL.SIZEOF_INT;
-
+
glPointVertex = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
- pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
- FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
+ FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size),
PGL.STATIC_DRAW);
glPointColor = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
- pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
- IntBuffer.wrap(tessGeo.pointColors, 0, size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
+ IntBuffer.wrap(tessGeo.pointColors, 0, size),
PGL.STATIC_DRAW);
-
+
glPointAttrib = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
- pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
- FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size),
+ pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
+ FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size),
PGL.STATIC_DRAW);
-
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
-
+
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+
glPointIndex = pg.createVertexBufferObject(context.code());
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
- pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
+ pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.pointIndexCount * PGL.SIZEOF_INDEX,
- ShortBuffer.wrap(tessGeo.pointIndices, 0,
+ ShortBuffer.wrap(tessGeo.pointIndices, 0,
tessGeo.pointIndexCount), PGL.STATIC_DRAW);
-
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
- }
-
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
// Removing the VBOs from the renderer's list so they
- // doesn't get deleted by OpenGL. The VBOs were already
- // automatically disposed when the old context was
+ // doesn't get deleted by OpenGL. The VBOs were already
+ // automatically disposed when the old context was
// destroyed.
pg.removeVertexBufferObject(glPolyVertex, context.code());
pg.removeVertexBufferObject(glPolyColor, context.code());
@@ -3384,21 +3490,21 @@ public class PShapeOpenGL extends PShape {
pg.removeVertexBufferObject(glPolyAmbient, context.code());
pg.removeVertexBufferObject(glPolySpecular, context.code());
pg.removeVertexBufferObject(glPolyEmissive, context.code());
- pg.removeVertexBufferObject(glPolyShininess, context.code());
+ pg.removeVertexBufferObject(glPolyShininess, context.code());
pg.removeVertexBufferObject(glPolyIndex, context.code());
-
+
pg.removeVertexBufferObject(glLineVertex, context.code());
pg.removeVertexBufferObject(glLineColor, context.code());
pg.removeVertexBufferObject(glLineAttrib, context.code());
pg.removeVertexBufferObject(glLineIndex, context.code());
-
+
pg.removeVertexBufferObject(glPointVertex, context.code());
pg.removeVertexBufferObject(glPointColor, context.code());
pg.removeVertexBufferObject(glPointAttrib, context.code());
pg.removeVertexBufferObject(glPointIndex, context.code());
-
+
// The OpenGL resources have been already deleted
- // when the context changed. We only need to zero
+ // when the context changed. We only need to zero
// them to avoid deleting them again when the GC
// runs the finalizers of the disposed object.
glPolyVertex = 0;
@@ -3408,14 +3514,14 @@ public class PShapeOpenGL extends PShape {
glPolyAmbient = 0;
glPolySpecular = 0;
glPolyEmissive = 0;
- glPolyShininess = 0;
+ glPolyShininess = 0;
glPolyIndex = 0;
-
+
glLineVertex = 0;
glLineColor = 0;
glLineAttrib = 0;
glLineIndex = 0;
-
+
glPointVertex = 0;
glPointColor = 0;
glPointAttrib = 0;
@@ -3423,510 +3529,511 @@ public class PShapeOpenGL extends PShape {
}
return outdated;
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Deletion methods
-
+
protected void release() {
deletePolyBuffers();
deleteLineBuffers();
deletePointBuffers();
- }
-
-
+ }
+
+
protected void deletePolyBuffers() {
- if (glPolyVertex != 0) {
- pg.deleteVertexBufferObject(glPolyVertex, context.code());
+ if (glPolyVertex != 0) {
+ pg.deleteVertexBufferObject(glPolyVertex, context.code());
glPolyVertex = 0;
- }
-
- if (glPolyColor != 0) {
- pg.deleteVertexBufferObject(glPolyColor, context.code());
+ }
+
+ if (glPolyColor != 0) {
+ pg.deleteVertexBufferObject(glPolyColor, context.code());
glPolyColor = 0;
- }
+ }
- if (glPolyNormal != 0) {
- pg.deleteVertexBufferObject(glPolyNormal, context.code());
+ if (glPolyNormal != 0) {
+ pg.deleteVertexBufferObject(glPolyNormal, context.code());
glPolyNormal = 0;
- }
+ }
- if (glPolyTexcoord != 0) {
- pg.deleteVertexBufferObject(glPolyTexcoord, context.code());
+ if (glPolyTexcoord != 0) {
+ pg.deleteVertexBufferObject(glPolyTexcoord, context.code());
glPolyTexcoord = 0;
- }
+ }
- if (glPolyAmbient != 0) {
- pg.deleteVertexBufferObject(glPolyAmbient, context.code());
+ if (glPolyAmbient != 0) {
+ pg.deleteVertexBufferObject(glPolyAmbient, context.code());
glPolyAmbient = 0;
- }
-
- if (glPolySpecular != 0) {
- pg.deleteVertexBufferObject(glPolySpecular, context.code());
+ }
+
+ if (glPolySpecular != 0) {
+ pg.deleteVertexBufferObject(glPolySpecular, context.code());
glPolySpecular = 0;
- }
+ }
- if (glPolyEmissive != 0) {
- pg.deleteVertexBufferObject(glPolyEmissive, context.code());
+ if (glPolyEmissive != 0) {
+ pg.deleteVertexBufferObject(glPolyEmissive, context.code());
glPolyEmissive = 0;
- }
+ }
- if (glPolyShininess != 0) {
- pg.deleteVertexBufferObject(glPolyShininess, context.code());
+ if (glPolyShininess != 0) {
+ pg.deleteVertexBufferObject(glPolyShininess, context.code());
glPolyShininess = 0;
- }
-
- if (glPolyIndex != 0) {
- pg.deleteVertexBufferObject(glPolyIndex, context.code());
+ }
+
+ if (glPolyIndex != 0) {
+ pg.deleteVertexBufferObject(glPolyIndex, context.code());
glPolyIndex = 0;
- }
- }
-
-
- protected void deleteLineBuffers() {
- if (glLineVertex != 0) {
- pg.deleteVertexBufferObject(glLineVertex, context.code());
- glLineVertex = 0;
- }
-
- if (glLineColor != 0) {
- pg.deleteVertexBufferObject(glLineColor, context.code());
- glLineColor = 0;
- }
-
- if (glLineAttrib != 0) {
- pg.deleteVertexBufferObject(glLineAttrib, context.code());
- glLineAttrib = 0;
- }
-
- if (glLineIndex != 0) {
- pg.deleteVertexBufferObject(glLineIndex, context.code());
- glLineIndex = 0;
- }
- }
-
-
- protected void deletePointBuffers() {
- if (glPointVertex != 0) {
- pg.deleteVertexBufferObject(glPointVertex, context.code());
- glPointVertex = 0;
- }
-
- if (glPointColor != 0) {
- pg.deleteVertexBufferObject(glPointColor, context.code());
- glPointColor = 0;
- }
-
- if (glPointAttrib != 0) {
- pg.deleteVertexBufferObject(glPointAttrib, context.code());
- glPointAttrib = 0;
- }
-
- if (glPointIndex != 0) {
- pg.deleteVertexBufferObject(glPointIndex, context.code());
- glPointIndex = 0;
- }
- }
-
-
- ///////////////////////////////////////////////////////////
-
- //
-
- // Geometry update
-
-
- protected void updateGeometry() {
- root.initBuffers();
- if (root.modified) {
- root.updateGeometryImpl();
}
}
-
-
+
+
+ protected void deleteLineBuffers() {
+ if (glLineVertex != 0) {
+ pg.deleteVertexBufferObject(glLineVertex, context.code());
+ glLineVertex = 0;
+ }
+
+ if (glLineColor != 0) {
+ pg.deleteVertexBufferObject(glLineColor, context.code());
+ glLineColor = 0;
+ }
+
+ if (glLineAttrib != 0) {
+ pg.deleteVertexBufferObject(glLineAttrib, context.code());
+ glLineAttrib = 0;
+ }
+
+ if (glLineIndex != 0) {
+ pg.deleteVertexBufferObject(glLineIndex, context.code());
+ glLineIndex = 0;
+ }
+ }
+
+
+ protected void deletePointBuffers() {
+ if (glPointVertex != 0) {
+ pg.deleteVertexBufferObject(glPointVertex, context.code());
+ glPointVertex = 0;
+ }
+
+ if (glPointColor != 0) {
+ pg.deleteVertexBufferObject(glPointColor, context.code());
+ glPointColor = 0;
+ }
+
+ if (glPointAttrib != 0) {
+ pg.deleteVertexBufferObject(glPointAttrib, context.code());
+ glPointAttrib = 0;
+ }
+
+ if (glPointIndex != 0) {
+ pg.deleteVertexBufferObject(glPointIndex, context.code());
+ glPointIndex = 0;
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
+ //
+
+ // Geometry update
+
+
+ protected void updateGeometry() {
+ root.initBuffers();
+ if (root.modified) {
+ root.updateGeometryImpl();
+ }
+ }
+
+
protected void updateGeometryImpl() {
if (modifiedPolyVertices) {
int offset = firstModifiedPolyVertex;
- int size = lastModifiedPolyVertex - offset + 1;
+ int size = lastModifiedPolyVertex - offset + 1;
copyPolyVertices(offset, size);
modifiedPolyVertices = false;
- firstModifiedPolyVertex = PConstants.MAX_INT;
+ firstModifiedPolyVertex = PConstants.MAX_INT;
lastModifiedPolyVertex = PConstants.MIN_INT;
- }
+ }
if (modifiedPolyColors) {
int offset = firstModifiedPolyColor;
- int size = lastModifiedPolyColor - offset + 1;
- copyPolyColors(offset, size);
+ int size = lastModifiedPolyColor - offset + 1;
+ copyPolyColors(offset, size);
modifiedPolyColors = false;
firstModifiedPolyColor = PConstants.MAX_INT;
lastModifiedPolyColor = PConstants.MIN_INT;
}
- if (modifiedPolyNormals) {
+ if (modifiedPolyNormals) {
int offset = firstModifiedPolyNormal;
- int size = lastModifiedPolyNormal - offset + 1;
- copyPolyNormals(offset, size);
- modifiedPolyNormals = false;
+ int size = lastModifiedPolyNormal - offset + 1;
+ copyPolyNormals(offset, size);
+ modifiedPolyNormals = false;
firstModifiedPolyNormal = PConstants.MAX_INT;
- lastModifiedPolyNormal = PConstants.MIN_INT;
+ lastModifiedPolyNormal = PConstants.MIN_INT;
}
- if (modifiedPolyTexcoords) {
+ if (modifiedPolyTexcoords) {
int offset = firstModifiedPolyTexcoord;
- int size = lastModifiedPolyTexcoord - offset + 1;
- copyPolyTexcoords(offset, size);
+ int size = lastModifiedPolyTexcoord - offset + 1;
+ copyPolyTexcoords(offset, size);
modifiedPolyTexcoords = false;
firstModifiedPolyTexcoord = PConstants.MAX_INT;
- lastModifiedPolyTexcoord = PConstants.MIN_INT;
+ lastModifiedPolyTexcoord = PConstants.MIN_INT;
}
- if (modifiedPolyAmbient) {
+ if (modifiedPolyAmbient) {
int offset = firstModifiedPolyAmbient;
- int size = lastModifiedPolyAmbient - offset + 1;
- copyPolyAmbient(offset, size);
+ int size = lastModifiedPolyAmbient - offset + 1;
+ copyPolyAmbient(offset, size);
modifiedPolyAmbient = false;
firstModifiedPolyAmbient = PConstants.MAX_INT;
lastModifiedPolyAmbient = PConstants.MIN_INT;
}
if (modifiedPolySpecular) {
int offset = firstModifiedPolySpecular;
- int size = lastModifiedPolySpecular - offset + 1;
- copyPolySpecular(offset, size);
+ int size = lastModifiedPolySpecular - offset + 1;
+ copyPolySpecular(offset, size);
modifiedPolySpecular = false;
firstModifiedPolySpecular = PConstants.MAX_INT;
lastModifiedPolySpecular = PConstants.MIN_INT;
}
- if (modifiedPolyEmissive) {
+ if (modifiedPolyEmissive) {
int offset = firstModifiedPolyEmissive;
- int size = lastModifiedPolyEmissive - offset + 1;
- copyPolyEmissive(offset, size);
+ int size = lastModifiedPolyEmissive - offset + 1;
+ copyPolyEmissive(offset, size);
modifiedPolyEmissive = false;
firstModifiedPolyEmissive = PConstants.MAX_INT;
- lastModifiedPolyEmissive = PConstants.MIN_INT;
+ lastModifiedPolyEmissive = PConstants.MIN_INT;
}
if (modifiedPolyShininess) {
int offset = firstModifiedPolyShininess;
- int size = lastModifiedPolyShininess - offset + 1;
- copyPolyShininess(offset, size);
+ int size = lastModifiedPolyShininess - offset + 1;
+ copyPolyShininess(offset, size);
modifiedPolyShininess = false;
firstModifiedPolyShininess = PConstants.MAX_INT;
lastModifiedPolyShininess = PConstants.MIN_INT;
}
-
+
if (modifiedLineVertices) {
int offset = firstModifiedLineVertex;
- int size = lastModifiedLineVertex - offset + 1;
- copyLineVertices(offset, size);
+ int size = lastModifiedLineVertex - offset + 1;
+ copyLineVertices(offset, size);
modifiedLineVertices = false;
firstModifiedLineVertex = PConstants.MAX_INT;
- lastModifiedLineVertex = PConstants.MIN_INT;
+ lastModifiedLineVertex = PConstants.MIN_INT;
}
if (modifiedLineColors) {
int offset = firstModifiedLineColor;
- int size = lastModifiedLineColor - offset + 1;
- copyLineColors(offset, size);
+ int size = lastModifiedLineColor - offset + 1;
+ copyLineColors(offset, size);
modifiedLineColors = false;
firstModifiedLineColor = PConstants.MAX_INT;
- lastModifiedLineColor = PConstants.MIN_INT;
+ lastModifiedLineColor = PConstants.MIN_INT;
}
if (modifiedLineAttributes) {
int offset = firstModifiedLineAttribute;
- int size = lastModifiedLineAttribute - offset + 1;
+ int size = lastModifiedLineAttribute - offset + 1;
copyLineAttributes(offset, size);
modifiedLineAttributes = false;
firstModifiedLineAttribute = PConstants.MAX_INT;
lastModifiedLineAttribute = PConstants.MIN_INT;
}
- if (modifiedPointVertices) {
+ if (modifiedPointVertices) {
int offset = firstModifiedPointVertex;
- int size = lastModifiedPointVertex - offset + 1;
- copyPointVertices(offset, size);
+ int size = lastModifiedPointVertex - offset + 1;
+ copyPointVertices(offset, size);
modifiedPointVertices = false;
firstModifiedPointVertex = PConstants.MAX_INT;
- lastModifiedPointVertex = PConstants.MIN_INT;
+ lastModifiedPointVertex = PConstants.MIN_INT;
}
- if (modifiedPointColors) {
+ if (modifiedPointColors) {
int offset = firstModifiedPointColor;
- int size = lastModifiedPointColor - offset + 1;
- copyPointColors(offset, size);
+ int size = lastModifiedPointColor - offset + 1;
+ copyPointColors(offset, size);
modifiedPointColors = false;
firstModifiedPointColor = PConstants.MAX_INT;
- lastModifiedPointColor = PConstants.MIN_INT;
+ lastModifiedPointColor = PConstants.MIN_INT;
}
- if (modifiedPointAttributes) {
+ if (modifiedPointAttributes) {
int offset = firstModifiedPointAttribute;
- int size = lastModifiedPointAttribute - offset + 1;
- copyPointAttributes(offset, size);
+ int size = lastModifiedPointAttribute - offset + 1;
+ copyPointAttributes(offset, size);
modifiedPointAttributes = false;
firstModifiedPointAttribute = PConstants.MAX_INT;
- lastModifiedPointAttribute = PConstants.MIN_INT;
+ lastModifiedPointAttribute = PConstants.MIN_INT;
}
-
+
modified = false;
}
-
- protected void copyPolyVertices(int offset, int size) {
+
+ protected void copyPolyVertices(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
- 4 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.polyVertices,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
+ 4 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.polyVertices,
4 * offset, 4 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
- protected void copyPolyColors(int offset, int size) {
+
+
+ protected void copyPolyColors(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
- IntBuffer.wrap(tessGeo.polyColors, offset, size));
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
+ IntBuffer.wrap(tessGeo.polyColors, offset, size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
-
-
+ }
+
+
protected void copyPolyNormals(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT,
- 3 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.polyNormals,
- 3 * offset, 3 * size));
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT,
+ 3 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.polyNormals,
+ 3 * offset, 3 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
+ }
+
-
protected void copyPolyTexcoords(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT,
- 2 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.polyTexcoords,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT,
+ 2 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.polyTexcoords,
2 * offset, 2 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
+ }
+
-
protected void copyPolyAmbient(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
IntBuffer.wrap(tessGeo.polyAmbient, offset, size));
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
+
+
protected void copyPolySpecular(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
- IntBuffer.wrap(tessGeo.polySpecular, offset, size));
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
+ IntBuffer.wrap(tessGeo.polySpecular, offset, size));
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
+
protected void copyPolyEmissive(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
- IntBuffer.wrap(tessGeo.polyEmissive, offset, size));
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
+ IntBuffer.wrap(tessGeo.polyEmissive, offset, size));
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+ }
+
-
protected void copyPolyShininess(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT,
- size * PGL.SIZEOF_FLOAT,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT,
+ size * PGL.SIZEOF_FLOAT,
FloatBuffer.wrap(tessGeo.polyShininess, offset, size));
- pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
-
-
- protected void copyLineVertices(int offset, int size) {
+ pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
+ }
+
+
+ protected void copyLineVertices(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
- 4 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.lineVertices,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
+ 4 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.lineVertices,
4 * offset, 4 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
- }
-
-
+ }
+
+
protected void copyLineColors(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
- IntBuffer.wrap(tessGeo.lineColors, offset, size));
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
+ IntBuffer.wrap(tessGeo.lineColors, offset, size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
+
+
protected void copyLineAttributes(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
- 4 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.lineAttribs,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
+ 4 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.lineAttribs,
4 * offset, 4 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
- protected void copyPointVertices(int offset, int size) {
+
+ protected void copyPointVertices(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
- 4 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.pointVertices,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
+ 4 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.pointVertices,
4 * offset, 4 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
+
+
protected void copyPointColors(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
- size * PGL.SIZEOF_INT,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT,
+ size * PGL.SIZEOF_INT,
IntBuffer.wrap(tessGeo.pointColors, offset, size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
+
+
protected void copyPointAttributes(int offset, int size) {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
- pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT,
- 2 * size * PGL.SIZEOF_FLOAT,
- FloatBuffer.wrap(tessGeo.pointAttribs,
+ pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT,
+ 2 * size * PGL.SIZEOF_FLOAT,
+ FloatBuffer.wrap(tessGeo.pointAttribs,
2 * offset, 2 * size));
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
-
-
+
+
protected void setModifiedPolyVertices(int first, int last) {
- if (first < firstModifiedPolyVertex) firstModifiedPolyVertex = first;
+ if (first < firstModifiedPolyVertex) firstModifiedPolyVertex = first;
if (last > lastModifiedPolyVertex) lastModifiedPolyVertex = last;
modifiedPolyVertices = true;
modified = true;
}
-
+
protected void setModifiedPolyColors(int first, int last) {
- if (first < firstModifiedPolyColor) firstModifiedPolyColor = first;
+ if (first < firstModifiedPolyColor) firstModifiedPolyColor = first;
if (last > lastModifiedPolyColor) lastModifiedPolyColor = last;
modifiedPolyColors = true;
modified = true;
- }
+ }
+
-
protected void setModifiedPolyNormals(int first, int last) {
- if (first < firstModifiedPolyNormal) firstModifiedPolyNormal = first;
+ if (first < firstModifiedPolyNormal) firstModifiedPolyNormal = first;
if (last > lastModifiedPolyNormal) lastModifiedPolyNormal = last;
modifiedPolyNormals = true;
modified = true;
}
-
-
+
+
protected void setModifiedPolyTexcoords(int first, int last) {
- if (first < firstModifiedPolyTexcoord) firstModifiedPolyTexcoord = first;
+ if (first < firstModifiedPolyTexcoord) firstModifiedPolyTexcoord = first;
if (last > lastModifiedPolyTexcoord) lastModifiedPolyTexcoord = last;
modifiedPolyTexcoords = true;
modified = true;
- }
-
+ }
+
protected void setModifiedPolyAmbient(int first, int last) {
- if (first < firstModifiedPolyAmbient) firstModifiedPolyAmbient = first;
+ if (first < firstModifiedPolyAmbient) firstModifiedPolyAmbient = first;
if (last > lastModifiedPolyAmbient) lastModifiedPolyAmbient = last;
modifiedPolyAmbient = true;
modified = true;
}
-
+
protected void setModifiedPolySpecular(int first, int last) {
- if (first < firstModifiedPolySpecular) firstModifiedPolySpecular = first;
+ if (first < firstModifiedPolySpecular) firstModifiedPolySpecular = first;
if (last > lastModifiedPolySpecular) lastModifiedPolySpecular = last;
modifiedPolySpecular = true;
modified = true;
- }
-
-
+ }
+
+
protected void setModifiedPolyEmissive(int first, int last) {
- if (first < firstModifiedPolyEmissive) firstModifiedPolyEmissive = first;
+ if (first < firstModifiedPolyEmissive) firstModifiedPolyEmissive = first;
if (last > lastModifiedPolyEmissive) lastModifiedPolyEmissive = last;
modifiedPolyEmissive = true;
modified = true;
- }
-
-
+ }
+
+
protected void setModifiedPolyShininess(int first, int last) {
- if (first < firstModifiedPolyShininess) firstModifiedPolyShininess = first;
+ if (first < firstModifiedPolyShininess) firstModifiedPolyShininess = first;
if (last > lastModifiedPolyShininess) lastModifiedPolyShininess = last;
modifiedPolyShininess = true;
modified = true;
- }
+ }
+
-
protected void setModifiedLineVertices(int first, int last) {
- if (first < firstModifiedLineVertex) firstModifiedLineVertex = first;
+ if (first < firstModifiedLineVertex) firstModifiedLineVertex = first;
if (last > lastModifiedLineVertex) lastModifiedLineVertex = last;
modifiedLineVertices = true;
modified = true;
}
-
+
protected void setModifiedLineColors(int first, int last) {
- if (first < firstModifiedLineColor) firstModifiedLineColor = first;
+ if (first < firstModifiedLineColor) firstModifiedLineColor = first;
if (last > lastModifiedLineColor) lastModifiedLineColor = last;
modifiedLineColors = true;
modified = true;
- }
-
-
+ }
+
+
protected void setModifiedLineAttributes(int first, int last) {
- if (first < firstModifiedLineAttribute) firstModifiedLineAttribute = first;
+ if (first < firstModifiedLineAttribute) firstModifiedLineAttribute = first;
if (last > lastModifiedLineAttribute) lastModifiedLineAttribute = last;
modifiedLineAttributes = true;
modified = true;
- }
+ }
+
-
protected void setModifiedPointVertices(int first, int last) {
- if (first < firstModifiedPointVertex) firstModifiedPointVertex = first;
+ if (first < firstModifiedPointVertex) firstModifiedPointVertex = first;
if (last > lastModifiedPointVertex) lastModifiedPointVertex = last;
modifiedPointVertices = true;
modified = true;
}
-
+
protected void setModifiedPointColors(int first, int last) {
- if (first < firstModifiedPointColor) firstModifiedPointColor = first;
+ if (first < firstModifiedPointColor) firstModifiedPointColor = first;
if (last > lastModifiedPointColor) lastModifiedPointColor = last;
modifiedPointColors = true;
modified = true;
- }
-
-
+ }
+
+
protected void setModifiedPointAttributes(int first, int last) {
- if (first < firstModifiedPointAttribute) firstModifiedPointAttribute = first;
- if (last > lastModifiedPointAttribute) lastModifiedPointAttribute = last;
+ if (first < firstModifiedPointAttribute) firstModifiedPointAttribute = first;
+ if (last > lastModifiedPointAttribute) lastModifiedPointAttribute = last;
modifiedPointAttributes = true;
modified = true;
- }
-
-
- ///////////////////////////////////////////////////////////
-
+ }
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Style handling
-
+
// Applies the styles of g.
+ @Override
protected void styles(PGraphics g) {
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);
@@ -3934,169 +4041,173 @@ public class PShapeOpenGL extends PShape {
noStroke();
}
- if (fill) {
+ if (fill) {
fill(g.fillColor);
} else {
noFill();
- }
-
- ambient(g.ambientColor);
- specular(g.specularColor);
+ }
+
+ ambient(g.ambientColor);
+ specular(g.specularColor);
emissive(g.emissiveColor);
- shininess(g.shininess);
-
+ 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?
+ // cap and weight... right?
} else {
super.styles(g);
}
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
//
-
+
// Rendering methods
-
-
+
+
public void draw() {
draw(pg);
}
-
-
+
+
+ @Override
public void draw(PGraphics g) {
if (g instanceof PGraphicsOpenGL) {
- if (visible) {
+ if (visible) {
pre(g);
-
- updateTessellation();
+
+ updateTessellation();
updateGeometry();
-
- if (family == GROUP) {
+
+ if (family == GROUP) {
if (fragmentedGroup(g)) {
for (int i = 0; i < childCount; i++) {
((PShapeOpenGL) children[i]).draw(g);
- }
- } else {
+ }
+ } else {
PImage tex = null;
if (textures != null && textures.size() == 1) {
tex = (PImage)textures.toArray()[0];
}
render((PGraphicsOpenGL)g, tex);
}
-
+
} else {
render((PGraphicsOpenGL)g, texture);
}
-
+
post(g);
- }
+ }
} else {
// The renderer is not PGraphicsOpenGL, which probably
- // means that the draw() method is being called by the
+ // means that the draw() method is being called by the
// recorder. We just use the default drawing from the
// parent class.
- super.draw(g);
- }
+ super.draw(g);
+ }
}
-
+
// Returns true if some child shapes below this one either
- // use different texture maps or have stroked textures,
+ // use different texture maps or have stroked textures,
// so they cannot rendered in a single call.
- // Or accurate 2D mode is enabled, which forces each
- // shape to be rendered separately.
+ // Or accurate 2D mode is enabled, which forces each
+ // shape to be rendered separately.
protected boolean fragmentedGroup(PGraphics g) {
- return g.hintEnabled(ENABLE_ACCURATE_2D) ||
- (textures != null && 1 < textures.size()) ||
+ return g.hintEnabled(ENABLE_ACCURATE_2D) ||
+ (textures != null && 1 < textures.size()) ||
strokedTexture;
}
-
-
+
+
+ @Override
protected void pre(PGraphics g) {
if (g instanceof PGraphicsOpenGL) {
if (!style) {
styles(g);
- }
+ }
} else {
super.pre(g);
}
}
-
-
- public void post(PGraphics g) {
+
+
+ @Override
+ protected 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
+
+ @Override
+ 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) {
if (root == null) {
// Some error. Root should never be null. At least it should be 'this'.
- throw new RuntimeException("Error rendering PShapeOpenGL, root shape is " +
+ throw new RuntimeException("Error rendering PShapeOpenGL, root shape is " +
"null");
}
- if (hasPolys) {
+ if (hasPolys) {
renderPolys(g, texture);
if (g.haveRaw()) {
- rawPolys(g, texture);
+ rawPolys(g, texture);
}
- }
-
+ }
+
if (is3D()) {
// In 3D mode, the lines and points need to be rendered separately
// as they require their own shaders.
- if (hasLines) {
+ if (hasLines) {
renderLines(g);
if (g.haveRaw()) {
rawLines(g);
}
- }
-
+ }
+
if (hasPoints) {
renderPoints(g);
if (g.haveRaw()) {
rawPoints(g);
- }
+ }
}
}
}
-
-
+
+
protected void renderPolys(PGraphicsOpenGL g, PImage textureImage) {
Texture tex = null;
if (textureImage != null) {
- tex = g.getTexture(textureImage);
+ tex = g.getTexture(textureImage);
if (tex != null) {
tex.bind();
}
- }
-
+ }
+
boolean renderingFill = false, renderingStroke = false;
PolyShader shader = null;
IndexCache cache = tessGeo.polyIndexCache;
for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
- if (is3D() || (tex != null && (firstLineIndexCache == -1 ||
- n < firstLineIndexCache) &&
- (firstPointIndexCache == -1 ||
+ if (is3D() || (tex != null && (firstLineIndexCache == -1 ||
+ n < firstLineIndexCache) &&
+ (firstPointIndexCache == -1 ||
n < firstPointIndexCache))) {
// Rendering fill triangles, which can be lit and textured.
if (!renderingFill) {
@@ -4111,83 +4222,83 @@ public class PShapeOpenGL extends PShape {
tex.unbind();
tex = null;
}
-
+
if (shader != null && shader.bound()) {
- shader.unbind();
+ shader.unbind();
}
-
+
// If the renderer is 2D, then g.lights should always be false,
- // so no need to worry about that.
+ // so no need to worry about that.
shader = g.getPolyShader(g.lights, false);
shader.bind();
-
+
renderingFill = false;
renderingStroke = true;
}
}
-
+
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
- shader.setVertexAttribute(root.glPolyVertex, 4, PGL.FLOAT,
- 0, 4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(root.glPolyColor, 4, PGL.UNSIGNED_BYTE,
- 0, 4 * voffset * PGL.SIZEOF_BYTE);
-
+
+ shader.setVertexAttribute(root.glPolyVertex, 4, PGL.FLOAT,
+ 0, 4 * voffset * PGL.SIZEOF_FLOAT);
+ shader.setColorAttribute(root.glPolyColor, 4, PGL.UNSIGNED_BYTE,
+ 0, 4 * voffset * PGL.SIZEOF_BYTE);
+
if (g.lights) {
- shader.setNormalAttribute(root.glPolyNormal, 3, PGL.FLOAT,
+ shader.setNormalAttribute(root.glPolyNormal, 3, PGL.FLOAT,
0, 3 * voffset * PGL.SIZEOF_FLOAT);
- shader.setAmbientAttribute(root.glPolyAmbient, 4, PGL.UNSIGNED_BYTE,
+ shader.setAmbientAttribute(root.glPolyAmbient, 4, PGL.UNSIGNED_BYTE,
0, 4 * voffset * PGL.SIZEOF_BYTE);
- shader.setSpecularAttribute(root.glPolySpecular, 4, PGL.UNSIGNED_BYTE,
+ shader.setSpecularAttribute(root.glPolySpecular, 4, PGL.UNSIGNED_BYTE,
0, 4 * voffset * PGL.SIZEOF_BYTE);
- shader.setEmissiveAttribute(root.glPolyEmissive, 4, PGL.UNSIGNED_BYTE,
+ shader.setEmissiveAttribute(root.glPolyEmissive, 4, PGL.UNSIGNED_BYTE,
0, 4 * voffset * PGL.SIZEOF_BYTE);
- shader.setShininessAttribute(root.glPolyShininess, 1, PGL.FLOAT,
+ shader.setShininessAttribute(root.glPolyShininess, 1, PGL.FLOAT,
0, voffset * PGL.SIZEOF_FLOAT);
}
-
- if (tex != null) {
- shader.setTexcoordAttribute(root.glPolyTexcoord, 2, PGL.FLOAT,
+
+ if (tex != null) {
+ shader.setTexcoordAttribute(root.glPolyTexcoord, 2, PGL.FLOAT,
0, 2 * voffset * PGL.SIZEOF_FLOAT);
shader.setTexture(tex);
- }
-
+ }
+
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPolyIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
ioffset * PGL.SIZEOF_INDEX);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
- }
-
- if (shader != null && shader.bound()) {
- shader.unbind();
}
-
+
+ if (shader != null && shader.bound()) {
+ shader.unbind();
+ }
+
if (tex != null) {
tex.unbind();
- }
- }
-
-
+ }
+ }
+
+
protected void rawPolys(PGraphicsOpenGL g, PImage textureImage) {
PGraphics raw = g.getRaw();
-
+
raw.colorMode(RGB);
raw.noStroke();
raw.beginShape(TRIANGLES);
-
+
float[] vertices = tessGeo.polyVertices;
int[] color = tessGeo.polyColors;
float[] uv = tessGeo.polyTexcoords;
- short[] indices = tessGeo.polyIndices;
-
+ short[] indices = tessGeo.polyIndices;
+
IndexCache cache = tessGeo.polyIndexCache;
- for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
+ for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
+
for (int tr = ioffset / 3; tr < (ioffset + icount) / 3; tr++) {
int i0 = voffset + indices[3 * tr + 0];
int i1 = voffset + indices[3 * tr + 1];
@@ -4195,14 +4306,14 @@ public class PShapeOpenGL extends PShape {
float[] src0 = {0, 0, 0, 0};
float[] src1 = {0, 0, 0, 0};
- float[] src2 = {0, 0, 0, 0};
+ float[] src2 = {0, 0, 0, 0};
float[] pt0 = {0, 0, 0, 0};
float[] pt1 = {0, 0, 0, 0};
float[] pt2 = {0, 0, 0, 0};
int argb0 = PGL.nativeToJavaARGB(color[i0]);
int argb1 = PGL.nativeToJavaARGB(color[i1]);
- int argb2 = PGL.nativeToJavaARGB(color[i2]);
-
+ int argb2 = PGL.nativeToJavaARGB(color[i2]);
+
PApplet.arrayCopy(vertices, 4 * i0, src0, 0, 4);
PApplet.arrayCopy(vertices, 4 * i1, src1, 0, 4);
PApplet.arrayCopy(vertices, 4 * i2, src2, 0, 4);
@@ -4210,30 +4321,30 @@ public class PShapeOpenGL extends PShape {
// modelview matrix of the renderer.
g.modelview.mult(src0, pt0);
g.modelview.mult(src1, pt1);
- g.modelview.mult(src2, pt2);
-
+ g.modelview.mult(src2, pt2);
+
if (textureImage != null) {
raw.texture(textureImage);
- if (raw.is3D()) {
+ if (raw.is3D()) {
raw.fill(argb0);
raw.vertex(pt0[X], pt0[Y], pt0[Z], uv[2 * i0 + 0], uv[2 * i0 + 1]);
raw.fill(argb1);
raw.vertex(pt1[X], pt1[Y], pt1[Z], uv[2 * i1 + 0], uv[2 * i1 + 1]);
raw.fill(argb2);
- raw.vertex(pt2[X], pt2[Y], pt2[Z], uv[2 * i2 + 0], uv[2 * i2 + 1]);
+ raw.vertex(pt2[X], pt2[Y], pt2[Z], uv[2 * i2 + 0], uv[2 * i2 + 1]);
} else if (raw.is2D()) {
- float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = g.screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = g.screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
- float sx2 = g.screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
- float sy2 = g.screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
+ float sx2 = g.screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
+ float sy2 = g.screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
raw.fill(argb0);
raw.vertex(sx0, sy0, uv[2 * i0 + 0], uv[2 * i0 + 1]);
raw.fill(argb1);
raw.vertex(sx1, sy1, uv[2 * i1 + 0], uv[2 * i1 + 1]);
raw.fill(argb1);
- raw.vertex(sx2, sy2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
+ raw.vertex(sx2, sy2, uv[2 * i2 + 0], uv[2 * i2 + 1]);
}
} else {
if (raw.is3D()) {
@@ -4242,103 +4353,103 @@ public class PShapeOpenGL extends PShape {
raw.fill(argb1);
raw.vertex(pt1[X], pt1[Y], pt1[Z]);
raw.fill(argb2);
- raw.vertex(pt2[X], pt2[Y], pt2[Z]);
+ raw.vertex(pt2[X], pt2[Y], pt2[Z]);
} else if (raw.is2D()) {
- float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = g.screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = g.screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
- float sx2 = g.screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
- float sy2 = g.screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
+ float sx2 = g.screenXImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
+ float sy2 = g.screenYImpl(pt2[0], pt2[1], pt2[2], pt2[3]);
raw.fill(argb0);
raw.vertex(sx0, sy0);
raw.fill(argb1);
raw.vertex(sx1, sy1);
raw.fill(argb2);
- raw.vertex(sx2, sy2);
+ raw.vertex(sx2, sy2);
}
}
}
}
-
+
raw.endShape();
}
-
-
+
+
protected void renderLines(PGraphicsOpenGL g) {
LineShader shader = g.getLineShader();
- shader.bind();
-
+ shader.bind();
+
IndexCache cache = tessGeo.lineIndexCache;
- for (int n = firstLineIndexCache; n <= lastLineIndexCache; n++) {
+ for (int n = firstLineIndexCache; n <= lastLineIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
- shader.setVertexAttribute(root.glLineVertex, 4, PGL.FLOAT,
- 0, 4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(root.glLineColor, 4, PGL.UNSIGNED_BYTE,
- 0, 4 * voffset * PGL.SIZEOF_BYTE);
- shader.setLineAttribute(root.glLineAttrib, 4, PGL.FLOAT,
- 0, 4 * voffset * PGL.SIZEOF_FLOAT);
-
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glLineIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
- ioffset * PGL.SIZEOF_INDEX);
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
- }
-
- shader.unbind();
- }
-
+ shader.setVertexAttribute(root.glLineVertex, 4, PGL.FLOAT,
+ 0, 4 * voffset * PGL.SIZEOF_FLOAT);
+ shader.setColorAttribute(root.glLineColor, 4, PGL.UNSIGNED_BYTE,
+ 0, 4 * voffset * PGL.SIZEOF_BYTE);
+ shader.setLineAttribute(root.glLineAttrib, 4, PGL.FLOAT,
+ 0, 4 * voffset * PGL.SIZEOF_FLOAT);
+
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glLineIndex);
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ ioffset * PGL.SIZEOF_INDEX);
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+ shader.unbind();
+ }
+
+
protected void rawLines(PGraphicsOpenGL g) {
PGraphics raw = g.getRaw();
-
+
raw.colorMode(RGB);
raw.noFill();
raw.strokeCap(strokeCap);
raw.strokeJoin(strokeJoin);
raw.beginShape(LINES);
-
+
float[] vertices = tessGeo.lineVertices;
int[] color = tessGeo.lineColors;
float[] attribs = tessGeo.lineAttribs;
- short[] indices = tessGeo.lineIndices;
-
+ short[] indices = tessGeo.lineIndices;
+
IndexCache cache = tessGeo.lineIndexCache;
- for (int n = firstLineIndexCache; n <= lastLineIndexCache; n++) {
+ for (int n = firstLineIndexCache; n <= lastLineIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
+
for (int ln = ioffset / 6; ln < (ioffset + icount) / 6; ln++) {
// Each line segment is defined by six indices since its
// formed by two triangles. We only need the first and last
// vertices.
// This bunch of vertices could also be the bevel triangles,
- // with we detect this situation by looking at the line weight.
+ // with we detect this situation by looking at the line weight.
int i0 = voffset + indices[6 * ln + 0];
int i1 = voffset + indices[6 * ln + 5];
float sw0 = 2 * attribs[4 * i0 + 3];
- float sw1 = 2 * attribs[4 * i1 + 3];
-
+ float sw1 = 2 * attribs[4 * i1 + 3];
+
if (PGraphicsOpenGL.zero(sw0)) continue; // Bevel triangles, skip.
-
+
float[] src0 = {0, 0, 0, 0};
- float[] src1 = {0, 0, 0, 0};
+ float[] src1 = {0, 0, 0, 0};
float[] pt0 = {0, 0, 0, 0};
- float[] pt1 = {0, 0, 0, 0};
+ float[] pt1 = {0, 0, 0, 0};
int argb0 = PGL.nativeToJavaARGB(color[i0]);
int argb1 = PGL.nativeToJavaARGB(color[i1]);
-
+
PApplet.arrayCopy(vertices, 4 * i0, src0, 0, 4);
- PApplet.arrayCopy(vertices, 4 * i1, src1, 0, 4);
+ PApplet.arrayCopy(vertices, 4 * i1, src1, 0, 4);
// Applying any transformation is currently stored in the
- // modelview matrix of the renderer.
+ // modelview matrix of the renderer.
g.modelview.mult(src0, pt0);
- g.modelview.mult(src1, pt1);
-
+ g.modelview.mult(src1, pt1);
+
if (raw.is3D()) {
raw.strokeWeight(sw0);
raw.stroke(argb0);
@@ -4347,70 +4458,70 @@ public class PShapeOpenGL extends PShape {
raw.stroke(argb1);
raw.vertex(pt1[X], pt1[Y], pt1[Z]);
} else if (raw.is2D()) {
- float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = g.screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
- float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
+ float sx1 = g.screenXImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
float sy1 = g.screenYImpl(pt1[0], pt1[1], pt1[2], pt1[3]);
raw.strokeWeight(sw0);
raw.stroke(argb0);
raw.vertex(sx0, sy0);
raw.strokeWeight(sw1);
raw.stroke(argb1);
- raw.vertex(sx1, sy1);
+ raw.vertex(sx1, sy1);
}
}
}
-
+
raw.endShape();
}
-
+
protected void renderPoints(PGraphicsOpenGL g) {
PointShader shader = g.getPointShader();
- shader.bind();
-
- IndexCache cache = tessGeo.pointIndexCache;
- for (int n = firstPointIndexCache; n <= lastPointIndexCache; n++) {
+ shader.bind();
+
+ IndexCache cache = tessGeo.pointIndexCache;
+ for (int n = firstPointIndexCache; n <= lastPointIndexCache; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
- shader.setVertexAttribute(root.glPointVertex, 4, PGL.FLOAT,
- 0, 4 * voffset * PGL.SIZEOF_FLOAT);
- shader.setColorAttribute(root.glPointColor, 4, PGL.UNSIGNED_BYTE,
- 0, 4 * voffset * PGL.SIZEOF_BYTE);
- shader.setPointAttribute(root.glPointAttrib, 2, PGL.FLOAT,
- 0, 2 * voffset * PGL.SIZEOF_FLOAT);
-
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPointIndex);
- pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
- ioffset * PGL.SIZEOF_INDEX);
- pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
+
+ shader.setVertexAttribute(root.glPointVertex, 4, PGL.FLOAT,
+ 0, 4 * voffset * PGL.SIZEOF_FLOAT);
+ shader.setColorAttribute(root.glPointColor, 4, PGL.UNSIGNED_BYTE,
+ 0, 4 * voffset * PGL.SIZEOF_BYTE);
+ shader.setPointAttribute(root.glPointAttrib, 2, PGL.FLOAT,
+ 0, 2 * voffset * PGL.SIZEOF_FLOAT);
+
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPointIndex);
+ pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
+ ioffset * PGL.SIZEOF_INDEX);
+ pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
}
-
+
shader.unbind();
- }
+ }
- protected void rawPoints(PGraphicsOpenGL g) {
+ protected void rawPoints(PGraphicsOpenGL g) {
PGraphics raw = g.getRaw();
-
+
raw.colorMode(RGB);
raw.noFill();
raw.strokeCap(strokeCap);
raw.beginShape(POINTS);
-
+
float[] vertices = tessGeo.pointVertices;
int[] color = tessGeo.pointColors;
float[] attribs = tessGeo.pointAttribs;
- short[] indices = tessGeo.pointIndices;
-
+ short[] indices = tessGeo.pointIndices;
+
IndexCache cache = tessGeo.pointIndexCache;
- for (int n = 0; n < cache.size; n++) {
+ for (int n = 0; n < cache.size; n++) {
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
-
+
int pt = ioffset;
while (pt < (ioffset + icount) / 3) {
float size = attribs[2 * pt + 2];
@@ -4418,38 +4529,38 @@ public class PShapeOpenGL extends PShape {
int perim;
if (0 < size) { // round point
weight = +size / 0.5f;
- perim = PApplet.max(PGraphicsOpenGL.MIN_POINT_ACCURACY,
- (int) (TWO_PI * weight /
- PGraphicsOpenGL.POINT_ACCURACY_FACTOR)) + 1;
+ perim = PApplet.max(PGraphicsOpenGL.MIN_POINT_ACCURACY,
+ (int) (TWO_PI * weight /
+ PGraphicsOpenGL.POINT_ACCURACY_FACTOR)) + 1;
} else { // Square point
weight = -size / 0.5f;
- perim = 5;
+ perim = 5;
}
-
+
int i0 = voffset + indices[3 * pt];
int argb0 = PGL.nativeToJavaARGB(color[i0]);
float[] pt0 = {0, 0, 0, 0};
-
- float[] src0 = {0, 0, 0, 0};
- PApplet.arrayCopy(vertices, 4 * i0, src0, 0, 4);
+
+ float[] src0 = {0, 0, 0, 0};
+ PApplet.arrayCopy(vertices, 4 * i0, src0, 0, 4);
g.modelview.mult(src0, pt0);
-
+
if (raw.is3D()) {
raw.strokeWeight(weight);
raw.stroke(argb0);
raw.vertex(pt0[X], pt0[Y], pt0[Z]);
} else if (raw.is2D()) {
- float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
+ float sx0 = g.screenXImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
float sy0 = g.screenYImpl(pt0[0], pt0[1], pt0[2], pt0[3]);
raw.strokeWeight(weight);
raw.stroke(argb0);
- raw.vertex(sx0, sy0);
- }
-
+ raw.vertex(sx0, sy0);
+ }
+
pt += perim;
}
- }
-
- raw.endShape();
- }
+ }
+
+ raw.endShape();
+ }
}
diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java
index f2703e523..da44be3a8 100644
--- a/core/src/processing/opengl/Texture.java
+++ b/core/src/processing/opengl/Texture.java
@@ -36,60 +36,60 @@ import java.util.NoSuchElementException;
/**
* This class wraps an OpenGL texture.
* By Andres Colubri
- *
+ *
*/
-public class Texture implements PConstants {
+public class Texture implements PConstants {
// texture constants
-
- /**
- * Texture with normalized UV.
+
+ /**
+ * Texture with normalized UV.
*/
protected static final int TEX2D = 0;
- /**
- * Texture with un-normalized UV.
+ /**
+ * Texture with un-normalized UV.
*/
protected static final int TEXRECT = 1;
- /** Point sampling: both magnification and minification filtering are set
+ /** Point sampling: both magnification and minification filtering are set
* to nearest */
protected static final int POINT = 2;
- /** Linear sampling: magnification filtering is nearest, minification set
+ /** Linear sampling: magnification filtering is nearest, minification set
* to linear */
- protected static final int LINEAR = 3;
- /** Bilinear sampling: both magnification filtering is set to linear and
- * minification either to linear-mipmap-nearest (linear interplation is used
+ protected static final int LINEAR = 3;
+ /** Bilinear sampling: both magnification filtering is set to linear and
+ * minification either to linear-mipmap-nearest (linear interplation is used
* within a mipmap, but not between different mipmaps). */
protected static final int BILINEAR = 4;
- /** Trilinear sampling: magnification filtering set to linear, minification to
- * linear-mipmap-linear, which offers the best mipmap quality since linear
- * interpolation to compute the value in each of two maps and then
+ /** Trilinear sampling: magnification filtering set to linear, minification to
+ * linear-mipmap-linear, which offers the best mipmap quality since linear
+ * interpolation to compute the value in each of two maps and then
* interpolates linearly between these two value. */
protected static final int TRILINEAR = 5;
public int width, height;
- public int glName;
+ public int glName;
public int glTarget;
public int glFormat;
- public int glMinFilter;
+ public int glMinFilter;
public int glMagFilter;
- public int glWrapS;
- public int glWrapT;
+ public int glWrapS;
+ public int glWrapT;
public int glWidth;
- public int glHeight;
-
+ public int glHeight;
+
protected PApplet parent; // The Processing applet
protected PGraphicsOpenGL pg; // The main renderer
protected PGL pgl; // The interface between Processing and OpenGL.
protected PGL.Context context; // The context that created this texture.
-
+
protected boolean usingMipmaps;
protected boolean usingRepeat;
protected float maxTexcoordU;
protected float maxTexcoordV;
protected boolean bound;
-
- protected boolean flippedX;
+
+ protected boolean flippedX;
protected boolean flippedY;
protected FrameBuffer tempFbo = null;
@@ -97,50 +97,51 @@ public class Texture implements PConstants {
/** Modified portion of the texture */
protected boolean modified;
protected int mx1, my1, mx2, my2;
-
+
protected Object bufferSource;
protected LinkedList bufferCache = null;
protected Method disposeBufferMethod;
- public static final int MAX_BUFFER_CACHE_SIZE = 3;
-
+ public static final int MAX_BUFFER_CACHE_SIZE = 3;
+
////////////////////////////////////////////////////////////
-
+
// Constructors.
-
+
/**
* Creates an instance of PTexture with size width x height. The texture is
* initialized (empty) to that size.
* @param parent PApplet
* @param width int
* @param height int
- */
+ */
public Texture(PApplet parent, int width, int height) {
this(parent, width, height, new Parameters());
}
-
-
+
+
/**
- * Creates an instance of PTexture with size width x height and with the
+ * Creates an instance of PTexture with size width x height and with the
* specified parameters. The texture is initialized (empty) to that size.
* @param parent PApplet
- * @param width int
- * @param height int
- * @param params Parameters
- */
- public Texture(PApplet parent, int width, int height, Object params) {
+ * @param width int
+ * @param height int
+ * @param params Parameters
+ */
+ public Texture(PApplet parent, int width, int height, Object params) {
this.parent = parent;
-
- pg = (PGraphicsOpenGL)parent.g;
- pgl = pg.pgl;
- context = pgl.createEmptyContext();
-
- glName = 0;
-
- init(width, height, (Parameters)params);
- }
-
+ pg = (PGraphicsOpenGL)parent.g;
+ pgl = pg.pgl;
+ context = pgl.createEmptyContext();
+
+ glName = 0;
+
+ init(width, height, (Parameters)params);
+ }
+
+
+ @Override
protected void finalize() throws Throwable {
try {
if (glName != 0) {
@@ -149,17 +150,17 @@ public class Texture implements PConstants {
} finally {
super.finalize();
}
- }
-
+ }
+
////////////////////////////////////////////////////////////
-
+
// Init, resize methods
-
-
+
+
/**
- * Sets the size of the image and texture to width x height. If the texture is
- * already initialized, it first destroys the current OpenGL texture object
+ * Sets the size of the image and texture to width x height. If the texture is
+ * already initialized, it first destroys the current OpenGL texture object
* and then creates a new one with the specified size.
* @param width int
* @param height int
@@ -169,212 +170,212 @@ public class Texture implements PConstants {
if (0 < glName) {
// Re-initializing a pre-existing texture.
// We use the current parameters as default:
- params = getParameters();
+ params = getParameters();
} else {
// Just built-in default parameters otherwise:
params = new Parameters();
}
init(width, height, params);
}
-
+
/**
- * Sets the size of the image and texture to width x height, and the
- * parameters of the texture to params. If the texture is already initialized,
- * it first destroys the current OpenGL texture object and then creates a new
+ * Sets the size of the image and texture to width x height, and the
+ * parameters of the texture to params. If the texture is already initialized,
+ * it first destroys the current OpenGL texture object and then creates a new
* one with the specified size.
* @param width int
* @param height int
- * @param params GLTextureParameters
+ * @param params GLTextureParameters
*/
public void init(int width, int height, Parameters params) {
setParameters(params);
setSize(width, height);
- allocate();
- }
+ allocate();
+ }
public void resize(int wide, int high) {
// Marking the texture object as finalized so it is deleted
// when creating the new texture.
release();
-
+
// Creating new texture with the appropriate size.
Texture tex = new Texture(parent, wide, high, getParameters());
-
+
// Copying the contents of this texture into tex.
tex.set(this);
-
+
// Now, overwriting "this" with tex.
copyObject(tex);
-
- // Nullifying some utility objects so they are recreated with the
+
+ // Nullifying some utility objects so they are recreated with the
// appropriate size when needed.
tempFbo = null;
}
-
+
/**
* Returns true if the texture has been initialized.
* @return boolean
- */
+ */
public boolean available() {
return 0 < glName;
}
-
+
////////////////////////////////////////////////////////////
-
+
// Set methods
-
+
public void set(PImage img) {
Texture tex = (Texture)img.getCache(pg);
set(tex);
}
-
-
+
+
public void set(PImage img, int x, int y, int w, int h) {
Texture tex = (Texture)img.getCache(pg);
set(tex, x, y, w, h);
}
-
-
+
+
public void set(Texture tex) {
copyTexture(tex, 0, 0, tex.width, tex.height, true);
}
-
-
+
+
public void set(Texture tex, int x, int y, int w, int h) {
copyTexture(tex, x, y, w, h, true);
- }
+ }
-
- public void set(int texTarget, int texName, int texWidth, int texHeight,
+
+ public void set(int texTarget, int texName, int texWidth, int texHeight,
int w, int h) {
copyTexture(texTarget, texName, texWidth, texHeight, 0, 0, w, h, true);
}
-
-
- public void set(int texTarget, int texName, int texWidth, int texHeight,
+
+
+ public void set(int texTarget, int texName, int texWidth, int texHeight,
int target, int tex, int x, int y, int w, int h) {
copyTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, true);
}
-
-
+
+
public void set(int[] pixels) {
- set(pixels, 0, 0, width, height, ARGB);
+ set(pixels, 0, 0, width, height, ARGB);
}
-
+
public void set(int[] pixels, int format) {
- set(pixels, 0, 0, width, height, format);
+ set(pixels, 0, 0, width, height, format);
}
-
-
+
+
public void set(int[] pixels, int x, int y, int w, int h) {
- set(pixels, x, y, w, h, ARGB);
+ set(pixels, x, y, w, h, ARGB);
}
-
-
+
+
public void set(int[] pixels, int x, int y, int w, int h, int format) {
if (pixels == null) {
pixels = null;
PGraphics.showWarning("The pixels array is null.");
return;
- }
+ }
if (pixels.length != w * h) {
- PGraphics.showWarning("The pixels array has a length of " +
+ PGraphics.showWarning("The pixels array has a length of " +
pixels.length + ", but it should be " + w * h);
return;
}
-
+
if (pixels.length == 0) {
// Nothing to do (means that w == h == 0) but not an erroneous situation
return;
}
-
+
boolean enabledTex = false;
if (!pgl.texturingIsEnabled(glTarget)) {
pgl.enableTexturing(glTarget);
enabledTex = true;
}
pgl.bindTexture(glTarget, glName);
-
+
if (usingMipmaps) {
if (PGraphicsOpenGL.autoMipmapGenSupported) {
// Automatic mipmap generation.
int[] rgbaPixels = new int[w * h];
convertToRGBA(pixels, rgbaPixels, format, w, h);
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
IntBuffer.wrap(rgbaPixels));
pgl.generateMipmap(glTarget);
rgbaPixels = null;
- } else {
+ } else {
// TODO: finish manual mipmap generation, replacing Bitmap with AWT's BufferedImage,
// making it work in npot textures (embed npot tex into larger pot tex?), subregions,
// and moving GLUtils.texImage2D (originally from Android SDK) into PGL.
// Actually, this whole code should go into PGL, so the Android implementation can
// use Bitmap, and desktop use BufferedImage.
-
+
/*
if (w != width || h != height) {
System.err.println("Sorry but I don't know how to generate mipmaps for a subregion.");
return;
}
-
+
// Code by Mike Miller obtained from here:
// http://insanitydesign.com/wp/2009/08/01/android-opengl-es-mipmaps/
int w0 = glWidth;
- int h0 = glHeight;
+ int h0 = glHeight;
int[] argbPixels = new int[w0 * h0];
convertToARGB(pixels, argbPixels, format);
int level = 0;
int denom = 1;
-
+
// We create a Bitmap because then we use its built-in filtered downsampling
// functionality.
Bitmap bitmap = Bitmap.createBitmap(w0, h0, Config.ARGB_8888);
bitmap.setPixels(argbPixels, 0, w0, 0, 0, w0, h0);
-
+
while (w0 >= 1 || h0 >= 1) {
//First of all, generate the texture from our bitmap and set it to the according level
GLUtils.texImage2D(glTarget, level, bitmap, 0);
-
+
// We are done.
if (w0 == 1 && h0 == 1) {
break;
}
-
+
// Increase the mipmap level
level++;
denom *= 2;
-
+
// Downsampling bitmap. We must eventually arrive to the 1x1 level,
// and if the width and height are different, there will be a few 1D
- // texture levels just before.
+ // texture levels just before.
// This update formula also allows for NPOT resolutions.
w0 = PApplet.max(1, PApplet.floor((float)glWidth / denom));
h0 = PApplet.max(1, PApplet.floor((float)glHeight / denom));
// (see getScaledInstance in AWT Image)
Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, w0, h0, true);
-
+
// Clean up
bitmap.recycle();
bitmap = bitmap2;
}
*/
-
+
int[] rgbaPixels = new int[w * h];
convertToRGBA(pixels, rgbaPixels, format, w, h);
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
IntBuffer.wrap(rgbaPixels));
- rgbaPixels = null;
- }
+ rgbaPixels = null;
+ }
} else {
int[] rgbaPixels = new int[w * h];
convertToRGBA(pixels, rgbaPixels, format, w, h);
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
IntBuffer.wrap(rgbaPixels));
rgbaPixels = null;
}
@@ -383,95 +384,95 @@ public class Texture implements PConstants {
if (enabledTex) {
pgl.disableTexturing(glTarget);
}
-
- updateTexels(x, y, w, h);
- }
-
-
+
+ updateTexels(x, y, w, h);
+ }
+
+
////////////////////////////////////////////////////////////
-
+
// Native set methods
-
+
public void setNative(int[] pixels) {
- setNative(pixels, 0, 0, width, height);
+ setNative(pixels, 0, 0, width, height);
}
-
-
+
+
public void setNative(int[] pixels, int x, int y, int w, int h) {
setNative(IntBuffer.wrap(pixels), x, y, w, h);
}
-
-
+
+
public void setNative(IntBuffer pixels, int x, int y, int w, int h) {
if (pixels == null) {
pixels = null;
PGraphics.showWarning("The pixel buffer is null.");
return;
- }
+ }
if (pixels.capacity() != w * h) {
- PGraphics.showWarning("The pixels array has a length of " +
+ PGraphics.showWarning("The pixels array has a length of " +
pixels.capacity() + ", but it should be " + w * h);
return;
}
-
+
if (pixels.capacity() == 0) {
// Nothing to do (means that w == h == 0) but not an erroneous situation
return;
}
-
+
boolean enabledTex = false;
if (!pgl.texturingIsEnabled(glTarget)) {
pgl.enableTexturing(glTarget);
enabledTex = true;
}
pgl.bindTexture(glTarget, glName);
-
+
if (usingMipmaps) {
if (PGraphicsOpenGL.autoMipmapGenSupported) {
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
pixels);
pgl.generateMipmap(glTarget);
- } else {
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
- pixels);
+ } else {
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ pixels);
}
- } else {
- pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
+ } else {
+ pgl.texSubImage2D(glTarget, 0, x, y, w, h, PGL.RGBA, PGL.UNSIGNED_BYTE,
pixels);
}
-
+
pgl.bindTexture(glTarget, 0);
if (enabledTex) {
pgl.disableTexturing(glTarget);
}
-
+
updateTexels(x, y, w, h);
- }
-
-
+ }
+
+
////////////////////////////////////////////////////////////
-
+
// Get methods
-
-
- /**
+
+
+ /**
* Copy texture to pixels. Involves video memory to main memory transfer (slow).
- */
+ */
public void get(int[] pixels) {
if (pixels == null) {
throw new RuntimeException("Trying to copy texture to null pixels array");
}
if (pixels.length != width * height) {
- throw new RuntimeException("Trying to copy texture to pixels array of " +
+ throw new RuntimeException("Trying to copy texture to pixels array of " +
"wrong size");
}
-
+
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
}
-
- // Attaching the texture to the color buffer of a FBO, binding the FBO and
+
+ // Attaching the texture to the color buffer of a FBO, binding the FBO and
// reading the pixels from the current draw buffer (which is the color
// buffer of the FBO).
tempFbo.setColorBuffer(this);
@@ -479,15 +480,15 @@ public class Texture implements PConstants {
pg.setFramebuffer(tempFbo);
tempFbo.readPixels();
pg.popFramebuffer();
-
+
tempFbo.getPixels(pixels);
convertToARGB(pixels);
-
+
if (flippedX) flipArrayOnX(pixels, 1);
- if (flippedY) flipArrayOnY(pixels, 1);
+ if (flippedY) flipArrayOnY(pixels, 1);
}
-
+
/**
* Copies the contents of the texture to the pixels array.
* @param pixels
@@ -495,199 +496,199 @@ public class Texture implements PConstants {
public void loadPixels(int[] pixels) {
if (hasBuffers()) {
// Updates the texture AND the pixels array of the image at the same time,
- // getting the pixels directly from the buffer data (and thus avoiding
+ // getting the pixels directly from the buffer data (and thus avoiding
// expensive transfer between video and main memory).
bufferUpdate(pixels);
}
-
+
if (isModified()) {
// Regular pixel copy from texture.
get(pixels);
}
-
+
setModified(false);
}
-
-
+
+
////////////////////////////////////////////////////////////
-
+
// Put methods (the source texture is not resized to cover the entire
// destination).
-
-
+
+
public void put(Texture tex) {
copyTexture(tex, 0, 0, tex.width, tex.height, false);
- }
+ }
+
-
public void put(Texture tex, int x, int y, int w, int h) {
copyTexture(tex, x, y, w, h, false);
- }
-
-
- public void put(int texTarget, int texName, int texWidth, int texHeight,
+ }
+
+
+ public void put(int texTarget, int texName, int texWidth, int texHeight,
int w, int h) {
copyTexture(texTarget, texName, texWidth, texHeight, 0, 0, w, h, false);
}
-
-
- public void put(int texTarget, int texName, int texWidth, int texHeight,
+
+
+ public void put(int texTarget, int texName, int texWidth, int texHeight,
int target, int tex, int x, int y, int w, int h) {
copyTexture(texTarget, texName, texWidth, texHeight, x, y, w, h, false);
}
-
-
- ////////////////////////////////////////////////////////////
-
+
+
+ ////////////////////////////////////////////////////////////
+
// Get OpenGL parameters
-
-
+
+
/**
* Returns true or false whether or not the texture is using mipmaps.
* @return boolean
- */
+ */
public boolean usingMipmaps() {
return usingMipmaps;
}
-
+
public void usingMipmaps(boolean mipmaps, int sampling) {
if (mipmaps) {
- if (glMinFilter != PGL.LINEAR_MIPMAP_NEAREST &&
+ if (glMinFilter != PGL.LINEAR_MIPMAP_NEAREST &&
glMinFilter != PGL.LINEAR_MIPMAP_LINEAR) {
if (sampling == POINT) {
glMagFilter = PGL.NEAREST;
glMinFilter = PGL.NEAREST;
} else if (sampling == LINEAR) {
glMagFilter = PGL.NEAREST;
- glMinFilter =
- PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
+ glMinFilter =
+ PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
} else if (sampling == BILINEAR) {
glMagFilter = PGL.LINEAR;
- glMinFilter =
+ glMinFilter =
PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
} else if (sampling == TRILINEAR) {
glMagFilter = PGL.LINEAR;
- glMinFilter =
+ glMinFilter =
PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
} else {
- throw new RuntimeException("Unknown texture filtering mode");
- }
+ throw new RuntimeException("Unknown texture filtering mode");
+ }
}
-
+
usingMipmaps = true;
} else {
- if (glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
+ if (glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
glMinFilter == PGL.LINEAR_MIPMAP_LINEAR) {
glMinFilter = PGL.LINEAR;
- }
+ }
usingMipmaps = false;
}
-
+
bind();
- pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
+ pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter);
if (usingMipmaps) {
if (PGraphicsOpenGL.autoMipmapGenSupported) {
pgl.generateMipmap(glTarget);
} else {
// TODO: need manual generation here..
- }
+ }
}
unbind();
- }
-
+ }
+
/**
* Returns true or false whether or not the texture is using repeat wrap mode
* along either U or V directions.
* @return boolean
- */
+ */
public boolean usingRepeat() {
return usingRepeat;
- }
-
-
+ }
+
+
public void usingRepeat(boolean repeat) {
if (repeat) {
- glWrapS = PGL.REPEAT;
+ glWrapS = PGL.REPEAT;
glWrapT = PGL.REPEAT;
usingRepeat = true;
} else {
- glWrapS = PGL.CLAMP_TO_EDGE;
- glWrapT = PGL.CLAMP_TO_EDGE;
+ glWrapS = PGL.CLAMP_TO_EDGE;
+ glWrapT = PGL.CLAMP_TO_EDGE;
usingRepeat = false;
}
-
+
bind();
pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS);
- pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT);
+ pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT);
unbind();
- }
-
-
+ }
+
+
/**
- * Returns the maximum possible value for the texture coordinate U
+ * Returns the maximum possible value for the texture coordinate U
* (horizontal).
* @return float
- */
+ */
public float getMaxU() {
return maxTexcoordU;
}
-
-
+
+
/**
* Returns the maximum possible value for the texture coordinate V (vertical).
* @return float
- */
+ */
public float getMaxV() {
return maxTexcoordV;
}
-
-
+
+
/**
* Returns true if the texture is flipped along the horizontal direction.
* @return boolean;
- */
+ */
public boolean isFlippedX() {
return flippedX;
}
-
+
/**
* Sets the texture as flipped or not flipped on the horizontal direction.
* @param v boolean;
- */
+ */
public void setFlippedX(boolean v) {
flippedX = v;
- }
-
-
+ }
+
+
/**
* Returns true if the texture is flipped along the vertical direction.
* @return boolean;
- */
+ */
public boolean isFlippedY() {
return flippedY;
}
-
+
/**
* Sets the texture as flipped or not flipped on the vertical direction.
* @param v boolean;
- */
+ */
public void setFlippedY(boolean v) {
flippedY = v;
}
- ////////////////////////////////////////////////////////////
-
- // Bind/unbind
-
-
+ ////////////////////////////////////////////////////////////
+
+ // Bind/unbind
+
+
public void bind() {
// Binding a texture automatically enables texturing for the
- // texture target from that moment onwards. Unbinding the texture
+ // texture target from that moment onwards. Unbinding the texture
// won't disable texturing.
if (!pgl.texturingIsEnabled(glTarget)) {
pgl.enableTexturing(glTarget);
@@ -695,31 +696,31 @@ public class Texture implements PConstants {
pgl.bindTexture(glTarget, glName);
bound = true;
}
-
-
+
+
public void unbind() {
if (pgl.textureIsBound(glTarget, glName)) {
// We don't want to unbind another texture
// that might be bound instead of this one.
if (!pgl.texturingIsEnabled(glTarget)) {
- pgl.enableTexturing(glTarget);
+ pgl.enableTexturing(glTarget);
pgl.bindTexture(glTarget, 0);
- pgl.disableTexturing(glTarget);
+ pgl.disableTexturing(glTarget);
} else {
pgl.bindTexture(glTarget, 0);
}
}
bound = false;
- }
-
-
+ }
+
+
public boolean bound() {
// A true result might not necessarily mean that texturing is enabled
// (a texture can be bound to the target, but texturing is disabled).
return bound;
}
-
-
+
+
//////////////////////////////////////////////////////////////
// Modified flag
@@ -737,39 +738,39 @@ public class Texture implements PConstants {
public void setModified(boolean m) {
modified = m;
- }
+ }
+
-
public int getModifiedX1() {
return mx1;
}
-
+
public int getModifiedX2() {
return mx2;
}
-
+
public int getModifiedY1() {
return my1;
}
-
+
public int getModifiedY2() {
return my2;
- }
-
+ }
+
public void updateTexels() {
updateTexelsImpl(0, 0, width, height);
- }
-
-
+ }
+
+
public void updateTexels(int x, int y, int w, int h) {
updateTexelsImpl(x, y, w, h);
}
-
+
protected void updateTexelsImpl(int x, int y, int w, int h) {
int x2 = x + w;
int y2 = y + h;
@@ -794,49 +795,49 @@ public class Texture implements PConstants {
}
}
-
+
////////////////////////////////////////////////////////////
-
+
// Buffer sink interface.
-
-
+
+
public void setBufferSource(Object source) {
bufferSource = source;
getSourceMethods();
- }
-
-
- public void copyBufferFromSource(Object natRef, ByteBuffer byteBuf,
+ }
+
+
+ public void copyBufferFromSource(Object natRef, ByteBuffer byteBuf,
int w, int h) {
if (bufferCache == null) {
bufferCache = new LinkedList();
}
-
+
if (bufferCache.size() + 1 <= MAX_BUFFER_CACHE_SIZE) {
bufferCache.add(new BufferData(natRef, byteBuf.asIntBuffer(), w, h));
- } else {
- // The buffer cache reached the maximum size, so we just dispose
+ } else {
+ // The buffer cache reached the maximum size, so we just dispose
// the new buffer.
try {
disposeBufferMethod.invoke(bufferSource, new Object[] { natRef });
} catch (Exception e) {
e.printStackTrace();
- }
+ }
}
}
-
-
+
+
public boolean hasBufferSource() {
return bufferSource != null;
}
-
-
+
+
public boolean hasBuffers() {
- return bufferSource != null && bufferCache != null &&
+ return bufferSource != null && bufferCache != null &&
0 < bufferCache.size();
- }
-
-
+ }
+
+
protected boolean bufferUpdate() {
BufferData data = null;
try {
@@ -844,19 +845,19 @@ public class Texture implements PConstants {
} catch (NoSuchElementException ex) {
PGraphics.showWarning("Don't have pixel data to copy to texture");
}
-
+
if (data != null) {
if ((data.w != width) || (data.h != height)) {
init(data.w, data.h);
}
setNative(data.rgbBuf, 0, 0, width, height);
-
+
data.dispose();
-
- return true;
+
+ return true;
} else {
return false;
- }
+ }
}
@@ -867,41 +868,41 @@ public class Texture implements PConstants {
} catch (NoSuchElementException ex) {
PGraphics.showWarning("Don't have pixel data to copy to texture");
}
-
+
if (data != null) {
if ((data.w != width) || (data.h != height)) {
init(data.w, data.h);
}
setNative(data.rgbBuf, 0, 0, width, height);
-
+
data.rgbBuf.get(pixels);
convertToARGB(pixels);
-
+
data.dispose();
-
- return true;
+
+ return true;
} else {
return false;
- }
+ }
}
-
+
protected void getSourceMethods() {
try {
disposeBufferMethod = bufferSource.getClass().
getMethod("disposeBuffer", new Class[] { Object.class });
} catch (Exception e) {
- throw new RuntimeException("Provided source object doesn't have a " +
+ throw new RuntimeException("Provided source object doesn't have a " +
"disposeBuffer method.");
- }
+ }
}
-
-
- ////////////////////////////////////////////////////////////
-
- // Utilities
-
-
+
+
+ ////////////////////////////////////////////////////////////
+
+ // Utilities
+
+
/**
* Flips intArray along the X axis.
* @param intArray int[]
@@ -919,7 +920,7 @@ public class Texture implements PConstants {
int temp = intArray[i];
intArray[i] = intArray[j];
intArray[j] = temp;
-
+
i++;
j++;
}
@@ -929,7 +930,7 @@ public class Texture implements PConstants {
xindex -= mult;
}
}
-
+
/**
* Flips intArray along the Y axis.
@@ -951,25 +952,25 @@ public class Texture implements PConstants {
yindex -= mult * width * 2;
}
}
-
-
+
+
/**
- * Reorders a pixel array in the given format into the order required by
- * OpenGL (RGBA). Both arrays are assumed to be of the same length. The width
+ * Reorders a pixel array in the given format into the order required by
+ * OpenGL (RGBA). Both arrays are assumed to be of the same length. The width
* and height parameters are used in the YUV420 to RBGBA conversion.
* @param intArray int[]
* @param tIntArray int[]
- * @param arrayFormat int
+ * @param arrayFormat int
* @param w int
* @param h int
*/
- protected void convertToRGBA(int[] intArray, int[] tIntArray, int arrayFormat,
+ protected void convertToRGBA(int[] intArray, int[] tIntArray, int arrayFormat,
int w, int h) {
if (PGL.BIG_ENDIAN) {
switch (arrayFormat) {
case ALPHA:
-
- // Converting from xxxA into RGBA. RGB is set to white
+
+ // Converting from xxxA into RGBA. RGB is set to white
// (0xFFFFFF, i.e.: (255, 255, 255))
for (int i = 0; i< intArray.length; i++) {
tIntArray[i] = 0xFFFFFF00 | intArray[i];
@@ -977,7 +978,7 @@ public class Texture implements PConstants {
break;
case RGB:
-
+
// Converting xRGB into RGBA. A is set to 0xFF (255, full opacity).
for (int i = 0; i< intArray.length; i++) {
int pixel = intArray[i];
@@ -986,7 +987,7 @@ public class Texture implements PConstants {
break;
case ARGB:
-
+
// Converting ARGB into RGBA. Shifting RGB to 8 bits to the left,
// and bringing A to the first byte.
for (int i = 0; i< intArray.length; i++) {
@@ -995,17 +996,17 @@ public class Texture implements PConstants {
}
break;
}
-
- } else {
+
+ } else {
// LITTLE_ENDIAN
// ARGB native, and RGBA opengl means ABGR on windows
// for the most part just need to swap two components here
// the sun.cpu.endian here might be "false", oddly enough..
// (that's why just using an "else", rather than check for "little")
-
- switch (arrayFormat) {
+
+ switch (arrayFormat) {
case ALPHA:
-
+
// Converting xxxA into ARGB, with RGB set to white.
for (int i = 0; i< intArray.length; i++) {
tIntArray[i] = (intArray[i] << 24) | 0x00FFFFFF;
@@ -1013,11 +1014,11 @@ public class Texture implements PConstants {
break;
case RGB:
-
+
// We need to convert xRGB into ABGR,
// so R and B must be swapped, and the x just made 0xFF.
for (int i = 0; i< intArray.length; i++) {
- int pixel = intArray[i];
+ int pixel = intArray[i];
tIntArray[i] = 0xFF000000 |
((pixel & 0xFF) << 16) |
((pixel & 0xFF0000) >> 16) |
@@ -1026,9 +1027,9 @@ public class Texture implements PConstants {
break;
case ARGB:
-
+
// We need to convert ARGB into ABGR,
- // so R and B must be swapped, A and G just brought back in.
+ // so R and B must be swapped, A and G just brought back in.
for (int i = 0; i < intArray.length; i++) {
int pixel = intArray[i];
tIntArray[i] = ((pixel & 0xFF) << 16) |
@@ -1036,20 +1037,20 @@ public class Texture implements PConstants {
(pixel & 0xFF00FF00);
}
break;
-
+
}
-
+
}
}
-
-
+
+
/**
* Reorders an OpenGL pixel array (RGBA) into ARGB. The array must be
* of size width * height.
- * @param intArray int[]
- */
+ * @param intArray int[]
+ */
protected void convertToARGB(int[] intArray) {
- int t = 0;
+ int t = 0;
int p = 0;
if (PGL.BIG_ENDIAN) {
@@ -1062,33 +1063,33 @@ public class Texture implements PConstants {
}
}
- } else {
+ } else {
- // We have to convert ABGR into ARGB, so R and B must be swapped,
- // A and G just brought back in.
+ // We have to convert ABGR into ARGB, so R and B must be swapped,
+ // A and G just brought back in.
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pixel = intArray[p++];
intArray[t++] = ((pixel & 0xFF) << 16) |
((pixel & 0xFF0000) >> 16) |
(pixel & 0xFF00FF00);
-
+
}
}
}
- }
+ }
-
-
- ///////////////////////////////////////////////////////////
- // Allocate/release texture.
-
+ ///////////////////////////////////////////////////////////
+
+ // Allocate/release texture.
+
+
protected void setSize(int w, int h) {
width = w;
height = h;
-
+
if (PGraphicsOpenGL.npotTexSupported) {
glWidth = w;
glHeight = h;
@@ -1096,112 +1097,112 @@ public class Texture implements PConstants {
glWidth = PGL.nextPowerOfTwo(w);
glHeight = PGL.nextPowerOfTwo(h);
}
-
- if (glWidth > PGraphicsOpenGL.maxTextureSize ||
+
+ if (glWidth > PGraphicsOpenGL.maxTextureSize ||
glHeight > PGraphicsOpenGL.maxTextureSize) {
glWidth = glHeight = 0;
throw new RuntimeException("Image width and height cannot be" +
- " larger than " +
+ " larger than " +
PGraphicsOpenGL.maxTextureSize +
" with this graphics card.");
}
-
- // If non-power-of-two textures are not supported, and the specified width
- // or height is non-power-of-two, then glWidth (glHeight) will be greater
- // than w (h) because it is chosen to be the next power of two, and this
- // quotient will give the appropriate maximum texture coordinate value given
+
+ // If non-power-of-two textures are not supported, and the specified width
+ // or height is non-power-of-two, then glWidth (glHeight) will be greater
+ // than w (h) because it is chosen to be the next power of two, and this
+ // quotient will give the appropriate maximum texture coordinate value given
// this situation.
maxTexcoordU = (float)width / glWidth;
- maxTexcoordV = (float)height / glHeight;
+ maxTexcoordV = (float)height / glHeight;
}
-
-
+
+
/**
- * Allocates the opengl texture object.
+ * Allocates the opengl texture object.
*/
protected void allocate() {
release(); // Just in the case this object is being re-allocated.
-
+
boolean enabledTex = false;
if (!pgl.texturingIsEnabled(glTarget)) {
pgl.enableTexturing(glTarget);
enabledTex = true;
}
-
- context = pgl.getCurrentContext();
- glName = pg.createTextureObject(context.code());
-
- pgl.bindTexture(glTarget, glName);
- pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
+
+ context = pgl.getCurrentContext();
+ glName = pg.createTextureObject(context.code());
+
+ pgl.bindTexture(glTarget, glName);
+ pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter);
pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS);
pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT);
-
- // First, we use glTexImage2D to set the full size of the texture (glW/glH
- // might be diff from w/h in the case that the GPU doesn't support NPOT
+
+ // First, we use glTexImage2D to set the full size of the texture (glW/glH
+ // might be diff from w/h in the case that the GPU doesn't support NPOT
// textures)
- pgl.texImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0,
+ pgl.texImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0,
PGL.RGBA, PGL.UNSIGNED_BYTE, null);
-
- // Makes sure that the texture buffer in video memory doesn't contain
+
+ // Makes sure that the texture buffer in video memory doesn't contain
// any garbage.
pgl.initTexture(glTarget, PGL.RGBA, width, height);
-
+
pgl.bindTexture(glTarget, 0);
if (enabledTex) {
pgl.disableTexturing(glTarget);
}
bound = false;
}
-
-
+
+
/**
* Marks the texture object for deletion.
*/
- protected void release() {
- if (glName != 0) {
+ protected void release() {
+ if (glName != 0) {
pg.finalizeTextureObject(glName, context.code());
glName = 0;
- }
+ }
}
-
+
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
// Removing the texture object from the renderer's list so it
- // doesn't get deleted by OpenGL. The texture object was
+ // doesn't get deleted by OpenGL. The texture object was
// automatically disposed when the old context was destroyed.
pg.removeTextureObject(glName, context.code());
-
+
// And then set the id to zero, so it doesn't try to be
// deleted when the object's finalizer is invoked by the GC.
- glName = 0;
+ glName = 0;
}
return outdated;
}
-
-
- ///////////////////////////////////////////////////////////
- // Utilities.
-
-
+
+ ///////////////////////////////////////////////////////////
+
+ // Utilities.
+
+
// Copies source texture tex into this.
- protected void copyTexture(Texture tex, int x, int y, int w, int h,
+ protected void copyTexture(Texture tex, int x, int y, int w, int h,
boolean scale) {
if (tex == null) {
throw new RuntimeException("Source texture is null");
- }
-
+ }
+
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
}
-
- // This texture is the color (destination) buffer of the FBO.
+
+ // This texture is the color (destination) buffer of the FBO.
tempFbo.setColorBuffer(this);
tempFbo.disableDepthTest();
-
+
// FBO copy:
pg.pushFramebuffer();
pg.setFramebuffer(tempFbo);
@@ -1210,9 +1211,9 @@ public class Texture implements PConstants {
// to cover the entire destination region.
pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight,
x, y, w, h, 0, 0, width, height);
-
+
} else {
- // Rendering tex into "this" but without scaling so the contents
+ // Rendering tex into "this" but without scaling so the contents
// of the source texture fall in the corresponding texels of the
// destination.
pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight,
@@ -1220,21 +1221,21 @@ public class Texture implements PConstants {
}
pg.popFramebuffer();
updateTexels(x, y, w, h);
- }
-
-
+ }
+
+
// Copies source texture tex into this.
- protected void copyTexture(int texTarget, int texName,
- int texWidth, int texHeight,
+ protected void copyTexture(int texTarget, int texName,
+ int texWidth, int texHeight,
int x, int y, int w, int h, boolean scale) {
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
}
-
- // This texture is the color (destination) buffer of the FBO.
+
+ // This texture is the color (destination) buffer of the FBO.
tempFbo.setColorBuffer(this);
tempFbo.disableDepthTest();
-
+
// FBO copy:
pg.pushFramebuffer();
pg.setFramebuffer(tempFbo);
@@ -1243,61 +1244,61 @@ public class Texture implements PConstants {
// to cover the entire destination region.
pgl.drawTexture(texTarget, texName, texWidth, texHeight,
x, y, w, h, 0, 0, width, height);
-
+
} else {
- // Rendering tex into "this" but without scaling so the contents
+ // Rendering tex into "this" but without scaling so the contents
// of the source texture fall in the corresponding texels of the
// destination.
pgl.drawTexture(texTarget, texName, texWidth, texHeight,
x, y, w, h, x, y, w, h);
}
pg.popFramebuffer();
- updateTexels(x, y, w, h);
+ updateTexels(x, y, w, h);
}
-
-
+
+
protected void copyObject(Texture src) {
- // The OpenGL texture of this object is replaced with the one from the
+ // The OpenGL texture of this object is replaced with the one from the
// source object, so we delete the former to avoid resource wasting.
- release();
-
+ release();
+
width = src.width;
height = src.height;
-
+
parent = src.parent;
pg = src.pg;
-
+
glName = src.glName;
glTarget = src.glTarget;
glFormat = src.glFormat;
- glMinFilter = src.glMinFilter;
+ glMinFilter = src.glMinFilter;
glMagFilter = src.glMagFilter;
glWidth= src.glWidth;
glHeight = src.glHeight;
-
+
usingMipmaps = src.usingMipmaps;
usingRepeat = src.usingRepeat;
maxTexcoordU = src.maxTexcoordU;
maxTexcoordV = src.maxTexcoordV;
-
- flippedX = src.flippedX;
+
+ flippedX = src.flippedX;
flippedY = src.flippedY;
}
-
-
- ///////////////////////////////////////////////////////////
-
+
+
+ ///////////////////////////////////////////////////////////
+
// Parameter handling
-
-
+
+
public Parameters getParameters() {
Parameters res = new Parameters();
-
+
if (glTarget == PGL.TEXTURE_2D) {
res.target = TEX2D;
}
-
+
if (glFormat == PGL.RGB) {
res.format = RGB;
} else if (glFormat == PGL.RGBA) {
@@ -1305,59 +1306,59 @@ public class Texture implements PConstants {
} else if (glFormat == PGL.ALPHA) {
res.format = ALPHA;
}
-
+
if (glMagFilter == PGL.NEAREST && glMinFilter == PGL.NEAREST) {
res.sampling = POINT;
res.mipmaps = false;
} else if (glMagFilter == PGL.NEAREST && glMinFilter == PGL.LINEAR) {
res.sampling = LINEAR;
res.mipmaps = false;
- } else if (glMagFilter == PGL.NEAREST &&
+ } else if (glMagFilter == PGL.NEAREST &&
glMinFilter == PGL.LINEAR_MIPMAP_NEAREST) {
res.sampling = LINEAR;
- res.mipmaps = true;
+ res.mipmaps = true;
} else if (glMagFilter == PGL.LINEAR && glMinFilter == PGL.LINEAR) {
res.sampling = BILINEAR;
res.mipmaps = false;
- } else if (glMagFilter == PGL.LINEAR &&
+ } else if (glMagFilter == PGL.LINEAR &&
glMinFilter == PGL.LINEAR_MIPMAP_NEAREST) {
res.sampling = BILINEAR;
res.mipmaps = true;
- } else if (glMagFilter == PGL.LINEAR &&
+ } else if (glMagFilter == PGL.LINEAR &&
glMinFilter == PGL.LINEAR_MIPMAP_LINEAR) {
res.sampling = TRILINEAR;
- res.mipmaps = true;
+ res.mipmaps = true;
}
-
+
if (glWrapS == PGL.CLAMP_TO_EDGE) {
- res.wrapU = CLAMP;
+ res.wrapU = CLAMP;
} else if (glWrapS == PGL.REPEAT) {
res.wrapU = REPEAT;
}
if (glWrapT == PGL.CLAMP_TO_EDGE) {
- res.wrapV = CLAMP;
+ res.wrapV = CLAMP;
} else if (glWrapT == PGL.REPEAT) {
res.wrapV = REPEAT;
}
-
+
return res;
}
-
-
+
+
/**
- * Sets texture target and internal format according to the target and
+ * Sets texture target and internal format according to the target and
* type specified.
- * @param target int
+ * @param target int
* @param params GLTextureParameters
- */
- protected void setParameters(Parameters params) {
+ */
+ protected void setParameters(Parameters params) {
if (params.target == TEX2D) {
glTarget = PGL.TEXTURE_2D;
} else {
- throw new RuntimeException("Unknown texture target");
+ throw new RuntimeException("Unknown texture target");
}
-
+
if (params.format == RGB) {
glFormat = PGL.RGB;
} else if (params.format == ARGB) {
@@ -1365,7 +1366,7 @@ public class Texture implements PConstants {
} else if (params.format == ALPHA) {
glFormat = PGL.ALPHA;
} else {
- throw new RuntimeException("Unknown texture format");
+ throw new RuntimeException("Unknown texture format");
}
if (params.sampling == POINT) {
@@ -1373,86 +1374,86 @@ public class Texture implements PConstants {
glMinFilter = PGL.NEAREST;
} else if (params.sampling == LINEAR) {
glMagFilter = PGL.NEAREST;
- glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
- PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
+ glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
+ PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
} else if (params.sampling == BILINEAR) {
glMagFilter = PGL.LINEAR;
- glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
+ glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
} else if (params.sampling == TRILINEAR) {
glMagFilter = PGL.LINEAR;
- glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
+ glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
} else {
- throw new RuntimeException("Unknown texture filtering mode");
+ throw new RuntimeException("Unknown texture filtering mode");
}
-
+
if (params.wrapU == CLAMP) {
- glWrapS = PGL.CLAMP_TO_EDGE;
+ glWrapS = PGL.CLAMP_TO_EDGE;
} else if (params.wrapU == REPEAT) {
glWrapS = PGL.REPEAT;
} else {
- throw new RuntimeException("Unknown wrapping mode");
+ throw new RuntimeException("Unknown wrapping mode");
}
-
+
if (params.wrapV == CLAMP) {
- glWrapT = PGL.CLAMP_TO_EDGE;
+ glWrapT = PGL.CLAMP_TO_EDGE;
} else if (params.wrapV == REPEAT) {
glWrapT = PGL.REPEAT;
} else {
- throw new RuntimeException("Unknown wrapping mode");
+ throw new RuntimeException("Unknown wrapping mode");
}
-
- usingMipmaps = glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
+
+ usingMipmaps = glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
glMinFilter == PGL.LINEAR_MIPMAP_LINEAR;
-
+
usingRepeat = glWrapS == PGL.REPEAT || glWrapT == PGL.REPEAT;
-
+
flippedX = false;
- flippedY = false;
- }
+ flippedY = false;
+ }
- ///////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////
+
+ // Parameters object
- // Parameters object
-
/**
- * This class stores the parameters for a texture: target, internal format,
- * minimization filter and magnification filter.
+ * This class stores the parameters for a texture: target, internal format,
+ * minimization filter and magnification filter.
*/
static public class Parameters {
/**
* Texture target.
*/
public int target;
-
+
/**
* Texture internal format.
*/
public int format;
-
+
/**
* Texture filtering (POINT, LINEAR, BILINEAR or TRILINEAR).
*/
public int sampling;
-
+
/**
* Use mipmaps or not.
- */
+ */
public boolean mipmaps;
-
+
/**
* Wrapping mode along U.
- */
+ */
public int wrapU;
-
+
/**
* Wrapping mode along V.
- */
+ */
public int wrapV;
-
+
/**
* Sets all the parameters to default values.
*/
@@ -1464,11 +1465,11 @@ public class Texture implements PConstants {
this.wrapU = CLAMP;
this.wrapV = CLAMP;
}
-
+
public Parameters(int format) {
this.target = TEX2D;
this.format = format;
- this.sampling = BILINEAR;
+ this.sampling = BILINEAR;
this.mipmaps = true;
this.wrapU = CLAMP;
this.wrapV = CLAMP;
@@ -1480,22 +1481,22 @@ public class Texture implements PConstants {
this.sampling = sampling;
this.mipmaps = true;
this.wrapU = CLAMP;
- this.wrapV = CLAMP;
+ this.wrapV = CLAMP;
}
-
+
public Parameters(int format, int sampling, boolean mipmaps) {
this.target = TEX2D;
this.format = format;
this.sampling = sampling;
this.mipmaps = mipmaps;
this.wrapU = CLAMP;
- this.wrapV = CLAMP;
+ this.wrapV = CLAMP;
}
-
+
public Parameters(Parameters src) {
set(src);
}
-
+
public void set(int format) {
this.format = format;
}
@@ -1504,50 +1505,50 @@ public class Texture implements PConstants {
this.format = format;
this.sampling = sampling;
}
-
+
public void set(int format, int sampling, boolean mipmaps) {
this.format = format;
this.sampling = sampling;
this.mipmaps = mipmaps;
- }
-
+ }
+
public void set(Parameters src) {
this.target = src.target;
this.format = src.format;
this.sampling = src.sampling;
this.mipmaps = src.mipmaps;
this.wrapU = src.wrapU;
- this.wrapV = src.wrapV;
- }
+ this.wrapV = src.wrapV;
+ }
}
-
+
/**
* This class stores a buffer copied from the buffer source.
*
*/
- protected class BufferData {
+ protected class BufferData {
int w, h;
// Native buffer object.
Object natBuf;
// Buffer viewed as int.
IntBuffer rgbBuf;
-
+
BufferData(Object nat, IntBuffer rgb, int w, int h) {
natBuf = nat;
rgbBuf = rgb;
this.w = w;
this.h = h;
}
-
+
void dispose() {
try {
// Disposing the native buffer.
disposeBufferMethod.invoke(bufferSource, new Object[] { natBuf });
- natBuf = null;
+ natBuf = null;
rgbBuf = null;
} catch (Exception e) {
e.printStackTrace();
- }
+ }
}
- }
+ }
}
diff --git a/core/todo.txt b/core/todo.txt
index 2f365871b..5662c417d 100644
--- a/core/todo.txt
+++ b/core/todo.txt
@@ -1,5 +1,57 @@
0208 core
+
+andres
+A implement repeating textures
+A http://code.google.com/p/processing/issues/detail?id=94
+_ CLAMP and REPEAT have now been added
+X lights don't work in GL renderers on low-end android devices
+X http://code.google.com/p/processing/issues/detail?id=1145
+X Pixels for createGraphics() should be transparent (P2D, P3D) in P2a7
+X http://code.google.com/p/processing/issues/detail?id=1156
+
+video
X remove/hide several video functions that weren't approved
+A Some videos give OpenGL error with P2D/P3D
+A http://code.google.com/p/processing/issues/detail?id=1166
+A Jump movie to multiple of the framerate
+A http://code.google.com/p/processing/issues/detail?id=1182
+A Movie functions not working in setup()
+A http://code.google.com/p/processing/issues/detail?id=1181
+A Capture needs better initialization API
+A http://code.google.com/p/processing/issues/detail?id=1184
+A Movie examples not working in P2D, P3D in 2.0a8
+A http://code.google.com/p/processing/issues/detail?id=1178
+A GettingStartedCapture in 2.0a8 launches X11 in Mountain Lion
+A http://code.google.com/p/processing/issues/detail?id=1191
+A Wrong resolutions reported by Capture.list()
+A http://code.google.com/p/processing/issues/detail?id=1192
+
+_ implement callbacks for images and other loadXxxx() functions
+_ remove requestImage() and friends
+
+PImage icon;
+
+void setup() {
+ loadImage("icon.jpg", "iconLoaded");
+}
+
+void draw() {
+ if (icon != null) {
+ // do something
+ }
+}
+
+// if this version is present, it'll be called
+void iconLoaded(PImage image) {
+ icon = image;
+ // filename can be ignored
+}
+
+// alternate version that can be used, and will be called if present
+void iconLoaded(PImage image, String filename) {
+ icon = image;
+ // filename can be ignored
+}
api to be fixed/removed
diff --git a/todo.txt b/todo.txt
index ea3cba663..464508e3a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,6 +2,58 @@
X Help menu broken when Processing has spaces in its path name in 2.0a8
X http://code.google.com/p/processing/issues/detail?id=1164
+_ remove preferences that refer to applets
+
+_ try to use appbundler to create a version that includes a JRE (JDK)
+_ http://java.net/downloads/appbundler/appbundler.html
+_ http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
+_ http://www.intransitione.com/blog/take-java-to-app-store/
+_ investigate the sandboxing situation on OS X
+_ http://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW1
+most sandbox violations are triggered by attempts to read/write to the
+filesystem without user intervention (eg. without using an open/save
+dialog) and/or from places outside the container (eg.
+~/Library/Containers/yourapp/...).
+A violation is also triggered by trying to execute an external process
+from Java (ex. using Runtime.exec()).
+If you look at the list of entitlements your application can have on
+the Apple site(*) you can think whether your application is performing
+an operation that would require enabling a specific entitlement, like
+connecting to a network, printing, interacting with a usb or bluetooth
+device, etc..
+
+. . .
+
+I encountered this problem too, I forgot to add it to my guide....
+If you sign all the files in the bundle it won't work as codesign
+doesn't follow the symlinks.
+
+First sign your bundle:
+codesign --verbose -f -s "$SIGNATURE_APP" --entitlements $ENTITLEMENTS
+$YOUR_APP.app
+
+Then sign all the libraries:
+find $YOUR_APP/Contents/ -type f \( -name "*.jar" -or -name "*.dylib"
+\) -exec codesign --verbose -f -s "$SIGNATURE_APP" --entitlements
+$ENTITLEMENTS {} \;
+
+Finally you can create the package:
+productbuild --component YOUR_APP.app /Applications --sign
+"$SIGNATURE_INST" YOUR_APP.pkg
+
+You can test if the package work with this command:
+
+sudo installer -store -pkg $YOUR_APP.pkg -target /
+
+You can also verify all libraries have been signed
+find YOUR_APP/Contents/ -type f \( -name "*.jar" -or -name "*.dylib"
+\) -exec codesign --verbose --verify {} \;
+
+. . .
+
+_ 'recent' menu doesn't respect examples folder of other p5 versions
+_ 'recent' menu paths can get enormous
+
2.0 FINAL / command line
_ kill external editor (for all its quirks) in favor of command line