From 92f62c45cec5fa42667112cde4bbe71e085fe2ef Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 10 Feb 2013 00:13:32 -0500 Subject: [PATCH] Android sync --- android/core/src/processing/core/PShape.java | 846 +++++++++++++- .../src/processing/opengl/FontTexture.java | 2 +- .../src/processing/opengl/FrameBuffer.java | 42 +- .../src/processing/opengl/LineShaderFrag.glsl | 2 +- .../src/processing/opengl/LineShaderVert.glsl | 30 +- .../src/processing/opengl/MaskShaderFrag.glsl | 14 +- android/core/src/processing/opengl/PGL.java | 57 +- .../src/processing/opengl/PGraphics2D.java | 11 +- .../src/processing/opengl/PGraphics3D.java | 16 +- .../processing/opengl/PGraphicsOpenGL.java | 471 ++++---- .../core/src/processing/opengl/PShader.java | 28 +- .../src/processing/opengl/PShapeOpenGL.java | 1010 +++++++++++++---- .../processing/opengl/PointShaderFrag.glsl | 2 +- .../processing/opengl/PointShaderVert.glsl | 24 +- .../opengl/PolyColorShaderVert.glsl | 14 +- .../opengl/PolyLightShaderVert.glsl | 48 +- .../opengl/PolyNoTexShaderFrag.glsl | 2 +- .../processing/opengl/PolyTexShaderFrag.glsl | 10 +- .../processing/opengl/PolyTexShaderVert.glsl | 22 +- .../opengl/PolyTexlightShaderVert.glsl | 56 +- .../core/src/processing/opengl/Texture.java | 16 +- 21 files changed, 1971 insertions(+), 752 deletions(-) diff --git a/android/core/src/processing/core/PShape.java b/android/core/src/processing/core/PShape.java index 514507ede..2fa801684 100644 --- a/android/core/src/processing/core/PShape.java +++ b/android/core/src/processing/core/PShape.java @@ -24,6 +24,8 @@ package processing.core; import java.util.HashMap; +import processing.core.PApplet; + /** * ( begin auto-generated from PShape.xml ) @@ -69,13 +71,12 @@ import java.util.HashMap; * * @webref shape * @usage Web & Application - * @see PApplet#shape(PShape) * @see PApplet#loadShape(String) + * @see PApplet#createShape() * @see PApplet#shapeMode(int) * @instanceName sh any variable of type PShape */ public class PShape implements PConstants { - protected String name; protected HashMap nameTable; @@ -96,9 +97,17 @@ public class PShape implements PConstants { protected PMatrix matrix; + protected int textureMode; + /** Texture or image data associated with this shape. */ protected PImage image; + public static final String OUTSIDE_BEGIN_END_ERROR = + "%1$s can only be called between beginShape() and endShape()"; + + public static final String INSIDE_BEGIN_END_ERROR = + "%1$s can only be called outside beginShape() and endShape()"; + // boundary box of this shape //protected float x; //protected float y; @@ -113,6 +122,7 @@ public class PShape implements PConstants { * @webref pshape:field * @usage web_application * @brief Shape document width + * @see PShape#height */ public float width; /** @@ -124,13 +134,20 @@ public class PShape implements PConstants { * @webref pshape:field * @usage web_application * @brief Shape document height + * @see PShape#width */ public float height; + public float depth; // set to false if the object is hidden in the layers palette protected boolean visible = true; + /** Retained shape being created with beginShape/endShape */ + protected boolean openShape = false; + + protected boolean openContour = false; + protected boolean stroke; protected int strokeColor; protected float strokeWeight; // default is 1 @@ -174,7 +191,6 @@ public class PShape implements PConstants { /** True if this is a closed path. */ protected boolean close; - // ........................................................ // internal color for setting/calculating @@ -207,7 +223,6 @@ public class PShape implements PConstants { /** True if contains 3D data */ protected boolean is3D = false; - // should this be called vertices (consistent with PGraphics internals) // or does that hurt flexibility? @@ -243,7 +258,6 @@ public class PShape implements PConstants { // public float px; // public float py; - public PShape() { this.family = GROUP; } @@ -285,11 +299,13 @@ public class PShape implements PConstants { * @webref pshape:method * @usage web_application * @brief Returns a boolean value "true" if the image is set to be visible, "false" if not + * @see PShape#setVisible(boolean) */ public boolean isVisible() { return visible; } + /** * ( begin auto-generated from PShape_setVisible.xml ) * @@ -305,6 +321,7 @@ public class PShape implements PConstants { * @usage web_application * @brief Sets the shape to be visible or invisible * @param visible "false" makes the shape invisible and "true" makes it visible + * @see PShape#isVisible() */ public void setVisible(boolean visible) { this.visible = visible; @@ -326,6 +343,7 @@ public class PShape implements PConstants { * @webref pshape:method * @usage web_application * @brief Disables the shape's style data and uses Processing styles + * @see PShape#enableStyle() */ public void disableStyle() { style = false; @@ -348,6 +366,7 @@ public class PShape implements PConstants { * @webref pshape:method * @usage web_application * @brief Enables the shape's style data and ignores the Processing styles + * @see PShape#disableStyle() */ public void enableStyle() { style = true; @@ -399,6 +418,7 @@ public class PShape implements PConstants { + /* // TODO unapproved protected PVector getTop() { return getTop(null); @@ -424,6 +444,7 @@ public class PShape implements PConstants { } return bottom; } + */ /** @@ -446,26 +467,97 @@ public class PShape implements PConstants { is3D = val; } + +// /** +// * Return true if this shape requires rendering through OpenGL. Defaults to false. +// */ +// // TODO unapproved +// public boolean isGL() { +// return false; +// } + + /////////////////////////////////////////////////////////// // // Drawing methods + public void textureMode(int mode) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "textureMode()"); + return; + } + + textureMode = mode; + } + public void texture(PImage tex) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "texture()"); + return; + } + + image = tex; } public void noTexture() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noTexture()"); + return; + } + + image = null; } // TODO unapproved protected void solid(boolean solid) { } + /** + * @webref shape:vertex + * @brief Starts a new contour + * @see PShape#endContour() + */ public void beginContour() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "beginContour()"); + return; + } + + if (family == GROUP) { + PGraphics.showWarning("Cannot begin contour in GROUP shapes"); + return; + } + + if (openContour) { + PGraphics.showWarning("Already called beginContour()."); + return; + } + openContour = true; } + /** + * @webref shape:vertex + * @brief Ends a contour + * @see PShape#beginContour() + */ public void endContour() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "endContour()"); + return; + } + + if (family == GROUP) { + PGraphics.showWarning("Cannot end contour in GROUP shapes"); + return; + } + + if (!openContour) { + PGraphics.showWarning("Need to call beginContour() first."); + return; + } + openContour = false; } public void vertex(float x, float y) { @@ -483,126 +575,407 @@ public class PShape implements PConstants { public void normal(float nx, float ny, float nz) { } - public void end() { + public void beginShape() { + beginShape(POLYGON); } - public void end(int mode) { + public void beginShape(int kind) { + this.kind = kind; + openShape = true; } + /** + * @webref pshape:method + * @brief Finishes the creation of a new PShape + * @see PApplet#createShape() + */ + public void endShape() { + endShape(OPEN); + } + + public void endShape(int mode) { + if (family == GROUP) { + PGraphics.showWarning("Cannot end GROUP shape"); + return; + } + + if (!openShape) { + PGraphics.showWarning("Need to call beginShape() first"); + return; + } + + openShape = false; + } + + ////////////////////////////////////////////////////////////// // STROKE CAP/JOIN/WEIGHT public void strokeWeight(float weight) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeWeight()"); + return; + } + + strokeWeight = weight; } public void strokeJoin(int join) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeJoin()"); + return; + } + + strokeJoin = join; } public void strokeCap(int cap) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeCap()"); + return; + } + + strokeCap = cap; } + ////////////////////////////////////////////////////////////// // FILL COLOR + public void noFill() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noFill()"); + return; + } + + fill = false; } + public void fill(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(rgb); + fillColor = calcColor; } + public void fill(int rgb, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(rgb, alpha); + fillColor = calcColor; } + public void fill(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(gray); + fillColor = calcColor; } + public void fill(float gray, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(gray, alpha); + fillColor = calcColor; } + public void fill(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(x, y, z); + fillColor = calcColor; } + public void fill(float x, float y, float z, float a) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()"); + return; + } + + fill = true; + colorCalc(x, y, z, a); + fillColor = calcColor; } + ////////////////////////////////////////////////////////////// // STROKE COLOR + public void noStroke() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noStroke()"); + return; + } + + stroke = false; } + public void stroke(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(rgb); + strokeColor = calcColor; } + public void stroke(int rgb, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(rgb, alpha); + strokeColor = calcColor; } + public void stroke(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(gray); + strokeColor = calcColor; } + public void stroke(float gray, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(gray, alpha); + strokeColor = calcColor; } + public void stroke(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(x, y, z); + strokeColor = calcColor; } + public void stroke(float x, float y, float z, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()"); + return; + } + + stroke = true; + colorCalc(x, y, z, alpha); + strokeColor = calcColor; } + ////////////////////////////////////////////////////////////// // TINT COLOR public void noTint() { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noTint()"); + return; + } + + tint = false; } + public void tint(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(rgb); + tintColor = calcColor; } + public void tint(int rgb, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(rgb, alpha); + tintColor = calcColor; } + public void tint(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(gray); + tintColor = calcColor; } + public void tint(float gray, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(gray, alpha); + tintColor = calcColor; } + public void tint(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(x, y, z); + tintColor = calcColor; } + public void tint(float x, float y, float z, float alpha) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()"); + return; + } + + tint = true; + colorCalc(x, y, z, alpha); + tintColor = calcColor; } + ////////////////////////////////////////////////////////////// // Ambient set/update public void ambient(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()"); + return; + } + + setAmbient = true; + colorCalc(rgb); + ambientColor = calcColor; } + public void ambient(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()"); + return; + } + + setAmbient = true; + colorCalc(gray); + ambientColor = calcColor; } + public void ambient(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()"); + return; + } + + setAmbient = true; + colorCalc(x, y, z); + ambientColor = calcColor; } + ////////////////////////////////////////////////////////////// // Specular set/update public void specular(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()"); + return; + } + + colorCalc(rgb); + specularColor = calcColor; } + public void specular(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()"); + return; + } + + colorCalc(gray); + specularColor = calcColor; } + public void specular(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()"); + return; + } + + colorCalc(x, y, z); + specularColor = calcColor; } @@ -611,19 +984,49 @@ public class PShape implements PConstants { // Emissive set/update public void emissive(int rgb) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()"); + return; + } + + colorCalc(rgb); + emissiveColor = calcColor; } + public void emissive(float gray) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()"); + return; + } + + colorCalc(gray); + emissiveColor = calcColor; } + public void emissive(float x, float y, float z) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()"); + return; + } + + colorCalc(x, y, z); + emissiveColor = calcColor; } + ////////////////////////////////////////////////////////////// // Shininess set/update public void shininess(float shine) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "shininess()"); + return; + } + + shininess = shine; } /////////////////////////////////////////////////////////// @@ -673,6 +1076,7 @@ public class PShape implements PConstants { } + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -818,6 +1222,8 @@ public class PShape implements PConstants { // TODO unapproved static protected void copyGeometry(PShape src, PShape dest) { + dest.beginShape(src.getKind()); + copyMatrix(src, dest); copyStyles(src, dest); copyImage(src, dest); @@ -826,10 +1232,12 @@ public class PShape implements PConstants { for (int i = 0; i < src.vertexCount; i++) { float[] vert = src.vertices[i]; - dest.fill(vert[PGraphics.R] * 255, - vert[PGraphics.G] * 255, - vert[PGraphics.B] * 255, - vert[PGraphics.A] * 255); + + + dest.fill((int)(vert[PGraphics.R] * 255) << 24 | + (int)(vert[PGraphics.G] * 255) << 16 | + (int)(vert[PGraphics.B] * 255) << 8 | + (int)(vert[PGraphics.A] * 255)); // Do we need to copy these as well? // dest.ambient(vert[PGraphics.AR] * 255, vert[PGraphics.AG] * 255, vert[PGraphics.AB] * 255); @@ -859,7 +1267,7 @@ public class PShape implements PConstants { } } - dest.end(); + dest.endShape(); } @@ -910,6 +1318,7 @@ public class PShape implements PConstants { } + //////////////////////////////////////////////////////////////////////// @@ -1189,9 +1598,9 @@ public class PShape implements PConstants { g.beginContour(); insideContour = true; } - } } } + } if (insideContour) { g.endContour(); } @@ -1206,7 +1615,6 @@ public class PShape implements PConstants { return parent; } - public int getChildCount() { return childCount; } @@ -1216,7 +1624,6 @@ public class PShape implements PConstants { return children; } - /** * ( begin auto-generated from PShape_getChild.xml ) * @@ -1229,15 +1636,15 @@ public class PShape implements PConstants { * @usage web_application * @brief Returns a child element of a shape as a PShape object * @param index the layer position of the shape to get + * @see PShape#addChild(PShape) */ public PShape getChild(int index) { return children[index]; } - - /** - * @param target the name of the shape to get - */ + /** + * @param target the name of the shape to get + */ public PShape getChild(String target) { if (name != null && name.equals(target)) { return this; @@ -1269,6 +1676,12 @@ public class PShape implements PConstants { // can't be just 'add' because that suggests additive geometry + /** + * @webref pshape:method + * @brief Adds a new child + * @param who any variable of type PShape + * @see PShape#getChild(int) + */ public void addChild(PShape who) { if (children == null) { children = new PShape[1]; @@ -1286,6 +1699,9 @@ public class PShape implements PConstants { // adds child who exactly at position idx in the array of children. + /** + * @param idx the layer position in which to insert the new child + */ public void addChild(PShape who, int idx) { if (idx < childCount) { if (childCount == children.length) { @@ -1430,18 +1846,31 @@ public class PShape implements PConstants { } } - + /** + * @webref pshape:method + * @brief Returns the total number of vertices as an int + * @see PShape#getVertex(int) + * @see PShape#setVertex(int, float, float) + */ public int getVertexCount() { return vertexCount; } - + /** + * @webref pshape:method + * @brief Returns the vertex at the index position + * @param index the location of the vertex + * @see PShape#setVertex(int, float, float) + * @see PShape#getVertexCount() + */ public PVector getVertex(int index) { return getVertex(index, null); } - + /** + * @param vec PVector to assign the data to + */ public PVector getVertex(int index, PVector vec) { if (vec == null) { vec = new PVector(); @@ -1467,21 +1896,48 @@ public class PShape implements PConstants { return vertices[index][Z]; } - + /** + * @webref pshape:method + * @brief Sets the vertex at the index position + * @param index the location of the vertex + * @param x the x value for the vertex + * @param y the y value for the vertex + * @see PShape#getVertex(int) + * @see PShape#getVertexCount() + */ public void setVertex(int index, float x, float y) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()"); + return; + } + vertices[index][X] = x; vertices[index][Y] = y; } - + /** + * @param z the z value for the vertex + */ public void setVertex(int index, float x, float y, float z) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()"); + return; + } + vertices[index][X] = x; vertices[index][Y] = y; vertices[index][Z] = z; } - + /** + * @param vec the PVector to define the x, y, z coordinates + */ public void setVertex(int index, PVector vec) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()"); + return; + } + vertices[index][X] = vec.x; vertices[index][Y] = vec.y; vertices[index][Z] = vec.z; @@ -1520,6 +1976,11 @@ public class PShape implements PConstants { public void setNormal(int index, float nx, float ny, float nz) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setNormal()"); + return; + } + vertices[index][PGraphics.NX] = nx; vertices[index][PGraphics.NY] = ny; vertices[index][PGraphics.NZ] = nz; @@ -1537,25 +1998,133 @@ public class PShape implements PConstants { public void setTextureUV(int index, float u, float v) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureUV()"); + return; + } + vertices[index][PGraphics.U] = u; vertices[index][PGraphics.V] = v; } + public void setTextureMode(int mode) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureMode()"); + return; + } + + textureMode = mode; + } + + + public void setTexture(PImage tex) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTexture()"); + return; + } + + image = tex; + } + + public int getFill(int index) { - int a = (int) (vertices[index][PGraphics.A] * 255); - int r = (int) (vertices[index][PGraphics.R] * 255); - int g = (int) (vertices[index][PGraphics.G] * 255); - int b = (int) (vertices[index][PGraphics.B] * 255); - return (a << 24) | (r << 16) | (g << 8) | b; + if (image == null) { + int a = (int) (vertices[index][PGraphics.A] * 255); + int r = (int) (vertices[index][PGraphics.R] * 255); + int g = (int) (vertices[index][PGraphics.G] * 255); + int b = (int) (vertices[index][PGraphics.B] * 255); + return (a << 24) | (r << 16) | (g << 8) | b; + } else { + return 0; + } + } + + + public void setFill(boolean fill) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + this.fill = fill; + } + + + public void setFill(int fill) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setFill(i, fill); + } } public void setFill(int index, int fill) { - vertices[index][PGraphics.A] = ((fill >> 24) & 0xFF) / 255.0f; - vertices[index][PGraphics.R] = ((fill >> 16) & 0xFF) / 255.0f; - vertices[index][PGraphics.G] = ((fill >> 8) & 0xFF) / 255.0f; - vertices[index][PGraphics.B] = ((fill >> 0) & 0xFF) / 255.0f; + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + if (image == null) { + vertices[index][PGraphics.A] = ((fill >> 24) & 0xFF) / 255.0f; + vertices[index][PGraphics.R] = ((fill >> 16) & 0xFF) / 255.0f; + vertices[index][PGraphics.G] = ((fill >> 8) & 0xFF) / 255.0f; + vertices[index][PGraphics.B] = ((fill >> 0) & 0xFF) / 255.0f; + } + } + + + public int getTint(int index) { + if (image != null) { + int a = (int) (vertices[index][PGraphics.A] * 255); + int r = (int) (vertices[index][PGraphics.R] * 255); + int g = (int) (vertices[index][PGraphics.G] * 255); + int b = (int) (vertices[index][PGraphics.B] * 255); + return (a << 24) | (r << 16) | (g << 8) | b; + } else { + return 0; + } + } + + + public void setTint(boolean tint) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + this.tint = tint; + } + + + public void setTint(int fill) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setFill(i, fill); + } + } + + + public void setTint(int index, int tint) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + if (image != null) { + vertices[index][PGraphics.A] = ((tint >> 24) & 0xFF) / 255.0f; + vertices[index][PGraphics.R] = ((tint >> 16) & 0xFF) / 255.0f; + vertices[index][PGraphics.G] = ((tint >> 8) & 0xFF) / 255.0f; + vertices[index][PGraphics.B] = ((tint >> 0) & 0xFF) / 255.0f; + } } @@ -1568,7 +2137,34 @@ public class PShape implements PConstants { } + public void setStroke(boolean stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + + this.stroke = stroke; + } + + + public void setStroke(int stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setStroke(i, stroke); + } + } + + public void setStroke(int index, int stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + vertices[index][PGraphics.SA] = ((stroke >> 24) & 0xFF) / 255.0f; vertices[index][PGraphics.SR] = ((stroke >> 16) & 0xFF) / 255.0f; vertices[index][PGraphics.SG] = ((stroke >> 8) & 0xFF) / 255.0f; @@ -1576,17 +2172,54 @@ public class PShape implements PConstants { } - protected float getStrokeWeight(int index) { + public float getStrokeWeight(int index) { return vertices[index][PGraphics.SW]; } - protected void setStrokeWeight(int index, float weight) { + public void setStrokeWeight(float weight) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setStrokeWeight(i, weight); + } + } + + + public void setStrokeWeight(int index, float weight) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()"); + return; + } + vertices[index][PGraphics.SW] = weight; } - protected int getAmbient(int index) { + public void setStrokeJoin(int join) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeJoin()"); + return; + } + + strokeJoin = join; + } + + + public void setStrokeCap(int cap) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeCap()"); + return; + } + + strokeCap = cap; + } + + + public int getAmbient(int index) { int r = (int) (vertices[index][PGraphics.AR] * 255); int g = (int) (vertices[index][PGraphics.AG] * 255); int b = (int) (vertices[index][PGraphics.AB] * 255); @@ -1594,13 +2227,31 @@ public class PShape implements PConstants { } - protected void setAmbient(int index, int ambient) { + public void setAmbient(int ambient) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setAmbient(i, ambient); + } + } + + + public void setAmbient(int index, int ambient) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()"); + return; + } + vertices[index][PGraphics.AR] = ((ambient >> 16) & 0xFF) / 255.0f; vertices[index][PGraphics.AG] = ((ambient >> 8) & 0xFF) / 255.0f; vertices[index][PGraphics.AB] = ((ambient >> 0) & 0xFF) / 255.0f; } - protected int getSpecular(int index) { + + public int getSpecular(int index) { int r = (int) (vertices[index][PGraphics.SPR] * 255); int g = (int) (vertices[index][PGraphics.SPG] * 255); int b = (int) (vertices[index][PGraphics.SPB] * 255); @@ -1608,14 +2259,31 @@ public class PShape implements PConstants { } - protected void setSpecular(int index, int specular) { + public void setSpecular(int specular) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setSpecular(i, specular); + } + } + + + public void setSpecular(int index, int specular) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()"); + return; + } + vertices[index][PGraphics.SPR] = ((specular >> 16) & 0xFF) / 255.0f; vertices[index][PGraphics.SPG] = ((specular >> 8) & 0xFF) / 255.0f; vertices[index][PGraphics.SPB] = ((specular >> 0) & 0xFF) / 255.0f; } - protected int getEmissive(int index) { + public int getEmissive(int index) { int r = (int) (vertices[index][PGraphics.ER] * 255); int g = (int) (vertices[index][PGraphics.EG] * 255); int b = (int) (vertices[index][PGraphics.EB] * 255); @@ -1623,19 +2291,53 @@ public class PShape implements PConstants { } - protected void setEmissive(int index, int emissive) { + public void setEmissive(int emissive) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setEmissive(i, emissive); + } + } + + + public void setEmissive(int index, int emissive) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()"); + return; + } + vertices[index][PGraphics.ER] = ((emissive >> 16) & 0xFF) / 255.0f; vertices[index][PGraphics.EG] = ((emissive >> 8) & 0xFF) / 255.0f; vertices[index][PGraphics.EB] = ((emissive >> 0) & 0xFF) / 255.0f; } - protected float getShininess(int index) { + public float getShininess(int index) { return vertices[index][PGraphics.SHINE]; } - protected void setShininess(int index, float shine) { + public void setShininess(float shine) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()"); + return; + } + + for (int i = 0; i < vertices.length; i++) { + setShininess(i, shine); + } + } + + + public void setShininess(int index, float shine) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()"); + return; + } + vertices[index][PGraphics.SHINE] = shine; } @@ -1723,18 +2425,21 @@ public class PShape implements PConstants { * @brief Displaces the shape * @param tx left/right translation * @param ty up/down translation + * @see PShape#rotate(float) + * @see PShape#scale(float) + * @see PShape#resetMatrix() */ - public void translate(float tx, float ty) { + public void translate(float x, float y) { checkMatrix(2); - matrix.translate(tx, ty); + matrix.translate(x, y); } /** * @param tz forward/back translation */ - public void translate(float tx, float ty, float tz) { + public void translate(float x, float y, float z) { checkMatrix(3); - matrix.translate(tx, ty, tz); + matrix.translate(x, y, z); } /** @@ -1759,6 +2464,12 @@ public class PShape implements PConstants { * @usage web_application * @brief Rotates the shape around the x-axis * @param angle angle of rotation specified in radians + * @see PShape#rotate(float) + * @see PShape#rotateY(float) + * @see PShape#rotateZ(float) + * @see PShape#scale(float) + * @see PShape#translate(float, float) + * @see PShape#resetMatrix() */ public void rotateX(float angle) { rotate(angle, 1, 0, 0); @@ -1790,6 +2501,9 @@ public class PShape implements PConstants { * @see PShape#rotate(float) * @see PShape#rotateX(float) * @see PShape#rotateZ(float) + * @see PShape#scale(float) + * @see PShape#translate(float, float) + * @see PShape#resetMatrix() */ public void rotateY(float angle) { rotate(angle, 0, 1, 0); @@ -1818,6 +2532,12 @@ public class PShape implements PConstants { * @usage web_application * @brief Rotates the shape around the z-axis * @param angle angle of rotation specified in radians + * @see PShape#rotate(float) + * @see PShape#rotateX(float) + * @see PShape#rotateY(float) + * @see PShape#scale(float) + * @see PShape#translate(float, float) + * @see PShape#resetMatrix() */ public void rotateZ(float angle) { rotate(angle, 0, 0, 1); @@ -1843,6 +2563,12 @@ public class PShape implements PConstants { * @usage web_application * @brief Rotates the shape * @param angle angle of rotation specified in radians + * @see PShape#rotateX(float) + * @see PShape#rotateY(float) + * @see PShape#rotateZ(float) + * @see PShape#scale(float) + * @see PShape#translate(float, float) + * @see PShape#resetMatrix() */ public void rotate(float angle) { checkMatrix(2); // at least 2... @@ -1888,6 +2614,9 @@ public class PShape implements PConstants { * @usage web_application * @brief Increases and decreases the size of a shape * @param s percentate to scale the object + * @see PShape#rotate(float) + * @see PShape#translate(float, float) + * @see PShape#resetMatrix() */ public void scale(float s) { checkMatrix(2); // at least 2... @@ -1900,12 +2629,11 @@ public class PShape implements PConstants { matrix.scale(x, y); } - - /** - * @param x percentage to scale the object in the x-axis - * @param y percentage to scale the object in the y-axis - * @param z percentage to scale the object in the z-axis - */ +/** + * @param x percentage to scale the object in the x-axis + * @param y percentage to scale the object in the y-axis + * @param z percentage to scale the object in the z-axis + */ public void scale(float x, float y, float z) { checkMatrix(3); matrix.scale(x, y, z); @@ -1921,9 +2649,12 @@ public class PShape implements PConstants { * equivalent function in OpenGL is glLoadIdentity(). * * ( end auto-generated ) - * @webref pshape:method - * @brief Replaces the current matrix of a shape with the identity matrix - * @usage web_application + * @webref pshape:method + * @brief Replaces the current matrix of a shape with the identity matrix + * @usage web_application + * @see PShape#rotate(float) + * @see PShape#scale(float) + * @see PShape#translate(float, float) */ public void resetMatrix() { checkMatrix(2); @@ -2194,5 +2925,4 @@ public class PShape implements PConstants { calcAlpha = (calcAi != 255); } - } \ No newline at end of file diff --git a/android/core/src/processing/opengl/FontTexture.java b/android/core/src/processing/opengl/FontTexture.java index 0445d611a..91a71c6c2 100644 --- a/android/core/src/processing/opengl/FontTexture.java +++ b/android/core/src/processing/opengl/FontTexture.java @@ -249,7 +249,7 @@ class FontTexture implements PConstants { } if (outdated) { for (int i = 0; i < textures.length; i++) { - pg.removeTextureObject(textures[i].glName, textures[i].context.id()); + pg.removeTextureObject(textures[i].glName, textures[i].context); textures[i].glName = 0; } } diff --git a/android/core/src/processing/opengl/FrameBuffer.java b/android/core/src/processing/opengl/FrameBuffer.java index 74d9c5292..fb49a171d 100644 --- a/android/core/src/processing/opengl/FrameBuffer.java +++ b/android/core/src/processing/opengl/FrameBuffer.java @@ -43,7 +43,7 @@ public class FrameBuffer implements PConstants { protected PApplet parent; protected PGraphicsOpenGL pg; protected PGL pgl; - protected PGL.Context context; // The context that created this framebuffer. + protected int context; // The context that created this framebuffer. public int glFbo; public int glDepth; @@ -151,19 +151,19 @@ public class FrameBuffer implements PConstants { try { if (!screenFb) { if (glFbo != 0) { - pg.finalizeFrameBufferObject(glFbo, context.id()); + pg.finalizeFrameBufferObject(glFbo, context); } if (glDepth != 0) { - pg.finalizeRenderBufferObject(glDepth, context.id()); + pg.finalizeRenderBufferObject(glDepth, context); } if (glStencil != 0) { - pg.finalizeRenderBufferObject(glStencil, context.id()); + pg.finalizeRenderBufferObject(glStencil, context); } if (glMultisample != 0) { - pg.finalizeRenderBufferObject(glMultisample, context.id()); + pg.finalizeRenderBufferObject(glMultisample, context); } if (glDepthStencil != 0) { - pg.finalizeRenderBufferObject(glDepthStencil, context.id()); + pg.finalizeRenderBufferObject(glDepthStencil, context); } } } finally { @@ -345,7 +345,7 @@ public class FrameBuffer implements PConstants { glFbo = 0; } else { //create the FBO object... - glFbo = pg.createFrameBufferObject(context.id()); + glFbo = pg.createFrameBufferObject(context); // ... and then create the rest of the stuff. if (multisample) { @@ -370,23 +370,23 @@ public class FrameBuffer implements PConstants { if (screenFb) return; if (glFbo != 0) { - pg.finalizeFrameBufferObject(glFbo, context.id()); + pg.finalizeFrameBufferObject(glFbo, context); glFbo = 0; } if (glDepth != 0) { - pg.finalizeRenderBufferObject(glDepth, context.id()); + pg.finalizeRenderBufferObject(glDepth, context); glDepth = 0; } if (glStencil != 0) { - pg.finalizeRenderBufferObject(glStencil, context.id()); + pg.finalizeRenderBufferObject(glStencil, context); glStencil = 0; } if (glMultisample != 0) { - pg.finalizeRenderBufferObject(glMultisample, context.id()); + pg.finalizeRenderBufferObject(glMultisample, context); glMultisample = 0; } if (glDepthStencil != 0) { - pg.finalizeRenderBufferObject(glDepthStencil, context.id()); + pg.finalizeRenderBufferObject(glDepthStencil, context); glDepthStencil = 0; } } @@ -397,11 +397,11 @@ public class FrameBuffer implements PConstants { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pg.removeFrameBufferObject(glFbo, context.id()); - pg.removeRenderBufferObject(glDepth, context.id()); - pg.removeRenderBufferObject(glStencil, context.id()); - pg.removeRenderBufferObject(glDepthStencil, context.id()); - pg.removeRenderBufferObject(glMultisample, context.id()); + pg.removeFrameBufferObject(glFbo, context); + pg.removeRenderBufferObject(glDepth, context); + pg.removeRenderBufferObject(glStencil, context); + pg.removeRenderBufferObject(glDepthStencil, context); + pg.removeRenderBufferObject(glMultisample, context); glFbo = 0; glDepth = 0; @@ -423,7 +423,7 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glMultisample = pg.createRenderBufferObject(context.id()); + glMultisample = pg.createRenderBufferObject(context); pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample); pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, PGL.RGBA8, width, height); @@ -444,7 +444,7 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepthStencil = pg.createRenderBufferObject(context.id()); + glDepthStencil = pg.createRenderBufferObject(context); pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil); if (multisample) { @@ -474,7 +474,7 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepth = pg.createRenderBufferObject(context.id()); + glDepth = pg.createRenderBufferObject(context); pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth); int glConst = PGL.DEPTH_COMPONENT16; @@ -510,7 +510,7 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glStencil = pg.createRenderBufferObject(context.id()); + glStencil = pg.createRenderBufferObject(context); pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil); int glConst = PGL.STENCIL_INDEX1; diff --git a/android/core/src/processing/opengl/LineShaderFrag.glsl b/android/core/src/processing/opengl/LineShaderFrag.glsl index b05b87776..dc08a3fa2 100644 --- a/android/core/src/processing/opengl/LineShaderFrag.glsl +++ b/android/core/src/processing/opengl/LineShaderFrag.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/android/core/src/processing/opengl/LineShaderVert.glsl b/android/core/src/processing/opengl/LineShaderVert.glsl index 5e6122c0d..b60633dae 100644 --- a/android/core/src/processing/opengl/LineShaderVert.glsl +++ b/android/core/src/processing/opengl/LineShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,16 +18,18 @@ Boston, MA 02111-1307 USA */ -uniform mat4 modelviewMatrix; -uniform mat4 projectionMatrix; +#define PROCESSING_LINE_SHADER + +uniform mat4 modelview; +uniform mat4 projection; uniform vec4 viewport; uniform int perspective; uniform vec3 scale; -attribute vec4 inVertex; -attribute vec4 inColor; -attribute vec4 inLine; +attribute vec4 vertex; +attribute vec4 color; +attribute vec4 endpoint; varying vec4 vertColor; @@ -43,21 +45,21 @@ vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) { } void main() { - vec4 pos_p = inVertex; - vec4 v_p = modelviewMatrix * pos_p; + vec4 pos_p = vertex; + vec4 v_p = modelview * pos_p; // Moving vertices slightly toward the camera // to avoid depth-fighting with the fill triangles. // Discussed here: // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 v_p.xyz = v_p.xyz * scale; - vec4 clip_p = projectionMatrix * v_p; - float thickness = inLine.w; + vec4 clip_p = projection * v_p; + float thickness = endpoint.w; if (thickness != 0.0) { - vec4 pos_q = vec4(inLine.xyz, 1); - vec4 v_q = modelviewMatrix * pos_q; + vec4 pos_q = vec4(endpoint.xyz, 1); + vec4 v_q = modelview * pos_q; v_q.xyz = v_q.xyz * scale; - vec4 clip_q = projectionMatrix * v_q; + vec4 clip_q = projection * v_q; vec3 window_p = clipToWindow(clip_p, viewport); vec3 window_q = clipToWindow(clip_q, viewport); @@ -81,5 +83,5 @@ void main() { gl_Position = clip_p; } - vertColor = inColor; + vertColor = color; } \ No newline at end of file diff --git a/android/core/src/processing/opengl/MaskShaderFrag.glsl b/android/core/src/processing/opengl/MaskShaderFrag.glsl index d70e76394..07e590009 100644 --- a/android/core/src/processing/opengl/MaskShaderFrag.glsl +++ b/android/core/src/processing/opengl/MaskShaderFrag.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2012 Ben Fry and Casey Reas + Copyright (c) 2012-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,14 +18,16 @@ Boston, MA 02111-1307 USA */ -uniform sampler2D textureSampler; -uniform sampler2D maskSampler; +#define PROCESSING_TEXTURE_SHADER + +uniform sampler2D texture; +uniform sampler2D mask; -varying vec4 vertTexcoord; +varying vec4 vertTexCoord; void main() { - vec3 texColor = texture2D(textureSampler, vertTexcoord.st).rgb; - vec3 maskColor = texture2D(maskSampler, vertTexcoord.st).rgb; + vec3 texColor = texture2D(texture, vertTexCoord.st).rgb; + vec3 maskColor = texture2D(mask, vertTexCoord.st).rgb; float luminance = dot(maskColor, vec3(0.2126, 0.7152, 0.0722)); gl_FragColor = vec4(texColor, luminance); } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index f7370a54b..b57bff47b 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -844,7 +844,7 @@ public class PGL { } - protected static boolean glThreadIsCurrent() { + protected boolean threadIsCurrent() { return Thread.currentThread() == glThread; } @@ -1502,48 +1502,13 @@ public class PGL { // Context interface - protected Context createEmptyContext() { - return new Context(); + protected int createEmptyContext() { + return -1; } - protected Context getCurrentContext() { - return new Context(context); - } - - - protected class Context { - protected int id; - - Context() { - id = -1; - } - - Context(EGLContext context) { - if (context != null) { - id = context.hashCode(); - } else { - id = -1; - } - } - - boolean current() { - return equal(context); - } - - boolean equal(EGLContext context) { - if (id == -1 || context == null) { - // A null context means a still non-created resource, - // so it is considered equal to the argument. - return true; - } else { - return id == context.hashCode(); - } - } - - int id() { - return id; - } + protected int getCurrentContext() { + return context.hashCode(); } @@ -1648,8 +1613,8 @@ public class PGL { // Utility functions - protected boolean contextIsCurrent(Context other) { - return other == null || other.current(); + protected boolean contextIsCurrent(int other) { + return other == -1 || other == context.hashCode(); } @@ -1742,8 +1707,6 @@ public class PGL { } if (texData == null) { - // This buffer has to be direct because vertexAttribPointer only accepts - // direct buffers. texData = allocateDirectFloatBuffer(texCoords.length); } @@ -1766,25 +1729,21 @@ public class PGL { // Vertex coordinates of the textured quad are specified // in normalized screen space (-1, 1): - // Corner 1 texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1; texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1; texCoords[ 2] = (float)texX0 / width; texCoords[ 3] = (float)texY0 / height; - // Corner 2 texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1; texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1; texCoords[ 6] = (float)texX1 / width; texCoords[ 7] = (float)texY0 / height; - // Corner 3 texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1; texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1; texCoords[10] = (float)texX0 / width; texCoords[11] = (float)texY1 / height; - // Corner 4 texCoords[12] = 2 * (float)scrX1 / pg.width - 1; texCoords[13] = 2 * (float)scrY1 / pg.height - 1; @@ -1802,6 +1761,8 @@ public class PGL { } bindTexture(target, id); + bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point. + texData.position(0); vertexAttribPointer(texVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, texData); diff --git a/android/core/src/processing/opengl/PGraphics2D.java b/android/core/src/processing/opengl/PGraphics2D.java index 83aaa8ab9..bf179211e 100644 --- a/android/core/src/processing/opengl/PGraphics2D.java +++ b/android/core/src/processing/opengl/PGraphics2D.java @@ -283,7 +283,7 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override public PShape createShape() { - return createShape(POLYGON); + return createShape(PShape.GEOMETRY); } @@ -305,7 +305,12 @@ public class PGraphics2D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PConstants.GROUP); } else if (type == PShape.PATH) { shape = new PShapeOpenGL(parent, PShape.PATH); - } else if (type == POINTS) { + } else if (type == PShape.GEOMETRY) { + shape = new PShapeOpenGL(parent, PShape.GEOMETRY); + } + + /* + if (type == POINTS) { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); shape.setKind(POINTS); } else if (type == LINES) { @@ -330,6 +335,8 @@ public class PGraphics2D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); shape.setKind(POLYGON); } + */ + shape.is3D(false); return shape; } diff --git a/android/core/src/processing/opengl/PGraphics3D.java b/android/core/src/processing/opengl/PGraphics3D.java index 1924206bd..0df1303d2 100644 --- a/android/core/src/processing/opengl/PGraphics3D.java +++ b/android/core/src/processing/opengl/PGraphics3D.java @@ -35,7 +35,7 @@ public class PGraphics3D extends PGraphicsOpenGL { public PGraphics3D() { super(); - hints[ENABLE_STROKE_PERSPECTIVE] = true; + hints[ENABLE_STROKE_PERSPECTIVE] = false; } ////////////////////////////////////////////////////////////// @@ -150,7 +150,7 @@ public class PGraphics3D extends PGraphicsOpenGL { @Override public PShape createShape() { - return createShape(POLYGON); + return createShape(PShape.GEOMETRY); } @@ -172,14 +172,22 @@ public class PGraphics3D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PConstants.GROUP); } else if (type == PShape.PATH) { shape = new PShapeOpenGL(parent, PShape.PATH); - } else if (type == POINTS) { + } else if (type == PShape.GEOMETRY) { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); + } + + /* + (type == POINTS) { + shape = new PShapeOpenGL(parent, PShape.GEOMETRY); + shape.setKind(POINTS); } else if (type == LINES) { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); + shape.setKind(LINES); } else if (type == TRIANGLE || type == TRIANGLES) { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); + shape.setKind(TRIANGLES); } else if (type == TRIANGLE_FAN) { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); @@ -197,6 +205,8 @@ public class PGraphics3D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.GEOMETRY); shape.setKind(POLYGON); } + */ + shape.is3D(true); return shape; } diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 9c15c917a..aad25248a 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2004-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,6 @@ import processing.core.*; import java.net.URL; import java.nio.*; import java.util.*; -import java.util.regex.*; /** * OpenGL renderer. @@ -138,21 +137,21 @@ public class PGraphicsOpenGL extends PGraphics { public int glPolyShininess; public int glPolyIndex; protected boolean polyBuffersCreated = false; - protected PGL.Context polyBuffersContext; + protected int polyBuffersContext; public int glLineVertex; public int glLineColor; public int glLineAttrib; public int glLineIndex; protected boolean lineBuffersCreated = false; - protected PGL.Context lineBuffersContext; + protected int lineBuffersContext; public int glPointVertex; public int glPointColor; public int glPointAttrib; public int glPointIndex; protected boolean pointBuffersCreated = false; - protected PGL.Context pointBuffersContext; + protected int pointBuffersContext; protected static final int INIT_VERTEX_BUFFER_SIZE = 256; protected static final int INIT_INDEX_BUFFER_SIZE = 512; @@ -1198,45 +1197,41 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPolyVertex = createVertexBufferObject(polyBuffersContext.id()); + glPolyVertex = createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); - glPolyColor = createVertexBufferObject(polyBuffersContext.id()); + glPolyColor = createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glPolyNormal = createVertexBufferObject(polyBuffersContext.id()); + glPolyNormal = createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); - glPolyTexcoord = createVertexBufferObject(polyBuffersContext.id()); + glPolyTexcoord = createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW); - glPolyAmbient = pgPrimary.createVertexBufferObject( - polyBuffersContext.id()); + glPolyAmbient = pgPrimary.createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glPolySpecular = pgPrimary.createVertexBufferObject( - polyBuffersContext.id()); + glPolySpecular = pgPrimary.createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glPolyEmissive = pgPrimary.createVertexBufferObject( - polyBuffersContext.id()); + glPolyEmissive = pgPrimary.createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glPolyShininess = pgPrimary.createVertexBufferObject( - polyBuffersContext.id()); + glPolyShininess = pgPrimary.createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess); pgl.bufferData(PGL.ARRAY_BUFFER, sizef, null, PGL.STATIC_DRAW); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); - glPolyIndex = createVertexBufferObject(polyBuffersContext.id()); + glPolyIndex = createVertexBufferObject(polyBuffersContext); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW); @@ -1319,31 +1314,31 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePolyBuffers() { if (polyBuffersCreated) { - deleteVertexBufferObject(glPolyVertex, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyVertex, polyBuffersContext); glPolyVertex = 0; - deleteVertexBufferObject(glPolyColor, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyColor, polyBuffersContext); glPolyColor = 0; - deleteVertexBufferObject(glPolyNormal, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyNormal, polyBuffersContext); glPolyNormal = 0; - deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext); glPolyTexcoord = 0; - deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyAmbient, polyBuffersContext); glPolyAmbient = 0; - deleteVertexBufferObject(glPolySpecular, polyBuffersContext.id()); + deleteVertexBufferObject(glPolySpecular, polyBuffersContext); glPolySpecular = 0; - deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyEmissive, polyBuffersContext); glPolyEmissive = 0; - deleteVertexBufferObject(glPolyShininess, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyShininess, polyBuffersContext); glPolyShininess = 0; - deleteVertexBufferObject(glPolyIndex, polyBuffersContext.id()); + deleteVertexBufferObject(glPolyIndex, polyBuffersContext); glPolyIndex = 0; polyBuffersCreated = false; @@ -1359,22 +1354,22 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glLineVertex = createVertexBufferObject(lineBuffersContext.id()); + glLineVertex = createVertexBufferObject(lineBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); - glLineColor = createVertexBufferObject(lineBuffersContext.id()); + glLineColor = createVertexBufferObject(lineBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glLineAttrib = createVertexBufferObject(lineBuffersContext.id()); + glLineAttrib = createVertexBufferObject(lineBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, null, PGL.STATIC_DRAW); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); - glLineIndex = createVertexBufferObject(lineBuffersContext.id()); + glLineIndex = createVertexBufferObject(lineBuffersContext); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW); @@ -1428,16 +1423,16 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteLineBuffers() { if (lineBuffersCreated) { - deleteVertexBufferObject(glLineVertex, lineBuffersContext.id()); + deleteVertexBufferObject(glLineVertex, lineBuffersContext); glLineVertex = 0; - deleteVertexBufferObject(glLineColor, lineBuffersContext.id()); + deleteVertexBufferObject(glLineColor, lineBuffersContext); glLineColor = 0; - deleteVertexBufferObject(glLineAttrib, lineBuffersContext.id()); + deleteVertexBufferObject(glLineAttrib, lineBuffersContext); glLineAttrib = 0; - deleteVertexBufferObject(glLineIndex, lineBuffersContext.id()); + deleteVertexBufferObject(glLineIndex, lineBuffersContext); glLineIndex = 0; lineBuffersCreated = false; @@ -1453,21 +1448,21 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPointVertex = createVertexBufferObject(pointBuffersContext.id()); + glPointVertex = createVertexBufferObject(pointBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); - glPointColor = createVertexBufferObject(pointBuffersContext.id()); + glPointColor = createVertexBufferObject(pointBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); - glPointAttrib = createVertexBufferObject(pointBuffersContext.id()); + glPointAttrib = createVertexBufferObject(pointBuffersContext); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); - glPointIndex = createVertexBufferObject(pointBuffersContext.id()); + glPointIndex = createVertexBufferObject(pointBuffersContext); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW); @@ -1521,16 +1516,16 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePointBuffers() { if (pointBuffersCreated) { - deleteVertexBufferObject(glPointVertex, pointBuffersContext.id()); + deleteVertexBufferObject(glPointVertex, pointBuffersContext); glPointVertex = 0; - deleteVertexBufferObject(glPointColor, pointBuffersContext.id()); + deleteVertexBufferObject(glPointColor, pointBuffersContext); glPointColor = 0; - deleteVertexBufferObject(glPointAttrib, pointBuffersContext.id()); + deleteVertexBufferObject(glPointAttrib, pointBuffersContext); glPointAttrib = 0; - deleteVertexBufferObject(glPointIndex, pointBuffersContext.id()); + deleteVertexBufferObject(glPointIndex, pointBuffersContext); glPointIndex = 0; pointBuffersCreated = false; @@ -5329,7 +5324,7 @@ public class PGraphicsOpenGL extends PGraphics { maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL, maskShaderFragURL); } - maskShader.set("maskSampler", alpha); + maskShader.set("mask", alpha); filter(maskShader); } @@ -5745,7 +5740,7 @@ public class PGraphicsOpenGL extends PGraphics { protected boolean checkGLThread() { - if (PGL.glThreadIsCurrent()) { + if (pgl.threadIsCurrent()) { return true; } else { PGraphics.showWarning(OPENGL_THREAD_ERROR); @@ -6130,27 +6125,47 @@ public class PGraphicsOpenGL extends PGraphics { @Override public PShader loadShader(String fragFilename) { - int shaderType = getTypeFromFragmentShader(fragFilename); + int shaderType = getShaderType(fragFilename); + if (shaderType == -1) { + PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR); + return null; + } PShader shader = null; - if (shaderType == PShader.TEXTURE) { + if (shaderType == PShader.POINT) { + shader = new PointShader(parent); + shader.setVertexShader(defPointShaderVertURL); + } else if (shaderType == PShader.LINE) { + shader = new LineShader(parent); + shader.setVertexShader(defLineShaderVertURL); + } else if (shaderType == PShader.TEXLIGHT) { + shader = new PolyTexlightShader(parent); + shader.setVertexShader(defPolyTexlightShaderVertURL); + } else if (shaderType == PShader.LIGHT) { + shader = new PolyLightShader(parent); + shader.setVertexShader(defPolyLightShaderVertURL); + } else if (shaderType == PShader.TEXTURE) { shader = new PolyTexShader(parent); shader.setVertexShader(defPolyTexShaderVertURL); } else if (shaderType == PShader.COLOR) { shader = new PolyColorShader(parent); shader.setVertexShader(defPolyColorShaderVertURL); } - if (shader == null){ - PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR); - } else { - shader.setFragmentShader(fragFilename); - } + shader.setFragmentShader(fragFilename); return shader; } @Override public PShader loadShader(String fragFilename, String vertFilename) { - int shaderType = getTypeFromVertexShader(vertFilename); + int shaderType = getShaderType(vertFilename); + if (shaderType == -1) { + shaderType = getShaderType(fragFilename); + } + if (shaderType == -1) { + PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR); + return null; + } + PShader shader = null; if (fragFilename == null || fragFilename.equals("")) { if (shaderType == PShader.POINT) { @@ -6190,9 +6205,6 @@ public class PGraphicsOpenGL extends PGraphics { shader = new PolyColorShader(parent, vertFilename, fragFilename); } } - if (shader == null) { - PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR); - } return shader; } @@ -6267,60 +6279,28 @@ public class PGraphicsOpenGL extends PGraphics { } - protected int getTypeFromFragmentShader(String filename) { + protected int getShaderType(String filename) { String[] source = parent.loadStrings(filename); - - Pattern pattern = Pattern.compile("uniform *sampler2D *textureSampler"); - - int type = PShader.COLOR; + int type = -1; for (int i = 0; i < source.length; i++) { - Matcher matcher = pattern.matcher(source[i]); - if (matcher.find()) { + if (source[i].equals("#define PROCESSING_POINT_SHADER")) { + type = PShader.POINT; + } else if (source[i].equals("#define PROCESSING_LINE_SHADER")) { + type = PShader.LINE; + } else if (source[i].equals("#define PROCESSING_COLOR_SHADER")) { + type = PShader.COLOR; + } else if (source[i].equals("#define PROCESSING_LIGHT_SHADER")) { + type = PShader.LIGHT; + } else if (source[i].equals("#define PROCESSING_TEXTURE_SHADER")) { type = PShader.TEXTURE; - break; + } else if (source[i].equals("#define PROCESSING_TEXLIGHT_SHADER")) { + type = PShader.TEXLIGHT; } } 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 texPattern = Pattern.compile("attribute vec2 inTexcoord"); - - boolean foundPoint = false; - boolean foundLine = false; - boolean foundLight = false; - boolean foundTex = false; - for (int i = 0; i < source.length; i++) { - foundPoint |= pointPattern.matcher(source[i]).find(); - foundLine |= linePattern.matcher(source[i]).find(); - foundLight |= lightPattern1.matcher(source[i]).find(); - foundLight |= lightPattern2.matcher(source[i]).find(); - foundTex |= texPattern.matcher(source[i]).find(); - } - - int type = PShader.COLOR; - if (foundPoint) { - type = PShader.POINT; - } else if (foundLine) { - type = PShader.LINE; - } else if (foundLight && foundTex) { - type = PShader.TEXLIGHT; - } else if (foundLight) { - type = PShader.LIGHT; - } else if (foundTex) { - type = PShader.TEXTURE; - } - return type; - } - - protected void deleteDefaultShaders() { // The default shaders contains references to the PGraphics object that // creates them, so when restarting the renderer, those references should @@ -6474,15 +6454,11 @@ public class PGraphicsOpenGL extends PGraphics { protected class BaseShader extends PShader { - protected int projmodelviewMatrixLoc; - protected int modelviewMatrixLoc; - protected int projectionMatrixLoc; - protected int pframeSamplerLoc; - protected int resolutionLoc; + protected int transformLoc; + protected int modelviewLoc; + protected int projectionLoc; + protected int bufferLoc; protected int viewportLoc; - protected int mouseLoc; - protected int pmouseLoc; - protected int timeLoc; public BaseShader(PApplet parent) { super(parent); @@ -6498,22 +6474,16 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); - projectionMatrixLoc = getUniformLoc("projectionMatrix"); - - resolutionLoc = getUniformLoc("resolution"); + transformLoc = getUniformLoc("transform"); + modelviewLoc = getUniformLoc("modelview"); + projectionLoc = getUniformLoc("projection"); viewportLoc = getUniformLoc("viewport"); - mouseLoc = getUniformLoc("mouse"); - pmouseLoc = getUniformLoc("pmouse"); - timeLoc = getUniformLoc("time"); - - pframeSamplerLoc = getUniformLoc("pframeSampler"); + bufferLoc = getUniformLoc("buffer"); } @Override public void unbind() { - if (-1 < pframeSamplerLoc) { + if (-1 < bufferLoc) { pgl.needFBOLayer(); pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit); pgCurrent.unbindBackTexture(); @@ -6526,25 +6496,19 @@ public class PGraphicsOpenGL extends PGraphics { } protected void setCommonUniforms() { - if (-1 < projmodelviewMatrixLoc) { + if (-1 < transformLoc) { pgCurrent.updateGLProjmodelview(); - setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(transformLoc, pgCurrent.glProjmodelview); } - if (-1 < modelviewMatrixLoc) { + if (-1 < modelviewLoc) { pgCurrent.updateGLModelview(); - setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewLoc, pgCurrent.glModelview); } - if (-1 < projectionMatrixLoc) { + if (-1 < projectionLoc) { pgCurrent.updateGLProjection(); - setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); - } - - if (1 < resolutionLoc) { - float w = pgCurrent.width; - float h = pgCurrent.height; - setUniformValue(resolutionLoc, w, h); + setUniformMatrix(projectionLoc, pgCurrent.glProjection); } if (-1 < viewportLoc) { @@ -6555,25 +6519,8 @@ public class PGraphicsOpenGL extends PGraphics { setUniformValue(viewportLoc, x, y, w, h); } - if (-1 < mouseLoc) { - float mx = pgCurrent.parent.mouseX; - float my = pgCurrent.parent.height - pgCurrent.parent.mouseY; - setUniformValue(mouseLoc, mx, my); - } - - if (-1 < pmouseLoc) { - float pmx = pgCurrent.parent.pmouseX; - float pmy = pgCurrent.parent.height - pgCurrent.parent.pmouseY; - setUniformValue(pmouseLoc, pmx, pmy); - } - - if (-1 < timeLoc) { - float sec = pgCurrent.parent.millis() / 1000.0f; - setUniformValue(timeLoc, sec); - } - - if (-1 < pframeSamplerLoc) { - setUniformValue(pframeSamplerLoc, lastTexUnit); + if (-1 < bufferLoc) { + setUniformValue(bufferLoc, lastTexUnit); pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit); pgCurrent.bindBackTexture(); } @@ -6600,8 +6547,8 @@ public class PGraphicsOpenGL extends PGraphics { protected class PolyColorShader extends BaseShader { - protected int inVertexLoc; - protected int inColorLoc; + protected int vertexLoc; + protected int colorLoc; public PolyColorShader(PApplet parent) { super(parent); @@ -6618,8 +6565,8 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void loadAttributes() { - inVertexLoc = getAttributeLoc("inVertex"); - inColorLoc = getAttributeLoc("inColor"); + vertexLoc = getAttributeLoc("vertex"); + colorLoc = getAttributeLoc("color"); } @Override @@ -6630,13 +6577,13 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset); } @Override public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset); } @Override @@ -6648,16 +6595,16 @@ public class PGraphicsOpenGL extends PGraphics { loadUniforms(); } - if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc); + if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc); setCommonUniforms(); } @Override public void unbind() { - if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc); + if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc); super.unbind(); } @@ -6673,17 +6620,17 @@ public class PGraphicsOpenGL extends PGraphics { protected int lightAmbientLoc; protected int lightDiffuseLoc; protected int lightSpecularLoc; - protected int lightFalloffCoefficientsLoc; - protected int lightSpotParametersLoc; + protected int lightFalloffLoc; + protected int lightSpotLoc; - protected int inVertexLoc; - protected int inColorLoc; - protected int inNormalLoc; + protected int vertexLoc; + protected int colorLoc; + protected int normalLoc; - protected int inAmbientLoc; - protected int inSpecularLoc; - protected int inEmissiveLoc; - protected int inShineLoc; + protected int ambientLoc; + protected int specularLoc; + protected int emissiveLoc; + protected int shininessLoc; public PolyLightShader(PApplet parent) { super(parent); @@ -6700,14 +6647,14 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void loadAttributes() { - inVertexLoc = getAttributeLoc("inVertex"); - inColorLoc = getAttributeLoc("inColor"); - inNormalLoc = getAttributeLoc("inNormal"); + vertexLoc = getAttributeLoc("vertex"); + colorLoc = getAttributeLoc("color"); + normalLoc = getAttributeLoc("normal"); - inAmbientLoc = getAttributeLoc("inAmbient"); - inSpecularLoc = getAttributeLoc("inSpecular"); - inEmissiveLoc = getAttributeLoc("inEmissive"); - inShineLoc = getAttributeLoc("inShine"); + ambientLoc = getAttributeLoc("ambient"); + specularLoc = getAttributeLoc("specular"); + emissiveLoc = getAttributeLoc("emissive"); + shininessLoc = getAttributeLoc("shininess"); } @Override @@ -6722,50 +6669,50 @@ public class PGraphicsOpenGL extends PGraphics { lightAmbientLoc = getUniformLoc("lightAmbient"); lightDiffuseLoc = getUniformLoc("lightDiffuse"); lightSpecularLoc = getUniformLoc("lightSpecular"); - lightFalloffCoefficientsLoc = getUniformLoc("lightFalloffCoefficients"); - lightSpotParametersLoc = getUniformLoc("lightSpotParameters"); + lightFalloffLoc = getUniformLoc("lightFalloff"); + lightSpotLoc = getUniformLoc("lightSpot"); } @Override public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset); } @Override public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset); } @Override public void setNormalAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inNormalLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset); } @Override public void setAmbientAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inAmbientLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset); } @Override public void setSpecularAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inSpecularLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset); } @Override public void setEmissiveAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inEmissiveLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset); } @Override public void setShininessAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inShineLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset); } @Override @@ -6777,14 +6724,14 @@ public class PGraphicsOpenGL extends PGraphics { loadUniforms(); } - if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc); - if (-1 < inNormalLoc) pgl.enableVertexAttribArray(inNormalLoc); + if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc); + if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc); - if (-1 < inAmbientLoc) pgl.enableVertexAttribArray(inAmbientLoc); - if (-1 < inSpecularLoc) pgl.enableVertexAttribArray(inSpecularLoc); - if (-1 < inEmissiveLoc) pgl.enableVertexAttribArray(inEmissiveLoc); - if (-1 < inShineLoc) pgl.enableVertexAttribArray(inShineLoc); + if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc); + if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc); + if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc); + if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc); if (-1 < normalMatrixLoc) { pgCurrent.updateGLNormal(); @@ -6798,9 +6745,9 @@ public class PGraphicsOpenGL extends PGraphics { setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3, count); setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3, count); setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3, count); - setUniformVector(lightFalloffCoefficientsLoc, + setUniformVector(lightFalloffLoc, pgCurrent.lightFalloffCoefficients, 3, count); - setUniformVector(lightSpotParametersLoc, + setUniformVector(lightSpotLoc, pgCurrent.lightSpotParameters, 2, count); setCommonUniforms(); @@ -6808,14 +6755,14 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void unbind() { - if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc); - if (-1 < inNormalLoc) pgl.disableVertexAttribArray(inNormalLoc); + if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc); + if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc); - if (-1 < inAmbientLoc) pgl.disableVertexAttribArray(inAmbientLoc); - if (-1 < inSpecularLoc) pgl.disableVertexAttribArray(inSpecularLoc); - if (-1 < inEmissiveLoc) pgl.disableVertexAttribArray(inEmissiveLoc); - if (-1 < inShineLoc) pgl.disableVertexAttribArray(inShineLoc); + if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc); + if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc); + if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc); + if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc); super.unbind(); } @@ -6823,11 +6770,11 @@ public class PGraphicsOpenGL extends PGraphics { protected class PolyTexShader extends PolyColorShader { - protected int inTexcoordLoc; + protected int texCoordLoc; - protected int textureSamplerLoc; - protected int texcoordMatrixLoc; - protected int texcoordOffsetLoc; + protected int textureLoc; + protected int texMatrixLoc; + protected int texOffsetLoc; protected float[] tcmat; @@ -6848,22 +6795,22 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - textureSamplerLoc = getUniformLoc("textureSampler"); - texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); - texcoordOffsetLoc = getUniformLoc("texcoordOffset"); + textureLoc = getUniformLoc("texture"); + texMatrixLoc = getUniformLoc("texMatrix"); + texOffsetLoc = getUniformLoc("texOffset"); } @Override public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttributeLoc("inTexcoord"); + texCoordLoc = getAttributeLoc("texCoord"); } @Override public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset); } @Override @@ -6888,7 +6835,7 @@ public class PGraphicsOpenGL extends PGraphics { scalev *= tex.maxTexcoordV(); dispv *= tex.maxTexcoordV(); - if (-1 < texcoordMatrixLoc) { + if (-1 < texMatrixLoc) { if (tcmat == null) { tcmat = new float[16]; } @@ -6896,12 +6843,12 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setUniformMatrix(texcoordMatrixLoc, tcmat); + setUniformMatrix(texMatrixLoc, tcmat); } - setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); - setUniformValue(textureSamplerLoc, 0); + setUniformValue(textureLoc, 0); } @Override @@ -6910,12 +6857,12 @@ public class PGraphicsOpenGL extends PGraphics { super.bind(); - if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc); + if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc); } @Override public void unbind() { - if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc); + if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc); super.unbind(); } @@ -6923,11 +6870,11 @@ public class PGraphicsOpenGL extends PGraphics { protected class PolyTexlightShader extends PolyLightShader { - protected int inTexcoordLoc; + protected int texCoordLoc; - protected int textureSamplerLoc; - protected int texcoordMatrixLoc; - protected int texcoordOffsetLoc; + protected int textureLoc; + protected int texMatrixLoc; + protected int texOffsetLoc; protected float[] tcmat; @@ -6948,22 +6895,22 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - textureSamplerLoc = getUniformLoc("textureSampler"); - texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); - texcoordOffsetLoc = getUniformLoc("texcoordOffset"); + textureLoc = getUniformLoc("texture"); + texMatrixLoc = getUniformLoc("texMatrix"); + texOffsetLoc = getUniformLoc("texOffset"); } @Override public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttributeLoc("inTexcoord"); + texCoordLoc = getAttributeLoc("texCoord"); } @Override public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset); } @Override @@ -6988,7 +6935,7 @@ public class PGraphicsOpenGL extends PGraphics { scalev *= tex.maxTexcoordV; dispv *= tex.maxTexcoordV; - if (-1 < texcoordMatrixLoc) { + if (-1 < texMatrixLoc) { if (tcmat == null) { tcmat = new float[16]; } @@ -6996,12 +6943,12 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setUniformMatrix(texcoordMatrixLoc, tcmat); + setUniformMatrix(texMatrixLoc, tcmat); } - setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); - setUniformValue(textureSamplerLoc, 0); + setUniformValue(textureLoc, 0); } @Override @@ -7010,12 +6957,12 @@ public class PGraphicsOpenGL extends PGraphics { super.bind(); - if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc); + if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc); } @Override public void unbind() { - if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc); + if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc); super.unbind(); } @@ -7026,9 +6973,9 @@ public class PGraphicsOpenGL extends PGraphics { protected int perspectiveLoc; protected int scaleLoc; - protected int inVertexLoc; - protected int inColorLoc; - protected int inAttribLoc; + protected int vertexLoc; + protected int colorLoc; + protected int endpointLoc; public LineShader(PApplet parent) { super(parent); @@ -7045,9 +6992,9 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void loadAttributes() { - inVertexLoc = getAttributeLoc("inVertex"); - inColorLoc = getAttributeLoc("inColor"); - inAttribLoc = getAttributeLoc("inLine"); + vertexLoc = getAttributeLoc("vertex"); + colorLoc = getAttributeLoc("color"); + endpointLoc = getAttributeLoc("endpoint"); } @Override @@ -7062,18 +7009,18 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset); } @Override public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset); } public void setLineAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inAttribLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(endpointLoc, vboId, size, type, false, stride, offset); } @Override @@ -7085,9 +7032,9 @@ public class PGraphicsOpenGL extends PGraphics { loadUniforms(); } - if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc); - if (-1 < inAttribLoc) pgl.enableVertexAttribArray(inAttribLoc); + if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc); + if (-1 < endpointLoc) pgl.enableVertexAttribArray(endpointLoc); if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) && pgCurrent.nonOrthoProjection()) { @@ -7111,9 +7058,9 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void unbind() { - if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc); - if (-1 < inAttribLoc) pgl.disableVertexAttribArray(inAttribLoc); + if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc); + if (-1 < endpointLoc) pgl.disableVertexAttribArray(endpointLoc); super.unbind(); } @@ -7123,9 +7070,9 @@ public class PGraphicsOpenGL extends PGraphics { protected class PointShader extends BaseShader { protected int perspectiveLoc; - protected int inVertexLoc; - protected int inColorLoc; - protected int inPointLoc; + protected int vertexLoc; + protected int colorLoc; + protected int offsetLoc; public PointShader(PApplet parent) { super(parent); @@ -7142,9 +7089,9 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void loadAttributes() { - inVertexLoc = getAttributeLoc("inVertex"); - inColorLoc = getAttributeLoc("inColor"); - inPointLoc = getAttributeLoc("inPoint"); + vertexLoc = getAttributeLoc("vertex"); + colorLoc = getAttributeLoc("color"); + offsetLoc = getAttributeLoc("offset"); } @Override @@ -7157,18 +7104,18 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset); } @Override public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset); } public void setPointAttribute(int vboId, int size, int type, int stride, int offset) { - setAttributeVBO(inPointLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset); } @Override @@ -7180,9 +7127,9 @@ public class PGraphicsOpenGL extends PGraphics { loadUniforms(); } - if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc); - if (-1 < inPointLoc) pgl.enableVertexAttribArray(inPointLoc); + if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc); + if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc); if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) && pgCurrent.nonOrthoProjection()) { @@ -7196,9 +7143,9 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void unbind() { - if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc); - if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc); - if (-1 < inPointLoc) pgl.disableVertexAttribArray(inPointLoc); + if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc); + if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc); + if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc); super.unbind(); } diff --git a/android/core/src/processing/opengl/PShader.java b/android/core/src/processing/opengl/PShader.java index d9f167746..4c385a0d1 100644 --- a/android/core/src/processing/opengl/PShader.java +++ b/android/core/src/processing/opengl/PShader.java @@ -58,7 +58,7 @@ public class PShader { protected PGraphicsOpenGL pgCurrent; protected PGL pgl; - protected PGL.Context context; // The context that created this shader. + protected int context; // The context that created this shader. public int glProgram; public int glVertex; @@ -89,7 +89,7 @@ public class PShader { parent = null; pgMain = null; pgl = null; - context = null; + context = -1; this.vertexURL = null; this.fragmentURL = null; @@ -172,13 +172,13 @@ public class PShader { protected void finalize() throws Throwable { try { if (glVertex != 0) { - pgMain.finalizeGLSLVertShaderObject(glVertex, context.id()); + pgMain.finalizeGLSLVertShaderObject(glVertex, context); } if (glFragment != 0) { - pgMain.finalizeGLSLFragShaderObject(glFragment, context.id()); + pgMain.finalizeGLSLFragShaderObject(glFragment, context); } if (glProgram != 0) { - pgMain.finalizeGLSLProgramObject(glProgram, context.id()); + pgMain.finalizeGLSLProgramObject(glProgram, context); } } finally { super.finalize(); @@ -698,7 +698,7 @@ public class PShader { protected void init() { if (glProgram == 0 || contextIsOutdated()) { context = pgl.getCurrentContext(); - glProgram = pgMain.createGLSLProgramObject(context.id()); + glProgram = pgMain.createGLSLProgramObject(context); boolean hasVert = false; if (vertexFilename != null) { @@ -761,9 +761,9 @@ public class PShader { protected boolean contextIsOutdated() { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pgMain.removeGLSLProgramObject(glProgram, context.id()); - pgMain.removeGLSLVertShaderObject(glVertex, context.id()); - pgMain.removeGLSLFragShaderObject(glFragment, context.id()); + pgMain.removeGLSLProgramObject(glProgram, context); + pgMain.removeGLSLVertShaderObject(glVertex, context); + pgMain.removeGLSLFragShaderObject(glFragment, context); glProgram = 0; glVertex = 0; @@ -833,7 +833,7 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileVertexShader() { - glVertex = pgMain.createGLSLVertShaderObject(context.id()); + glVertex = pgMain.createGLSLVertShaderObject(context); pgl.shaderSource(glVertex, vertexShaderSource); pgl.compileShader(glVertex); @@ -854,7 +854,7 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileFragmentShader() { - glFragment = pgMain.createGLSLFragShaderObject(context.id()); + glFragment = pgMain.createGLSLFragShaderObject(context); pgl.shaderSource(glFragment, fragmentShaderSource); pgl.compileShader(glFragment); @@ -883,15 +883,15 @@ public class PShader { protected void release() { if (glVertex != 0) { - pgMain.deleteGLSLVertShaderObject(glVertex, context.id()); + pgMain.deleteGLSLVertShaderObject(glVertex, context); glVertex = 0; } if (glFragment != 0) { - pgMain.deleteGLSLFragShaderObject(glFragment, context.id()); + pgMain.deleteGLSLFragShaderObject(glFragment, context); glFragment = 0; } if (glProgram != 0) { - pgMain.deleteGLSLProgramObject(glProgram, context.id()); + pgMain.deleteGLSLProgramObject(glProgram, context); glProgram = 0; } } diff --git a/android/core/src/processing/opengl/PShapeOpenGL.java b/android/core/src/processing/opengl/PShapeOpenGL.java index d8920294a..4de45355d 100644 --- a/android/core/src/processing/opengl/PShapeOpenGL.java +++ b/android/core/src/processing/opengl/PShapeOpenGL.java @@ -67,7 +67,7 @@ public class PShapeOpenGL extends PShape { protected PGraphicsOpenGL pg; protected PGL pgl; - protected PGL.Context context; // The context that created this shape. + protected int context; // The context that created this shape. protected PShapeOpenGL root; @@ -166,9 +166,8 @@ public class PShapeOpenGL extends PShape { protected boolean isSolid; protected boolean isClosed; - protected boolean openContour = false; protected boolean breakShape = false; - protected boolean shapeEnded = false; + protected boolean shapeCreated = false; // These variables indicate if the shape contains // polygon, line and/or point geometry. In the case of @@ -185,7 +184,6 @@ public class PShapeOpenGL extends PShape { // Modes inherited from renderer - protected int textureMode; protected int rectMode; protected int ellipseMode; protected int shapeMode; @@ -353,7 +351,7 @@ public class PShapeOpenGL extends PShape { if (family == GROUP) { // GROUP shapes are always marked as ended. - shapeEnded = true; + shapeCreated = true; } } @@ -420,77 +418,77 @@ public class PShapeOpenGL extends PShape { protected void finalizePolyBuffers() { if (glPolyVertex != 0) { - pg.finalizeVertexBufferObject(glPolyVertex, context.id()); + pg.finalizeVertexBufferObject(glPolyVertex, context); } if (glPolyColor != 0) { - pg.finalizeVertexBufferObject(glPolyColor, context.id()); + pg.finalizeVertexBufferObject(glPolyColor, context); } if (glPolyNormal != 0) { - pg.finalizeVertexBufferObject(glPolyNormal, context.id()); + pg.finalizeVertexBufferObject(glPolyNormal, context); } if (glPolyTexcoord != 0) { - pg.finalizeVertexBufferObject(glPolyTexcoord, context.id()); + pg.finalizeVertexBufferObject(glPolyTexcoord, context); } if (glPolyAmbient != 0) { - pg.finalizeVertexBufferObject(glPolyAmbient, context.id()); + pg.finalizeVertexBufferObject(glPolyAmbient, context); } if (glPolySpecular != 0) { - pg.finalizeVertexBufferObject(glPolySpecular, context.id()); + pg.finalizeVertexBufferObject(glPolySpecular, context); } if (glPolyEmissive != 0) { - pg.finalizeVertexBufferObject(glPolyEmissive, context.id()); + pg.finalizeVertexBufferObject(glPolyEmissive, context); } if (glPolyShininess != 0) { - pg.finalizeVertexBufferObject(glPolyShininess, context.id()); + pg.finalizeVertexBufferObject(glPolyShininess, context); } if (glPolyIndex != 0) { - pg.finalizeVertexBufferObject(glPolyIndex, context.id()); + pg.finalizeVertexBufferObject(glPolyIndex, context); } } protected void finalizeLineBuffers() { if (glLineVertex != 0) { - pg.finalizeVertexBufferObject(glLineVertex, context.id()); + pg.finalizeVertexBufferObject(glLineVertex, context); } if (glLineColor != 0) { - pg.finalizeVertexBufferObject(glLineColor, context.id()); + pg.finalizeVertexBufferObject(glLineColor, context); } if (glLineAttrib != 0) { - pg.finalizeVertexBufferObject(glLineAttrib, context.id()); + pg.finalizeVertexBufferObject(glLineAttrib, context); } if (glLineIndex != 0) { - pg.finalizeVertexBufferObject(glLineIndex, context.id()); + pg.finalizeVertexBufferObject(glLineIndex, context); } } protected void finalizePointBuffers() { if (glPointVertex != 0) { - pg.finalizeVertexBufferObject(glPointVertex, context.id()); + pg.finalizeVertexBufferObject(glPointVertex, context); } if (glPointColor != 0) { - pg.finalizeVertexBufferObject(glPointColor, context.id()); + pg.finalizeVertexBufferObject(glPointColor, context); } if (glPointAttrib != 0) { - pg.finalizeVertexBufferObject(glPointAttrib, context.id()); + pg.finalizeVertexBufferObject(glPointAttrib, context); } if (glPointIndex != 0) { - pg.finalizeVertexBufferObject(glPointIndex, context.id()); + pg.finalizeVertexBufferObject(glPointIndex, context); } } @@ -500,7 +498,7 @@ public class PShapeOpenGL extends PShape { // Shape creation (temporary hack) - static protected PShapeOpenGL createShape3D(PApplet parent, PShape src) { + public static PShapeOpenGL createShape3D(PApplet parent, PShape src) { PShapeOpenGL dest = null; if (src.getFamily() == GROUP) { dest = PGraphics3D.createShapeImpl(parent, GROUP); @@ -510,7 +508,7 @@ public class PShapeOpenGL extends PShape { src.getParams()); PShape.copyPrimitive(src, dest); } else if (src.getFamily() == GEOMETRY) { - dest = PGraphics3D.createShapeImpl(parent, src.getKind()); + dest = PGraphics3D.createShapeImpl(parent, PShape.GEOMETRY); PShape.copyGeometry(src, dest); } else if (src.getFamily() == PATH) { dest = PGraphics3D.createShapeImpl(parent, PATH); @@ -531,7 +529,7 @@ public class PShapeOpenGL extends PShape { src.getParams()); PShape.copyPrimitive(src, dest); } else if (src.getFamily() == GEOMETRY) { - dest = PGraphics2D.createShapeImpl(parent, src.getKind()); + dest = PGraphics2D.createShapeImpl(parent, PShape.GEOMETRY); PShape.copyGeometry(src, dest); } else if (src.getFamily() == PATH) { dest = PGraphics2D.createShapeImpl(parent, PATH); @@ -579,7 +577,7 @@ public class PShapeOpenGL extends PShape { Float.POSITIVE_INFINITY); PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); - if (shapeEnded) { + if (shapeCreated) { getVertexMin(min); getVertexMax(max); } @@ -594,7 +592,7 @@ public class PShapeOpenGL extends PShape { Float.POSITIVE_INFINITY); PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); - if (shapeEnded) { + if (shapeCreated) { getVertexMin(min); getVertexMax(max); } @@ -609,7 +607,7 @@ public class PShapeOpenGL extends PShape { Float.POSITIVE_INFINITY); PVector max = new PVector(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); - if (shapeEnded) { + if (shapeCreated) { getVertexMin(min); getVertexMax(max); } @@ -726,7 +724,13 @@ public class PShapeOpenGL extends PShape { // Drawing methods - public void textureMode(int mode) { + @Override + public void setTextureMode(int mode) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureMode()"); + return; + } + if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; @@ -739,7 +743,12 @@ public class PShapeOpenGL extends PShape { @Override - public void texture(PImage tex) { + public void setTexture(PImage tex) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTexture()"); + return; + } + if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; @@ -761,26 +770,6 @@ public class PShapeOpenGL extends PShape { } - @Override - public void noTexture() { - if (family == GROUP) { - for (int i = 0; i < childCount; i++) { - PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.noTexture(); - } - } else { - PImage tex0 = image; - image = null; - if (tex0 != null && parent != null) { - ((PShapeOpenGL)parent).removeTexture(tex0); - if (is2D()) { - ((PShapeOpenGL)parent).strokedTexture(false); - } - } - } - } - - protected void addTexture(PImage tex) { if (textures == null) { textures = new HashSet(); @@ -886,35 +875,11 @@ public class PShapeOpenGL extends PShape { @Override public void beginContour() { - if (family == GROUP) { - PGraphics.showWarning("Cannot begin contour in GROUP shapes"); - return; - } - - if (openContour) { - PGraphics.showWarning("Already called beginContour()."); - return; - } - openContour = true; + super.beginContour(); breakShape = true; } - @Override - public void endContour() { - if (family == GROUP) { - PGraphics.showWarning("Cannot end contour in GROUP shapes"); - return; - } - - if (!openContour) { - PGraphics.showWarning("Need to call beginContour() first."); - return; - } - openContour = false; - } - - @Override public void vertex(float x, float y) { vertexImpl(x, y, 0, 0, 0); @@ -940,6 +905,11 @@ public class PShapeOpenGL extends PShape { protected void vertexImpl(float x, float y, float z, float u, float v) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "vertex()"); + return; + } + if (family == GROUP) { PGraphics.showWarning("Cannot add vertices to GROUP shape"); return; @@ -995,6 +965,11 @@ public class PShapeOpenGL extends PShape { @Override public void normal(float nx, float ny, float nz) { + if (!openShape) { + PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "normal()"); + return; + } + if (family == GROUP) { PGraphics.showWarning("Cannot set normal in GROUP shape"); return; @@ -1015,19 +990,29 @@ public class PShapeOpenGL extends PShape { } } - +/* @Override - public void end() { - end(OPEN); + public void beginShape() { + beginShape(POLYGON); } @Override - public void end(int mode) { - if (family == GROUP) { - PGraphics.showWarning("Cannot end GROUP shape"); - return; - } + public void beginShape(int kind) { + this.kind = kind; + openShape = true; + } + + + @Override + public void endShape() { + endShape(OPEN); + } +*/ + + @Override + public void endShape(int mode) { + super.endShape(mode); // Input arrays are trimmed since they are expanded by doubling their old // size, which might lead to arrays larger than the vertex counts. @@ -1035,7 +1020,7 @@ public class PShapeOpenGL extends PShape { isClosed = mode == CLOSE; markForTessellation(); - shapeEnded = true; + shapeCreated = true; } @@ -1048,7 +1033,7 @@ public class PShapeOpenGL extends PShape { super.setParams(source); markForTessellation(); - shapeEnded = true; + shapeCreated = true; } @@ -1062,7 +1047,7 @@ public class PShapeOpenGL extends PShape { super.setPath(vcount, verts, ccount, codes); markForTessellation(); - shapeEnded = true; + shapeCreated = true; } @@ -1070,7 +1055,7 @@ public class PShapeOpenGL extends PShape { // Stroke cap/join/weight set/update - +/* @Override public void strokeWeight(float weight) { if (family == GROUP) { @@ -1090,7 +1075,7 @@ public class PShapeOpenGL extends PShape { strokeWeight = newWeight; Arrays.fill(inGeo.strokeWeights, 0, inGeo.vertexCount, strokeWeight); - if (shapeEnded && tessellated && (hasLines || hasPoints)) { + if (shapeCreated && tessellated && (hasLines || hasPoints)) { float resizeFactor = newWeight / oldWeight; if (hasLines) { if (is3D()) { @@ -1159,27 +1144,34 @@ public class PShapeOpenGL extends PShape { 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(); - } - } else { - fill = false; - updateFillColor(0x0); - } + fill = false; +// if (family == GROUP) { +// for (int i = 0; i < childCount; i++) { +// PShapeOpenGL child = (PShapeOpenGL) children[i]; +// child.noFill(); +// } +// } else { +// fill = false; +// updateFillColor(0x0); +// } } + @Override + public void fill(int argb) { + } + */ + +/* @Override public void fill(int rgb) { if (family == GROUP) { @@ -1280,35 +1272,20 @@ public class PShapeOpenGL extends PShape { protected void updateFillColor(int newFillColor) { - if (fillColor == newFillColor) return; - fillColor = newFillColor; - - if (image == null) { - Arrays.fill(inGeo.colors, 0, inGeo.vertexCount, - PGL.javaToNativeARGB(fillColor)); - if (shapeEnded && tessellated && hasPolys) { - if (is3D()) { - 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)); - root.setModifiedPolyColors(firstPolyVertex, last1 - 1); - } - } + if (!openShape) { + PGraphics.showWarning("Neet to call beginShape() first"); + return; } - } + fillColor = newFillColor; + } +*/ ////////////////////////////////////////////////////////////// // Stroke (color) set/update - +/* @Override public void noStroke() { if (family == GROUP) { @@ -1432,43 +1409,20 @@ public class PShapeOpenGL extends PShape { protected void updateStrokeColor(int newStrokeColor) { - if (strokeColor == newStrokeColor) return; - strokeColor = newStrokeColor; - - Arrays.fill(inGeo.strokeColors, 0, inGeo.vertexCount, - PGL.javaToNativeARGB(strokeColor)); - if (shapeEnded && tessellated && (hasLines || hasPoints)) { - if (hasLines) { - if (is3D()) { - Arrays.fill(tessGeo.lineColors, firstLineVertex, lastLineVertex + 1, - PGL.javaToNativeARGB(strokeColor)); - root.setModifiedLineColors(firstLineVertex, lastLineVertex); - } else if (is2D()) { - 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, - PGL.javaToNativeARGB(strokeColor)); - root.setModifiedPointColors(firstPointVertex, lastPointVertex); - } else if (is2D()) { - Arrays.fill(tessGeo.polyColors, firstPointVertex, lastPointVertex + 1, - PGL.javaToNativeARGB(strokeColor)); - root.setModifiedPolyColors(firstPointVertex, lastPointVertex); - } - } + if (!openShape) { + PGraphics.showWarning("Neet to call beginShape() first"); + return; } - } + strokeColor = newStrokeColor; + } +*/ ////////////////////////////////////////////////////////////// // Tint set/update - +/* @Override public void noTint() { if (family == GROUP) { @@ -1580,7 +1534,7 @@ public class PShapeOpenGL extends PShape { if (image != null) { Arrays.fill(inGeo.colors, 0, inGeo.vertexCount, PGL.javaToNativeARGB(tintColor)); - if (shapeEnded && tessellated && hasPolys) { + if (shapeCreated && tessellated && hasPolys) { if (is3D()) { Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1, PGL.javaToNativeARGB(tintColor)); @@ -1596,13 +1550,13 @@ public class PShapeOpenGL extends PShape { } } } - +*/ ////////////////////////////////////////////////////////////// // Ambient set/update - +/* @Override public void ambient(int rgb) { if (family == GROUP) { @@ -1657,7 +1611,7 @@ public class PShapeOpenGL extends PShape { Arrays.fill(inGeo.ambient, 0, inGeo.vertexCount, PGL.javaToNativeARGB(ambientColor)); - if (shapeEnded && tessellated && hasPolys) { + if (shapeCreated && tessellated && hasPolys) { if (is3D()) { Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, lastPolyVertex + 1, PGL.javaToNativeARGB(ambientColor)); @@ -1672,13 +1626,13 @@ public class PShapeOpenGL extends PShape { } } } - +*/ ////////////////////////////////////////////////////////////// // Specular set/update - +/* @Override public void specular(int rgb) { if (family == GROUP) { @@ -1732,7 +1686,7 @@ public class PShapeOpenGL extends PShape { Arrays.fill(inGeo.specular, 0, inGeo.vertexCount, PGL.javaToNativeARGB(specularColor)); - if (shapeEnded && tessellated && hasPolys) { + if (shapeCreated && tessellated && hasPolys) { if (is3D()) { Arrays.fill(tessGeo.polySpecular, firstPolyVertex, lastPolyVertex + 1, PGL.javaToNativeARGB(specularColor)); @@ -1747,13 +1701,13 @@ public class PShapeOpenGL extends PShape { } } } - +*/ ////////////////////////////////////////////////////////////// // Emissive set/update - +/* @Override public void emissive(int rgb) { if (family == GROUP) { @@ -1807,7 +1761,7 @@ public class PShapeOpenGL extends PShape { Arrays.fill(inGeo.emissive, 0, inGeo.vertexCount, PGL.javaToNativeARGB(emissiveColor)); - if (shapeEnded && tessellated && 0 < tessGeo.polyVertexCount) { + if (shapeCreated && tessellated && 0 < tessGeo.polyVertexCount) { if (is3D()) { Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, lastPolyVertex + 1, PGL.javaToNativeARGB(emissiveColor)); @@ -1822,13 +1776,13 @@ public class PShapeOpenGL extends PShape { } } } - +*/ ////////////////////////////////////////////////////////////// // Shininess set/update - +/* @Override public void shininess(float shine) { if (family == GROUP) { @@ -1847,7 +1801,7 @@ public class PShapeOpenGL extends PShape { shininess = newShininess; Arrays.fill(inGeo.shininess, 0, inGeo.vertexCount, shininess); - if (shapeEnded && tessellated && hasPolys) { + if (shapeCreated && tessellated && hasPolys) { if (is3D()) { Arrays.fill(tessGeo.polyShininess, firstPolyVertex, lastPolyVertex + 1, shininess); @@ -1861,7 +1815,7 @@ public class PShapeOpenGL extends PShape { } } } - +*/ /////////////////////////////////////////////////////////// @@ -1959,7 +1913,7 @@ public class PShapeOpenGL extends PShape { @Override public void resetMatrix() { - if (shapeEnded && matrix != null) { + if (shapeCreated && matrix != null) { if (family == GROUP) { updateTessellation(); } @@ -2239,6 +2193,14 @@ public class PShapeOpenGL extends PShape { @Override public void setVertex(int index, float x, float y, float z) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()"); + return; + } + + // TODO: in certain cases (kind = TRIANGLE, etc) the correspondence between + // input and tessellated vertices is 1-1, so in those cases re-tessellation + // wouldnt' be neccessary. inGeo.vertices[3 * index + 0] = x; inGeo.vertices[3 * index + 1] = y; inGeo.vertices[3 * index + 2] = z; @@ -2248,6 +2210,11 @@ public class PShapeOpenGL extends PShape { @Override public void setVertex(int index, PVector vec) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()"); + return; + } + inGeo.vertices[3 * index + 0] = vec.x; inGeo.vertices[3 * index + 1] = vec.y; inGeo.vertices[3 * index + 2] = vec.z; @@ -2287,6 +2254,11 @@ public class PShapeOpenGL extends PShape { @Override public void setNormal(int index, float nx, float ny, float nz) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setNormal()"); + return; + } + inGeo.normals[3 * index + 0] = nx; inGeo.normals[3 * index + 1] = ny; inGeo.normals[3 * index + 2] = nz; @@ -2308,6 +2280,11 @@ public class PShapeOpenGL extends PShape { @Override public void setTextureUV(int index, float u, float v) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureUV()"); + return; + } + inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; markForTessellation(); @@ -2316,25 +2293,282 @@ public class PShapeOpenGL extends PShape { @Override public int getFill(int index) { - return PGL.nativeToJavaARGB(inGeo.colors[index]); + if (family != GROUP && image == null) { + return PGL.nativeToJavaARGB(inGeo.colors[index]); + } else { + return 0; + } + } + + + @Override + public void setFill(boolean fill) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setFill(fill); + } + } else if (this.fill && !fill) { + setFillImpl(0x0); + } + this.fill = fill; + } + + + @Override + public void setFill(int fill) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setFill(fill); + } + } else { + setFillImpl(fill); + } + } + + + protected void setFillImpl(int fill) { + if (fillColor == fill) return; + fillColor = fill; + + if (image == null) { + Arrays.fill(inGeo.colors, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(fillColor)); + if (shapeCreated && tessellated && hasPolys) { + if (is3D()) { + 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)); + root.setModifiedPolyColors(firstPolyVertex, last1 - 1); + } + } + } + + if (!setAmbient) { + // Setting the ambient color from the current fill + // is what the old P3D did and allows to have an + // default ambient color when the user doesn't specify + // it explicitly. + setAmbientImpl(fill); + setAmbient = false; + } } @Override public void setFill(int index, int fill) { - inGeo.colors[index] = PGL.javaToNativeARGB(fill); - markForTessellation(); + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()"); + return; + } + + if (image == null) { + inGeo.colors[index] = PGL.javaToNativeARGB(fill); + markForTessellation(); + } + } + + + @Override + public int getTint(int index) { + if (family != GROUP && image != null) { + return PGL.nativeToJavaARGB(inGeo.colors[index]); + } else { + return 0; + } + } + + + @Override + public void setTint(boolean tint) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setTint(fill); + } + } else if (this.tint && !tint) { + setTintImpl(0xFFFFFFFF); + } + this.tint = tint; + } + + + @Override + public void setTint(int tint) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setTint(tint); + } + } else { + setTintImpl(tint); + } + } + + + protected void setTintImpl(int tint) { + if (tintColor == tint) return; + tintColor = tint; + + if (image != null) { + Arrays.fill(inGeo.colors, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(tintColor)); + if (shapeCreated && tessellated && hasPolys) { + if (is3D()) { + 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); + } + } + } + } + + + @Override + public void setTint(int index, int tint) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()"); + return; + } + + if (image != null) { + inGeo.colors[index] = PGL.javaToNativeARGB(tint); + markForTessellation(); + } } @Override public int getStroke(int index) { - return PGL.nativeToJavaARGB(inGeo.strokeColors[index]); + if (family != GROUP) { + return PGL.nativeToJavaARGB(inGeo.strokeColors[index]); + } else { + return 0; + } + } + + + @Override + public void setStroke(boolean stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setStroke(stroke); + } + } else if (this.stroke != stroke) { + if (this.stroke) { + // Disabling stroke on a shape previously with + // stroke needs a re-tesellation in order to remove + // the additional geometry of lines and/or points. + markForTessellation(); + stroke = false; + } + setStrokeImpl(0x0); + if (is2D() && parent != null) { + ((PShapeOpenGL)parent).strokedTexture(false); + } + } + this.stroke = stroke; + } + + + @Override + public void setStroke(int stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setStroke(stroke); + } + } else { + setStrokeImpl(stroke); + } + } + + + protected void setStrokeImpl(int stroke) { + if (strokeColor == stroke) return; + strokeColor = stroke; + + Arrays.fill(inGeo.strokeColors, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(strokeColor)); + if (shapeCreated && tessellated && (hasLines || hasPoints)) { + if (hasLines) { + if (is3D()) { + Arrays.fill(tessGeo.lineColors, firstLineVertex, lastLineVertex + 1, + PGL.javaToNativeARGB(strokeColor)); + root.setModifiedLineColors(firstLineVertex, lastLineVertex); + } else if (is2D()) { + 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, + PGL.javaToNativeARGB(strokeColor)); + root.setModifiedPointColors(firstPointVertex, lastPointVertex); + } else if (is2D()) { + Arrays.fill(tessGeo.polyColors, firstPointVertex, lastPointVertex + 1, + PGL.javaToNativeARGB(strokeColor)); + root.setModifiedPolyColors(firstPointVertex, lastPointVertex); + } + } + } } @Override public void setStroke(int index, int stroke) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()"); + return; + } + inGeo.strokeColors[index] = PGL.javaToNativeARGB(stroke); markForTessellation(); } @@ -2342,37 +2576,254 @@ public class PShapeOpenGL extends PShape { @Override public float getStrokeWeight(int index) { - return inGeo.strokeWeights[index]; + if (family != GROUP) { + return inGeo.strokeWeights[index]; + } else { + return 0; + } + } + + + @Override + public void setStrokeWeight(float weight) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setStrokeWeight(weight); + } + } else { + setStrokeWeightImpl(weight); + } + } + + + protected void setStrokeWeightImpl(float weight) { + if (PGraphicsOpenGL.same(strokeWeight, weight)) return; + float oldWeight = strokeWeight; + strokeWeight = weight; + + Arrays.fill(inGeo.strokeWeights, 0, inGeo.vertexCount, strokeWeight); + if (shapeCreated && tessellated && (hasLines || hasPoints)) { + float resizeFactor = weight / oldWeight; + 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 + // re-tesellation in order to replace the old line + // geometry. + markForTessellation(); + } + } + if (hasPoints) { + if (is3D()) { + 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 + // re-tesellation in order to replace the old point + // geometry. + markForTessellation(); + } + } + } } @Override public void setStrokeWeight(int index, float weight) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()"); + return; + } + inGeo.strokeWeights[index] = weight; markForTessellation(); } + @Override + public void setStrokeJoin(int join) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeJoin()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setStrokeJoin(join); + } + } else { + if (is2D() && strokeJoin != join) { + // Changing the stroke join on a 2D shape needs a + // re-tesellation in order to replace the old join + // geometry. + markForTessellation(); + } + strokeJoin = join; + } + } + + + @Override + public void setStrokeCap(int cap) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeCap()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setStrokeCap(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 + // geometry. + markForTessellation(); + } + strokeCap = cap; + } + } + + @Override public int getAmbient(int index) { - return PGL.nativeToJavaARGB(inGeo.ambient[index]); + if (family != GROUP) { + return PGL.nativeToJavaARGB(inGeo.ambient[index]); + } else { + return 0; + } + } + + + @Override + public void setAmbient(int ambient) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setAmbient(ambient); + } + } else { + setAmbientImpl(ambient); + } + } + + + protected void setAmbientImpl(int ambient) { + if (ambientColor == ambient) return; + ambientColor = ambient; + + Arrays.fill(inGeo.ambient, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(ambientColor)); + if (shapeCreated && tessellated && hasPolys) { + if (is3D()) { + 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); + } + } + setAmbient = true; } @Override public void setAmbient(int index, int ambient) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()"); + return; + } + inGeo.ambient[index] = PGL.javaToNativeARGB(ambient); markForTessellation(); + setAmbient = true; } + @Override public int getSpecular(int index) { - return PGL.nativeToJavaARGB(inGeo.specular[index]); + if (family == GROUP) { + return PGL.nativeToJavaARGB(inGeo.specular[index]); + } else { + return 0; + } + } + + + @Override + public void setSpecular(int specular) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setSpecular(specular); + } + } else { + setSpecularImpl(specular); + } + } + + + protected void setSpecularImpl(int specular) { + if (specularColor == specular) return; + specularColor = specular; + + Arrays.fill(inGeo.specular, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(specularColor)); + if (shapeCreated && tessellated && hasPolys) { + if (is3D()) { + 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)); + root.setModifiedPolyColors(firstPolyVertex, last1 - 1); + } + } } @Override public void setSpecular(int index, int specular) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()"); + return; + } + inGeo.specular[index] = PGL.javaToNativeARGB(specular); markForTessellation(); } @@ -2380,12 +2831,62 @@ public class PShapeOpenGL extends PShape { @Override public int getEmissive(int index) { - return PGL.nativeToJavaARGB(inGeo.emissive[index]); + if (family == GROUP) { + return PGL.nativeToJavaARGB(inGeo.emissive[index]); + } else { + return 0; + } + } + + + @Override + public void setEmissive(int emissive) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setEmissive(emissive); + } + } else { + setEmissiveImpl(emissive); + } + } + + + protected void setEmissiveImpl(int emissive) { + if (emissiveColor == emissive) return; + emissiveColor = emissive; + + Arrays.fill(inGeo.emissive, 0, inGeo.vertexCount, + PGL.javaToNativeARGB(emissiveColor)); + if (shapeCreated && tessellated && 0 < tessGeo.polyVertexCount) { + if (is3D()) { + 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)); + root.setModifiedPolyColors(firstPolyVertex, last1 - 1); + } + } } @Override public void setEmissive(int index, int emissive) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()"); + return; + } + inGeo.emissive[index] = PGL.javaToNativeARGB(emissive); markForTessellation(); } @@ -2393,12 +2894,60 @@ public class PShapeOpenGL extends PShape { @Override public float getShininess(int index) { - return inGeo.shininess[index]; + if (family == GROUP) { + return inGeo.shininess[index]; + } else { + return 0; + } + } + + + @Override + public void setShininess(float shininess) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()"); + return; + } + + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShapeOpenGL child = (PShapeOpenGL) children[i]; + child.setShininess(shininess); + } + } else { + setShininessImpl(shininess); + } + } + + + protected void setShininessImpl(float shininess) { + if (PGraphicsOpenGL.same(this.shininess, shininess)) return; + this.shininess = shininess; + + Arrays.fill(inGeo.shininess, 0, inGeo.vertexCount, shininess); + if (shapeCreated && tessellated && hasPolys) { + if (is3D()) { + 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); + root.setModifiedPolyColors(firstPolyVertex, last1 - 1); + } + } } @Override public void setShininess(int index, float shine) { + if (openShape) { + PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()"); + return; + } + inGeo.shininess[index] = shine; markForTessellation(); } @@ -2422,13 +2971,14 @@ public class PShapeOpenGL extends PShape { PShape tess; if (is3D()) { - tess = PGraphics3D.createShapeImpl(pg.parent, TRIANGLES); + tess = PGraphics3D.createShapeImpl(pg.parent, PShape.GEOMETRY); } else if (is2D()) { - tess = PGraphics2D.createShapeImpl(pg.parent, TRIANGLES); + tess = PGraphics2D.createShapeImpl(pg.parent, PShape.GEOMETRY); } else { PGraphics.showWarning("This shape is not either 2D or 3D!"); return null; } + tess.beginShape(TRIANGLES); tess.noStroke(); IndexCache cache = tessGeo.polyIndexCache; @@ -2498,7 +3048,7 @@ public class PShapeOpenGL extends PShape { } } } - tess.end(); + tess.endShape(); return tess; } @@ -2608,7 +3158,7 @@ public class PShapeOpenGL extends PShape { child.tessellateImpl(); } } else { - if (shapeEnded) { + if (shapeCreated) { // 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 @@ -3448,50 +3998,50 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updatePolyVerticesBuffer(); - glPolyVertex = pg.createVertexBufferObject(context.id()); + glPolyVertex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.polyVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyColorsBuffer(); - glPolyColor = pg.createVertexBufferObject(context.id()); + glPolyColor = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyColorsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyNormalsBuffer(); - glPolyNormal = pg.createVertexBufferObject(context.id()); + glPolyNormal = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, tessGeo.polyNormalsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyTexcoordsBuffer(); - glPolyTexcoord = pg.createVertexBufferObject(context.id()); + glPolyTexcoord = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, tessGeo.polyTexcoordsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyAmbientBuffer(); - glPolyAmbient = pg.createVertexBufferObject(context.id()); + glPolyAmbient = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyAmbientBuffer, PGL.STATIC_DRAW); tessGeo.updatePolySpecularBuffer(); - glPolySpecular = pg.createVertexBufferObject(context.id()); + glPolySpecular = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polySpecularBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyEmissiveBuffer(); - glPolyEmissive = pg.createVertexBufferObject(context.id()); + glPolyEmissive = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyEmissiveBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyShininessBuffer(); - glPolyShininess = pg.createVertexBufferObject(context.id()); + glPolyShininess = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess); pgl.bufferData(PGL.ARRAY_BUFFER, sizef, tessGeo.polyShininessBuffer, PGL.STATIC_DRAW); @@ -3499,7 +4049,7 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updatePolyIndicesBuffer(); - glPolyIndex = pg.createVertexBufferObject(context.id()); + glPolyIndex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, @@ -3515,19 +4065,19 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updateLineVerticesBuffer(); - glLineVertex = pg.createVertexBufferObject(context.id()); + glLineVertex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.lineVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updateLineColorsBuffer(); - glLineColor = pg.createVertexBufferObject(context.id()); + glLineColor = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.lineColorsBuffer, PGL.STATIC_DRAW); tessGeo.updateLineAttribsBuffer(); - glLineAttrib = pg.createVertexBufferObject(context.id()); + glLineAttrib = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.lineAttribsBuffer, PGL.STATIC_DRAW); @@ -3535,7 +4085,7 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updateLineIndicesBuffer(); - glLineIndex = pg.createVertexBufferObject(context.id()); + glLineIndex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, @@ -3551,19 +4101,19 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updatePointVerticesBuffer(); - glPointVertex = pg.createVertexBufferObject(context.id()); + glPointVertex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.pointVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updatePointColorsBuffer(); - glPointColor = pg.createVertexBufferObject(context.id()); + glPointColor = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.pointColorsBuffer, PGL.STATIC_DRAW); tessGeo.updatePointAttribsBuffer(); - glPointAttrib = pg.createVertexBufferObject(context.id()); + glPointAttrib = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, tessGeo.pointAttribsBuffer, PGL.STATIC_DRAW); @@ -3571,7 +4121,7 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updatePointIndicesBuffer(); - glPointIndex = pg.createVertexBufferObject(context.id()); + glPointIndex = pg.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, @@ -3588,25 +4138,25 @@ public class PShapeOpenGL extends PShape { // doesn't get deleted by OpenGL. The VBOs were already // automatically disposed when the old context was // destroyed. - pg.removeVertexBufferObject(glPolyVertex, context.id()); - pg.removeVertexBufferObject(glPolyColor, context.id()); - pg.removeVertexBufferObject(glPolyNormal, context.id()); - pg.removeVertexBufferObject(glPolyTexcoord, context.id()); - pg.removeVertexBufferObject(glPolyAmbient, context.id()); - pg.removeVertexBufferObject(glPolySpecular, context.id()); - pg.removeVertexBufferObject(glPolyEmissive, context.id()); - pg.removeVertexBufferObject(glPolyShininess, context.id()); - pg.removeVertexBufferObject(glPolyIndex, context.id()); + pg.removeVertexBufferObject(glPolyVertex, context); + pg.removeVertexBufferObject(glPolyColor, context); + pg.removeVertexBufferObject(glPolyNormal, context); + pg.removeVertexBufferObject(glPolyTexcoord, context); + pg.removeVertexBufferObject(glPolyAmbient, context); + pg.removeVertexBufferObject(glPolySpecular, context); + pg.removeVertexBufferObject(glPolyEmissive, context); + pg.removeVertexBufferObject(glPolyShininess, context); + pg.removeVertexBufferObject(glPolyIndex, context); - pg.removeVertexBufferObject(glLineVertex, context.id()); - pg.removeVertexBufferObject(glLineColor, context.id()); - pg.removeVertexBufferObject(glLineAttrib, context.id()); - pg.removeVertexBufferObject(glLineIndex, context.id()); + pg.removeVertexBufferObject(glLineVertex, context); + pg.removeVertexBufferObject(glLineColor, context); + pg.removeVertexBufferObject(glLineAttrib, context); + pg.removeVertexBufferObject(glLineIndex, context); - pg.removeVertexBufferObject(glPointVertex, context.id()); - pg.removeVertexBufferObject(glPointColor, context.id()); - pg.removeVertexBufferObject(glPointAttrib, context.id()); - pg.removeVertexBufferObject(glPointIndex, context.id()); + pg.removeVertexBufferObject(glPointVertex, context); + pg.removeVertexBufferObject(glPointColor, context); + pg.removeVertexBufferObject(glPointAttrib, context); + pg.removeVertexBufferObject(glPointIndex, context); // The OpenGL resources have been already deleted // when the context changed. We only need to zero @@ -3652,47 +4202,47 @@ public class PShapeOpenGL extends PShape { protected void deletePolyBuffers() { if (glPolyVertex != 0) { - pg.deleteVertexBufferObject(glPolyVertex, context.id()); + pg.deleteVertexBufferObject(glPolyVertex, context); glPolyVertex = 0; } if (glPolyColor != 0) { - pg.deleteVertexBufferObject(glPolyColor, context.id()); + pg.deleteVertexBufferObject(glPolyColor, context); glPolyColor = 0; } if (glPolyNormal != 0) { - pg.deleteVertexBufferObject(glPolyNormal, context.id()); + pg.deleteVertexBufferObject(glPolyNormal, context); glPolyNormal = 0; } if (glPolyTexcoord != 0) { - pg.deleteVertexBufferObject(glPolyTexcoord, context.id()); + pg.deleteVertexBufferObject(glPolyTexcoord, context); glPolyTexcoord = 0; } if (glPolyAmbient != 0) { - pg.deleteVertexBufferObject(glPolyAmbient, context.id()); + pg.deleteVertexBufferObject(glPolyAmbient, context); glPolyAmbient = 0; } if (glPolySpecular != 0) { - pg.deleteVertexBufferObject(glPolySpecular, context.id()); + pg.deleteVertexBufferObject(glPolySpecular, context); glPolySpecular = 0; } if (glPolyEmissive != 0) { - pg.deleteVertexBufferObject(glPolyEmissive, context.id()); + pg.deleteVertexBufferObject(glPolyEmissive, context); glPolyEmissive = 0; } if (glPolyShininess != 0) { - pg.deleteVertexBufferObject(glPolyShininess, context.id()); + pg.deleteVertexBufferObject(glPolyShininess, context); glPolyShininess = 0; } if (glPolyIndex != 0) { - pg.deleteVertexBufferObject(glPolyIndex, context.id()); + pg.deleteVertexBufferObject(glPolyIndex, context); glPolyIndex = 0; } } @@ -3700,22 +4250,22 @@ public class PShapeOpenGL extends PShape { protected void deleteLineBuffers() { if (glLineVertex != 0) { - pg.deleteVertexBufferObject(glLineVertex, context.id()); + pg.deleteVertexBufferObject(glLineVertex, context); glLineVertex = 0; } if (glLineColor != 0) { - pg.deleteVertexBufferObject(glLineColor, context.id()); + pg.deleteVertexBufferObject(glLineColor, context); glLineColor = 0; } if (glLineAttrib != 0) { - pg.deleteVertexBufferObject(glLineAttrib, context.id()); + pg.deleteVertexBufferObject(glLineAttrib, context); glLineAttrib = 0; } if (glLineIndex != 0) { - pg.deleteVertexBufferObject(glLineIndex, context.id()); + pg.deleteVertexBufferObject(glLineIndex, context); glLineIndex = 0; } } @@ -3723,22 +4273,22 @@ public class PShapeOpenGL extends PShape { protected void deletePointBuffers() { if (glPointVertex != 0) { - pg.deleteVertexBufferObject(glPointVertex, context.id()); + pg.deleteVertexBufferObject(glPointVertex, context); glPointVertex = 0; } if (glPointColor != 0) { - pg.deleteVertexBufferObject(glPointColor, context.id()); + pg.deleteVertexBufferObject(glPointColor, context); glPointColor = 0; } if (glPointAttrib != 0) { - pg.deleteVertexBufferObject(glPointAttrib, context.id()); + pg.deleteVertexBufferObject(glPointAttrib, context); glPointAttrib = 0; } if (glPointIndex != 0) { - pg.deleteVertexBufferObject(glPointIndex, context.id()); + pg.deleteVertexBufferObject(glPointIndex, context); glPointIndex = 0; } } diff --git a/android/core/src/processing/opengl/PointShaderFrag.glsl b/android/core/src/processing/opengl/PointShaderFrag.glsl index 16742d2bd..d5d23ae22 100644 --- a/android/core/src/processing/opengl/PointShaderFrag.glsl +++ b/android/core/src/processing/opengl/PointShaderFrag.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/android/core/src/processing/opengl/PointShaderVert.glsl b/android/core/src/processing/opengl/PointShaderVert.glsl index 25b226b5b..fd64d0dc1 100644 --- a/android/core/src/processing/opengl/PointShaderVert.glsl +++ b/android/core/src/processing/opengl/PointShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,15 +18,17 @@ Boston, MA 02111-1307 USA */ -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; +#define PROCESSING_POINT_SHADER + +uniform mat4 projection; +uniform mat4 modelview; uniform vec4 viewport; uniform int perspective; -attribute vec4 inVertex; -attribute vec4 inColor; -attribute vec2 inPoint; +attribute vec4 vertex; +attribute vec4 color; +attribute vec2 offset; varying vec4 vertColor; @@ -36,18 +38,18 @@ vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) { } void main() { - vec4 pos = modelviewMatrix * inVertex; - vec4 clip = projectionMatrix * pos; + vec4 pos = modelview * vertex; + vec4 clip = projection * pos; if (0 < perspective) { // Perspective correction (points will look thiner as they move away // from the view position). - gl_Position = clip + projectionMatrix * vec4(inPoint.xy, 0, 0); + gl_Position = clip + projection * vec4(offset.xy, 0, 0); } else { // No perspective correction. - vec4 offset = windowToClipVector(inPoint.xy, viewport, clip.w); + vec4 offset = windowToClipVector(offset.xy, viewport, clip.w); gl_Position = clip + offset; } - vertColor = inColor; + vertColor = color; } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PolyColorShaderVert.glsl b/android/core/src/processing/opengl/PolyColorShaderVert.glsl index 95c266a76..5a03b41a0 100644 --- a/android/core/src/processing/opengl/PolyColorShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyColorShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,15 +18,17 @@ Boston, MA 02111-1307 USA */ -uniform mat4 projmodelviewMatrix; +#define PROCESSING_COLOR_SHADER -attribute vec4 inVertex; -attribute vec4 inColor; +uniform mat4 transform; + +attribute vec4 vertex; +attribute vec4 color; varying vec4 vertColor; void main() { - gl_Position = projmodelviewMatrix * inVertex; + gl_Position = transform * vertex; - vertColor = inColor; + vertColor = color; } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PolyLightShaderVert.glsl b/android/core/src/processing/opengl/PolyLightShaderVert.glsl index b271b020a..6e5829fe2 100644 --- a/android/core/src/processing/opengl/PolyLightShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyLightShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +18,10 @@ Boston, MA 02111-1307 USA */ -uniform mat4 modelviewMatrix; -uniform mat4 projmodelviewMatrix; +#define PROCESSING_LIGHT_SHADER + +uniform mat4 modelview; +uniform mat4 transform; uniform mat3 normalMatrix; uniform int lightCount; @@ -28,17 +30,17 @@ uniform vec3 lightNormal[8]; uniform vec3 lightAmbient[8]; uniform vec3 lightDiffuse[8]; uniform vec3 lightSpecular[8]; -uniform vec3 lightFalloffCoefficients[8]; -uniform vec2 lightSpotParameters[8]; +uniform vec3 lightFalloff[8]; +uniform vec2 lightSpot[8]; -attribute vec4 inVertex; -attribute vec4 inColor; -attribute vec3 inNormal; +attribute vec4 vertex; +attribute vec4 color; +attribute vec3 normal; -attribute vec4 inAmbient; -attribute vec4 inSpecular; -attribute vec4 inEmissive; -attribute float inShine; +attribute vec4 ambient; +attribute vec4 specular; +attribute vec4 emissive; +attribute float shininess; varying vec4 vertColor; @@ -73,13 +75,13 @@ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) void main() { // Vertex in clip coordinates - gl_Position = projmodelviewMatrix * inVertex; + gl_Position = transform * vertex; // Vertex in eye coordinates - vec3 ecVertex = vec3(modelviewMatrix * inVertex); + vec3 ecVertex = vec3(modelview * vertex); // Normal vector in eye coordinates - vec3 ecNormal = normalize(normalMatrix * inNormal); + vec3 ecNormal = normalize(normalMatrix * normal); if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. @@ -96,8 +98,8 @@ void main() { vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; - float spotCos = lightSpotParameters[i].x; - float spotExp = lightSpotParameters[i].y; + float spotCos = lightSpot[i].x; + float spotExp = lightSpot[i].y; vec3 lightDir; float falloff; @@ -107,7 +109,7 @@ void main() { falloff = one_float; lightDir = -one_float * lightNormal[i]; } else { - falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); + falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]); lightDir = normalize(lightPos - ecVertex); } @@ -126,14 +128,14 @@ void main() { if (any(greaterThan(lightSpecular[i], zero_vec3))) { totalSpecular += lightSpecular[i] * falloff * spotf * - blinnPhongFactor(lightDir, ecVertex, ecNormal, inShine); + blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess); } } // Calculating final color as result of all lights (plus emissive term). // Transparency is determined exclusively by the diffuse component. - vertColor = vec4(totalAmbient, 0) * inAmbient + - vec4(totalDiffuse, 1) * inColor + - vec4(totalSpecular, 0) * inSpecular + - vec4(inEmissive.rgb, 0); + vertColor = vec4(totalAmbient, 0) * ambient + + vec4(totalDiffuse, 1) * color + + vec4(totalSpecular, 0) * specular + + vec4(emissive.rgb, 0); } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PolyNoTexShaderFrag.glsl b/android/core/src/processing/opengl/PolyNoTexShaderFrag.glsl index 16742d2bd..d5d23ae22 100644 --- a/android/core/src/processing/opengl/PolyNoTexShaderFrag.glsl +++ b/android/core/src/processing/opengl/PolyNoTexShaderFrag.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/android/core/src/processing/opengl/PolyTexShaderFrag.glsl b/android/core/src/processing/opengl/PolyTexShaderFrag.glsl index 9d09c61a0..f041e61d1 100644 --- a/android/core/src/processing/opengl/PolyTexShaderFrag.glsl +++ b/android/core/src/processing/opengl/PolyTexShaderFrag.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -23,13 +23,13 @@ precision mediump float; precision mediump int; #endif -uniform sampler2D textureSampler; +uniform sampler2D texture; -uniform vec2 texcoordOffset; +uniform vec2 texOffset; varying vec4 vertColor; -varying vec4 vertTexcoord; +varying vec4 vertTexCoord; void main() { - gl_FragColor = texture2D(textureSampler, vertTexcoord.st) * vertColor; + gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor; } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PolyTexShaderVert.glsl b/android/core/src/processing/opengl/PolyTexShaderVert.glsl index bc257dda7..5260321fb 100644 --- a/android/core/src/processing/opengl/PolyTexShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyTexShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,19 +18,21 @@ Boston, MA 02111-1307 USA */ -uniform mat4 projmodelviewMatrix; -uniform mat4 texcoordMatrix; +#define PROCESSING_TEXTURE_SHADER -attribute vec4 inVertex; -attribute vec4 inColor; -attribute vec2 inTexcoord; +uniform mat4 transform; +uniform mat4 texMatrix; + +attribute vec4 vertex; +attribute vec4 color; +attribute vec2 texCoord; varying vec4 vertColor; -varying vec4 vertTexcoord; +varying vec4 vertTexCoord; void main() { - gl_Position = projmodelviewMatrix * inVertex; + gl_Position = transform * vertex; - vertColor = inColor; - vertTexcoord = texcoordMatrix * vec4(inTexcoord, 1.0, 1.0); + vertColor = color; + vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); } \ No newline at end of file diff --git a/android/core/src/processing/opengl/PolyTexlightShaderVert.glsl b/android/core/src/processing/opengl/PolyTexlightShaderVert.glsl index 7ce8cf92f..ff981c59c 100644 --- a/android/core/src/processing/opengl/PolyTexlightShaderVert.glsl +++ b/android/core/src/processing/opengl/PolyTexlightShaderVert.glsl @@ -1,7 +1,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2011-12 Ben Fry and Casey Reas + Copyright (c) 2011-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,10 +18,12 @@ Boston, MA 02111-1307 USA */ -uniform mat4 modelviewMatrix; -uniform mat4 projmodelviewMatrix; +#define PROCESSING_TEXLIGHT_SHADER + +uniform mat4 modelview; +uniform mat4 transform; uniform mat3 normalMatrix; -uniform mat4 texcoordMatrix; +uniform mat4 texMatrix; uniform int lightCount; uniform vec4 lightPosition[8]; @@ -29,21 +31,21 @@ uniform vec3 lightNormal[8]; uniform vec3 lightAmbient[8]; uniform vec3 lightDiffuse[8]; uniform vec3 lightSpecular[8]; -uniform vec3 lightFalloffCoefficients[8]; -uniform vec2 lightSpotParameters[8]; +uniform vec3 lightFalloff[8]; +uniform vec2 lightSpot[8]; -attribute vec4 inVertex; -attribute vec4 inColor; -attribute vec3 inNormal; -attribute vec2 inTexcoord; +attribute vec4 vertex; +attribute vec4 color; +attribute vec3 normal; +attribute vec2 texCoord; -attribute vec4 inAmbient; -attribute vec4 inSpecular; -attribute vec4 inEmissive; -attribute float inShine; +attribute vec4 ambient; +attribute vec4 specular; +attribute vec4 emissive; +attribute float shininess; varying vec4 vertColor; -varying vec4 vertTexcoord; +varying vec4 vertTexCoord; const float zero_float = 0.0; const float one_float = 1.0; @@ -76,13 +78,13 @@ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) void main() { // Vertex in clip coordinates - gl_Position = projmodelviewMatrix * inVertex; + gl_Position = transform * vertex; // Vertex in eye coordinates - vec3 ecVertex = vec3(modelviewMatrix * inVertex); + vec3 ecVertex = vec3(modelview * vertex); // Normal vector in eye coordinates - vec3 ecNormal = normalize(normalMatrix * inNormal); + vec3 ecNormal = normalize(normalMatrix * normal); if (dot(-one_float * ecVertex, ecNormal) < zero_float) { // If normal is away from camera, choose its opposite. @@ -99,8 +101,8 @@ void main() { vec3 lightPos = lightPosition[i].xyz; bool isDir = zero_float < lightPosition[i].w; - float spotCos = lightSpotParameters[i].x; - float spotExp = lightSpotParameters[i].y; + float spotCos = lightSpot[i].x; + float spotExp = lightSpot[i].y; vec3 lightDir; float falloff; @@ -110,7 +112,7 @@ void main() { falloff = one_float; lightDir = -one_float * lightNormal[i]; } else { - falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]); + falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]); lightDir = normalize(lightPos - ecVertex); } @@ -129,17 +131,17 @@ void main() { if (any(greaterThan(lightSpecular[i], zero_vec3))) { totalSpecular += lightSpecular[i] * falloff * spotf * - blinnPhongFactor(lightDir, ecVertex, ecNormal, inShine); + blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess); } } // Calculating final color as result of all lights (plus emissive term). // Transparency is determined exclusively by the diffuse component. - vertColor = vec4(totalAmbient, 0) * inAmbient + - vec4(totalDiffuse, 1) * inColor + - vec4(totalSpecular, 0) * inSpecular + - vec4(inEmissive.rgb, 0); + vertColor = vec4(totalAmbient, 0) * ambient + + vec4(totalDiffuse, 1) * color + + vec4(totalSpecular, 0) * specular + + vec4(emissive.rgb, 0); // Calculating texture coordinates, with r and q set both to one - vertTexcoord = texcoordMatrix * vec4(inTexcoord, 1.0, 1.0); + vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); } diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 7dbe884e6..f4eacf60a 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -78,10 +78,10 @@ public class Texture implements PConstants { public int glWidth; 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 PApplet parent; // The Processing applet + protected PGraphicsOpenGL pg; // The main renderer + protected PGL pgl; // The interface between Processing and OpenGL. + protected int context; // The context that created this texture. protected PGraphicsOpenGL pgDraw; // The main renderer is the color buffer of. protected boolean usingMipmaps; @@ -162,7 +162,7 @@ public class Texture implements PConstants { protected void finalize() throws Throwable { try { if (glName != 0) { - pg.finalizeTextureObject(glName, context.id()); + pg.finalizeTextureObject(glName, context); } } finally { super.finalize(); @@ -1193,7 +1193,7 @@ public class Texture implements PConstants { } context = pgl.getCurrentContext(); - glName = pg.createTextureObject(context.id()); + glName = pg.createTextureObject(context); pgl.bindTexture(glTarget, glName); pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter); @@ -1228,7 +1228,7 @@ public class Texture implements PConstants { */ protected void release() { if (glName != 0) { - pg.finalizeTextureObject(glName, context.id()); + pg.finalizeTextureObject(glName, context); glName = 0; } } @@ -1240,7 +1240,7 @@ public class Texture implements PConstants { // Removing the texture object from the renderer's list so it // doesn't get deleted by OpenGL. The texture object was // automatically disposed when the old context was destroyed. - pg.removeTextureObject(glName, context.id()); + pg.removeTextureObject(glName, context); // 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.