diff --git a/android/core/src/processing/core/PGL.java b/android/core/src/processing/core/PGL.java index f2bc047ad..bdd6033ca 100644 --- a/android/core/src/processing/core/PGL.java +++ b/android/core/src/processing/core/PGL.java @@ -80,6 +80,14 @@ public class PGL { public static final int DEFAULT_TESS_VERTICES = 16; public static final int DEFAULT_TESS_INDICES = 32; + /** In and tess increments used in retained mode, where + * arrays are not doubled in size but increased linearly. + * */ + public static final int IN_VERTICES_INCREMENT = 8; + public static final int IN_EDGES_INCREMENT = 16; + public static final int TESS_VERTICES_INCREMENT = 8; + public static final int TESS_INDICES_INCREMENT = 16; + /** Initial sizes for vertex cache used in PShape3D. */ public static final int DEFAULT_VERTEX_CACHE_SIZE = 512; diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index 554787fcc..31204b7dd 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -394,7 +394,7 @@ public class PGraphicsAndroid3D extends PGraphics { tessellator = new Tessellator(); - inGeo = newInGeometry(); + inGeo = newInGeometry(IMMEDIATE); tessGeo = newTessGeometry(IMMEDIATE); texCache = newTexCache(); @@ -6085,8 +6085,8 @@ public class PGraphicsAndroid3D extends PGraphics { } } - public InGeometry newInGeometry() { - return new InGeometry(); + public InGeometry newInGeometry(int mode) { + return new InGeometry(mode); } protected TessGeometry newTessGeometry(int mode) { @@ -6175,6 +6175,7 @@ public class PGraphicsAndroid3D extends PGraphics { } public class InGeometry { + int renderMode; public int vertexCount; public int edgeCount; @@ -6203,7 +6204,8 @@ public class PGraphicsAndroid3D extends PGraphics { //public float[][] mtexcoords; //public float[][] attributes; - public InGeometry() { + public InGeometry(int mode) { + renderMode = mode; allocate(); } @@ -6349,7 +6351,22 @@ public class PGraphicsAndroid3D extends PGraphics { public void vertexCheck() { if (vertexCount == vertices.length / 3) { - int newSize = vertexCount << 1; + int newSize = vertexCount; + + // Increase of vertex arrays is different between + // immediate and retained modes: + // * in immediate mode, since we need to very quickly + // have larger arrays in order to accomodate the + // incoming geometry, doubling of size is used. + // * in retained mode, since the arrays are used + // to create arrays for individual shapes that + // don't change afterwards, we only need linear + // increase. + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.IN_VERTICES_INCREMENT; + } expandCodes(newSize); expandVertices(newSize); @@ -6432,7 +6449,15 @@ public class PGraphicsAndroid3D extends PGraphics { public void edgeCheck() { if (edgeCount == edges.length) { - int temp[][] = new int[edgeCount << 1][3]; + int newLen = edgeCount; + + if (renderMode == IMMEDIATE) { + newLen <<= 1; + } else { + newLen += PGL.IN_EDGES_INCREMENT; + } + + int temp[][] = new int[newLen][3]; PApplet.arrayCopy(edges, 0, temp, 0, edgeCount); edges = temp; } @@ -7080,8 +7105,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addFillVertices(int count) { int oldSize = fillVertices.length / 3; - if (fillVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, fillVertexCount + count); + if (fillVertexCount + count > oldSize) { + int newSize = expandVertSize(oldSize, fillVertexCount + count); expandFillVertices(newSize); expandFillColors(newSize); @@ -7096,8 +7121,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addFillIndices(int count) { int oldSize = fillIndices.length; - if (fillIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, fillIndexCount + count); + if (fillIndexCount + count > oldSize) { + int newSize = expandIndSize(oldSize, fillIndexCount + count); expandFillIndices(newSize); } @@ -7133,8 +7158,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addLineVertices(int count) { int oldSize = lineVertices.length / 3; - if (lineVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, lineVertexCount + count); + if (lineVertexCount + count > oldSize) { + int newSize = expandVertSize(oldSize, lineVertexCount + count); expandLineVertices(newSize); expandLineColors(newSize); @@ -7173,8 +7198,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addLineIndices(int count) { int oldSize = lineIndices.length; - if (lineIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, lineIndexCount + count); + if (lineIndexCount + count > oldSize) { + int newSize = expandIndSize(oldSize, lineIndexCount + count); expandLineIndices(newSize); } @@ -7192,8 +7217,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addPointVertices(int count) { int oldSize = pointVertices.length / 3; - if (pointVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, pointVertexCount + count); + if (pointVertexCount + count > oldSize) { + int newSize = expandVertSize(oldSize, pointVertexCount + count); expandPointVertices(newSize); expandPointColors(newSize); @@ -7232,8 +7257,8 @@ public class PGraphicsAndroid3D extends PGraphics { public void addPointIndices(int count) { int oldSize = pointIndices.length; - if (pointIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, pointIndexCount + count); + if (pointIndexCount + count > oldSize) { + int newSize = expandIndSize(oldSize, pointIndexCount + count); expandPointIndices(newSize); } @@ -7513,13 +7538,29 @@ public class PGraphicsAndroid3D extends PGraphics { pointColors[index ] = a; } - public int expandSize(int currSize, int newMinSize) { + public int expandVertSize(int currSize, int newMinSize) { int newSize = currSize; while (newSize < newMinSize) { - newSize = newSize << 1; + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.TESS_VERTICES_INCREMENT; + } } return newSize; } + + public int expandIndSize(int currSize, int newMinSize) { + int newSize = currSize; + while (newSize < newMinSize) { + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.TESS_INDICES_INCREMENT; + } + } + return newSize; + } public void center(float cx, float cy) { int index; @@ -7535,7 +7576,7 @@ public class PGraphicsAndroid3D extends PGraphics { for (int i = 0; i < lineVertexCount; i++) { index = 3 * i; cx0 += lineVertices[index++]; - cy0 += lineVertices[index ]; + cy0 += lineVertices[index ]; } for (int i = 0; i < pointVertexCount; i++) { index = 3 * i; diff --git a/android/core/src/processing/core/PShape3D.java b/android/core/src/processing/core/PShape3D.java index 9db0cdd55..0909dee1d 100644 --- a/android/core/src/processing/core/PShape3D.java +++ b/android/core/src/processing/core/PShape3D.java @@ -256,13 +256,13 @@ public class PShape3D extends PShape { this.parent = null; this.tessellated = false; + if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { + in = renderer.newInGeometry(RETAINED); + } tess = renderer.newTessGeometry(RETAINED); fillIndexData = new ArrayList(); lineIndexData = new ArrayList(); pointIndexData = new ArrayList(); - if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { - in = renderer.newInGeometry(); - } // Modes are retrieved from the current values in the renderer. textureMode = renderer.textureMode; diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index c029f6ed9..f30264619 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -98,6 +98,14 @@ public class PGL { public static final int DEFAULT_TESS_VERTICES = 64; public static final int DEFAULT_TESS_INDICES = 128; + /** In and tess increments used in retained mode, where + * arrays are not doubled in size but increased linearly. + * */ + public static final int IN_VERTICES_INCREMENT = 32; + public static final int IN_EDGES_INCREMENT = 64; + public static final int TESS_VERTICES_INCREMENT = 32; + public static final int TESS_INDICES_INCREMENT = 64; + /** Initial sizes for vertex cache used in PShape3D. */ public static final int DEFAULT_VERTEX_CACHE_SIZE = 128; diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 3f7f4afa0..4b0fd54e5 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -401,7 +401,7 @@ public class PGraphicsOpenGL extends PGraphics { tessellator = new Tessellator(); - inGeo = newInGeometry(); + inGeo = newInGeometry(IMMEDIATE); tessGeo = newTessGeometry(IMMEDIATE); texCache = newTexCache(); @@ -6092,8 +6092,8 @@ public class PGraphicsOpenGL extends PGraphics { } } - public InGeometry newInGeometry() { - return new InGeometry(); + public InGeometry newInGeometry(int mode) { + return new InGeometry(mode); } protected TessGeometry newTessGeometry(int mode) { @@ -6182,6 +6182,7 @@ public class PGraphicsOpenGL extends PGraphics { } public class InGeometry { + int renderMode; public int vertexCount; public int edgeCount; @@ -6210,9 +6211,10 @@ public class PGraphicsOpenGL extends PGraphics { //public float[][] mtexcoords; //public float[][] attributes; - public InGeometry() { + public InGeometry(int mode) { + renderMode = mode; allocate(); - } + } public void reset() { vertexCount = firstVertex = lastVertex = 0; @@ -6356,7 +6358,22 @@ public class PGraphicsOpenGL extends PGraphics { public void vertexCheck() { if (vertexCount == vertices.length / 3) { - int newSize = vertexCount << 1; + int newSize = vertexCount; + + // Increase of vertex arrays is different between + // immediate and retained modes: + // * in immediate mode, since we need to very quickly + // have larger arrays in order to accomodate the + // incoming geometry, doubling of size is used. + // * in retained mode, since the arrays are used + // to create arrays for individual shapes that + // don't change afterwards, we only need linear + // increase. + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.IN_VERTICES_INCREMENT; + } expandCodes(newSize); expandVertices(newSize); @@ -6439,7 +6456,15 @@ public class PGraphicsOpenGL extends PGraphics { public void edgeCheck() { if (edgeCount == edges.length) { - int temp[][] = new int[edgeCount << 1][3]; + int newLen = edgeCount; + + if (renderMode == IMMEDIATE) { + newLen <<= 1; + } else { + newLen += PGL.IN_EDGES_INCREMENT; + } + + int temp[][] = new int[newLen][3]; PApplet.arrayCopy(edges, 0, temp, 0, edgeCount); edges = temp; } @@ -6474,7 +6499,7 @@ public class PGraphicsOpenGL extends PGraphics { PApplet.arrayCopy(texcoords, 0, temp, 0, 2 * vertexCount); texcoords = temp; } - + protected void expandStrokes(int n) { float temp[] = new float[5 * n]; PApplet.arrayCopy(strokes, 0, temp, 0, 5 * vertexCount); @@ -7088,7 +7113,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addFillVertices(int count) { int oldSize = fillVertices.length / 3; if (fillVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, fillVertexCount + count); + int newSize = expandVertSize(oldSize, fillVertexCount + count); expandFillVertices(newSize); expandFillColors(newSize); @@ -7104,7 +7129,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addFillIndices(int count) { int oldSize = fillIndices.length; if (fillIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, fillIndexCount + count); + int newSize = expandIndSize(oldSize, fillIndexCount + count); expandFillIndices(newSize); } @@ -7141,7 +7166,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addLineVertices(int count) { int oldSize = lineVertices.length / 3; if (lineVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, lineVertexCount + count); + int newSize = expandVertSize(oldSize, lineVertexCount + count); expandLineVertices(newSize); expandLineColors(newSize); @@ -7181,7 +7206,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addLineIndices(int count) { int oldSize = lineIndices.length; if (lineIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, lineIndexCount + count); + int newSize = expandIndSize(oldSize, lineIndexCount + count); expandLineIndices(newSize); } @@ -7200,7 +7225,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addPointVertices(int count) { int oldSize = pointVertices.length / 3; if (pointVertexCount + count >= oldSize) { - int newSize = expandSize(oldSize, pointVertexCount + count); + int newSize = expandVertSize(oldSize, pointVertexCount + count); expandPointVertices(newSize); expandPointColors(newSize); @@ -7240,7 +7265,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addPointIndices(int count) { int oldSize = pointIndices.length; if (pointIndexCount + count >= oldSize) { - int newSize = expandSize(oldSize, pointIndexCount + count); + int newSize = expandIndSize(oldSize, pointIndexCount + count); expandPointIndices(newSize); } @@ -7520,13 +7545,29 @@ public class PGraphicsOpenGL extends PGraphics { pointColors[index ] = a; } - public int expandSize(int currSize, int newMinSize) { + public int expandVertSize(int currSize, int newMinSize) { int newSize = currSize; while (newSize < newMinSize) { - newSize = newSize << 1; + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.TESS_VERTICES_INCREMENT; + } } return newSize; } + + public int expandIndSize(int currSize, int newMinSize) { + int newSize = currSize; + while (newSize < newMinSize) { + if (renderMode == IMMEDIATE) { + newSize <<= 1; + } else { + newSize += PGL.TESS_INDICES_INCREMENT; + } + } + return newSize; + } public void center(float cx, float cy) { int index; diff --git a/java/libraries/opengl/src/processing/opengl/PShape3D.java b/java/libraries/opengl/src/processing/opengl/PShape3D.java index 99beb0e3a..e8c7fe7e6 100644 --- a/java/libraries/opengl/src/processing/opengl/PShape3D.java +++ b/java/libraries/opengl/src/processing/opengl/PShape3D.java @@ -280,13 +280,13 @@ public class PShape3D extends PShape { this.parent = null; this.tessellated = false; + if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { + in = renderer.newInGeometry(RETAINED); + } tess = renderer.newTessGeometry(RETAINED); fillIndexData = new ArrayList(); lineIndexData = new ArrayList(); pointIndexData = new ArrayList(); - if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { - in = renderer.newInGeometry(); - } // Modes are retrieved from the current values in the renderer. textureMode = renderer.textureMode;