diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index edc86ffbd..e26853561 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -976,6 +976,11 @@ public class PApplet extends Activity implements PConstants, Runnable { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + public int sketchQuality() { + return 1; + } + + public int sketchWidth() { return displayWidth; } diff --git a/android/core/src/processing/opengl/PFontTexture.java b/android/core/src/processing/opengl/PFontTexture.java index e4bf64888..dff2bba66 100644 --- a/android/core/src/processing/opengl/PFontTexture.java +++ b/android/core/src/processing/opengl/PFontTexture.java @@ -269,7 +269,7 @@ class PFontTexture implements PConstants { rgba[t++] = 0xFFFFFF00; // Set the leftmost pixel in this row as blank for (int x = 0; x < glyph.width; x++) { rgba[t++] = 0xFFFFFF00 | glyph.image.pixels[p++]; - } + } rgba[t++] = 0xFFFFFF00; // Set the rightmost pixel in this row as blank } java.util.Arrays.fill(rgba, (h - 1) * w, h * w, 0xFFFFFF00); // Set the last row to blank pixels. @@ -342,7 +342,6 @@ class PFontTexture implements PConstants { public float u0, u1; public float v0, v1; public int[] pixels; - public TextureInfo(int tidx, int cropX, int cropY, int cropW, int cropH, int[] pix) { texIndex = tidx; diff --git a/android/core/src/processing/opengl/PGraphics2D.java b/android/core/src/processing/opengl/PGraphics2D.java index 01f1b7128..34e2d0ae4 100644 --- a/android/core/src/processing/opengl/PGraphics2D.java +++ b/android/core/src/processing/opengl/PGraphics2D.java @@ -68,6 +68,82 @@ public class PGraphics2D extends PGraphicsOpenGL { } super.hint(which); } + + + ////////////////////////////////////////////////////////////// + + // PROJECTION + + + public void ortho() { + showMethodWarning("ortho"); + } + + + public void ortho(float left, float right, + float bottom, float top) { + showMethodWarning("ortho"); + } + + + public void ortho(float left, float right, + float bottom, float top, + float near, float far) { + showMethodWarning("ortho"); + } + + + public void perspective() { + showMethodWarning("perspective"); + } + + + public void perspective(float fov, float aspect, float zNear, float zFar) { + showMethodWarning("perspective"); + } + + + public void frustum(float left, float right, float bottom, float top, + float znear, float zfar) { + showMethodWarning("frustum"); + } + + + protected void defaultPerspective() { + super.ortho(-width/2, +width/2, -height/2, +height/2, cameraNear, cameraFar); + } + + + ////////////////////////////////////////////////////////////// + + // CAMERA + + + public void beginCamera() { + showMethodWarning("beginCamera"); + } + + + public void endCamera() { + showMethodWarning("endCamera"); + } + + + public void camera() { + showMethodWarning("camera"); + } + + + public void camera(float eyeX, float eyeY, float eyeZ, + float centerX, float centerY, float centerZ, + float upX, float upY, float upZ) { + showMethodWarning("camera"); + } + + + protected void defaultCamera() { + super.camera(cameraX, cameraY, cameraZ, cameraX, cameraY, 0, 0, 1, 0); + } ////////////////////////////////////////////////////////////// diff --git a/android/core/src/processing/opengl/PGraphics3D.java b/android/core/src/processing/opengl/PGraphics3D.java index 81fb8f64e..1744f9b21 100644 --- a/android/core/src/processing/opengl/PGraphics3D.java +++ b/android/core/src/processing/opengl/PGraphics3D.java @@ -49,6 +49,26 @@ public class PGraphics3D extends PGraphicsOpenGL { } + ////////////////////////////////////////////////////////////// + + // PROJECTION + + + protected void defaultPerspective() { + perspective(); + } + + + ////////////////////////////////////////////////////////////// + + // CAMERA + + + protected void defaultCamera() { + camera(); + } + + ////////////////////////////////////////////////////////////// // SHAPE I/O diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index dcee2bd77..7523f66d3 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -293,8 +293,8 @@ public class PGraphicsOpenGL extends PGraphics { // Texturing: - public int textureWrap = Texture.CLAMP; - public int textureQuality = Texture.BEST; + public int textureWrap = Texture.CLAMP; + public int textureSampling = Texture.TRILINEAR; // ........................................................ @@ -446,7 +446,10 @@ public class PGraphicsOpenGL extends PGraphics { } - //public void setParent(PApplet parent) // PGraphics + public void setParent(PApplet parent) { + super.setParent(parent); + quality = parent.sketchQuality(); + } public void setPrimary(boolean primary) { @@ -1516,13 +1519,12 @@ public class PGraphicsOpenGL extends PGraphics { } if (sizeChanged) { - // defaults to perspective, if the user has setup up their - // own projection, they'll need to fix it after resize anyway. - // this helps the people who haven't set up their own projection. - perspective(); - - // set up the default camera and initializes modelview matrix. - camera(); + // Sets the default projection and camera (initializes modelview). + // If the user has setup up their own projection, they'll need + // to fix it after resize anyway. This helps the people who haven't + // set up their own projection. + defaultPerspective(); + defaultCamera(); // clear the flag sizeChanged = false; @@ -1687,9 +1689,6 @@ public class PGraphicsOpenGL extends PGraphics { if (quality < 2) { pgl.glDisable(PGL.GL_MULTISAMPLE); -// pgl.glEnable(PGL.GL_POINT_SMOOTH); -// pgl.glEnable(PGL.GL_LINE_SMOOTH); -// pgl.glEnable(PGL.GL_POLYGON_SMOOTH); } else { pgl.glEnable(PGL.GL_MULTISAMPLE); pgl.glDisable(PGL.GL_POINT_SMOOTH); @@ -2052,13 +2051,13 @@ public class PGraphicsOpenGL extends PGraphics { public void textureWrap(int wrap) { this.textureWrap = wrap; } - - - public void textureQuality(int quality) { - this.textureQuality = quality; - } - + + public void textureSampling(int sampling) { + this.textureSampling = sampling; + } + + public void texture(PImage image) { if (flushMode == FLUSH_WHEN_FULL && hints[DISABLE_TEXTURE_CACHE] && image != textureImage0) { @@ -3269,15 +3268,15 @@ public class PGraphicsOpenGL extends PGraphics { } if (textMode == MODEL) { - float high = glyph.height / (float) textFont.getSize(); - float bwidth = glyph.width / (float) textFont.getSize(); + float high = glyph.height / (float) textFont.getSize(); + float bwidth = glyph.width / (float) textFont.getSize(); float lextent = glyph.leftExtent / (float) textFont.getSize(); - float textent = glyph.topExtent / (float) textFont.getSize(); + float textent = glyph.topExtent / (float) textFont.getSize(); float x1 = x + lextent * textSize; float y1 = y - textent * textSize; float x2 = x1 + bwidth * textSize; - float y2 = y1 + high * textSize; + float y2 = y1 + high * textSize; textCharModelImpl(tinfo, x1, y1, x2, y2); } @@ -3921,6 +3920,11 @@ public class PGraphicsOpenGL extends PGraphics { camera.print(); } + + protected void defaultCamera() { + camera(); + } + ////////////////////////////////////////////////////////////// @@ -3932,7 +3936,7 @@ public class PGraphicsOpenGL extends PGraphics { * orthographic projection. */ public void ortho() { - ortho(0, width, 0, height, cameraNear, cameraFar); + ortho(-width/2, +width/2, -height/2, +height/2, cameraNear, cameraFar); } @@ -3961,19 +3965,21 @@ public class PGraphicsOpenGL extends PGraphics { // Flushing geometry with a different perspective configuration. flush(); - float x = 2.0f / (right - left); - float y = 2.0f / (top - bottom); + float x = +2.0f / (right - left); + float y = +2.0f / (top - bottom); float z = -2.0f / (far - near); float tx = -(right + left) / (right - left); float ty = -(top + bottom) / (top - bottom); - float tz = -(far + near) / (far - near); + float tz = -(far + near) / (far - near); // The minus sign is needed to invert the Y axis. projection.set(x, 0, 0, tx, 0, -y, 0, ty, 0, 0, z, tz, 0, 0, 0, 1); + + calcProjmodelview(); } @@ -4025,22 +4031,20 @@ public class PGraphicsOpenGL extends PGraphics { // Flushing geometry with a different perspective configuration. flush(); - float temp, temp2, temp3, temp4; - temp = 2.0f * znear; - temp2 = right - left; - temp3 = top - bottom; - temp4 = zfar - znear; + float n2 = 2 * znear; + float w = right - left; + float h = top - bottom; + float d = zfar - znear; - // The minus sign in the temp / temp3 term is to invert the Y axis. - projection.set(temp / temp2, 0, (right + left) / temp2, 0, - 0, -temp / temp3, (top + bottom) / temp3, 0, - 0, 0, (-zfar - znear) / temp4, (-temp * zfar) / temp4, - 0, 0, -1, 1); + projection.set(n2 / w, 0, (right + left) / w, 0, + 0, -n2 / h, (top + bottom) / h, 0, + 0, 0, -(zfar + znear) / d, -(n2 * zfar) / d, + 0, 0, -1, 0); calcProjmodelview(); } - + /** * Print the current projection matrix. */ @@ -4049,6 +4053,11 @@ public class PGraphicsOpenGL extends PGraphics { } + protected void defaultPerspective() { + perspective(); + } + + ////////////////////////////////////////////////////////////// // SCREEN AND MODEL COORDS @@ -5248,19 +5257,10 @@ public class PGraphicsOpenGL extends PGraphics { } else { params.mipmaps = true; } - if (textureQuality == Texture.LOW) { - params.sampling = POINT; - } else if (textureQuality == Texture.MEDIUM) { - params.sampling = Texture.LINEAR; - } else if (textureQuality == Texture.HIGH) { + params.sampling = textureSampling; + if (params.sampling == Texture.TRILINEAR && !params.mipmaps) { params.sampling = Texture.BILINEAR; - } else if (textureQuality == Texture.BEST) { - if (params.mipmaps) { - params.sampling = Texture.TRILINEAR; - } else { - params.sampling = Texture.BILINEAR; - PGraphics.showWarning("BEST texture quality requires mipmaps, will switch to HIGH."); - } + PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. Will use BILINEAR instead."); } params.wrapU = textureWrap; params.wrapV = textureWrap; @@ -6530,7 +6530,7 @@ public class PGraphicsOpenGL extends PGraphics { InGeometry(int mode) { renderMode = mode; allocate(); - } + } // ----------------------------------------------------------------- // @@ -7085,6 +7085,57 @@ public class PGraphicsOpenGL extends PGraphics { curveVertexCount = savedCount; } + // Returns the vertex data in the PGraphics double array format. + float[][] getVertexData() { + float[][] data = new float[vertexCount][VERTEX_FIELD_COUNT]; + for (int i = 0; i < vertexCount; i++) { + float[] vert = data[i]; + + vert[X] = vertices[3 * i + 0]; + vert[Y] = vertices[3 * i + 1]; + vert[Z] = vertices[3 * i + 2]; + + vert[R] = ((colors[i] >> 16) & 0xFF) / 255.0f; + vert[G] = ((colors[i] >> 8) & 0xFF) / 255.0f; + vert[B] = ((colors[i] >> 0) & 0xFF) / 255.0f; + vert[A] = ((colors[i] >> 24) & 0xFF) / 255.0f; + + vert[U] = texcoords[2 * i + 0]; + vert[V] = texcoords[2 * i + 1]; + + vert[NX] = normals[3 * i + 0]; + vert[NY] = normals[3 * i + 1]; + vert[NZ] = normals[3 * i + 2]; + + vert[SR] = ((strokeColors[i] >> 16) & 0xFF) / 255.0f; + vert[SG] = ((strokeColors[i] >> 8) & 0xFF) / 255.0f; + vert[SB] = ((strokeColors[i] >> 0) & 0xFF) / 255.0f; + vert[SA] = ((strokeColors[i] >> 24) & 0xFF) / 255.0f; + + vert[SW] = strokeWeights[i]; + + /* + // Android doesn't have these: + vert[AR] = ((ambient[i] >> 16) & 0xFF) / 255.0f; + vert[AG] = ((ambient[i] >> 8) & 0xFF) / 255.0f; + vert[AB] = ((ambient[i] >> 0) & 0xFF) / 255.0f; + + vert[SPR] = ((specular[i] >> 16) & 0xFF) / 255.0f; + vert[SPG] = ((specular[i] >> 8) & 0xFF) / 255.0f; + vert[SPB] = ((specular[i] >> 0) & 0xFF) / 255.0f; + + vert[ER] = ((emissive[i] >> 16) & 0xFF) / 255.0f; + vert[EG] = ((emissive[i] >> 8) & 0xFF) / 255.0f; + vert[EB] = ((emissive[i] >> 0) & 0xFF) / 255.0f; + + vert[SHINE] = shininess[i]; + */ + + } + + return data; + } + // ----------------------------------------------------------------- // // Edges @@ -7874,7 +7925,7 @@ public class PGraphicsOpenGL extends PGraphics { indCount += 3 * detailU; return indices; - } + } } diff --git a/android/core/src/processing/opengl/PShapeOpenGL.java b/android/core/src/processing/opengl/PShapeOpenGL.java index 511b9c191..2a67fb237 100644 --- a/android/core/src/processing/opengl/PShapeOpenGL.java +++ b/android/core/src/processing/opengl/PShapeOpenGL.java @@ -3744,31 +3744,35 @@ public class PShapeOpenGL extends PShape { // Applies the styles of g. protected void styles(PGraphics g) { - if (stroke) { - stroke(g.strokeColor); - strokeWeight(g.strokeWeight); - - // These two don't to nothing probably: - strokeCap(g.strokeCap); - strokeJoin(g.strokeJoin); - } else { - noStroke(); - } + if (g instanceof PGraphicsOpenGL) { + if (stroke) { + stroke(g.strokeColor); + strokeWeight(g.strokeWeight); + + // These two don't to nothing probably: + strokeCap(g.strokeCap); + strokeJoin(g.strokeJoin); + } else { + noStroke(); + } - if (fill) { - fill(g.fillColor); + if (fill) { + fill(g.fillColor); + } else { + noFill(); + } + + ambient(g.ambientColor); + specular(g.specularColor); + emissive(g.emissiveColor); + shininess(g.shininess); + + // What about other style parameters, such as rectMode, etc? + // These should force a tessellation update, same as stroke + // cap and weight... right? } else { - noFill(); - } - - ambient(g.ambientColor); - specular(g.specularColor); - emissive(g.emissiveColor); - shininess(g.shininess); - - // What about other style parameters, such as rectMode, etc? - // These should force a tessellation update, same as stroke - // cap and weight... right? + super.styles(g); + } } @@ -3785,31 +3789,39 @@ public class PShapeOpenGL extends PShape { public void draw(PGraphics g) { - if (visible) { - pre(g); - - updateTessellation(); - updateGeometry(); - - if (family == GROUP) { - if (fragmentedGroup(g)) { - for (int i = 0; i < childCount; i++) { - ((PShapeOpenGL) children[i]).draw(g); - } - } else { - PImage tex = null; - if (textures != null && textures.size() == 1) { - tex = (PImage)textures.toArray()[0]; + if (g instanceof PGraphicsOpenGL) { + if (visible) { + pre(g); + + updateTessellation(); + updateGeometry(); + + if (family == GROUP) { + if (fragmentedGroup(g)) { + for (int i = 0; i < childCount; i++) { + ((PShapeOpenGL) children[i]).draw(g); + } + } else { + PImage tex = null; + if (textures != null && textures.size() == 1) { + tex = (PImage)textures.toArray()[0]; + } + render((PGraphicsOpenGL)g, tex); } - render((PGraphicsOpenGL)g, tex); + + } else { + render((PGraphicsOpenGL)g, texture); } - - } else { - render((PGraphicsOpenGL)g, texture); - } - - post(g); - } + + post(g); + } + } else { + // The renderer is not PGraphicsOpenGL, which probably + // means that the draw() method is being called by the + // recorder. We just use the default drawing from the + // parent class. + super.draw(g); + } } @@ -3826,16 +3838,35 @@ public class PShapeOpenGL extends PShape { protected void pre(PGraphics g) { - if (!style) { - styles(g); + if (g instanceof PGraphicsOpenGL) { + if (!style) { + styles(g); + } + } else { + super.pre(g); } } public void post(PGraphics g) { + if (g instanceof PGraphicsOpenGL) { + } else { + super.post(g); + } } + protected void drawGeometry(PGraphics g) { + vertexCount = inGeo.vertexCount; + vertices = inGeo.getVertexData(); + + super.drawGeometry(g); + + vertexCount = 0; + vertices = null; + } + + // Render the geometry stored in the root shape as VBOs, for the vertices // corresponding to this shape. Sometimes we can have root == this. protected void render(PGraphicsOpenGL g, PImage texture) { diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 534f119fd..3196fc62d 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -40,20 +40,18 @@ import java.util.NoSuchElementException; */ public class Texture implements PConstants { // texture constants - /** - * This constant identifies the texture target GL_TEXTURE_2D, that is, - * textures with normalized coordinates - */ - public static final int TEXTURE2D = 0; - /** Texture quality constants */ - public static final int LOW = 0; - public static final int MEDIUM = 1; - public static final int HIGH = 2; - public static final int BEST = 3; + /** + * Texture with normalized UV. + */ + public static final int TEX2D = 0; + /** + * Texture with un-normalized UV. + */ + public static final int TEXRECT = 1; /** Point sampling: both magnification and minification filtering are set to nearest */ - //public static final int POINT = 2; // shared with shape feature + public static final int POINT = 2; /** Linear sampling: magnification filtering is nearest, minification set to linear */ public static final int LINEAR = 3; /** Bilinear sampling: both magnification filtering is set to linear and minification @@ -1026,7 +1024,7 @@ public class Texture implements PConstants { Parameters res = new Parameters(); if (glTarget == PGL.GL_TEXTURE_2D) { - res.target = TEXTURE2D; + res.target = TEX2D; } if (glFormat == PGL.GL_RGB) { @@ -1079,7 +1077,7 @@ public class Texture implements PConstants { * @param params GLTextureParameters */ protected void setParameters(Parameters params) { - if (params.target == TEXTURE2D) { + if (params.target == TEX2D) { glTarget = PGL.GL_TEXTURE_2D; } else { throw new RuntimeException("Unknown texture target"); @@ -1094,7 +1092,7 @@ public class Texture implements PConstants { } else { throw new RuntimeException("Unknown texture format"); } - + if (params.sampling == POINT) { glMagFilter = PGL.GL_NEAREST; glMinFilter = PGL.GL_NEAREST; @@ -1179,7 +1177,7 @@ public class Texture implements PConstants { * Sets all the parameters to default values. */ public Parameters() { - this.target = TEXTURE2D; + this.target = TEX2D; this.format = ARGB; this.sampling = BILINEAR; this.mipmaps = true; @@ -1188,7 +1186,7 @@ public class Texture implements PConstants { } public Parameters(int format) { - this.target = TEXTURE2D; + this.target = TEX2D; this.format = format; this.sampling = BILINEAR; this.mipmaps = true; @@ -1197,7 +1195,7 @@ public class Texture implements PConstants { } public Parameters(int format, int sampling) { - this.target = TEXTURE2D; + this.target = TEX2D; this.format = format; this.sampling = sampling; this.mipmaps = true; @@ -1206,7 +1204,7 @@ public class Texture implements PConstants { } public Parameters(int format, int sampling, boolean mipmaps) { - this.target = TEXTURE2D; + this.target = TEX2D; this.format = format; this.sampling = sampling; this.mipmaps = mipmaps; diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 1e682bcf2..61c965fb3 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -4030,15 +4030,16 @@ public class PGraphicsOpenGL extends PGraphics { // Flushing geometry with a different perspective configuration. flush(); + float n2 = 2 * znear; float w = right - left; float h = top - bottom; float d = zfar - znear; - float n2 = 2 * znear; - projection.set(n2/w, 0, (right + left) / w, 0, - 0, -n2 / h, (top + bottom) / h, 0, - 0, 0, -(zfar + znear) / d, -(n2 * zfar) / d, - 0, 0, -1, 0); - + + projection.set(n2 / w, 0, (right + left) / w, 0, + 0, -n2 / h, (top + bottom) / h, 0, + 0, 0, -(zfar + znear) / d, -(n2 * zfar) / d, + 0, 0, -1, 0); + calcProjmodelview(); } @@ -7112,6 +7113,8 @@ public class PGraphicsOpenGL extends PGraphics { vert[SW] = strokeWeights[i]; + /* + // Android doesn't have these: vert[AR] = ((ambient[i] >> 16) & 0xFF) / 255.0f; vert[AG] = ((ambient[i] >> 8) & 0xFF) / 255.0f; vert[AB] = ((ambient[i] >> 0) & 0xFF) / 255.0f; @@ -7124,7 +7127,9 @@ public class PGraphicsOpenGL extends PGraphics { vert[EG] = ((emissive[i] >> 8) & 0xFF) / 255.0f; vert[EB] = ((emissive[i] >> 0) & 0xFF) / 255.0f; - vert[SHINE] = shininess[i]; + vert[SHINE] = shininess[i]; + */ + } return data; diff --git a/java/libraries/opengl/src/processing/opengl/PShader.java b/java/libraries/opengl/src/processing/opengl/PShader.java index 08c1871f1..ca8f682f4 100644 --- a/java/libraries/opengl/src/processing/opengl/PShader.java +++ b/java/libraries/opengl/src/processing/opengl/PShader.java @@ -24,6 +24,7 @@ package processing.opengl; import processing.core.*; + import java.io.IOException; import java.net.URL;