From 2b758dbba4a74dce08f0b3538b00d8d3e417c0f4 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 26 May 2012 20:46:14 +0000 Subject: [PATCH] removed TessMap --- .../processing/opengl/PGraphicsOpenGL.java | 426 +--------------- .../src/processing/opengl/PShapeOpenGL.java | 454 +----------------- 2 files changed, 38 insertions(+), 842 deletions(-) diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index a3aa96de4..4ace3db88 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -6395,164 +6395,7 @@ public class PGraphicsOpenGL extends PGraphics { vertexOffset = temp; } } - - // This class allows to define a multi-valued mapping - // from input to tessellated vertices. - protected class TessMap { - /* - InGeometry in; - TessGeometry tess; - - int[][] pointIndices; - int firstPointIndex; - int[][] lineIndices0; - int[][] lineIndices1; - int firstLineIndex; - int[][] fillIndices; - float[][] fillWeights; - int firstFillIndex; - - TessMap() { - in = null; - tess = null; - pointIndices = null; - lineIndices0 = null; - lineIndices1 = null; - fillIndices = null; - fillWeights = null; - firstPointIndex = -1; - firstLineIndex = -1; - firstFillIndex = -1; - } - - void init(InGeometry in, TessGeometry tess) { - this.in = in; - this.tess = tess; - pointIndices = new int[in.vertexCount][0]; - lineIndices0 = new int[in.vertexCount][0]; - lineIndices1 = new int[in.vertexCount][0]; - fillIndices = new int[in.vertexCount][0]; - fillWeights = new float[in.vertexCount][0]; - } - - void dispose() { - in = null; - tess = null; - pointIndices = null; - lineIndices0 = null; - lineIndices1 = null; - fillIndices = null; - fillWeights = null; - } - - void compact() { - firstPointIndex = -1; - firstLineIndex = -1; - - // When the in and tess indices are in a 1-1 mapping, there - // is no need to define it using the indices and weights arrays. - // Only the first offset between the two is needed. - boolean contiguous = true; - for (int i = in.firstVertex; i <= in.lastVertex; i++) { - int[] indices = fillIndices[i]; - float[] weigths = fillWeights[i]; - if (indices.length == 1 && weigths[0] == 1) { - if (i < in.lastVertex) { - int[] indices1 = fillIndices[i + 1]; - if (indices[0] + 1 != indices1[0]) { - contiguous = false; - break; - } - } - } else { - contiguous = false; - break; - } - } - if (contiguous) { - firstFillIndex = 0 < fillIndices.length ? fillIndices[in.firstVertex][0] : 0; - fillIndices = null; - fillWeights = null; - } else { - firstFillIndex = -1; - } - } - - void addPointIndex(int inIdx, int tessIdx) { - int[] indices = pointIndices[inIdx]; - int pos; - if (indices.length == 0) { - indices = new int[1]; - pos = 0; - } else { - int len = indices.length; - indices = new int[len + 1]; - PApplet.arrayCopy(pointIndices[inIdx], indices, len); - pos = len; - } - indices[pos] = tessIdx; - pointIndices[inIdx] = indices; - } - - void addLineIndex0(int inIdx, int tessIdx) { - int[] indices = lineIndices0[inIdx]; - int pos; - if (indices.length == 0) { - indices = new int[1]; - pos = 0; - } else { - int len = indices.length; - indices = new int[len + 1]; - PApplet.arrayCopy(lineIndices0[inIdx], indices, len); - pos = len; - } - indices[pos] = tessIdx; - lineIndices0[inIdx] = indices; - } - - void addLineIndex1(int inIdx, int tessIdx) { - int[] indices = lineIndices1[inIdx]; - int pos; - if (indices.length == 0) { - indices = new int[1]; - pos = 0; - } else { - int len = indices.length; - indices = new int[len + 1]; - PApplet.arrayCopy(lineIndices1[inIdx], indices, len); - pos = len; - } - indices[pos] = tessIdx; - lineIndices1[inIdx] = indices; - } - - void addFillIndex(int inIdx, int tessIdx, float weight) { - int[] indices = fillIndices[inIdx]; - float[] weights = fillWeights[inIdx]; - int pos; - if (indices.length == 0) { - indices = new int[1]; - weights = new float[1]; - pos = 0; - } else { - int len = indices.length; - indices = new int[len + 1]; - weights = new float[len + 1]; - PApplet.arrayCopy(fillIndices[inIdx], indices, len); - PApplet.arrayCopy(fillWeights[inIdx], weights, len); - pos = len; - } - indices[pos] = tessIdx; - weights[pos] = weight; - fillIndices[inIdx] = indices; - fillWeights[inIdx] = weights; - } - - void addFillIndex(int inIdx, int tessIdx) { - addFillIndex(inIdx, tessIdx, 1); - } - */ - } + // Holds the input vertices: xyz coordinates, fill/tint color, // normal, texture coordinates and stroke color and weight. @@ -6599,8 +6442,6 @@ public class PGraphicsOpenGL extends PGraphics { int emissiveColor; float shininessFactor; float normalX, normalY, normalZ; - - TessMap tessMap; InGeometry(int mode) { renderMode = mode; @@ -6634,10 +6475,6 @@ public class PGraphicsOpenGL extends PGraphics { breaks = new boolean[PGL.DEFAULT_IN_VERTICES]; edges = new int[PGL.DEFAULT_IN_EDGES][3]; - if (renderMode == RETAINED) { -// tessMap = new TessMap(); - } - clear(); } @@ -6654,10 +6491,6 @@ public class PGraphicsOpenGL extends PGraphics { emissive = null; shininess = null; edges = null; - - if (renderMode == RETAINED) { -// tessMap.dispose(); - } } void vertexCheck() { @@ -6685,51 +6518,7 @@ public class PGraphicsOpenGL extends PGraphics { expandEdges(newLen); } } - - - // ----------------------------------------------------------------- - // - // Tess mapping - - void initTessMap(TessGeometry tess) { - if (renderMode == RETAINED) { -// tessMap.init(this, tess); - } - } - - void disposeTessMap() { -// tessMap.dispose(); - } - - void compactTessMap() { -// tessMap.compact(); - } - - /* - // The new API to implement later... - void addPointMapping(int firstIn, int lastIn, int firstTess, int pointSize) { - } - - void addLineMapping(int firstIn, int lastIn) { - } - - void setLineMapping(int firstIn, int lastIn, int firstTess) { - } - - void addLinearMapping(int firstIn, int lastIn, int firstTess) { -// for (int i = 0; i < nvert; i++) { -// [i0, i1] -> map = (i - i0) + firstFillVertex; -// } - } - - void addWeightedMapping(int firstIn, int lastIn) { - } - - void setWeightedMapping(int[] inIdxs, float[] inWeights, int tessIdx) { - //if vertices != null && weights != null - } - */ - + // ----------------------------------------------------------------- // // Query @@ -8675,10 +8464,6 @@ public class PGraphicsOpenGL extends PGraphics { } pointColors[tessIdx] = in.strokeColors[inIdx]; - - if (renderMode == RETAINED) { -// in.tessMap.addPointIndex(inIdx, tessIdx); - } } // ----------------------------------------------------------------- @@ -8727,34 +8512,25 @@ public class PGraphicsOpenGL extends PGraphics { lineColors[tessIdx] = rgba; lineAttribs[4 * tessIdx + 3] = weight; - - if (renderMode == RETAINED) { -// in.tessMap.addLineIndex0(inIdx0, tessIdx); -// in.tessMap.addLineIndex1(inIdx1, tessIdx); - } } // ----------------------------------------------------------------- // // Add poly geometry - void setPolyVertex(int tessIdx, float x, float y, float z, - int rgba, - InGeometry in, int[] vertices) { + void setPolyVertex(int tessIdx, float x, float y, float z, int rgba) { setPolyVertex(tessIdx, x, y, z, rgba, 0, 0, 1, 0, 0, - 0, 0, 0, 0, - in, vertices); + 0, 0, 0, 0); } void setPolyVertex(int tessIdx, float x, float y, float z, int rgba, float nx, float ny, float nz, float u, float v, - int am, int sp, int em, float shine, - InGeometry in, int[] vertices) { + int am, int sp, int em, float shine) { int index; if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL && !hints[DISABLE_TRANSFORM_CACHE]) { @@ -8793,27 +8569,14 @@ public class PGraphicsOpenGL extends PGraphics { polyAmbient[tessIdx] = am; polySpecular[tessIdx] = sp; polyEmissive[tessIdx] = em; - polyShininess[tessIdx] = shine; - -// NEW TESSMAP API -// if (renderMode == RETAINED) { -// ???? -// } - - if (renderMode == RETAINED && vertices != null) { - int len = vertices.length; - for (int i = 0; i < len; i++) { -// in.tessMap.addFillIndex(vertices[i], tessIdx); - } - } + polyShininess[tessIdx] = shine; } void addPolyVertex(float x, float y, float z, int rgba, float nx, float ny, float nz, float u, float v, - int am, int sp, int em, float shine, - InGeometry in, int[] vertices, float[] weights) { + int am, int sp, int em, float shine) { polyVertexCheck(); int index; int count = polyVertexCount - 1; @@ -8854,19 +8617,7 @@ public class PGraphicsOpenGL extends PGraphics { polyAmbient[count] = am; polySpecular[count] = sp; polyEmissive[count] = em; - polyShininess[count] = shine; - -// NEW TESSMAP API -// if (renderMode == RETAINED) { -// in.setWeightedMapping(vertices, weights, count); -// } - - if (renderMode == RETAINED && vertices != null && weights != null) { - int len = vertices.length; - for (int i = 0; i < len; i++) { -// in.tessMap.addFillIndex(vertices[i], count, weights[i]); - } - } + polyShininess[count] = shine; } void addPolyVertices(InGeometry in) { @@ -8979,19 +8730,7 @@ public class PGraphicsOpenGL extends PGraphics { PApplet.arrayCopy(in.specular, i0, polySpecular, firstPolyVertex, nvert); PApplet.arrayCopy(in.emissive, i0, polyEmissive, firstPolyVertex, nvert); PApplet.arrayCopy(in.shininess, i0, polyShininess, firstPolyVertex, nvert); - } - -// if (renderMode == RETAINED) { -// in.addLinearMapping(i0, i1, firstFillVertex); -// } - - if (renderMode == RETAINED) { - for (int i = 0; i < nvert; i++) { -// int inIdx = i0 + i; -// int tessIdx = firstPolyVertex + i; -// in.tessMap.addFillIndex(inIdx, tessIdx); - } - } + } } // ----------------------------------------------------------------- @@ -9365,12 +9104,7 @@ public class PGraphicsOpenGL extends PGraphics { cache.incCounts(index, 3 * (nPtVert - 1), nPtVert); } - lastPointIndexCache = index; - -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// in.addPointMapping(in.firstVertex, in.lastVertex, tess.firstPointVertex, nPtVert); -// } + lastPointIndexCache = index; } void tessellateRoundPoints2D(int nvertTot, int nindTot, int nPtVert) { @@ -9393,17 +9127,14 @@ public class PGraphicsOpenGL extends PGraphics { float x0 = in.vertices[3 * i + 0]; float y0 = in.vertices[3 * i + 1]; int rgba = in.strokeColors[i]; - if (in.renderMode == RETAINED) { -// in.tessMap.addFillIndex(i, -1); - } float val = 0; float inc = (float) SINCOS_LENGTH / perim; - tess.setPolyVertex(vertIdx, x0, y0, 0, rgba, in, null); + tess.setPolyVertex(vertIdx, x0, y0, 0, rgba); vertIdx++; for (int k = 0; k < perim; k++) { tess.setPolyVertex(vertIdx, x0 + 0.5f * cosLUT[(int) val] * strokeWeight, - y0 + 0.5f * sinLUT[(int) val] * strokeWeight, 0, rgba, in, null); + y0 + 0.5f * sinLUT[(int) val] * strokeWeight, 0, rgba); vertIdx++; val = (val + inc) % SINCOS_LENGTH; } @@ -9423,10 +9154,6 @@ public class PGraphicsOpenGL extends PGraphics { cache.incCounts(index, 3 * (nPtVert - 1), nPtVert); } lastPointIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ???? -// } } void tessellateSquarePoints() { @@ -9501,11 +9228,6 @@ public class PGraphicsOpenGL extends PGraphics { cache.incCounts(index, 12, 5); } lastPointIndexCache = index; - -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// in.addPointMapping(in.firstVertex, in.lastVertex, tess.firstPointVertex, 5); -// } } void tessellateSquarePoints2D(int nvertTot, int nindTot) { @@ -9528,15 +9250,12 @@ public class PGraphicsOpenGL extends PGraphics { float x0 = in.vertices[3 * i + 0]; float y0 = in.vertices[3 * i + 1]; int rgba = in.strokeColors[i]; - if (in.renderMode == RETAINED) { -// in.tessMap.addFillIndex(i, -1); - } - tess.setPolyVertex(vertIdx, x0, y0, 0, rgba, in, null); + tess.setPolyVertex(vertIdx, x0, y0, 0, rgba); vertIdx++; for (int k = 0; k < nvert - 1; k++) { tess.setPolyVertex(vertIdx, x0 + 0.5f * QUAD_POINT_SIGNS[k][0] * strokeWeight, - y0 + 0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight, 0, rgba, in, null); + y0 + 0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight, 0, rgba); vertIdx++; } @@ -9552,11 +9271,7 @@ public class PGraphicsOpenGL extends PGraphics { cache.incCounts(index, 12, 5); } - lastPointIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ????? -// } + lastPointIndexCache = lastPolyIndexCache = index; } // ----------------------------------------------------------------- @@ -9596,10 +9311,6 @@ public class PGraphicsOpenGL extends PGraphics { index = addLine3D(i0, i1, index, false); } lastLineIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// addLineMapping(in.firstVertex, in.lastVertex); -// } } void tessellateLines2D(int lineCount) { @@ -9618,10 +9329,6 @@ public class PGraphicsOpenGL extends PGraphics { index = addLine2D(i0, i1, index, false); } lastLineIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ???? -// } } else { // full stroking algorithm LinePath path = new LinePath(LinePath.WIND_NON_ZERO); for (int ln = 0; ln < lineCount; ln++) { @@ -9629,11 +9336,6 @@ public class PGraphicsOpenGL extends PGraphics { int i1 = first + 2 * ln + 1; path.moveTo(in.vertices[3 * i0 + 0], in.vertices[3 * i0 + 1]); path.lineTo(in.vertices[3 * i1 + 0], in.vertices[3 * i1 + 1]); - if (tess.renderMode == RETAINED) { - // The input vertices cannot the tessellated geometry -// in.tessMap.addFillIndex(i0, -1); -// in.tessMap.addFillIndex(i1, -1); - } } tessellateLinePath(path); } @@ -9668,10 +9370,6 @@ public class PGraphicsOpenGL extends PGraphics { i0 = i1; } lastLineIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// addLineMapping(in.firstVertex, in.lastVertex); -// } } void tessellateLineStrip2D(int lineCount) { @@ -9690,23 +9388,13 @@ public class PGraphicsOpenGL extends PGraphics { i0 = i1; } lastLineIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ????? -// } } else { // full stroking algorithm int first = in.firstVertex; LinePath path = new LinePath(LinePath.WIND_NON_ZERO); path.moveTo(in.vertices[3 * first + 0], in.vertices[3 * first + 1]); - if (tess.renderMode == RETAINED) { -// in.tessMap.addFillIndex(first, -1); - } for (int ln = 0; ln < lineCount; ln++) { int i1 = first + ln + 1; path.lineTo(in.vertices[3 * i1 + 0], in.vertices[3 * i1 + 1]); - if (tess.renderMode == RETAINED) { -// in.tessMap.addFillIndex(i1, -1); - } } tessellateLinePath(path); } @@ -9742,10 +9430,6 @@ public class PGraphicsOpenGL extends PGraphics { } index = addLine3D(in.lastVertex, in.firstVertex, index, false); lastLineIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// addLineMapping(in.firstVertex, in.lastVertex); -// } } void tessellateLineLoop2D(int lineCount) { @@ -9765,23 +9449,13 @@ public class PGraphicsOpenGL extends PGraphics { } index = addLine2D(in.lastVertex, in.firstVertex, index, false); lastLineIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ????? -// } } else { // full stroking algorithm int first = in.firstVertex; LinePath path = new LinePath(LinePath.WIND_NON_ZERO); path.moveTo(in.vertices[3 * first + 0], in.vertices[3 * first + 1]); - if (tess.renderMode == RETAINED) { -// in.tessMap.addFillIndex(first, -1); - } for (int ln = 0; ln < lineCount - 1; ln++) { int i1 = first + ln + 1; path.lineTo(in.vertices[3 * i1 + 0], in.vertices[3 * i1 + 1]); - if (tess.renderMode == RETAINED) { -// in.tessMap.addFillIndex(i1, -1); - } } path.closePath(); tessellateLinePath(path); @@ -9813,10 +9487,6 @@ public class PGraphicsOpenGL extends PGraphics { index = addLine3D(edge[0], edge[1], index, true); } lastLineIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// addLineMapping(in.firstVertex, in.lastVertex); -// } } void tessellateEdges2D() { @@ -9835,10 +9505,6 @@ public class PGraphicsOpenGL extends PGraphics { index = addLine2D(i0, i1, index, true); } lastLineIndexCache = lastPolyIndexCache = index; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ???? -// } } else { // full stroking algorithm LinePath path = new LinePath(LinePath.WIND_NON_ZERO); for (int i = in.firstEdge; i <= in.lastEdge; i++) { @@ -9863,10 +9529,6 @@ public class PGraphicsOpenGL extends PGraphics { path.closePath(); break; } - if (tess.renderMode == RETAINED) { -// in.tessMap.addFillIndex(i0, -1); -// in.tessMap.addFillIndex(i1, -1); - } } tessellateLinePath(path); } @@ -9912,11 +9574,6 @@ public class PGraphicsOpenGL extends PGraphics { tess.setLineVertex(vidx, in, i1, i0, color, +weight/2); tess.lineIndices[iidx++] = (short) (count + 3); -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// in.setLineMapping(i0, i1, vidx - 4); -// } - cache.incCounts(index, 6, 4); return index; } @@ -9939,7 +9596,6 @@ public class PGraphicsOpenGL extends PGraphics { color = constStroke ? strokeColor : in.strokeColors[i0]; weight = constStroke ? strokeWeight : in.strokeWeights[i0]; - int[] verts = {i0, i1}; float x0 = in.vertices[3 * i0 + 0]; float y0 = in.vertices[3 * i0 + 1]; @@ -9954,18 +9610,18 @@ public class PGraphicsOpenGL extends PGraphics { float normx = -diry / llen; float normy = +dirx / llen; - tess.setPolyVertex(vidx, x0 + normx * weight/2, y0 + normy * weight/2, 0, color, in, verts); + tess.setPolyVertex(vidx, x0 + normx * weight/2, y0 + normy * weight/2, 0, color); tess.polyIndices[iidx++] = (short) (count + 0); vidx++; - tess.setPolyVertex(vidx, x0 - normx * weight/2, y0 - normy * weight/2, 0, color, in, verts); + tess.setPolyVertex(vidx, x0 - normx * weight/2, y0 - normy * weight/2, 0, color); tess.polyIndices[iidx++] = (short) (count + 1); color = constStroke ? strokeColor : in.strokeColors[i1]; weight = constStroke ? strokeWeight : in.strokeWeights[i1]; vidx++; - tess.setPolyVertex(vidx, x1 - normx * weight/2, y1 - normy * weight/2, 0, color, in, verts); + tess.setPolyVertex(vidx, x1 - normx * weight/2, y1 - normy * weight/2, 0, color); tess.polyIndices[iidx++] = (short) (count + 2); // Starting a new triangle re-using prev vertices. @@ -9973,13 +9629,8 @@ public class PGraphicsOpenGL extends PGraphics { tess.polyIndices[iidx++] = (short) (count + 0); vidx++; - tess.setPolyVertex(vidx, x1 + normx * weight/2, y1 + normy * weight/2, 0, color, in, verts); - tess.polyIndices[iidx++] = (short) (count + 3); - -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// ???? -// } + tess.setPolyVertex(vidx, x1 + normx * weight/2, y1 + normy * weight/2, 0, color); + tess.polyIndices[iidx++] = (short) (count + 3); cache.incCounts(index, 6, 4); return index; @@ -10308,11 +9959,6 @@ public class PGraphicsOpenGL extends PGraphics { int nInVert = in.lastVertex - in.firstVertex + 1; -// NEW TESSMAP API -// if (tess.renderMode == RETAINED) { -// in.addWeightedMapping(in.firstVertex, in.lastVertex); -// } - if (fill && 3 <= nInVert) { firstPolyIndexCache = -1; @@ -10364,8 +10010,7 @@ public class PGraphicsOpenGL extends PGraphics { fa, fr, fg, fb, in.normals [3 * i + 0], in.normals [3 * i + 1], in.normals [3 * i + 2], in.texcoords[2 * i + 0], in.texcoords[2 * i + 1], - aa, ar, ag, ab, sa, sr, sg, sb, ea, er, eg, eb, in.shininess[i], - i, 1.0 }; + aa, ar, ag, ab, sa, sr, sg, sb, ea, er, eg, eb, in.shininess[i]}; gluTess.addVertex(vertex); } @@ -10432,8 +10077,7 @@ public class PGraphicsOpenGL extends PGraphics { sa, sr, sg, sb, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0.0 }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; gluTess.addVertex(vertex); @@ -10584,32 +10228,18 @@ public class PGraphicsOpenGL extends PGraphics { } if (vertCount < PGL.MAX_VERTEX_INDEX1) { - // Combining individual rgba components back into int color values int fcolor = ((int) d[ 3] << 24) | ((int) d[ 4] << 16) | ((int) d[ 5] << 8) | (int) d[ 6]; int acolor = ((int) d[12] << 24) | ((int) d[13] << 16) | ((int) d[14] << 8) | (int) d[15]; int scolor = ((int) d[16] << 24) | ((int) d[17] << 16) | ((int) d[18] << 8) | (int) d[19]; int ecolor = ((int) d[20] << 24) | ((int) d[21] << 16) | ((int) d[22] << 8) | (int) d[23]; - int[] vertices = null; - float[] weights = null; - int nvert = (l - 25) / 2; - if (0 < nvert) { - vertices = new int[nvert]; - weights = new float[nvert]; - for (int n = 0; n < nvert; n++) { - vertices[n] = (int) d[25 + 2 * n + 0]; - weights[n] = (float) d[25 + 2 * n + 1]; - } - } - tess.addPolyVertex((float) d[ 0], (float) d[ 1], (float) d[ 2], fcolor, (float) d[ 7], (float) d[ 8], (float) d[ 9], (float) d[10], (float) d[11], acolor, scolor, ecolor, - (float) d[24], - in, vertices, weights); + (float) d[24]); vertCount++; } else { @@ -10659,16 +10289,6 @@ public class PGraphicsOpenGL extends PGraphics { } } - // Adding the indices and weights of the 4 input vertices - // used to construct this combined vertex. - for (int j = 0; j < 4; j++) { - double[] vertData = (double[])data[j]; - if (vertData != null) { - vertex[25 + 2 * j + 0] = vertData[25]; - vertex[25 + 2 * j + 1] = weight[j]; - } - } - // Normalizing normal vector, since the weighted // combination of normal vectors is not necessarily // normal. diff --git a/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java b/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java index 1f6d22388..273d28b0c 100644 --- a/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java @@ -2017,94 +2017,6 @@ public class PShapeOpenGL extends PShape { public void setVertex(int index, float x, float y, float z) { root.tessellated = false; tessellated = false; - - /* - if (tessellated) { - int[] indices; - int[] indices1; - float[] vertices; - float[] attribs; - - if (havePoints) { - indices = inGeo.tessMap.pointIndices[index]; - vertices = tessGeo.pointVertices; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - vertices[4 * tessIdx + 0] = x; - vertices[4 * tessIdx + 1] = y; - vertices[4 * tessIdx + 2] = z; - root.setModifiedPointVertices(tessIdx, tessIdx); - } - } - - if (haveLines) { - indices = inGeo.tessMap.lineIndices0[index]; - indices1 = inGeo.tessMap.lineIndices1[index]; - vertices = tessGeo.lineVertices; - attribs = tessGeo.lineDirWidths; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - vertices[4 * tessIdx + 0] = x; - vertices[4 * tessIdx + 1] = y; - vertices[4 * tessIdx + 2] = z; - root.setModifiedLineVertices(tessIdx, tessIdx); - - int tessIdx1 = indices1[i]; - attribs[4 * tessIdx1 + 0] = x; - attribs[4 * tessIdx1 + 1] = y; - attribs[4 * tessIdx1 + 2] = z; - root.setModifiedLineAttributes(tessIdx1, tessIdx1); - } - } - - if (haveFill) { - vertices = tessGeo.polyVertices; - if (-1 < inGeo.tessMap.firstFillIndex) { - // 1-1 mapping, only need to offset the input index - int tessIdx = inGeo.tessMap.firstFillIndex + index; - vertices[4 * tessIdx + 0] = x; - vertices[4 * tessIdx + 1] = y; - vertices[4 * tessIdx + 2] = z; - root.setModifiedFillVertices(tessIdx, tessIdx); - } else { - // Multi-valued mapping. Going through all the tess - // vertices affected by inIdx. - float x0 = inGeo.vertices[4 * index + 0]; - float y0 = inGeo.vertices[4 * index + 1]; - float z0 = inGeo.vertices[4 * index + 2]; - indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - for (int i = 0; i < indices.length; i++) { - // tessIdx is a linear combination of input vertices, - // including inIdx: - // tessVert[tessIdx] = SUM(i from I, inVert[i]), inIdx in I - // For example: - // xt = w0 * x0 + w1 * x1 + w2 * x2 - // If x2 changes from x2 to x2', then the new value of xt is: - // xt' = w0 * x0 + w1 * x1 + w2 * x2' = - // = w0 * x0 + w1 * x1 + w2 * x2' + w2 * x2 - w2 * x2 - // = xt + w2 * (x2' - x2) - // This explains the calculations below: - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - float tx0 = vertices[4 * tessIdx + 0]; - float ty0 = vertices[4 * tessIdx + 1]; - float tz0 = vertices[4 * tessIdx + 2]; - vertices[4 * tessIdx + 0] = tx0 + weight * (x - x0); - vertices[4 * tessIdx + 1] = ty0 + weight * (y - y0); - vertices[4 * tessIdx + 2] = tz0 + weight * (z - z0); - root.setModifiedFillVertices(tessIdx, tessIdx); - } else { - root.forceTessellation = true; - break; - } - } - } - } - - } -*/ inGeo.vertices[3 * index + 0] = x; inGeo.vertices[3 * index + 1] = y; inGeo.vertices[3 * index + 2] = z; @@ -2140,51 +2052,6 @@ public class PShapeOpenGL extends PShape { public void setNormal(int index, float nx, float ny, float nz) { root.tessellated = false; tessellated = false; - - /* - if (haveFill) { - float[] normals = tessGeo.polyNormals; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - normals[3 * tessIdx + 0] = nx; - normals[3 * tessIdx + 1] = ny; - normals[3 * tessIdx + 2] = nz; - root.setModifiedFillNormals(tessIdx, tessIdx); - } else { - float nx0 = inGeo.normals[3 * index + 0]; - float ny0 = inGeo.normals[3 * index + 1]; - float nz0 = inGeo.normals[3 * index + 2]; - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - float tnx0 = normals[3 * tessIdx + 0]; - float tny0 = normals[3 * tessIdx + 1]; - float tnz0 = normals[3 * tessIdx + 2]; - float tnx = tnx0 + weight * (nx - nx0); - float tny = tny0 + weight * (ny - ny0); - float tnz = tnz0 + weight * (nz - nz0); - - // Making sure that the new normal vector is indeed - // normalized. - float sum = tnx * tnx + tny * tny + tnz * tnz; - float len = PApplet.sqrt(sum); - tnx /= len; - tny /= len; - tnz /= len; - - normals[3 * tessIdx + 0] = tnx; - normals[3 * tessIdx + 1] = tny; - normals[3 * tessIdx + 2] = tnz; - root.setModifiedFillNormals(tessIdx, tessIdx); - } - } - } - } - */ inGeo.normals[3 * index + 0] = nx; inGeo.normals[3 * index + 1] = ny; inGeo.normals[3 * index + 2] = nz; @@ -2204,37 +2071,6 @@ public class PShapeOpenGL extends PShape { public void setTextureUV(int index, float u, float v) { root.tessellated = false; tessellated = false; - - /* - if (haveFill) { - float[] texcoords = tessGeo.polyTexcoords; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - tessGeo.polyTexcoords[2 * tessIdx + 0] = u; - tessGeo.polyTexcoords[2 * tessIdx + 1] = v; - root.setModifiedFillTexcoords(tessIdx, tessIdx); - } else { - float u0 = inGeo.texcoords[2 * index + 0]; - float v0 = inGeo.texcoords[2 * index + 1]; - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - float tu0 = texcoords[2 * tessIdx + 0]; - float tv0 = texcoords[2 * tessIdx + 1]; - float tu = tu0 + weight * (u - u0); - float tv = tv0 + weight * (v - v0); - texcoords[2 * tessIdx + 0] = tu; - texcoords[2 * tessIdx + 1] = tv; - root.setModifiedFillTexcoords(tessIdx, tessIdx); - } - } - } - } - */ inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; } @@ -2248,30 +2084,7 @@ public class PShapeOpenGL extends PShape { public void setFill(int index, int fill) { root.tessellated = false; tessellated = false; - fill = PGL.javaToNativeARGB(fill); -/* - if (haveFill) { - int[] colors = tessGeo.polyColors; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - colors[tessIdx] = fill; - root.setModifiedFillColors(tessIdx, tessIdx); - } else { - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - int fill0 = inGeo.colors[index]; - setColorARGB(colors, fill, fill0, indices, weights); - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - root.setModifiedFillColors(tessIdx, indices[i]); - } - } - } - } - */ - inGeo.colors[index] = fill; + inGeo.colors[index] = PGL.javaToNativeARGB(fill); } @@ -2283,35 +2096,7 @@ public class PShapeOpenGL extends PShape { public void setStroke(int index, int stroke) { root.tessellated = false; tessellated = false; - stroke = PGL.javaToNativeARGB(stroke); - /* - if (havePoints) { - int[] indices = inGeo.tessMap.pointIndices[index]; - int[] colors = tessGeo.pointColors; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - colors[tessIdx] = stroke; - root.setModifiedPointColors(tessIdx, tessIdx); - } - } - - if (haveLines) { - int[] colors = tessGeo.lineColors; - int[] indices = inGeo.tessMap.lineIndices0[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - colors[tessIdx] = stroke; - root.setModifiedLineColors(tessIdx, tessIdx); - } - indices = inGeo.tessMap.lineIndices1[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - colors[tessIdx] = stroke; - root.setModifiedLineColors(tessIdx, tessIdx); - } - } - */ - inGeo.strokeColors[index] = stroke; + inGeo.strokeColors[index] = PGL.javaToNativeARGB(stroke); } @@ -2323,42 +2108,6 @@ public class PShapeOpenGL extends PShape { public void setStrokeWeight(int index, float weight) { root.tessellated = false; tessellated = false; - /* - if (havePoints || haveLines) { - int[] indices; - float[] attribs; - - float weight0 = inGeo.sweights[index]; - float resizeFactor = weight / weight0; - - if (havePoints) { - indices = inGeo.tessMap.pointIndices[index]; - attribs = tessGeo.pointSizes; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - attribs[2 * tessIdx + 0] *= resizeFactor; - attribs[2 * tessIdx + 1] *= resizeFactor; - root.setModifiedPointAttributes(tessIdx, tessIdx); - } - } - - if (haveLines) { - attribs = tessGeo.lineDirWidths; - indices = inGeo.tessMap.lineIndices0[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - attribs[4 * tessIdx + 3] *= resizeFactor; - root.setModifiedLineAttributes(tessIdx, tessIdx); - } - indices = inGeo.tessMap.lineIndices1[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - attribs[4 * tessIdx + 3] *= resizeFactor; - root.setModifiedLineAttributes(tessIdx, tessIdx); - } - } - } - */ inGeo.strokeWeights[index] = weight; } @@ -2371,30 +2120,7 @@ public class PShapeOpenGL extends PShape { public void setAmbient(int index, int ambient) { root.tessellated = false; tessellated = false; - ambient = PGL.javaToNativeARGB(ambient); - /* - if (haveFill) { - int[] colors = tessGeo.polyAmbient; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - colors[tessIdx] = ambient; - root.setModifiedFillAmbient(tessIdx, tessIdx); - } else { - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - int ambient0 = inGeo.ambient[index]; - setColorRGB(colors, ambient, ambient0, indices, weights); - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - root.setModifiedFillAmbient(tessIdx, indices[i]); - } - } - } - } - */ - inGeo.ambient[index] = ambient; + inGeo.ambient[index] = PGL.javaToNativeARGB(ambient); } public int getSpecular(int index) { @@ -2405,30 +2131,7 @@ public class PShapeOpenGL extends PShape { public void setSpecular(int index, int specular) { root.tessellated = false; tessellated = false; - specular = PGL.javaToNativeARGB(specular); - /* - if (haveFill) { - int[] colors = tessGeo.polySpecular; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - colors[tessIdx] = specular; - root.setModifiedFillSpecular(tessIdx, tessIdx); - } else { - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - int specular0 = inGeo.specular[index]; - setColorRGB(colors, specular, specular0, indices, weights); - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - root.setModifiedFillSpecular(tessIdx, indices[i]); - } - } - } - } - */ - inGeo.specular[index] = specular; + inGeo.specular[index] = PGL.javaToNativeARGB(specular); } @@ -2440,30 +2143,7 @@ public class PShapeOpenGL extends PShape { public void setEmissive(int index, int emissive) { root.tessellated = false; tessellated = false; - emissive = PGL.javaToNativeARGB(emissive); - /* - if (haveFill) { - int[] colors = tessGeo.polyEmissive; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - colors[tessIdx] = emissive; - root.setModifiedFillEmissive(tessIdx, tessIdx); - } else { - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - int emissive0 = inGeo.emissive[index]; - setColorRGB(colors, emissive, emissive0, indices, weights); - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - root.setModifiedFillEmissive(tessIdx, indices[i]); - } - } - } - } - */ - inGeo.emissive[index] = emissive; + inGeo.emissive[index] = PGL.javaToNativeARGB(emissive); } @@ -2475,94 +2155,9 @@ public class PShapeOpenGL extends PShape { public void setShininess(int index, float shine) { root.tessellated = false; tessellated = false; - /* - if (haveFill) { - float[] shininess = tessGeo.polyShininess; - - if (-1 < inGeo.tessMap.firstFillIndex) { - int tessIdx = inGeo.tessMap.firstFillIndex + index; - shininess[tessIdx] = shine; - root.setModifiedFillShininess(tessIdx, tessIdx); - } else { - float shine0 = inGeo.shininess[index]; - int[] indices = inGeo.tessMap.fillIndices[index]; - float[] weights = inGeo.tessMap.fillWeights[index]; - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - float tshine0 = shininess[tessIdx]; - float tshine = tshine0 + weight * (shine - shine0); - shininess[tessIdx] = tshine; - root.setModifiedFillShininess(tessIdx, tessIdx); - } - } - } - } - */ inGeo.shininess[index] = shine; } - /* - protected void setColorARGB(int[] colors, int fill, int fill0, int[] indices, float[] weights) { - float a = (fill >> 24) & 0xFF; - float r = (fill >> 16) & 0xFF; - float g = (fill >> 8) & 0xFF; - float b = (fill >> 0) & 0xFF; - - float a0 = (fill0 >> 24) & 0xFF; - float r0 = (fill0 >> 16) & 0xFF; - float g0 = (fill0 >> 8) & 0xFF; - float b0 = (fill0 >> 0) & 0xFF; - - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - int tfill0 = colors[tessIdx]; - float ta0 = (tfill0 >> 24) & 0xFF; - float tr0 = (tfill0 >> 16) & 0xFF; - float tg0 = (tfill0 >> 8) & 0xFF; - float tb0 = (tfill0 >> 0) & 0xFF; - - int ta = (int) (ta0 + weight * (a - a0)); - int tr = (int) (tr0 + weight * (r - r0)); - int tg = (int) (tg0 + weight * (g - g0)); - int tb = (int) (tb0 + weight * (b - b0)); - - colors[tessIdx] = (ta << 24) | (tr << 16) | (tg << 8) | tb; - } - } - } - - - protected void setColorRGB(int[] colors, int fill, int fill0, int[] indices, float[] weights) { - float r = (fill >> 16) & 0xFF; - float g = (fill >> 8) & 0xFF; - float b = (fill >> 0) & 0xFF; - - float r0 = (fill0 >> 16) & 0xFF; - float g0 = (fill0 >> 8) & 0xFF; - float b0 = (fill0 >> 0) & 0xFF; - - for (int i = 0; i < indices.length; i++) { - int tessIdx = indices[i]; - if (-1 < tessIdx) { - float weight = weights[i]; - int tfill0 = colors[tessIdx]; - float tr0 = (tfill0 >> 16) & 0xFF; - float tg0 = (tfill0 >> 8) & 0xFF; - float tb0 = (tfill0 >> 0) & 0xFF; - - int tr = (int) (tr0 + weight * (r - r0)); - int tg = (int) (tg0 + weight * (g - g0)); - int tb = (int) (tb0 + weight * (b - b0)); - - colors[tessIdx] = 0xff000000 | (tr << 16) | (tg << 8) | tb; - } - } - } - */ /////////////////////////////////////////////////////////// @@ -2681,7 +2276,7 @@ public class PShapeOpenGL extends PShape { tessGeo.trim(); modified = false; - needBufferInit = true; + needBufferInit = true; modifiedPolyVertices = false; modifiedPolyColors = false; @@ -2770,12 +2365,6 @@ public class PShapeOpenGL extends PShape { tessellator.set3D(is3D()); if (family == GEOMETRY) { - // The tessellation maps are used to associate input - // vertices with the corresponding tessellated vertices. - // This correspondence might not be one-to-one, in the - // case of lines and polygon shapes for example. - inGeo.initTessMap(tessGeo); - if (kind == POINTS) { tessellator.tessellatePoints(); } else if (kind == LINES) { @@ -2841,8 +2430,6 @@ public class PShapeOpenGL extends PShape { if (texture != null && parent != null) { ((PShapeOpenGL)parent).addTexture(texture); } - - inGeo.compactTessMap(); firstPolyIndexCache = tessellator.firstPolyIndexCache; lastPolyIndexCache = tessellator.lastPolyIndexCache; @@ -2876,8 +2463,7 @@ public class PShapeOpenGL extends PShape { inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addPoint(x, y, z, fill, stroke); - inGeo.initTessMap(tessGeo); + inGeo.addPoint(x, y, z, fill, stroke); tessellator.tessellatePoints(); } @@ -2904,8 +2490,7 @@ public class PShapeOpenGL extends PShape { inGeo.setNormal(normalX, normalY, normalZ); inGeo.addLine(x1, y1, z1, x2, y2, z2, - fill, stroke); - inGeo.initTessMap(tessGeo); + fill, stroke); tessellator.tessellateLines(); } @@ -2929,8 +2514,7 @@ public class PShapeOpenGL extends PShape { inGeo.addTriangle(x1, y1, 0, x2, y2, 0, x3, y3, 0, - fill, stroke); - inGeo.initTessMap(tessGeo); + fill, stroke); tessellator.tessellateTriangles(); } @@ -2958,8 +2542,7 @@ public class PShapeOpenGL extends PShape { x2, y2, 0, x3, y3, 0, x4, y4, 0, - fill, stroke); - inGeo.initTessMap(tessGeo); + fill, stroke); tessellator.tessellateQuads(); } @@ -3000,13 +2583,11 @@ public class PShapeOpenGL extends PShape { if (rounded) { inGeo.addRect(a, b, c, d, tl, tr, br, bl, - fill, stroke, bezierDetail, rectMode); - inGeo.initTessMap(tessGeo); + fill, stroke, bezierDetail, rectMode); tessellator.tessellatePolygon(false, true, true); } else { inGeo.addRect(a, b, c, d, - fill, stroke, rectMode); - inGeo.initTessMap(tessGeo); + fill, stroke, rectMode); tessellator.tessellateQuads(); } } @@ -3026,7 +2607,6 @@ public class PShapeOpenGL extends PShape { ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode); - inGeo.initTessMap(tessGeo); tessellator.tessellateTriangleFan(); } @@ -3048,7 +2628,6 @@ public class PShapeOpenGL extends PShape { ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); inGeo.addArc(a, b, c, d, start, stop, fill, stroke, ellipseMode); - inGeo.initTessMap(tessGeo); tessellator.tessellateTriangleFan(); } @@ -3065,8 +2644,7 @@ public class PShapeOpenGL extends PShape { inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); - inGeo.addBox(w, h, d, fill, stroke); - inGeo.initTessMap(tessGeo); + inGeo.addBox(w, h, d, fill, stroke); tessellator.tessellateQuads(); } @@ -3082,8 +2660,7 @@ public class PShapeOpenGL extends PShape { inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); - int[] indices = inGeo.addSphere(r, nu, nv, fill, stroke); - inGeo.initTessMap(tessGeo); + int[] indices = inGeo.addSphere(r, nu, nv, fill, stroke); tessellator.tessellateTriangles(indices); } @@ -3187,8 +2764,7 @@ public class PShapeOpenGL extends PShape { } } - if (stroke) inGeo.addPolygonEdges(isClosed); - inGeo.initTessMap(tessGeo); + if (stroke) inGeo.addPolygonEdges(isClosed); tessellator.tessellatePolygon(false, isClosed, true); }