Source Code Cross Referenced for J3DBuffer.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) 


001:        /*
002:         * $RCSfile: J3DBuffer.java,v $
003:         *
004:         * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006:         *
007:         * This code is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU General Public License version 2 only, as
009:         * published by the Free Software Foundation.  Sun designates this
010:         * particular file as subject to the "Classpath" exception as provided
011:         * by Sun in the LICENSE file that accompanied this code.
012:         *
013:         * This code is distributed in the hope that it will be useful, but WITHOUT
014:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:         * version 2 for more details (a copy is included in the LICENSE file that
017:         * accompanied this code).
018:         *
019:         * You should have received a copy of the GNU General Public License version
020:         * 2 along with this work; if not, write to the Free Software Foundation,
021:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022:         *
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024:         * CA 95054 USA or visit www.sun.com if you need additional information or
025:         * have any questions.
026:         *
027:         * $Revision: 1.7 $
028:         * $Date: 2008/02/28 20:17:25 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import com.sun.j3d.internal.ByteBufferWrapper;
035:        import com.sun.j3d.internal.BufferWrapper;
036:        import com.sun.j3d.internal.FloatBufferWrapper;
037:        import com.sun.j3d.internal.DoubleBufferWrapper;
038:        import com.sun.j3d.internal.ByteOrderWrapper;
039:
040:        /**
041:         * Java 3D wrapper class for java.nio.Buffer objects.
042:         * When used to wrap a non-null NIO buffer object, this class will
043:         * create a read-only view of the wrapped NIO buffer, and will call
044:         * <code>rewind</code> on the read-only view, so that elements 0
045:         * through <code>buffer.limit()-1</code> will be available internally.
046:         *
047:         * @see GeometryArray#setCoordRefBuffer(J3DBuffer)
048:         * @see GeometryArray#setColorRefBuffer(J3DBuffer)
049:         * @see GeometryArray#setNormalRefBuffer(J3DBuffer)
050:         * @see GeometryArray#setTexCoordRefBuffer(int,J3DBuffer)
051:         * @see GeometryArray#setVertexAttrRefBuffer(int,J3DBuffer)
052:         * @see GeometryArray#setInterleavedVertexBuffer(J3DBuffer)
053:         * @see CompressedGeometry#CompressedGeometry(CompressedGeometryHeader,J3DBuffer)
054:         *
055:         * @since Java 3D 1.3
056:         */
057:
058:        public class J3DBuffer {
059:            static final int TYPE_NULL = 0;
060:            static final int TYPE_UNKNOWN = 1;
061:            static final int TYPE_BYTE = 2;
062:            static final int TYPE_CHAR = 3;
063:            static final int TYPE_SHORT = 4;
064:            static final int TYPE_INT = 5;
065:            static final int TYPE_LONG = 6;
066:            static final int TYPE_FLOAT = 7;
067:            static final int TYPE_DOUBLE = 8;
068:
069:            static boolean unsupportedOperation = false;
070:
071:            private java.nio.Buffer originalBuffer = null;
072:            private BufferWrapper bufferImpl = null;
073:            private int bufferType = TYPE_NULL;
074:
075:            /**
076:             * Constructs a J3DBuffer object and initializes it with
077:             * a null NIO buffer object.  The NIO buffer object
078:             * must be set to a non-null value before using this J3DBuffer
079:             * object in a Java 3D node component.
080:             *
081:             * @exception UnsupportedOperationException if the JVM does not
082:             * support native access to direct NIO buffers
083:             */
084:            public J3DBuffer() {
085:                this (null);
086:            }
087:
088:            /**
089:             * Constructs a J3DBuffer object and initializes it with
090:             * the specified NIO buffer object.
091:             *
092:             * @param buffer the NIO buffer wrapped by this J3DBuffer
093:             *
094:             * @exception UnsupportedOperationException if the JVM does not
095:             * support native access to direct NIO buffers
096:             *
097:             * @exception IllegalArgumentException if the specified buffer is
098:             * not a direct buffer, or if the byte order of the specified
099:             * buffer does not match the native byte order of the underlying
100:             * platform.
101:             */
102:            public J3DBuffer(java.nio.Buffer buffer) {
103:                if (unsupportedOperation)
104:                    throw new UnsupportedOperationException(J3dI18N
105:                            .getString("J3DBuffer0"));
106:
107:                setBuffer(buffer);
108:            }
109:
110:            /**
111:             * Sets the NIO buffer object in this J3DBuffer to
112:             * the specified object.
113:             *
114:             * @param buffer the NIO buffer wrapped by this J3DBuffer
115:             *
116:             * @exception IllegalArgumentException if the specified buffer is
117:             * not a direct buffer, or if the byte order of the specified
118:             * buffer does not match the native byte order of the underlying
119:             * platform.
120:             */
121:            public void setBuffer(java.nio.Buffer buffer) {
122:                int bType = TYPE_NULL;
123:                boolean direct = false;
124:                java.nio.ByteOrder order = java.nio.ByteOrder.BIG_ENDIAN;
125:
126:                if (buffer == null) {
127:                    bType = TYPE_NULL;
128:                } else if (buffer instanceof  java.nio.ByteBuffer) {
129:                    bType = TYPE_BYTE;
130:                    direct = ((java.nio.ByteBuffer) buffer).isDirect();
131:                    order = ((java.nio.ByteBuffer) buffer).order();
132:                } else if (buffer instanceof  java.nio.CharBuffer) {
133:                    bType = TYPE_CHAR;
134:                    direct = ((java.nio.CharBuffer) buffer).isDirect();
135:                    order = ((java.nio.CharBuffer) buffer).order();
136:                } else if (buffer instanceof  java.nio.ShortBuffer) {
137:                    bType = TYPE_SHORT;
138:                    direct = ((java.nio.ShortBuffer) buffer).isDirect();
139:                    order = ((java.nio.ShortBuffer) buffer).order();
140:                } else if (buffer instanceof  java.nio.IntBuffer) {
141:                    bType = TYPE_INT;
142:                    direct = ((java.nio.IntBuffer) buffer).isDirect();
143:                    order = ((java.nio.IntBuffer) buffer).order();
144:                } else if (buffer instanceof  java.nio.LongBuffer) {
145:                    bType = TYPE_LONG;
146:                    direct = ((java.nio.LongBuffer) buffer).isDirect();
147:                    order = ((java.nio.LongBuffer) buffer).order();
148:                } else if (buffer instanceof  java.nio.FloatBuffer) {
149:                    bType = TYPE_FLOAT;
150:                    direct = ((java.nio.FloatBuffer) buffer).isDirect();
151:                    order = ((java.nio.FloatBuffer) buffer).order();
152:                } else if (buffer instanceof  java.nio.DoubleBuffer) {
153:                    bType = TYPE_DOUBLE;
154:                    direct = ((java.nio.DoubleBuffer) buffer).isDirect();
155:                    order = ((java.nio.DoubleBuffer) buffer).order();
156:                } else {
157:                    bType = TYPE_UNKNOWN;
158:                }
159:
160:                // Verify that the buffer is direct and has the correct byte order
161:                if (buffer != null) {
162:                    if (!direct) {
163:                        throw new IllegalArgumentException(J3dI18N
164:                                .getString("J3DBuffer1"));
165:                    }
166:
167:                    if (order != java.nio.ByteOrder.nativeOrder()) {
168:                        throw new IllegalArgumentException(J3dI18N
169:                                .getString("J3DBuffer2"));
170:                    }
171:                }
172:
173:                bufferType = bType;
174:                originalBuffer = buffer;
175:
176:                // Make a read-only view of the buffer if the type is one
177:                // of the internally supported types: byte, float, or double
178:                switch (bufferType) {
179:                case TYPE_BYTE:
180:                    java.nio.ByteBuffer byteBuffer = ((java.nio.ByteBuffer) buffer)
181:                            .asReadOnlyBuffer();
182:                    byteBuffer.rewind();
183:                    bufferImpl = new ByteBufferWrapper(byteBuffer);
184:                    break;
185:                case TYPE_FLOAT:
186:                    java.nio.FloatBuffer floatBuffer = ((java.nio.FloatBuffer) buffer)
187:                            .asReadOnlyBuffer();
188:                    floatBuffer.rewind();
189:                    bufferImpl = new FloatBufferWrapper(floatBuffer);
190:                    break;
191:                case TYPE_DOUBLE:
192:                    java.nio.DoubleBuffer doubleBuffer = ((java.nio.DoubleBuffer) buffer)
193:                            .asReadOnlyBuffer();
194:                    doubleBuffer.rewind();
195:                    bufferImpl = new DoubleBufferWrapper(doubleBuffer);
196:                    break;
197:                default:
198:                    bufferImpl = null;
199:                }
200:            }
201:
202:            /**
203:             * Retrieves the NIO buffer object from this J3DBuffer.
204:             *
205:             * @return the current NIO buffer wrapped by this J3DBuffer
206:             */
207:            public java.nio.Buffer getBuffer() {
208:                return originalBuffer;
209:            }
210:
211:            int getBufferType() {
212:                return bufferType;
213:            }
214:
215:            BufferWrapper getBufferImpl() {
216:                return bufferImpl;
217:            }
218:
219:            private static boolean checkNativeBufferAccess(
220:                    java.nio.Buffer buffer) {
221:                if (buffer == null /*|| !Pipeline.getPipeline().checkNativeBufferAccess(buffer)*/) {
222:                    return false;
223:                } else {
224:                    return true;
225:                }
226:            }
227:
228:            static {
229:                // Allocate a direct byte buffer and verify that we can
230:                // access the data pointer from native code
231:                java.nio.ByteBuffer buffer = java.nio.ByteBuffer
232:                        .allocateDirect(8);
233:
234:                if (!checkNativeBufferAccess(buffer)) {
235:                    unsupportedOperation = true;
236:                }
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.