001: /*
002: * $RCSfile: IndexedGeometryStripArrayRetained.java,v $
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.8 $
028: * $Date: 2008/02/28 20:17:24 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035:
036: /**
037: * The IndexedGeometryStripArray object is an abstract class that is extended for
038: * a set of IndexedGeometryArray strip primitives. These include LINE_STRIP,
039: * TRIANGLE_STRIP, and TRIANGLE_FAN.
040: */
041:
042: abstract class IndexedGeometryStripArrayRetained extends
043: IndexedGeometryArrayRetained {
044:
045: // Array of per-strip vertex counts
046: int stripIndexCounts[];
047:
048: // Following variables are only used in compile mode
049: int[] compileStripICOffset;
050: int[] compileIndexLength;
051:
052: /**
053: * Set stripIndexCount data into local array
054: */
055: void setStripIndexCounts(int stripIndexCounts[]) {
056: int i, num = stripIndexCounts.length, total = 0;
057:
058: for (i = 0; i < num; i++) {
059: total += stripIndexCounts[i];
060: if (this instanceof IndexedLineStripArrayRetained) {
061: if (stripIndexCounts[i] < 2) {
062: throw new IllegalArgumentException(
063: J3dI18N
064: .getString("IndexedLineStripArrayRetained1"));
065: }
066: } else if (this instanceof IndexedTriangleStripArrayRetained) {
067: if (stripIndexCounts[i] < 3) {
068: throw new IllegalArgumentException(
069: J3dI18N
070: .getString("IndexedTriangleStripArrayRetained1"));
071: }
072: } else if (this instanceof IndexedTriangleFanArrayRetained) {
073: if (stripIndexCounts[i] < 3) {
074: throw new IllegalArgumentException(
075: J3dI18N
076: .getString("IndexedTriangleFanArrayRetained1"));
077: }
078: }
079: }
080:
081: // Sum of all stripIndexCounts MUST be same as indexCount
082: if ((initialIndexIndex + total) > indexCount)
083: throw new IllegalArgumentException(J3dI18N
084: .getString("IndexedGeometryStripArrayRetained0"));
085: int newCoordMax = 0;
086: int newColorIndex = 0;
087: int newNormalIndex = 0;
088: int[] newTexCoordIndex = null;
089: int[] newVertexAttrIndex = null;
090:
091: newCoordMax = computeMaxIndex(initialIndexIndex, total,
092: indexCoord);
093: doErrorCheck(newCoordMax);
094: if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
095: if ((vertexFormat & GeometryArray.COLOR) != 0) {
096: newColorIndex = computeMaxIndex(initialIndexIndex,
097: total, indexColor);
098: doColorCheck(newColorIndex);
099: }
100: if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
101: newTexCoordIndex = new int[texCoordSetCount];
102: for (i = 0; i < texCoordSetCount; i++) {
103: newTexCoordIndex[i] = computeMaxIndex(
104: initialIndexIndex, total, indexTexCoord[i]);
105: doTexCoordCheck(newTexCoordIndex[i], i);
106: }
107: }
108: if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
109: newVertexAttrIndex = new int[vertexAttrCount];
110: for (i = 0; i < vertexAttrCount; i++) {
111: newVertexAttrIndex[i] = computeMaxIndex(
112: initialIndexIndex, total,
113: indexVertexAttr[i]);
114: doTexCoordCheck(newVertexAttrIndex[i], i);
115: }
116: }
117: if ((vertexFormat & GeometryArray.NORMALS) != 0) {
118: newNormalIndex = computeMaxIndex(initialIndexIndex,
119: total, indexNormal);
120: doNormalCheck(newNormalIndex);
121: }
122: }
123:
124: boolean isLive = source != null && source.isLive();
125: if (isLive) {
126: geomLock.getLock();
127: }
128: validIndexCount = total;
129: this .stripIndexCounts = new int[num];
130: for (i = 0; i < num; i++) {
131: this .stripIndexCounts[i] = stripIndexCounts[i];
132: }
133: maxCoordIndex = newCoordMax;
134: if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
135: maxColorIndex = newColorIndex;
136: if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
137: for (i = 0; i < texCoordSetCount; i++) {
138: maxTexCoordIndices[i] = newTexCoordIndex[i];
139: }
140: }
141: if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
142: for (i = 0; i < vertexAttrCount; i++) {
143: maxVertexAttrIndices[i] = newVertexAttrIndex[i];
144: }
145: }
146: maxNormalIndex = newNormalIndex;
147: } else {
148: maxColorIndex = maxCoordIndex;
149: maxNormalIndex = maxCoordIndex;
150: if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
151: for (i = 0; i < texCoordSetCount; i++) {
152: maxTexCoordIndices[i] = maxCoordIndex;
153: }
154: }
155: if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
156: for (i = 0; i < vertexAttrCount; i++) {
157: maxVertexAttrIndices[i] = maxCoordIndex;
158: }
159: }
160: }
161: if (isLive) {
162: geomLock.unLock();
163: }
164: // bbox is computed for the entries list.
165: // so, send as false
166: if (!inUpdater && isLive) {
167: sendDataChangedMessage(true);
168: }
169:
170: }
171:
172: @Override
173: GeometryArrayRetained cloneNonIndexedGeometry() {
174: GeometryStripArrayRetained obj = null;
175:
176: switch (this .geoType) {
177: case GEO_TYPE_INDEXED_LINE_STRIP_SET:
178: obj = new LineStripArrayRetained();
179: break;
180: case GEO_TYPE_INDEXED_TRI_FAN_SET:
181: obj = new TriangleFanArrayRetained();
182: break;
183: case GEO_TYPE_INDEXED_TRI_STRIP_SET:
184: obj = new TriangleStripArrayRetained();
185: break;
186: }
187: obj
188: .createGeometryArrayData(
189: validIndexCount,
190: (vertexFormat & ~(GeometryArray.BY_REFERENCE
191: | GeometryArray.INTERLEAVED | GeometryArray.USE_NIO_BUFFER)),
192: texCoordSetCount, texCoordSetMap,
193: vertexAttrCount, vertexAttrSizes);
194: obj.unIndexify(this );
195: obj.setStripVertexCounts(stripIndexCounts);
196: obj.cloneSourceArray = this ;
197: obj.source = source;
198:
199: return obj;
200: }
201:
202: /**
203: * Get number of strips in the GeometryStripArray
204: * @return numStrips number of strips
205: */
206: int getNumStrips() {
207: return stripIndexCounts.length;
208: }
209:
210: /**
211: * Get a list of vertexCounts for each strip
212: * @param stripIndexCounts an array that will receive vertexCounts
213: */
214: void getStripIndexCounts(int stripIndexCounts[]) {
215: for (int i = stripIndexCounts.length - 1; i >= 0; i--) {
216: stripIndexCounts[i] = this .stripIndexCounts[i];
217: }
218: }
219:
220: void mergeGeometryArrays(ArrayList list) {
221: int numMerge = list.size();
222: int numCount = 0;
223: int i, j;
224:
225: for (i = 0; i < numMerge; i++) {
226: IndexedGeometryStripArrayRetained geo = (IndexedGeometryStripArrayRetained) list
227: .get(i);
228: numCount += geo.stripIndexCounts.length;
229: }
230:
231: stripIndexCounts = new int[numCount];
232: compileIndexLength = new int[numCount];
233: compileStripICOffset = new int[numMerge];
234: int curICOffset = 0;
235: for (i = 0; i < numMerge; i++) {
236: IndexedGeometryStripArrayRetained geo = (IndexedGeometryStripArrayRetained) list
237: .get(i);
238: compileStripICOffset[i] = curICOffset;
239: compileIndexLength[i] = geo.stripIndexCounts.length;
240: System.arraycopy(geo.stripIndexCounts, 0, stripIndexCounts,
241: curICOffset, geo.stripIndexCounts.length);
242: curICOffset += geo.stripIndexCounts.length;
243: }
244: super .mergeGeometryArrays(list);
245:
246: }
247:
248: int getNumStrips(int id) {
249: return compileIndexLength[id];
250: }
251:
252: /**
253: * Get a list of vertexCounts for each strip
254: * @param stripIndexCounts an array that will receive vertexCounts
255: */
256: void getStripIndexCounts(int id, int stripIndexCounts[]) {
257: int count = compileIndexLength[id];
258: int coffset = compileStripICOffset[id];
259: for (int i = 0; i < count; i++) {
260: stripIndexCounts[i] = this .stripIndexCounts[coffset + 1];
261: }
262: }
263:
264: }
|