Source Code Cross Referenced for IndexedGeometryArrayRetained.java in  » 6.0-JDK-Modules » java-3d » javax » media » j3d » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » javax.media.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $RCSfile: IndexedGeometryArrayRetained.java,v $
0003:         *
0004:         * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
0005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0006:         *
0007:         * This code is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU General Public License version 2 only, as
0009:         * published by the Free Software Foundation.  Sun designates this
0010:         * particular file as subject to the "Classpath" exception as provided
0011:         * by Sun in the LICENSE file that accompanied this code.
0012:         *
0013:         * This code is distributed in the hope that it will be useful, but WITHOUT
0014:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0015:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0016:         * version 2 for more details (a copy is included in the LICENSE file that
0017:         * accompanied this code).
0018:         *
0019:         * You should have received a copy of the GNU General Public License version
0020:         * 2 along with this work; if not, write to the Free Software Foundation,
0021:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0022:         *
0023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0024:         * CA 95054 USA or visit www.sun.com if you need additional information or
0025:         * have any questions.
0026:         *
0027:         * $Revision: 1.12 $
0028:         * $Date: 2008/02/28 20:17:24 $
0029:         * $State: Exp $
0030:         */
0031:
0032:        package javax.media.j3d;
0033:
0034:        import javax.vecmath.*;
0035:        import java.util.ArrayList;
0036:        import com.sun.j3d.internal.FloatBufferWrapper;
0037:
0038:        /**
0039:         * The IndexedGeometryArray object contains arrays of positional coordinates,
0040:         * colors, normals and/or texture coordinates that describe
0041:         * point, line, or surface geometry.  It is extended to create
0042:         * the various primitive types (e.g., lines, triangle_strips, etc.)
0043:         */
0044:
0045:        abstract class IndexedGeometryArrayRetained extends
0046:                GeometryArrayRetained {
0047:
0048:            // arrays to save indices for coord, color, normal, texcoord, vertexAttr
0049:            int[] indexCoord;
0050:            int[] indexColor;
0051:            int[] indexNormal;
0052:            int[][] indexTexCoord;
0053:            int[][] indexVertexAttr;
0054:
0055:            int indexCount = 0;
0056:
0057:            int initialIndexIndex = 0;
0058:            int validIndexCount = 0;
0059:
0060:            // Following variables are only used in compile mode
0061:            int[] compileIndexCount;
0062:            int[] compileIndexOffset;
0063:
0064:            int maxCoordIndex = 0;
0065:            int maxColorIndex = 0;
0066:            int maxNormalIndex = 0;
0067:            int[] maxTexCoordIndices = null;
0068:            int[] maxVertexAttrIndices = null;
0069:
0070:            void createIndexedGeometryArrayData(int indexCount) {
0071:                this .indexCount = indexCount;
0072:                this .validIndexCount = indexCount;
0073:
0074:                // Only allocate color, normal, texCoord, and vertexAttr
0075:                // index arrays if USE_COORD_INDEX_ONLY is not set
0076:                boolean notUCIO = (this .vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0;
0077:
0078:                //NVaidya
0079:                // Only allocate indexCoord if BY_REFERENCE_INDICES not set
0080:                if (((this .vertexFormat & GeometryArray.COORDINATES) != 0)
0081:                        && ((this .vertexFormat & GeometryArray.BY_REFERENCE_INDICES) == 0))
0082:                    this .indexCoord = new int[indexCount];
0083:
0084:                if (((this .vertexFormat & GeometryArray.NORMALS) != 0)
0085:                        && notUCIO)
0086:                    this .indexNormal = new int[indexCount];
0087:
0088:                if (((this .vertexFormat & GeometryArray.COLOR) != 0) && notUCIO)
0089:                    this .indexColor = new int[indexCount];
0090:
0091:                if ((this .vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0092:                    this .indexTexCoord = new int[this .texCoordSetCount][];
0093:                    if (notUCIO) {
0094:                        for (int i = 0; i < this .texCoordSetCount; i++) {
0095:                            this .indexTexCoord[i] = new int[indexCount];
0096:                        }
0097:                    }
0098:                    maxTexCoordIndices = new int[texCoordSetCount];
0099:                }
0100:
0101:                if ((this .vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0102:                    this .indexVertexAttr = new int[this .vertexAttrCount][];
0103:                    if (notUCIO) {
0104:                        for (int i = 0; i < this .vertexAttrCount; i++) {
0105:                            this .indexVertexAttr[i] = new int[indexCount];
0106:                        }
0107:                    }
0108:                    this .maxVertexAttrIndices = new int[this .vertexAttrCount];
0109:                }
0110:            }
0111:
0112:            GeometryArrayRetained cloneNonIndexedGeometry() {
0113:                GeometryArrayRetained obj = null;
0114:
0115:                switch (this .geoType) {
0116:                case GEO_TYPE_INDEXED_LINE_SET:
0117:                    obj = new LineArrayRetained();
0118:                    break;
0119:                case GEO_TYPE_INDEXED_POINT_SET:
0120:                    obj = new PointArrayRetained();
0121:                    break;
0122:                case GEO_TYPE_INDEXED_QUAD_SET:
0123:                    obj = new QuadArrayRetained();
0124:                    break;
0125:                case GEO_TYPE_INDEXED_TRI_SET:
0126:                    obj = new TriangleArrayRetained();
0127:                    break;
0128:                default:
0129:                    assert false; // Should never get here
0130:                }
0131:
0132:                obj
0133:                        .createGeometryArrayData(
0134:                                validIndexCount,
0135:                                (vertexFormat & ~(GeometryArray.BY_REFERENCE
0136:                                        | GeometryArray.INTERLEAVED | GeometryArray.USE_NIO_BUFFER)),
0137:                                texCoordSetCount, texCoordSetMap,
0138:                                vertexAttrCount, vertexAttrSizes);
0139:                obj.cloneSourceArray = this ;
0140:                obj.unIndexify(this );
0141:                obj.source = source;
0142:
0143:                return obj;
0144:            }
0145:
0146:            /**
0147:             * Gets current number of indices
0148:             * @return indexCount
0149:             */
0150:            int getIndexCount() {
0151:                return indexCount;
0152:            }
0153:
0154:            void doErrorCheck(int newMax) {
0155:                doCoordCheck(newMax);
0156:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) {
0157:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
0158:                        doColorCheck(newMax);
0159:                    }
0160:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0161:                        for (int i = 0; i < texCoordSetCount; i++) {
0162:                            doTexCoordCheck(newMax, i);
0163:                        }
0164:                    }
0165:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0166:                        for (int i = 0; i < vertexAttrCount; i++) {
0167:                            doVertexAttrCheck(newMax, i);
0168:                        }
0169:                    }
0170:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
0171:                        doNormalCheck(newMax);
0172:                    }
0173:                }
0174:            }
0175:
0176:            void doCoordCheck(int newMax) {
0177:                // Check to make sure that the array length defined by the user is ateast maxCoordIndex long
0178:                if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
0179:                    if (newMax >= vertexCount) {
0180:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0181:                                .getString("IndexedGeometryArray23"));
0182:                    }
0183:                } else {
0184:                    if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
0185:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0186:                            switch ((vertexType & GeometryArrayRetained.VERTEX_DEFINED)) {
0187:                            case PF:
0188:                                if (floatBufferRefCoords != null
0189:                                        && 3 * newMax >= floatBufferRefCoords
0190:                                                .limit()) {
0191:                                    throw new ArrayIndexOutOfBoundsException(
0192:                                            J3dI18N
0193:                                                    .getString("IndexedGeometryArray23"));
0194:                                }
0195:                                break;
0196:                            case PD:
0197:                                if (doubleBufferRefCoords != null
0198:                                        && 3 * newMax >= doubleBufferRefCoords
0199:                                                .limit()) {
0200:                                    throw new ArrayIndexOutOfBoundsException(
0201:                                            J3dI18N
0202:                                                    .getString("IndexedGeometryArray23"));
0203:                                }
0204:                                break;
0205:                            }
0206:                        } else {
0207:                            if (interleavedFloatBufferImpl != null
0208:                                    && stride * newMax >= interleavedFloatBufferImpl
0209:                                            .limit()) {
0210:                                throw new ArrayIndexOutOfBoundsException(
0211:                                        J3dI18N
0212:                                                .getString("IndexedGeometryArray23"));
0213:                            }
0214:                        }
0215:                    } else {
0216:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0217:                            switch ((vertexType & VERTEX_DEFINED)) {
0218:                            case PF:
0219:                                if (floatRefCoords != null
0220:                                        && (3 * newMax >= floatRefCoords.length)) {
0221:                                    throw new ArrayIndexOutOfBoundsException(
0222:                                            J3dI18N
0223:                                                    .getString("IndexedGeometryArray23"));
0224:                                }
0225:                                break;
0226:                            case PD:
0227:                                if (doubleRefCoords != null
0228:                                        && (3 * newMax >= doubleRefCoords.length)) {
0229:                                    throw new ArrayIndexOutOfBoundsException(
0230:                                            J3dI18N
0231:                                                    .getString("IndexedGeometryArray23"));
0232:                                }
0233:
0234:                                break;
0235:                            case P3F:
0236:                                if (p3fRefCoords != null
0237:                                        && (newMax >= p3fRefCoords.length)) {
0238:                                    throw new ArrayIndexOutOfBoundsException(
0239:                                            J3dI18N
0240:                                                    .getString("IndexedGeometryArray23"));
0241:                                }
0242:                                break;
0243:                            case P3D:
0244:                                if (p3dRefCoords != null
0245:                                        && (newMax >= p3dRefCoords.length)) {
0246:                                    throw new ArrayIndexOutOfBoundsException(
0247:                                            J3dI18N
0248:                                                    .getString("IndexedGeometryArray23"));
0249:                                }
0250:                                break;
0251:                            default:
0252:                                break;
0253:                            }
0254:                        } else {
0255:                            if (interLeavedVertexData != null
0256:                                    && (stride * newMax >= interLeavedVertexData.length)) {
0257:                                throw new ArrayIndexOutOfBoundsException(
0258:                                        J3dI18N
0259:                                                .getString("IndexedGeometryArray23"));
0260:                            }
0261:                        }
0262:                    }
0263:                }
0264:
0265:            }
0266:
0267:            void doColorCheck(int newMax) {
0268:                // If the new Value is greater than the old value, make sure there is array length
0269:                // to support the change
0270:                // Check to make sure that the array length defined by the user is ateast maxCoordIndex long
0271:                if ((vertexFormat & GeometryArray.COLOR) == 0)
0272:                    return;
0273:
0274:                if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
0275:                    if (newMax >= vertexCount) {
0276:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0277:                                .getString("IndexedGeometryArray24"));
0278:                    }
0279:                } else {
0280:                    int multiplier = getColorStride();
0281:
0282:                    if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
0283:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0284:                            switch ((vertexType & COLOR_DEFINED)) {
0285:                            case CF:
0286:                                if (floatBufferRefColors != null
0287:                                        && multiplier * newMax >= floatBufferRefColors
0288:                                                .limit()) {
0289:                                    throw new ArrayIndexOutOfBoundsException(
0290:                                            J3dI18N
0291:                                                    .getString("IndexedGeometryArray24"));
0292:                                }
0293:                                break;
0294:                            case CUB:
0295:                                if (byteBufferRefColors != null
0296:                                        && multiplier * newMax >= byteBufferRefColors
0297:                                                .limit()) {
0298:                                    throw new ArrayIndexOutOfBoundsException(
0299:                                            J3dI18N
0300:                                                    .getString("IndexedGeometryArray24"));
0301:                                }
0302:                                break;
0303:                            }
0304:                        } else {
0305:                            if (interleavedFloatBufferImpl != null
0306:                                    && stride * newMax >= interleavedFloatBufferImpl
0307:                                            .limit()) {
0308:                                throw new ArrayIndexOutOfBoundsException(
0309:                                        J3dI18N
0310:                                                .getString("IndexedGeometryArray24"));
0311:                            }
0312:                        }
0313:                    } else {
0314:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0315:                            switch ((vertexType & COLOR_DEFINED)) {
0316:                            case CF:
0317:                                if (floatRefColors != null
0318:                                        && (multiplier * newMax >= floatRefColors.length)) {
0319:                                    throw new ArrayIndexOutOfBoundsException(
0320:                                            J3dI18N
0321:                                                    .getString("IndexedGeometryArray24"));
0322:                                }
0323:                                break;
0324:                            case CUB:
0325:                                if (byteRefColors != null
0326:                                        && (multiplier * newMax >= byteRefColors.length)) {
0327:                                    throw new ArrayIndexOutOfBoundsException(
0328:                                            J3dI18N
0329:                                                    .getString("IndexedGeometryArray24"));
0330:                                }
0331:
0332:                                break;
0333:                            case C3F:
0334:                                if (c3fRefColors != null
0335:                                        && (newMax >= c3fRefColors.length)) {
0336:                                    throw new ArrayIndexOutOfBoundsException(
0337:                                            J3dI18N
0338:                                                    .getString("IndexedGeometryArray24"));
0339:                                }
0340:                                break;
0341:                            case C4F:
0342:                                if (c4fRefColors != null
0343:                                        && (newMax >= c4fRefColors.length)) {
0344:                                    throw new ArrayIndexOutOfBoundsException(
0345:                                            J3dI18N
0346:                                                    .getString("IndexedGeometryArray24"));
0347:                                }
0348:                                break;
0349:                            case C3UB:
0350:                                if (c3bRefColors != null
0351:                                        && (newMax >= c3bRefColors.length)) {
0352:                                    throw new ArrayIndexOutOfBoundsException(
0353:                                            J3dI18N
0354:                                                    .getString("IndexedGeometryArray24"));
0355:                                }
0356:                                break;
0357:                            case C4UB:
0358:                                if (c4bRefColors != null
0359:                                        && (newMax >= c4bRefColors.length)) {
0360:                                    throw new ArrayIndexOutOfBoundsException(
0361:                                            J3dI18N
0362:                                                    .getString("IndexedGeometryArray24"));
0363:                                }
0364:                                break;
0365:                            default:
0366:                                break;
0367:                            }
0368:                        } else {
0369:                            if (interLeavedVertexData != null
0370:                                    && (stride * newMax >= interLeavedVertexData.length)) {
0371:                                throw new ArrayIndexOutOfBoundsException(
0372:                                        J3dI18N
0373:                                                .getString("IndexedGeometryArray24"));
0374:                            }
0375:                        }
0376:                    }
0377:                }
0378:
0379:            }
0380:
0381:            void doNormalCheck(int newMax) {
0382:                if ((vertexFormat & GeometryArray.NORMALS) == 0)
0383:                    return;
0384:
0385:                // Check to make sure that the array length defined by the user is ateast maxCoordIndex long
0386:                if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
0387:                    if (newMax >= vertexCount) {
0388:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0389:                                .getString("IndexedGeometryArray26"));
0390:                    }
0391:                } else {
0392:                    if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
0393:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0394:                            switch ((vertexType & GeometryArrayRetained.NORMAL_DEFINED)) {
0395:                            case NF:
0396:                                if (floatBufferRefNormals != null
0397:                                        && 3 * newMax >= floatBufferRefNormals
0398:                                                .limit()) {
0399:                                    throw new ArrayIndexOutOfBoundsException(
0400:                                            J3dI18N
0401:                                                    .getString("IndexedGeometryArray26"));
0402:                                }
0403:                                break;
0404:                            }
0405:                        } else {
0406:                            if (interleavedFloatBufferImpl != null
0407:                                    && stride * newMax >= interleavedFloatBufferImpl
0408:                                            .limit()) {
0409:                                throw new ArrayIndexOutOfBoundsException(
0410:                                        J3dI18N
0411:                                                .getString("IndexedGeometryArray26"));
0412:                            }
0413:                        }
0414:                    } else {
0415:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0416:                            switch ((vertexType & NORMAL_DEFINED)) {
0417:                            case NF:
0418:                                if (floatRefNormals != null
0419:                                        && (3 * newMax >= floatRefNormals.length)) {
0420:                                    throw new ArrayIndexOutOfBoundsException(
0421:                                            J3dI18N
0422:                                                    .getString("IndexedGeometryArray26"));
0423:                                }
0424:                                break;
0425:                            case N3F:
0426:                                if (v3fRefNormals != null
0427:                                        && (newMax >= v3fRefNormals.length)) {
0428:                                    throw new ArrayIndexOutOfBoundsException(
0429:                                            J3dI18N
0430:                                                    .getString("IndexedGeometryArray26"));
0431:                                }
0432:
0433:                                break;
0434:                            default:
0435:                                break;
0436:                            }
0437:                        } else {
0438:                            if (interLeavedVertexData != null
0439:                                    && (stride * newMax >= interLeavedVertexData.length)) {
0440:                                throw new ArrayIndexOutOfBoundsException(
0441:                                        J3dI18N
0442:                                                .getString("IndexedGeometryArray26"));
0443:                            }
0444:                        }
0445:                    }
0446:                }
0447:
0448:            }
0449:
0450:            void doTexCoordCheck(int newMax, int texCoordSet) {
0451:
0452:                // Check to make sure that the array length defined by the user is ateast maxCoordIndex long
0453:                if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) == 0)
0454:                    return;
0455:
0456:                if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
0457:                    if (newMax >= vertexCount) {
0458:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0459:                                .getString("IndexedGeometryArray25"));
0460:                    }
0461:                } else {
0462:                    int multiplier = getTexStride();
0463:
0464:                    if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
0465:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0466:                            switch ((vertexType & GeometryArrayRetained.TEXCOORD_DEFINED)) {
0467:                            case TF:
0468:                                FloatBufferWrapper texBuffer;
0469:                                texBuffer = (FloatBufferWrapper) (((J3DBuffer) refTexCoordsBuffer[texCoordSet])
0470:                                        .getBufferImpl());
0471:                                if (refTexCoords[texCoordSet] != null
0472:                                        && multiplier * newMax >= texBuffer
0473:                                                .limit()) {
0474:                                    throw new ArrayIndexOutOfBoundsException(
0475:                                            J3dI18N
0476:                                                    .getString("IndexedGeometryArray25"));
0477:                                }
0478:                                break;
0479:                            }
0480:                        } else {
0481:                            if (interleavedFloatBufferImpl != null
0482:                                    && stride * newMax >= interleavedFloatBufferImpl
0483:                                            .limit()) {
0484:                                throw new ArrayIndexOutOfBoundsException(
0485:                                        J3dI18N
0486:                                                .getString("IndexedGeometryArray25"));
0487:                            }
0488:                        }
0489:                    } else {
0490:
0491:                        if ((vertexFormat & GeometryArray.INTERLEAVED) == 0) {
0492:                            switch ((vertexType & TEXCOORD_DEFINED)) {
0493:                            case TF:
0494:                                if (refTexCoords[texCoordSet] != null
0495:                                        && (multiplier * newMax >= ((float[]) refTexCoords[texCoordSet]).length)) {
0496:                                    throw new ArrayIndexOutOfBoundsException(
0497:                                            J3dI18N
0498:                                                    .getString("IndexedGeometryArray25"));
0499:                                }
0500:                                break;
0501:                            case T2F:
0502:                                if (refTexCoords[texCoordSet] != null
0503:                                        && (newMax >= ((TexCoord2f[]) refTexCoords[texCoordSet]).length)) {
0504:                                    throw new ArrayIndexOutOfBoundsException(
0505:                                            J3dI18N
0506:                                                    .getString("IndexedGeometryArray25"));
0507:                                }
0508:
0509:                                break;
0510:                            case T3F:
0511:                                if (refTexCoords[texCoordSet] != null
0512:                                        && (newMax >= ((TexCoord3f[]) refTexCoords[texCoordSet]).length)) {
0513:                                    throw new ArrayIndexOutOfBoundsException(
0514:                                            J3dI18N
0515:                                                    .getString("IndexedGeometryArray25"));
0516:                                }
0517:                                break;
0518:                            default:
0519:                                break;
0520:                            }
0521:                        } else {
0522:                            if (interLeavedVertexData != null
0523:                                    && (stride * newMax >= interLeavedVertexData.length)) {
0524:                                throw new ArrayIndexOutOfBoundsException(
0525:                                        J3dI18N
0526:                                                .getString("IndexedGeometryArray25"));
0527:                            }
0528:                        }
0529:                    }
0530:                }
0531:
0532:            }
0533:
0534:            void doVertexAttrCheck(int newMax, int vertexAttrNum) {
0535:
0536:                // Check to make sure that the array length defined by the user is ateast maxVertexAttrIndex long
0537:                if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) == 0) {
0538:                    return;
0539:                }
0540:
0541:                // Vertex attributes must not be interleaved
0542:                assert (vertexFormat & GeometryArray.INTERLEAVED) == 0;
0543:
0544:                if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
0545:                    if (newMax >= vertexCount) {
0546:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0547:                                .getString("IndexedGeometryArray30"));
0548:                    }
0549:                } else {
0550:                    int multiplier = vertexAttrSizes[vertexAttrNum];
0551:
0552:                    if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) {
0553:                        switch (vertexType & VATTR_DEFINED) {
0554:                        case AF:
0555:                            if (multiplier * newMax >= floatBufferRefVertexAttrs[vertexAttrNum]
0556:                                    .limit()) {
0557:                                throw new ArrayIndexOutOfBoundsException(
0558:                                        J3dI18N
0559:                                                .getString("IndexedGeometryArray30"));
0560:                            }
0561:                            break;
0562:                        }
0563:                    } else {
0564:                        switch (vertexType & VATTR_DEFINED) {
0565:                        case AF:
0566:                            if (multiplier * newMax >= floatRefVertexAttrs[vertexAttrNum].length) {
0567:                                throw new ArrayIndexOutOfBoundsException(
0568:                                        J3dI18N
0569:                                                .getString("IndexedGeometryArray30"));
0570:                            }
0571:                            break;
0572:                        }
0573:                    }
0574:                }
0575:            }
0576:
0577:            /**
0578:             * Sets the coordinate index associated with the vertex at
0579:             * the specified index for this object.
0580:             * @param index the vertex index
0581:             * @param coordinateIndex the new coordinate index
0582:             */
0583:            final void setCoordinateIndex(int index, int coordinateIndex) {
0584:                int newMax;
0585:                newMax = doIndexCheck(index, maxCoordIndex, indexCoord,
0586:                        coordinateIndex);
0587:                if (newMax > maxCoordIndex) {
0588:                    doErrorCheck(newMax);
0589:                }
0590:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) {
0591:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
0592:                        maxColorIndex = newMax;
0593:                    }
0594:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0595:                        for (int i = 0; i < texCoordSetCount; i++) {
0596:                            maxTexCoordIndices[i] = newMax;
0597:                        }
0598:                    }
0599:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0600:                        for (int i = 0; i < vertexAttrCount; i++) {
0601:                            maxVertexAttrIndices[i] = newMax;
0602:                        }
0603:                    }
0604:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
0605:                        maxNormalIndex = newMax;
0606:                    }
0607:                }
0608:
0609:                boolean isLive = source != null && source.isLive();
0610:                if (isLive) {
0611:                    geomLock.getLock();
0612:                }
0613:                dirtyFlag |= INDEX_CHANGED;
0614:                this .indexCoord[index] = coordinateIndex;
0615:                maxCoordIndex = newMax;
0616:                if (isLive) {
0617:                    geomLock.unLock();
0618:                }
0619:                if (!inUpdater && isLive) {
0620:                    sendDataChangedMessage(true);
0621:                }
0622:            }
0623:
0624:            int doIndexCheck(int index, int maxIndex, int[] indices,
0625:                    int dataValue) {
0626:                int newMax = maxIndex;
0627:                if (index < initialIndexIndex)
0628:                    return newMax;
0629:
0630:                if (index >= (initialIndexIndex + validIndexCount))
0631:                    return newMax;
0632:
0633:                if (dataValue < 0) {
0634:                    // Throw an exception, since index is negative
0635:                    throw new ArrayIndexOutOfBoundsException(J3dI18N
0636:                            .getString("IndexedGeometryArray27"));
0637:
0638:                }
0639:
0640:                if (newMax == indices[index]) {
0641:                    if (dataValue >= newMax) {
0642:                        newMax = dataValue;
0643:                    }
0644:                    // Go thru the entire list and look for the max
0645:                    else {
0646:                        for (int i = 0; i < indices.length; i++) {
0647:                            if (indices[i] > newMax) {
0648:                                newMax = indices[i];
0649:                            }
0650:                        }
0651:                    }
0652:                } else if (dataValue > newMax) {
0653:                    newMax = dataValue;
0654:                }
0655:                return newMax;
0656:            }
0657:
0658:            int doIndicesCheck(int index, int maxIndex, int[] indices,
0659:                    int[] newIndices) {
0660:                int newMax = maxIndex;
0661:                boolean computeNewMax = false;
0662:                int i, j, num = newIndices.length;
0663:                boolean maxReset = false;
0664:                for (j = 0; j < num; j++) {
0665:                    if ((index + j) < initialIndexIndex)
0666:                        continue;
0667:
0668:                    if ((index + j) >= (initialIndexIndex + validIndexCount))
0669:                        continue;
0670:                    if (newIndices[j] < 0) {
0671:                        // Throw an exception, since index is negative
0672:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
0673:                                .getString("IndexedGeometryArray27"));
0674:
0675:                    }
0676:                    if (indices[index + j] == maxIndex) {
0677:                        if (newIndices[j] >= newMax) {
0678:                            newMax = newIndices[j];
0679:                            computeNewMax = false;
0680:                            maxReset = true;
0681:                        }
0682:                        // Go thru the entire list and look for the max
0683:                        // If in the new list there is no value that is >=
0684:                        // to the old maximum
0685:                        else if (!maxReset) {
0686:                            computeNewMax = true;
0687:                        }
0688:                    } else if (newIndices[j] >= newMax) {
0689:                        newMax = newIndices[j];
0690:                        computeNewMax = false;
0691:                        maxReset = true;
0692:                    }
0693:                }
0694:                if (computeNewMax) {
0695:                    for (i = 0; i < indices.length; i++) {
0696:                        if (indices[i] > newMax) {
0697:                            newMax = indices[i];
0698:                        }
0699:                    }
0700:                }
0701:                return newMax;
0702:            }
0703:
0704:            /**
0705:             * Sets the coordinate indices associated with the vertices starting at
0706:             * the specified index for this object.
0707:             * @param index the vertex index
0708:             * @param coordinateIndices an array of coordinate indices
0709:             */
0710:            final void setCoordinateIndices(int index, int coordinateIndices[]) {
0711:                int newMax;
0712:                int i, j, num = coordinateIndices.length;
0713:                newMax = doIndicesCheck(index, maxCoordIndex, indexCoord,
0714:                        coordinateIndices);
0715:                if (newMax > maxCoordIndex) {
0716:                    doErrorCheck(newMax);
0717:                }
0718:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) {
0719:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
0720:                        maxColorIndex = newMax;
0721:                    }
0722:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0723:                        for (i = 0; i < texCoordSetCount; i++) {
0724:                            maxTexCoordIndices[i] = newMax;
0725:                        }
0726:                    }
0727:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0728:                        for (i = 0; i < vertexAttrCount; i++) {
0729:                            maxVertexAttrIndices[i] = newMax;
0730:                        }
0731:                    }
0732:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
0733:                        maxNormalIndex = newMax;
0734:                    }
0735:                }
0736:
0737:                boolean isLive = source != null && source.isLive();
0738:                if (isLive) {
0739:                    geomLock.getLock();
0740:                }
0741:                dirtyFlag |= INDEX_CHANGED;
0742:                maxCoordIndex = newMax;
0743:                for (i = 0, j = index; i < num; i++, j++) {
0744:                    this .indexCoord[j] = coordinateIndices[i];
0745:                }
0746:                if (isLive) {
0747:                    geomLock.unLock();
0748:                }
0749:                if (!inUpdater && isLive) {
0750:                    sendDataChangedMessage(true);
0751:                }
0752:            }
0753:
0754:            //NVaidya
0755:            /**
0756:             * Sets the coordinate indices by reference to the specified array
0757:             * @param coordinateIndices an array of coordinate indices
0758:             */
0759:            final void setCoordIndicesRef(int coordinateIndices[]) {
0760:                int newMax = 0;
0761:
0762:                if (coordinateIndices != null) {
0763:                    if (coordinateIndices.length < initialIndexIndex
0764:                            + validIndexCount) {
0765:                        throw new IllegalArgumentException(J3dI18N
0766:                                .getString("IndexedGeometryArray33"));
0767:                    }
0768:
0769:                    //
0770:                    // option 1: could fake the args to "re-use" doIndicesCheck()
0771:                    //NVaidya
0772:                    // newMax = doIndicesCheck(0, maxCoordIndex, coordinateIndices, coordinateIndices);
0773:                    // if (newMax > maxCoordIndex) {
0774:                    //     doErrorCheck(newMax);
0775:                    // }
0776:                    //
0777:                    // option 2: same logic as in setInitialIndexIndex: Better, I Think ?
0778:                    // computeMaxIndex() doesn't check for index < 0 while doIndicesCheck() does.
0779:                    // So, a new method computeMaxIndexWithCheck
0780:                    //NVaidya
0781:                    newMax = computeMaxIndexWithCheck(initialIndexIndex,
0782:                            validIndexCount, coordinateIndices);
0783:                    if (newMax > maxCoordIndex) {
0784:                        doErrorCheck(newMax);
0785:                    }
0786:                }
0787:
0788:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) {
0789:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
0790:                        maxColorIndex = newMax;
0791:                    }
0792:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0793:                        for (int i = 0; i < texCoordSetCount; i++) {
0794:                            maxTexCoordIndices[i] = newMax;
0795:                        }
0796:                    }
0797:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0798:                        for (int i = 0; i < vertexAttrCount; i++) {
0799:                            maxVertexAttrIndices[i] = newMax;
0800:                        }
0801:                    }
0802:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
0803:                        maxNormalIndex = newMax;
0804:                    }
0805:                }
0806:
0807:                boolean isLive = source != null && source.isLive();
0808:                if (isLive) {
0809:                    geomLock.getLock();
0810:                }
0811:                dirtyFlag |= INDEX_CHANGED;
0812:                maxCoordIndex = newMax;
0813:                this .indexCoord = coordinateIndices;
0814:                if (isLive) {
0815:                    geomLock.unLock();
0816:                }
0817:                if (!inUpdater && isLive) {
0818:                    sendDataChangedMessage(true);
0819:                }
0820:            }
0821:
0822:            //NVaidya
0823:            /**
0824:             * trigger from GeometryArrayRetained#updateData()
0825:             * to recompute maxCoordIndex and perform index integrity checks
0826:             */
0827:            final void doPostUpdaterUpdate() {
0828:                // user may have called setCoordIndicesRef and/or
0829:                // changed contents of indexCoord array. Thus, need to
0830:                // recompute maxCoordIndex unconditionally (and redundantly 
0831:                // if user had only invoked setCoordIndicesRef but not also 
0832:                // changed contents). geomLock is currently locked.
0833:
0834:                // Option 1:
0835:                // simply call setCoordIndicesRef(indexCoord); but this seems to cause
0836:                // deadlock or freeze - probably because the !inUpdater branch sends
0837:                // out too many sendDataChangedMessage(true) - occurs if updateData
0838:                // method is called rapidly.
0839:                // setCoordIndicesRef(indexCoord);
0840:
0841:                // Option 2:
0842:                // use only necessary code from setCoordIndicesRef
0843:                // System.err.println("IndexedGeometryArrayretained#doUpdaterUpdate");
0844:                int newMax = 0;
0845:
0846:                if (indexCoord != null) {
0847:                    newMax = computeMaxIndexWithCheck(initialIndexIndex,
0848:                            validIndexCount, indexCoord);
0849:                    if (newMax > maxCoordIndex) {
0850:                        doErrorCheck(newMax);
0851:                    }
0852:                }
0853:
0854:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) {
0855:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
0856:                        maxColorIndex = newMax;
0857:                    }
0858:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
0859:                        for (int i = 0; i < texCoordSetCount; i++) {
0860:                            maxTexCoordIndices[i] = newMax;
0861:                        }
0862:                    }
0863:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
0864:                        for (int i = 0; i < vertexAttrCount; i++) {
0865:                            maxVertexAttrIndices[i] = newMax;
0866:                        }
0867:                    }
0868:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
0869:                        maxNormalIndex = newMax;
0870:                    }
0871:                }
0872:
0873:                dirtyFlag |= INDEX_CHANGED;
0874:                maxCoordIndex = newMax;
0875:            }
0876:
0877:            /**
0878:             * Sets the color index associated with the vertex at
0879:             * the specified index for this object.
0880:             * @param index the vertex index
0881:             * @param colorIndex the new color index
0882:             */
0883:            final void setColorIndex(int index, int colorIndex) {
0884:                int newMax = maxColorIndex;
0885:
0886:                newMax = doIndexCheck(index, maxColorIndex, indexColor,
0887:                        colorIndex);
0888:                if (newMax > maxColorIndex) {
0889:                    doColorCheck(newMax);
0890:                }
0891:                boolean isLive = source != null && source.isLive();
0892:                if (isLive) {
0893:                    geomLock.getLock();
0894:                }
0895:                // No need to set INDEX_CHANGED since IndexBuffer
0896:                // is used only when USE_COORD_INDEX_ONLY specified.
0897:                // In this case only coordinate index array is 
0898:                // considered.
0899:                this .indexColor[index] = colorIndex;
0900:                maxColorIndex = newMax;
0901:                if (isLive) {
0902:                    geomLock.unLock();
0903:                }
0904:                if (!inUpdater && isLive) {
0905:                    sendDataChangedMessage(false);
0906:                }
0907:            }
0908:
0909:            /**
0910:             * Sets the color indices associated with the vertices starting at
0911:             * the specified index for this object.
0912:             * @param index the vertex index
0913:             * @param colorIndices an array of color indices
0914:             */
0915:            final void setColorIndices(int index, int colorIndices[]) {
0916:                int i, j, num = colorIndices.length;
0917:                int newMax;
0918:
0919:                newMax = doIndicesCheck(index, maxColorIndex, indexColor,
0920:                        colorIndices);
0921:                if (newMax > maxColorIndex) {
0922:                    doColorCheck(newMax);
0923:                }
0924:                boolean isLive = source != null && source.isLive();
0925:                if (isLive) {
0926:                    geomLock.getLock();
0927:                }
0928:                maxColorIndex = newMax;
0929:                for (i = 0, j = index; i < num; i++, j++) {
0930:                    this .indexColor[j] = colorIndices[i];
0931:                }
0932:                if (isLive) {
0933:                    geomLock.unLock();
0934:                }
0935:                if (!inUpdater && isLive) {
0936:                    sendDataChangedMessage(false);
0937:                }
0938:            }
0939:
0940:            /**
0941:             * Sets the normal index associated with the vertex at
0942:             * the specified index for this object.
0943:             * @param index the vertex index
0944:             * @param normalIndex the new normal index
0945:             */
0946:            final void setNormalIndex(int index, int normalIndex) {
0947:                int newMax;
0948:
0949:                newMax = doIndexCheck(index, maxNormalIndex, indexNormal,
0950:                        normalIndex);
0951:                if (newMax > maxNormalIndex) {
0952:                    doNormalCheck(newMax);
0953:                }
0954:                boolean isLive = source != null && source.isLive();
0955:                if (isLive) {
0956:                    geomLock.getLock();
0957:                }
0958:                maxNormalIndex = newMax;
0959:                this .indexNormal[index] = normalIndex;
0960:                if (isLive) {
0961:                    geomLock.unLock();
0962:                }
0963:                if (!inUpdater && isLive) {
0964:                    sendDataChangedMessage(false);
0965:                }
0966:            }
0967:
0968:            /**
0969:             * Sets the normal indices associated with the vertices starting at
0970:             * the specified index for this object.
0971:             * @param index the vertex index
0972:             * @param normalIndices an array of normal indices
0973:             */
0974:            final void setNormalIndices(int index, int normalIndices[]) {
0975:                int i, j, num = normalIndices.length;
0976:                int newMax;
0977:
0978:                newMax = doIndicesCheck(index, maxNormalIndex, indexNormal,
0979:                        normalIndices);
0980:                if (newMax > maxNormalIndex) {
0981:                    doNormalCheck(newMax);
0982:                }
0983:                boolean isLive = source != null && source.isLive();
0984:                if (isLive) {
0985:                    geomLock.getLock();
0986:                }
0987:                for (i = 0, j = index; i < num; i++, j++) {
0988:                    this .indexNormal[j] = normalIndices[i];
0989:                }
0990:                maxNormalIndex = newMax;
0991:                if (isLive) {
0992:                    geomLock.unLock();
0993:                }
0994:                if (!inUpdater && isLive) {
0995:                    sendDataChangedMessage(false);
0996:                }
0997:            }
0998:
0999:            /**
1000:             * Sets the texture coordinate index associated with the vertex at
1001:             * the specified index for this object.
1002:             * @param texCoordSet the texture coordinate set
1003:             * @param index the vertex index
1004:             * @param texCoordIndex the new texture coordinate index
1005:             */
1006:            final void setTextureCoordinateIndex(int texCoordSet, int index,
1007:                    int texCoordIndex) {
1008:                int newMax;
1009:                int[] indices = this .indexTexCoord[texCoordSet];
1010:
1011:                newMax = doIndexCheck(index, maxTexCoordIndices[texCoordSet],
1012:                        indices, texCoordIndex);
1013:                if (newMax > maxTexCoordIndices[texCoordSet]) {
1014:                    doTexCoordCheck(newMax, texCoordSet);
1015:                }
1016:                boolean isLive = source != null && source.isLive();
1017:                if (isLive) {
1018:                    geomLock.getLock();
1019:                }
1020:                maxTexCoordIndices[texCoordSet] = newMax;
1021:                indices[index] = texCoordIndex;
1022:                if (isLive) {
1023:                    geomLock.unLock();
1024:                }
1025:                if (!inUpdater && isLive) {
1026:                    sendDataChangedMessage(false);
1027:                }
1028:            }
1029:
1030:            /**
1031:             * Sets the texture coordinate indices associated with the vertices
1032:             * starting at the specified index for this object.
1033:             * @param texCoordSet the texture coordinate set
1034:             * @param index the vertex index
1035:             * @param texCoordIndices an array of texture coordinate indices
1036:             */
1037:            final void setTextureCoordinateIndices(int texCoordSet, int index,
1038:                    int texCoordIndices[]) {
1039:                int i, j, num = texCoordIndices.length;
1040:                int[] indices = this .indexTexCoord[texCoordSet];
1041:
1042:                int newMax;
1043:
1044:                newMax = doIndicesCheck(index, maxTexCoordIndices[texCoordSet],
1045:                        indices, texCoordIndices);
1046:                if (newMax > maxTexCoordIndices[texCoordSet]) {
1047:                    doTexCoordCheck(newMax, texCoordSet);
1048:                }
1049:                boolean isLive = source != null && source.isLive();
1050:                if (isLive) {
1051:                    geomLock.getLock();
1052:                }
1053:                maxTexCoordIndices[texCoordSet] = newMax;
1054:                for (i = 0, j = index; i < num; i++, j++) {
1055:                    indices[j] = texCoordIndices[i];
1056:                }
1057:                if (isLive) {
1058:                    geomLock.unLock();
1059:                }
1060:                if (!inUpdater && isLive) {
1061:                    sendDataChangedMessage(false);
1062:                }
1063:            }
1064:
1065:            /**
1066:             * Sets the vertex attribute index associated with the vertex at
1067:             * the specified index for the specified vertex attribute number
1068:             * for this object.
1069:             */
1070:            void setVertexAttrIndex(int vertexAttrNum, int index,
1071:                    int vertexAttrIndex) {
1072:
1073:                int newMax;
1074:                int[] indices = this .indexVertexAttr[vertexAttrNum];
1075:
1076:                newMax = doIndexCheck(index,
1077:                        maxVertexAttrIndices[vertexAttrNum], indices,
1078:                        vertexAttrIndex);
1079:                if (newMax > maxVertexAttrIndices[vertexAttrNum]) {
1080:                    doVertexAttrCheck(newMax, vertexAttrNum);
1081:                }
1082:                boolean isLive = source != null && source.isLive();
1083:                if (isLive) {
1084:                    geomLock.getLock();
1085:                }
1086:                maxVertexAttrIndices[vertexAttrNum] = newMax;
1087:                indices[index] = vertexAttrIndex;
1088:                if (isLive) {
1089:                    geomLock.unLock();
1090:                }
1091:                if (!inUpdater && isLive) {
1092:                    sendDataChangedMessage(false);
1093:                }
1094:            }
1095:
1096:            /**
1097:             * Sets the vertex attribute indices associated with the vertices
1098:             * starting at the specified index for the specified vertex attribute number
1099:             * for this object.
1100:             */
1101:            void setVertexAttrIndices(int vertexAttrNum, int index,
1102:                    int[] vertexAttrIndices) {
1103:
1104:                int i, j, num = vertexAttrIndices.length;
1105:                int[] indices = this .indexVertexAttr[vertexAttrNum];
1106:
1107:                int newMax;
1108:
1109:                newMax = doIndicesCheck(index,
1110:                        maxVertexAttrIndices[vertexAttrNum], indices,
1111:                        vertexAttrIndices);
1112:                if (newMax > maxVertexAttrIndices[vertexAttrNum]) {
1113:                    doVertexAttrCheck(newMax, vertexAttrNum);
1114:                }
1115:                boolean isLive = source != null && source.isLive();
1116:                if (isLive) {
1117:                    geomLock.getLock();
1118:                }
1119:                maxVertexAttrIndices[vertexAttrNum] = newMax;
1120:                for (i = 0, j = index; i < num; i++, j++) {
1121:                    indices[j] = vertexAttrIndices[i];
1122:                }
1123:                if (isLive) {
1124:                    geomLock.unLock();
1125:                }
1126:                if (!inUpdater && isLive) {
1127:                    sendDataChangedMessage(false);
1128:                }
1129:            }
1130:
1131:            /**
1132:             * Retrieves the coordinate index associated with the vertex at
1133:             * the specified index for this object.
1134:             * @param index the vertex index
1135:             * @return the coordinate index
1136:             */
1137:            final int getCoordinateIndex(int index) {
1138:                return this .indexCoord[index];
1139:            }
1140:
1141:            /**
1142:             * Retrieves the coordinate indices associated with the vertices starting at
1143:             * the specified index for this object.
1144:             * @param index the vertex index
1145:             * @param coordinateIndices array that will receive the coordinate indices
1146:             */
1147:            final void getCoordinateIndices(int index, int coordinateIndices[]) {
1148:                int i, j, num = coordinateIndices.length;
1149:
1150:                for (i = 0, j = index; i < num; i++, j++) {
1151:                    coordinateIndices[i] = this .indexCoord[j];
1152:                }
1153:            }
1154:
1155:            //NVaidya
1156:            /**
1157:             * Returns a reference to the coordinate indices associated 
1158:             * with the vertices
1159:             */
1160:            final int[] getCoordIndicesRef() {
1161:                return this .indexCoord;
1162:            }
1163:
1164:            /**
1165:             * Retrieves the color index associated with the vertex at
1166:             * the specified index for this object.
1167:             * @param index the vertex index
1168:             * @return the color index
1169:             */
1170:            final int getColorIndex(int index) {
1171:                return this .indexColor[index];
1172:            }
1173:
1174:            /**
1175:             * Retrieves the color indices associated with the vertices starting at
1176:             * the specified index for this object.
1177:             * @param index the vertex index
1178:             * @param colorIndices array that will receive the color indices
1179:             */
1180:            final void getColorIndices(int index, int colorIndices[]) {
1181:                int i, j, num = colorIndices.length;
1182:
1183:                for (i = 0, j = index; i < num; i++, j++) {
1184:                    colorIndices[i] = this .indexColor[j];
1185:                }
1186:            }
1187:
1188:            /**
1189:             * Retrieves the normal index associated with the vertex at
1190:             * the specified index for this object.
1191:             * @param index the vertex index
1192:             * @return the normal index
1193:             */
1194:            final int getNormalIndex(int index) {
1195:                return this .indexNormal[index];
1196:            }
1197:
1198:            /**
1199:             * Retrieves the normal indices associated with the vertices starting at
1200:             * the specified index for this object.
1201:             * @param index the vertex index
1202:             * @param normalIndices array that will receive the normal indices
1203:             */
1204:            final void getNormalIndices(int index, int normalIndices[]) {
1205:                int i, j, num = normalIndices.length;
1206:
1207:                for (i = 0, j = index; i < num; i++, j++) {
1208:                    normalIndices[i] = this .indexNormal[j];
1209:                }
1210:            }
1211:
1212:            /**
1213:             * Retrieves the texture coordinate index associated with the vertex at
1214:             * the specified index for this object.
1215:             * @param texCoordSet the texture coordinate set
1216:             * @param index the vertex index
1217:             * @return the texture coordinate index
1218:             */
1219:            final int getTextureCoordinateIndex(int texCoordSet, int index) {
1220:                int[] indices = this .indexTexCoord[texCoordSet];
1221:
1222:                return indices[index];
1223:            }
1224:
1225:            /**
1226:             * Retrieves the texture coordinate indices associated with the vertices
1227:             * starting at the specified index for this object.
1228:             * @param texCoordSet the texture coordinate set
1229:             * @param index the vertex index
1230:             * @param texCoordIndices array that will receive the texture coordinate indices
1231:             */
1232:            final void getTextureCoordinateIndices(int texCoordSet, int index,
1233:                    int texCoordIndices[]) {
1234:                int i, j, num = texCoordIndices.length;
1235:                int[] indices = this .indexTexCoord[texCoordSet];
1236:
1237:                for (i = 0, j = index; i < num; i++, j++) {
1238:                    texCoordIndices[i] = indices[j];
1239:                }
1240:            }
1241:
1242:            /**
1243:             * Retrieves the vertex attribute index associated with the vertex at
1244:             * the specified index for the specified vertex attribute number
1245:             * for this object.
1246:             */
1247:            int getVertexAttrIndex(int vertexAttrNum, int index) {
1248:
1249:                int[] indices = this .indexVertexAttr[vertexAttrNum];
1250:
1251:                return indices[index];
1252:            }
1253:
1254:            /**
1255:             * Retrieves the vertex attribute indices associated with the vertices
1256:             * starting at the specified index for the specified vertex attribute number
1257:             * for this object.
1258:             */
1259:            void getVertexAttrIndices(int vertexAttrNum, int index,
1260:                    int[] vertexAttrIndices) {
1261:
1262:                int i, j, num = vertexAttrIndices.length;
1263:                int[] indices = this .indexVertexAttr[vertexAttrNum];
1264:
1265:                for (i = 0, j = index; i < num; i++, j++) {
1266:                    vertexAttrIndices[i] = indices[j];
1267:                }
1268:            }
1269:
1270:            void execute(Canvas3D cv, RenderAtom ra, boolean isNonUniformScale,
1271:                    boolean updateAlpha, float alpha, int screen,
1272:                    boolean ignoreVertexColors) {
1273:
1274:                int cdirty;
1275:                boolean useAlpha = false;
1276:                Object[] retVal;
1277:                if (mirrorGeometry != null) {
1278:                    mirrorGeometry.execute(cv, ra, isNonUniformScale,
1279:                            updateAlpha, alpha, screen, ignoreVertexColors);
1280:                    return;
1281:                }
1282:
1283:                // Check if index array is null; if yes, don't draw anything
1284:                if (indexCoord == null) {
1285:                    return;
1286:                }
1287:
1288:                //By reference with java array
1289:                if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) == 0) {
1290:                    if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
1291:                        float[] vdata;
1292:                        //	    System.err.println("by-copy");
1293:                        synchronized (this ) {
1294:                            cdirty = dirtyFlag;
1295:                            if (updateAlpha && !ignoreVertexColors) {
1296:                                // update the alpha values
1297:                                retVal = updateAlphaInVertexData(cv, screen,
1298:                                        alpha);
1299:                                useAlpha = (retVal[0] == Boolean.TRUE);
1300:                                vdata = (float[]) retVal[1];
1301:
1302:                                // D3D only
1303:                                if (alpha != lastScreenAlpha) {
1304:                                    // handle multiple screen case
1305:                                    lastScreenAlpha = alpha;
1306:                                    cdirty |= COLOR_CHANGED;
1307:                                }
1308:                            } else {
1309:                                vdata = vertexData;
1310:                                // if transparency switch between on/off
1311:                                if (lastScreenAlpha != -1) {
1312:                                    lastScreenAlpha = -1;
1313:                                    cdirty |= COLOR_CHANGED;
1314:                                }
1315:                            }
1316:                            // geomLock is get in MasterControl when
1317:                            // RenderBin render the geometry. So it is safe
1318:                            // just to set the dirty flag here
1319:                            dirtyFlag = 0;
1320:                        }
1321:
1322:                        Pipeline
1323:                                .getPipeline()
1324:                                .executeIndexedGeometry(
1325:                                        cv.ctx,
1326:                                        this ,
1327:                                        geoType,
1328:                                        isNonUniformScale,
1329:                                        useAlpha,
1330:                                        ignoreVertexColors,
1331:                                        initialIndexIndex,
1332:                                        validIndexCount,
1333:                                        // Vertex Count is maxCoordIndex + 1
1334:                                        maxCoordIndex + 1,
1335:                                        ((vertexFormat & GeometryArray.COLOR) != 0) ? (vertexFormat | GeometryArray.COLOR_4)
1336:                                                : vertexFormat,
1337:                                        vertexAttrCount,
1338:                                        vertexAttrSizes,
1339:                                        texCoordSetCount,
1340:                                        texCoordSetMap,
1341:                                        (texCoordSetMap == null) ? 0
1342:                                                : texCoordSetMap.length,
1343:                                        texCoordSetMapOffset,
1344:                                        cv.numActiveTexUnit, vdata, null,
1345:                                        cdirty, indexCoord);
1346:
1347:                    } // end of non by reference
1348:                    else if ((vertexFormat & GeometryArray.INTERLEAVED) != 0) {
1349:                        if (interLeavedVertexData == null)
1350:                            return;
1351:
1352:                        float[] cdata = null;
1353:
1354:                        synchronized (this ) {
1355:                            cdirty = dirtyFlag;
1356:                            if (updateAlpha && !ignoreVertexColors) {
1357:                                // update the alpha values
1358:                                retVal = updateAlphaInInterLeavedData(cv,
1359:                                        screen, alpha);
1360:                                useAlpha = (retVal[0] == Boolean.TRUE);
1361:                                cdata = (float[]) retVal[1];
1362:                                if (alpha != lastScreenAlpha) {
1363:                                    lastScreenAlpha = alpha;
1364:                                    cdirty |= COLOR_CHANGED;
1365:                                }
1366:                            } else {
1367:                                // if transparency switch between on/off
1368:                                if (lastScreenAlpha != -1) {
1369:                                    lastScreenAlpha = -1;
1370:                                    cdirty |= COLOR_CHANGED;
1371:                                }
1372:                            }
1373:                            dirtyFlag = 0;
1374:                        }
1375:
1376:                        Pipeline.getPipeline().executeIndexedGeometry(
1377:                                cv.ctx,
1378:                                this ,
1379:                                geoType,
1380:                                isNonUniformScale,
1381:                                useAlpha,
1382:                                ignoreVertexColors,
1383:                                initialIndexIndex,
1384:                                validIndexCount,
1385:                                maxCoordIndex + 1,
1386:                                vertexFormat,
1387:                                vertexAttrCount,
1388:                                vertexAttrSizes,
1389:                                texCoordSetCount,
1390:                                texCoordSetMap,
1391:                                (texCoordSetMap == null) ? 0
1392:                                        : texCoordSetMap.length,
1393:                                texCoordSetMapOffset, cv.numActiveTexUnit,
1394:                                interLeavedVertexData, cdata, cdirty,
1395:                                indexCoord);
1396:                    } //end of interleaved
1397:                    else {
1398:                        // Check if a vertexformat is set, but the array is null
1399:                        // if yes, don't draw anything
1400:                        if ((vertexType == 0)
1401:                                || ((vertexType & VERTEX_DEFINED) == 0)
1402:                                || (((vertexFormat & GeometryArray.COLOR) != 0) && (vertexType & COLOR_DEFINED) == 0)
1403:                                || (((vertexFormat & GeometryArray.NORMALS) != 0) && (vertexType & NORMAL_DEFINED) == 0)
1404:                                || (((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) && (vertexType & VATTR_DEFINED) == 0)
1405:                                || (((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) && (vertexType & TEXCOORD_DEFINED) == 0)) {
1406:                            return;
1407:                        } else {
1408:                            byte[] cbdata = null;
1409:                            float[] cfdata = null;
1410:
1411:                            if ((vertexType & (CF | C3F | C4F)) != 0) {
1412:                                synchronized (this ) {
1413:                                    cdirty = dirtyFlag;
1414:                                    if (updateAlpha && !ignoreVertexColors) {
1415:                                        cfdata = updateAlphaInFloatRefColors(
1416:                                                cv, screen, alpha);
1417:                                        if (alpha != lastScreenAlpha) {
1418:                                            lastScreenAlpha = alpha;
1419:                                            cdirty |= COLOR_CHANGED;
1420:                                        }
1421:                                    } else {
1422:                                        cfdata = mirrorFloatRefColors[0];
1423:                                        // if transparency switch between on/off
1424:                                        if (lastScreenAlpha != -1) {
1425:                                            lastScreenAlpha = -1;
1426:                                            cdirty |= COLOR_CHANGED;
1427:                                        }
1428:
1429:                                    }
1430:                                    dirtyFlag = 0;
1431:                                }
1432:                            } else if ((vertexType & (CUB | C3UB | C4UB)) != 0) {
1433:                                synchronized (this ) {
1434:                                    cdirty = dirtyFlag;
1435:                                    if (updateAlpha && !ignoreVertexColors) {
1436:                                        cbdata = updateAlphaInByteRefColors(cv,
1437:                                                screen, alpha);
1438:                                        if (alpha != lastScreenAlpha) {
1439:                                            lastScreenAlpha = alpha;
1440:                                            cdirty |= COLOR_CHANGED;
1441:                                        }
1442:                                    } else {
1443:                                        cbdata = mirrorUnsignedByteRefColors[0];
1444:                                        // if transparency switch between on/off
1445:                                        if (lastScreenAlpha != -1) {
1446:                                            lastScreenAlpha = -1;
1447:                                            cdirty |= COLOR_CHANGED;
1448:                                        }
1449:                                    }
1450:                                    dirtyFlag = 0;
1451:                                }
1452:                            } else {
1453:                                cdirty = dirtyFlag;
1454:                            }
1455:
1456:                            int vdefined = 0;
1457:                            if ((vertexType & (PF | P3F)) != 0)
1458:                                vdefined |= COORD_FLOAT;
1459:                            if ((vertexType & (PD | P3D)) != 0)
1460:                                vdefined |= COORD_DOUBLE;
1461:                            if ((vertexType & (CF | C3F | C4F)) != 0)
1462:                                vdefined |= COLOR_FLOAT;
1463:                            if ((vertexType & (CUB | C3UB | C4UB)) != 0)
1464:                                vdefined |= COLOR_BYTE;
1465:                            if ((vertexType & NORMAL_DEFINED) != 0)
1466:                                vdefined |= NORMAL_FLOAT;
1467:                            if ((vertexType & VATTR_DEFINED) != 0)
1468:                                vdefined |= VATTR_FLOAT;
1469:                            if ((vertexType & TEXCOORD_DEFINED) != 0)
1470:                                vdefined |= TEXCOORD_FLOAT;
1471:
1472:                            Pipeline.getPipeline().executeIndexedGeometryVA(
1473:                                    cv.ctx,
1474:                                    this ,
1475:                                    geoType,
1476:                                    isNonUniformScale,
1477:                                    ignoreVertexColors,
1478:                                    initialIndexIndex,
1479:                                    validIndexCount,
1480:                                    maxCoordIndex + 1,
1481:                                    (vertexFormat | c4fAllocated),
1482:                                    vdefined,
1483:                                    mirrorFloatRefCoords,
1484:                                    mirrorDoubleRefCoords,
1485:                                    cfdata,
1486:                                    cbdata,
1487:                                    mirrorFloatRefNormals,
1488:                                    vertexAttrCount,
1489:                                    vertexAttrSizes,
1490:                                    mirrorFloatRefVertexAttrs,
1491:                                    ((texCoordSetMap == null) ? 0
1492:                                            : texCoordSetMap.length),
1493:                                    texCoordSetMap, cv.numActiveTexUnit,
1494:                                    texCoordStride, mirrorRefTexCoords, cdirty,
1495:                                    indexCoord);
1496:                        }
1497:                    } // end of non interleaved and by reference
1498:                }//end of non io buffer
1499:
1500:                else {
1501:                    if ((vertexFormat & GeometryArray.INTERLEAVED) != 0) {
1502:                        if (interleavedFloatBufferImpl == null)
1503:                            return;
1504:
1505:                        float[] cdata = null;
1506:
1507:                        synchronized (this ) {
1508:                            cdirty = dirtyFlag;
1509:                            if (updateAlpha && !ignoreVertexColors) {
1510:                                // update the alpha values
1511:                                retVal = updateAlphaInInterLeavedData(cv,
1512:                                        screen, alpha);
1513:                                useAlpha = (retVal[0] == Boolean.TRUE);
1514:                                cdata = (float[]) retVal[1];
1515:                                if (alpha != lastScreenAlpha) {
1516:                                    lastScreenAlpha = alpha;
1517:                                    cdirty |= COLOR_CHANGED;
1518:                                }
1519:                            } else {
1520:                                // if transparency switch between on/off
1521:                                if (lastScreenAlpha != -1) {
1522:                                    lastScreenAlpha = -1;
1523:                                    cdirty |= COLOR_CHANGED;
1524:                                }
1525:                            }
1526:                            dirtyFlag = 0;
1527:                        }
1528:
1529:                        Pipeline.getPipeline().executeIndexedGeometryBuffer(
1530:                                cv.ctx,
1531:                                this ,
1532:                                geoType,
1533:                                isNonUniformScale,
1534:                                useAlpha,
1535:                                ignoreVertexColors,
1536:                                initialIndexIndex,
1537:                                validIndexCount,
1538:                                maxCoordIndex + 1,
1539:                                vertexFormat,
1540:                                texCoordSetCount,
1541:                                texCoordSetMap,
1542:                                (texCoordSetMap == null) ? 0
1543:                                        : texCoordSetMap.length,
1544:                                texCoordSetMapOffset, cv.numActiveTexUnit,
1545:                                interleavedFloatBufferImpl.getBufferAsObject(),
1546:                                cdata, cdirty, indexCoord);
1547:                    } //end of interleaved
1548:                    else {
1549:                        // Check if a vertexformat is set, but the array is null
1550:                        // if yes, don't draw anything
1551:                        if ((vertexType == 0)
1552:                                || ((vertexType & VERTEX_DEFINED) == 0)
1553:                                || (((vertexFormat & GeometryArray.COLOR) != 0) && (vertexType & COLOR_DEFINED) == 0)
1554:                                || (((vertexFormat & GeometryArray.NORMALS) != 0) && (vertexType & NORMAL_DEFINED) == 0)
1555:                                || (((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) && (vertexType & VATTR_DEFINED) == 0)
1556:                                || (((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) && (vertexType & TEXCOORD_DEFINED) == 0)) {
1557:                            return;
1558:                        } else {
1559:                            byte[] cbdata = null;
1560:                            float[] cfdata = null;
1561:
1562:                            if ((vertexType & CF) != 0) {
1563:                                synchronized (this ) {
1564:                                    cdirty = dirtyFlag;
1565:                                    if (updateAlpha && !ignoreVertexColors) {
1566:                                        cfdata = updateAlphaInFloatRefColors(
1567:                                                cv, screen, alpha);
1568:                                        if (alpha != lastScreenAlpha) {
1569:                                            lastScreenAlpha = alpha;
1570:                                            cdirty |= COLOR_CHANGED;
1571:                                        }
1572:                                    } else {
1573:                                        // XXXX: handle transparency case
1574:                                        //cfdata = null;
1575:                                        cfdata = mirrorFloatRefColors[0];
1576:                                        // if transparency switch between on/off
1577:                                        if (lastScreenAlpha != -1) {
1578:                                            lastScreenAlpha = -1;
1579:                                            cdirty |= COLOR_CHANGED;
1580:                                        }
1581:
1582:                                    }
1583:                                    dirtyFlag = 0;
1584:                                }
1585:                            } else if ((vertexType & CUB) != 0) {
1586:                                synchronized (this ) {
1587:                                    cdirty = dirtyFlag;
1588:                                    if (updateAlpha && !ignoreVertexColors) {
1589:                                        cbdata = updateAlphaInByteRefColors(cv,
1590:                                                screen, alpha);
1591:                                        if (alpha != lastScreenAlpha) {
1592:                                            lastScreenAlpha = alpha;
1593:                                            cdirty |= COLOR_CHANGED;
1594:                                        }
1595:                                    } else {
1596:                                        // XXXX: handle transparency case
1597:                                        // cbdata = null;
1598:                                        cbdata = mirrorUnsignedByteRefColors[0];
1599:                                        // if transparency switch between on/off
1600:                                        if (lastScreenAlpha != -1) {
1601:                                            lastScreenAlpha = -1;
1602:                                            cdirty |= COLOR_CHANGED;
1603:                                        }
1604:                                    }
1605:                                    dirtyFlag = 0;
1606:                                }
1607:                            } else {
1608:                                cdirty = dirtyFlag;
1609:                            }
1610:
1611:                            Object vcoord = null, cdataBuffer = null, normal = null;
1612:
1613:                            int vdefined = 0;
1614:                            if ((vertexType & PF) != 0) {
1615:                                vdefined |= COORD_FLOAT;
1616:                                vcoord = floatBufferRefCoords
1617:                                        .getBufferAsObject();
1618:                            } else if ((vertexType & PD) != 0) {
1619:                                vdefined |= COORD_DOUBLE;
1620:                                vcoord = doubleBufferRefCoords
1621:                                        .getBufferAsObject();
1622:                            }
1623:                            if ((vertexType & CF) != 0) {
1624:                                vdefined |= COLOR_FLOAT;
1625:                                cdataBuffer = floatBufferRefColors
1626:                                        .getBufferAsObject();
1627:                            } else if ((vertexType & CUB) != 0) {
1628:                                vdefined |= COLOR_BYTE;
1629:                                cdataBuffer = byteBufferRefColors
1630:                                        .getBufferAsObject();
1631:                            }
1632:
1633:                            if ((vertexType & NORMAL_DEFINED) != 0) {
1634:                                vdefined |= NORMAL_FLOAT;
1635:                                normal = floatBufferRefNormals
1636:                                        .getBufferAsObject();
1637:                            }
1638:
1639:                            if ((vertexType & VATTR_DEFINED) != 0) {
1640:                                vdefined |= VATTR_FLOAT;
1641:                            }
1642:
1643:                            if ((vertexType & TEXCOORD_DEFINED) != 0) {
1644:                                vdefined |= TEXCOORD_FLOAT;
1645:                            }
1646:
1647:                            Pipeline.getPipeline()
1648:                                    .executeIndexedGeometryVABuffer(
1649:                                            cv.ctx,
1650:                                            this ,
1651:                                            geoType,
1652:                                            isNonUniformScale,
1653:                                            ignoreVertexColors,
1654:                                            initialIndexIndex,
1655:                                            validIndexCount,
1656:                                            maxCoordIndex + 1,
1657:                                            (vertexFormat | c4fAllocated),
1658:                                            vdefined,
1659:                                            vcoord,
1660:                                            cdataBuffer,
1661:                                            cfdata,
1662:                                            cbdata,
1663:                                            normal,
1664:                                            vertexAttrCount,
1665:                                            vertexAttrSizes,
1666:                                            nioFloatBufferRefVertexAttrs,
1667:                                            ((texCoordSetMap == null) ? 0
1668:                                                    : texCoordSetMap.length),
1669:                                            texCoordSetMap,
1670:                                            cv.numActiveTexUnit,
1671:                                            texCoordStride, refTexCoords,
1672:                                            cdirty, indexCoord);
1673:
1674:                        }
1675:                    } // end of non interleaved and by reference
1676:                } // end of nio buffer
1677:            }
1678:
1679:            void buildGA(Canvas3D cv, RenderAtom ra, boolean isNonUniformScale,
1680:                    boolean updateAlpha, float alpha,
1681:                    boolean ignoreVertexColors, Transform3D xform,
1682:                    Transform3D nxform) {
1683:                int cdirty;
1684:                boolean useAlpha = false;
1685:                Object[] retVal;
1686:                if (mirrorGeometry != null) {
1687:                    ((GeometryArrayRetained) mirrorGeometry).buildGA(cv, ra,
1688:                            isNonUniformScale, updateAlpha, alpha,
1689:                            ignoreVertexColors, xform, nxform);
1690:                } else {
1691:
1692:                    if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {
1693:                        float[] vdata;
1694:                        //	    System.err.println("by-copy");
1695:                        synchronized (this ) {
1696:                            cdirty = dirtyFlag;
1697:                            if (updateAlpha && !ignoreVertexColors) {
1698:                                // update the alpha values
1699:                                retVal = updateAlphaInVertexData(cv,
1700:                                        cv.screen.screen, alpha);
1701:                                useAlpha = (retVal[0] == Boolean.TRUE);
1702:                                vdata = (float[]) retVal[1];
1703:
1704:                                // D3D only
1705:                                if (alpha != lastScreenAlpha) {
1706:                                    // handle multiple screen case
1707:                                    lastScreenAlpha = alpha;
1708:                                    cdirty |= COLOR_CHANGED;
1709:                                }
1710:                            } else {
1711:                                vdata = vertexData;
1712:                                // if transparency switch between on/off
1713:                                if (lastScreenAlpha != -1) {
1714:                                    lastScreenAlpha = -1;
1715:                                    cdirty |= COLOR_CHANGED;
1716:                                }
1717:                            }
1718:                            // geomLock is get in MasterControl when
1719:                            // RenderBin render the geometry. So it is safe
1720:                            // just to set the dirty flag here
1721:                            dirtyFlag = 0;
1722:                        }
1723:
1724:                        Pipeline.getPipeline().buildIndexedGeometry(
1725:                                cv.ctx,
1726:                                this ,
1727:                                geoType,
1728:                                isNonUniformScale,
1729:                                updateAlpha,
1730:                                alpha,
1731:                                ignoreVertexColors,
1732:                                initialIndexIndex,
1733:                                validIndexCount,
1734:                                maxCoordIndex + 1,
1735:                                vertexFormat,
1736:                                vertexAttrCount,
1737:                                vertexAttrSizes,
1738:                                texCoordSetCount,
1739:                                texCoordSetMap,
1740:                                (texCoordSetMap == null) ? 0
1741:                                        : texCoordSetMap.length,
1742:                                texCoordSetMapOffset,
1743:                                (xform == null) ? null : xform.mat,
1744:                                (nxform == null) ? null : nxform.mat, vdata,
1745:                                indexCoord);
1746:                    }
1747:                    // XXXX: Note that there is no "else" clause here, and no
1748:                    // buildIndexedGeometryForByRef() method.
1749:                    // We would need to create one if we ever wanted to support by-ref
1750:                    // indexed geometry in display lists. Better yet, we could fix
1751:                    // canBeInDisplayList so that unindexified by-ref geometry could
1752:                    // go into a display list.
1753:                }
1754:            }
1755:
1756:            void mergeGeometryArrays(ArrayList list) {
1757:                int numMerge = list.size();
1758:                int[] texCoord = null;
1759:                indexCount = 0;
1760:                for (int i = 0; i < numMerge; i++) {
1761:                    IndexedGeometryArrayRetained geo = (IndexedGeometryArrayRetained) list
1762:                            .get(i);
1763:                    indexCount += geo.validIndexCount;
1764:                }
1765:                validIndexCount = indexCount;
1766:                initialIndexIndex = 0;
1767:                compileIndexCount = new int[numMerge];
1768:                compileIndexOffset = new int[numMerge];
1769:                indexCoord = new int[indexCount];
1770:                boolean notUCIO = (vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0;
1771:                if (notUCIO) {
1772:                    if ((vertexFormat & GeometryArray.COLOR) != 0)
1773:                        indexColor = new int[indexCount];
1774:                    if ((vertexFormat & GeometryArray.NORMALS) != 0)
1775:                        indexNormal = new int[indexCount];
1776:                    // We only merge if the texCoordSetCount is 1 and there are no
1777:                    // vertex attrs
1778:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
1779:                        indexTexCoord = new int[1][];
1780:                        indexTexCoord[0] = new int[indexCount];
1781:                        texCoord = indexTexCoord[0];
1782:                    }
1783:                }
1784:                int curDataOffset = 0;
1785:                int curIndexOffset = 0;
1786:                for (int i = 0; i < numMerge; i++) {
1787:                    IndexedGeometryArrayRetained geo = (IndexedGeometryArrayRetained) list
1788:                            .get(i);
1789:                    int curIndexCount = geo.validIndexCount;
1790:                    compileIndexCount[i] = curIndexCount;
1791:                    // Copy all the indices
1792:                    for (int j = 0; j < curIndexCount; j++) {
1793:                        indexCoord[j + curIndexOffset] = geo.indexCoord[j
1794:                                + geo.initialIndexIndex]
1795:                                + curDataOffset;
1796:                        if (notUCIO) {
1797:                            if ((vertexFormat & GeometryArray.COLOR) != 0)
1798:                                indexColor[j + curIndexOffset] = geo.indexColor[j
1799:                                        + geo.initialIndexIndex]
1800:                                        + curDataOffset;
1801:                            if ((vertexFormat & GeometryArray.NORMALS) != 0)
1802:                                indexNormal[j + curIndexOffset] = geo.indexNormal[j
1803:                                        + geo.initialIndexIndex]
1804:                                        + curDataOffset;
1805:                            if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0)
1806:                                texCoord[j + curIndexOffset] = geo.indexTexCoord[0][j
1807:                                        + geo.initialIndexIndex]
1808:                                        + curDataOffset;
1809:                        }
1810:                    }
1811:                    maxCoordIndex = geo.maxCoordIndex + curDataOffset;
1812:                    compileIndexOffset[i] = curIndexOffset;
1813:                    curDataOffset += geo.vertexCount;
1814:                    curIndexOffset += curIndexCount;
1815:                }
1816:                // reset the max Values
1817:
1818:                // call the super to merge the vertex data
1819:                super .mergeGeometryArrays(list);
1820:            }
1821:
1822:            boolean isWriteStatic() {
1823:
1824:                if (!super .isWriteStatic()
1825:                        || source
1826:                                .getCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_WRITE)
1827:                        || source
1828:                                .getCapability(IndexedGeometryArray.ALLOW_COLOR_INDEX_WRITE)
1829:                        || source
1830:                                .getCapability(IndexedGeometryArray.ALLOW_NORMAL_INDEX_WRITE)
1831:                        || source
1832:                                .getCapability(IndexedGeometryArray.ALLOW_VERTEX_ATTR_INDEX_WRITE)
1833:                        || source
1834:                                .getCapability(IndexedGeometryArray.ALLOW_TEXCOORD_INDEX_WRITE)) {
1835:                    return false;
1836:                }
1837:
1838:                return true;
1839:            }
1840:
1841:            /**
1842:             * Gets current number of indices
1843:             * @return indexCount
1844:             */
1845:            int getIndexCount(int id) {
1846:                return compileIndexCount[id];
1847:            }
1848:
1849:            int computeMaxIndex(int initial, int count, int[] indices) {
1850:                int maxIndex = 0;
1851:                if (indices != null) {
1852:                    for (int i = initial; i < (initial + count); i++) {
1853:                        if (indices[i] > maxIndex) {
1854:                            maxIndex = indices[i];
1855:                        }
1856:                    }
1857:                }
1858:                return maxIndex;
1859:
1860:            }
1861:
1862:            //NVaidya
1863:            // same as computeMaxIndex method but checks for index < 0
1864:            int computeMaxIndexWithCheck(int initial, int count, int[] indices) {
1865:                int maxIndex = 0;
1866:                for (int i = initial; i < (initial + count); i++) {
1867:                    // Throw an exception, since index is negative
1868:                    if (indices[i] < 0)
1869:                        throw new ArrayIndexOutOfBoundsException(J3dI18N
1870:                                .getString("IndexedGeometryArray27"));
1871:                    if (indices[i] > maxIndex) {
1872:                        maxIndex = indices[i];
1873:                    }
1874:                }
1875:                return maxIndex;
1876:
1877:            }
1878:
1879:            void setValidIndexCount(int validIndexCount) {
1880:                if (validIndexCount < 0) {
1881:                    throw new IllegalArgumentException(J3dI18N
1882:                            .getString("IndexedGeometryArray21"));
1883:                }
1884:                if ((initialIndexIndex + validIndexCount) > indexCount) {
1885:                    throw new IllegalArgumentException(J3dI18N
1886:                            .getString("IndexedGeometryArray22"));
1887:                }
1888:                if ((vertexFormat & GeometryArray.BY_REFERENCE_INDICES) != 0) {
1889:                    if (indexCoord != null
1890:                            && indexCoord.length < initialIndexIndex
1891:                                    + validIndexCount) {
1892:                        throw new IllegalArgumentException(J3dI18N
1893:                                .getString("IndexedGeometryArray33"));
1894:                    }
1895:                }
1896:                int newCoordMax = 0;
1897:                int newColorIndex = 0;
1898:                int newNormalIndex = 0;
1899:                int[] newTexCoordIndex = null;
1900:                int[] newVertexAttrIndex = null;
1901:
1902:                newCoordMax = computeMaxIndex(initialIndexIndex,
1903:                        validIndexCount, indexCoord);
1904:                doErrorCheck(newCoordMax);
1905:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
1906:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
1907:                        newColorIndex = computeMaxIndex(initialIndexIndex,
1908:                                validIndexCount, indexColor);
1909:                        doColorCheck(newColorIndex);
1910:                    }
1911:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
1912:                        newTexCoordIndex = new int[texCoordSetCount];
1913:                        for (int i = 0; i < texCoordSetCount; i++) {
1914:                            newTexCoordIndex[i] = computeMaxIndex(
1915:                                    initialIndexIndex, validIndexCount,
1916:                                    indexTexCoord[i]);
1917:                            doTexCoordCheck(newTexCoordIndex[i], i);
1918:                        }
1919:                    }
1920:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
1921:                        newVertexAttrIndex = new int[vertexAttrCount];
1922:                        for (int i = 0; i < vertexAttrCount; i++) {
1923:                            newVertexAttrIndex[i] = computeMaxIndex(
1924:                                    initialIndexIndex, validIndexCount,
1925:                                    indexVertexAttr[i]);
1926:                            doVertexAttrCheck(newVertexAttrIndex[i], i);
1927:                        }
1928:                    }
1929:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
1930:                        newNormalIndex = computeMaxIndex(initialIndexIndex,
1931:                                validIndexCount, indexNormal);
1932:                        doNormalCheck(newNormalIndex);
1933:                    }
1934:                }
1935:
1936:                boolean isLive = source != null && source.isLive();
1937:                if (isLive) {
1938:                    geomLock.getLock();
1939:                }
1940:                this .validIndexCount = validIndexCount;
1941:                maxCoordIndex = newCoordMax;
1942:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
1943:                    maxColorIndex = newColorIndex;
1944:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
1945:                        for (int i = 0; i < texCoordSetCount; i++) {
1946:                            maxTexCoordIndices[i] = newTexCoordIndex[i];
1947:                        }
1948:                    }
1949:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
1950:                        for (int i = 0; i < vertexAttrCount; i++) {
1951:                            maxVertexAttrIndices[i] = newVertexAttrIndex[i];
1952:                        }
1953:                    }
1954:                    maxNormalIndex = newNormalIndex;
1955:                } else {
1956:                    maxColorIndex = maxCoordIndex;
1957:                    maxNormalIndex = maxCoordIndex;
1958:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
1959:                        for (int i = 0; i < texCoordSetCount; i++) {
1960:                            maxTexCoordIndices[i] = maxCoordIndex;
1961:                        }
1962:                    }
1963:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
1964:                        for (int i = 0; i < vertexAttrCount; i++) {
1965:                            maxVertexAttrIndices[i] = maxCoordIndex;
1966:                        }
1967:                    }
1968:                }
1969:                if (isLive) {
1970:                    geomLock.unLock();
1971:                }
1972:                // bbox is computed for the entries list.
1973:                // so, send as false
1974:                if (!inUpdater && isLive) {
1975:                    sendDataChangedMessage(true);
1976:                }
1977:
1978:            }
1979:
1980:            void setInitialIndexIndex(int initialIndexIndex) {
1981:                if ((initialIndexIndex + validIndexCount) > indexCount) {
1982:                    throw new IllegalArgumentException(J3dI18N
1983:                            .getString("IndexedGeometryArray22"));
1984:                }
1985:                if ((vertexFormat & GeometryArray.BY_REFERENCE_INDICES) != 0) {
1986:                    if (indexCoord != null
1987:                            && indexCoord.length < initialIndexIndex
1988:                                    + validIndexCount) {
1989:                        throw new IllegalArgumentException(J3dI18N
1990:                                .getString("IndexedGeometryArray33"));
1991:                    }
1992:                }
1993:
1994:                int newCoordMax = 0;
1995:                int newColorIndex = 0;
1996:                int newNormalIndex = 0;
1997:                int[] newTexCoordIndex = null;
1998:                int[] newVertexAttrIndex = null;
1999:
2000:                newCoordMax = computeMaxIndex(initialIndexIndex,
2001:                        validIndexCount, indexCoord);
2002:                doErrorCheck(newCoordMax);
2003:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
2004:                    if ((vertexFormat & GeometryArray.COLOR) != 0) {
2005:                        newColorIndex = computeMaxIndex(initialIndexIndex,
2006:                                validIndexCount, indexColor);
2007:                        doColorCheck(newColorIndex);
2008:                    }
2009:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
2010:                        newTexCoordIndex = new int[texCoordSetCount];
2011:                        for (int i = 0; i < texCoordSetCount; i++) {
2012:                            newTexCoordIndex[i] = computeMaxIndex(
2013:                                    initialIndexIndex, validIndexCount,
2014:                                    indexTexCoord[i]);
2015:                            doTexCoordCheck(newTexCoordIndex[i], i);
2016:                        }
2017:                    }
2018:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
2019:                        newVertexAttrIndex = new int[vertexAttrCount];
2020:                        for (int i = 0; i < vertexAttrCount; i++) {
2021:                            newVertexAttrIndex[i] = computeMaxIndex(
2022:                                    initialIndexIndex, validIndexCount,
2023:                                    indexVertexAttr[i]);
2024:                            doVertexAttrCheck(newVertexAttrIndex[i], i);
2025:                        }
2026:                    }
2027:                    if ((vertexFormat & GeometryArray.NORMALS) != 0) {
2028:                        newNormalIndex = computeMaxIndex(initialIndexIndex,
2029:                                validIndexCount, indexNormal);
2030:                        doNormalCheck(newNormalIndex);
2031:                    }
2032:                }
2033:
2034:                boolean isLive = source != null && source.isLive();
2035:                if (isLive) {
2036:                    geomLock.getLock();
2037:                }
2038:                dirtyFlag |= INDEX_CHANGED;
2039:                this .initialIndexIndex = initialIndexIndex;
2040:                maxCoordIndex = newCoordMax;
2041:                if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
2042:                    maxColorIndex = newColorIndex;
2043:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
2044:                        for (int i = 0; i < texCoordSetCount; i++) {
2045:                            maxTexCoordIndices[i] = newTexCoordIndex[i];
2046:                        }
2047:                    }
2048:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
2049:                        for (int i = 0; i < vertexAttrCount; i++) {
2050:                            maxVertexAttrIndices[i] = newVertexAttrIndex[i];
2051:                        }
2052:                    }
2053:                    maxNormalIndex = newNormalIndex;
2054:                } else {
2055:                    maxColorIndex = maxCoordIndex;
2056:                    maxNormalIndex = maxCoordIndex;
2057:                    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) {
2058:                        for (int i = 0; i < texCoordSetCount; i++) {
2059:                            maxTexCoordIndices[i] = maxCoordIndex;
2060:                        }
2061:                    }
2062:                    if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) {
2063:                        for (int i = 0; i < vertexAttrCount; i++) {
2064:                            maxVertexAttrIndices[i] = maxCoordIndex;
2065:                        }
2066:                    }
2067:                }
2068:                if (isLive) {
2069:                    geomLock.unLock();
2070:                }
2071:                // bbox is computed for the entries list.
2072:                // so, send as false
2073:                if (!inUpdater && isLive) {
2074:                    sendDataChangedMessage(true);
2075:                }
2076:            }
2077:
2078:            int getInitialIndexIndex() {
2079:                return initialIndexIndex;
2080:            }
2081:
2082:            int getValidIndexCount() {
2083:                return validIndexCount;
2084:            }
2085:
2086:            void handleFrequencyChange(int bit) {
2087:                if ((bit == IndexedGeometryArray.ALLOW_COORDINATE_INDEX_WRITE)
2088:                        || (((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0)
2089:                                && ((vertexFormat & GeometryArray.COLOR) != 0) && bit == IndexedGeometryArray.ALLOW_COLOR_INDEX_WRITE)
2090:                        || (((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0)
2091:                                && ((vertexFormat & GeometryArray.NORMALS) != 0) && bit == IndexedGeometryArray.ALLOW_NORMAL_INDEX_WRITE)
2092:                        || (((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0)
2093:                                && ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) && bit == IndexedGeometryArray.ALLOW_VERTEX_ATTR_INDEX_WRITE)
2094:                        || (((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0)
2095:                                && ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) && bit == IndexedGeometryArray.ALLOW_TEXCOORD_INDEX_WRITE)) {
2096:
2097:                    setFrequencyChangeMask(bit, 0x1);
2098:                } else {
2099:                    super.handleFrequencyChange(bit);
2100:                }
2101:            }
2102:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.