From 760e1578b9625259a2cb9282ec9b039623bebc0e Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 24 Nov 2010 00:19:07 +0000 Subject: [PATCH] Small fix in shape recording with multitexturing, texture coordinate array is resized as needed, some TODO notes. --- .../core/src/processing/core/PGraphics.java | 7 +++- .../processing/core/PGraphicsAndroid3D.java | 37 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 1301f8c03..b0814b92f 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -990,8 +990,7 @@ public class PGraphics extends PImage implements PConstants { vertex[EDGE] = edge ? 1 : 0; - //boolean textured = textureImages.hasImages(); - boolean textured = false; + boolean textured = textureImage != null; if (fill || textured) { if (textured) { vertex[R] = fillR; @@ -1041,6 +1040,8 @@ public class PGraphics extends PImage implements PConstants { vertex[U] = textureU; vertex[V] = textureV; + // TODO: properly define auto-normalization methods to enable/disable this: + /* float norm2 = normalX * normalX + normalY * normalY + normalZ * normalZ; if (norm2 < EPSILON) { vertex[HAS_NORMAL] = 0; @@ -1054,6 +1055,8 @@ public class PGraphics extends PImage implements PConstants { } vertex[HAS_NORMAL] = 1; } + */ + vertex[HAS_NORMAL] = 1; vertex[NX] = normalX; vertex[NY] = normalY; diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index b3bf6f6fe..27eaa5ff9 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -504,7 +504,7 @@ public class PGraphicsAndroid3D extends PGraphics { vertexArray = new int[DEFAULT_BUFFER_SIZE * 3]; colorArray = new int[DEFAULT_BUFFER_SIZE * 4]; normalArray = new int[DEFAULT_BUFFER_SIZE * 3]; - texCoordArray = new int[MAX_TEXTURES][DEFAULT_BUFFER_SIZE * 2]; + texCoordArray = new int[1][DEFAULT_BUFFER_SIZE * 2]; getsetBuffer = IntBuffer.allocate(1); getsetBuffer.rewind(); @@ -1395,6 +1395,32 @@ public class PGraphicsAndroid3D extends PGraphics { public void vertex(float x, float y) { super.vertex(x, y); + + /* + // TODO: Use multitexture information. + float[] vertex = vertices[vertexCount - 1]; + boolean textured = textureImage != null; + if (fill || textured) { + if (textured) { + vertex[R] = fillR; + vertex[G] = fillG; + vertex[B] = fillB; + vertex[A] = fillA; + } else { + if (tint) { + vertex[R] = tintR; + vertex[G] = tintG; + vertex[B] = tintB; + vertex[A] = tintA; + } else { + vertex[R] = 1; + vertex[G] = 1; + vertex[B] = 1; + vertex[A] = 1; + } + } + */ + setVertexTex(vertexCount - 1); } @@ -1502,8 +1528,10 @@ public class PGraphicsAndroid3D extends PGraphics { tbb.order(ByteOrder.nativeOrder()); texCoordBuffer[n0 + i] = tbb.asIntBuffer(); } - numTexBuffers += more; + texCoordArray = new int[numTexBuffers + more][size]; + + numTexBuffers += more; } // public void breakShape() @@ -1798,14 +1826,11 @@ public class PGraphicsAndroid3D extends PGraphics { shape.setNormal(recordedNormals); shape.endUpdate(); - int tu0 = textureUnit; for (int t = 0; t < numRecordedTextures; t++) { - textureUnit = t; - shape.beginUpdate(TEXTURES); + shape.beginUpdate(TEXTURES0 + textureUnit); shape.setTexCoord(recordedTexCoords[t]); shape.endUpdate(); } - textureUnit = tu0; shape.setGroups(recordedGroups); shape.optimizeGroups();