changeset 3651:ad014e2245f6

Fix to RT-30448: FX 8 3D: Change Mesh's indexBuffer type from unsigned int to unsigned short Reviewed by Dave and Kevin
author Chien Yang <chien.yang@orcale.com>
date Tue, 21 May 2013 17:30:13 -0700
parents 9134051bb8fb
children a702113db3bb db64797fc2eb
files javafx-ui-common/src/javafx/scene/shape/TriangleMesh.java prism-common/src/com/sun/prism/impl/BaseMesh.java prism-d3d-native/src/D3DContext.cc prism-d3d-native/src/D3DMesh.cc prism-d3d-native/src/D3DMesh.h prism-d3d/src/com/sun/prism/d3d/D3DContext.java prism-d3d/src/com/sun/prism/d3d/D3DMesh.java prism-es2-native/src/GLContext.c prism-es2/src/com/sun/prism/es2/ES2Context.java prism-es2/src/com/sun/prism/es2/ES2Mesh.java prism-es2/src/com/sun/prism/es2/GLContext.java
diffstat 11 files changed, 48 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/shape/TriangleMesh.java	Tue May 21 13:54:04 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/shape/TriangleMesh.java	Tue May 21 17:30:13 2013 -0700
@@ -76,6 +76,20 @@
  * where p0, p1, p2 and p3 are indices into the points array, and t0, t1, t2
  * and t3 are indices into the texCoords array.
  * 
+ * <p> The maximum number of vertices in the mesh can not exceed 65536.
+ * Therefore the maximum array lengths are 65536 * 3 (x, y, z per point) for points,
+ * and 65536 * 2 (u, v per texture coordinate) for texCoords. 
+ * The length of {@code points}, {@code texCoords}, and {@code faces} must be
+ * divisible by 3, 2, and 6 respectively.
+ * The values in the faces array must be within the range of the number of vertices
+ * in the points array (0 to points.length / 3 - 1) for the point indices and 
+ * within the range of the number of the vertices in 
+ * the texCoords array (0 to texCoords.length / 2 - 1) for the texture coordinate indices.
+ * 
+ * <p> A warning will be recorded to the logger and the mesh will not be rendered
+ * (and will have an empty bounds) if any of the array lengths are invalid
+ * or if any of the values in the faces array are out of range.
+ * 
  * @since JavaFX 8
  */
 public class TriangleMesh extends Mesh {
@@ -84,6 +98,12 @@
     public static final int NUM_COMPONENTS_PER_TEXCOORD = 2;
     public static final int NUM_COMPONENTS_PER_FACE = 6;
 
+    // TODO: 3D - Need to validate the size and range of these arrays.
+    // A warning will be recorded to the logger and the mesh will have an empty
+    // bounds if the validation failed. (RT-30451)
+    // The maximum length for points (65536 * 3), texCoords (65536 * 2)
+    // or faces (65536 * 6) arrays. The values in faces must be within range.
+    // The length of points, texCoords and faces must be divisible by 3, 2 and 6 respectively.
     private final ObservableFloatArray points = FXCollections.observableFloatArray();
     private final ObservableFloatArray texCoords = FXCollections.observableFloatArray();
     private final ObservableIntegerArray faces = FXCollections.observableIntegerArray();
@@ -133,7 +153,7 @@
      * 6 integers p0, t0, p1, t1, p3, t3, where p0, p1 and p2 are indices of 
      * points in points {@code ObservableFloatArray} and t0, t1 and t2 are 
      * indices of texture coordinates in texCoords {@code ObservableFloatArray}.
-     * Both indices are in terms of elements (points or textCoords), not individual
+     * Both indices are in terms of vertices (points or texCoords), not individual
      * floats.
      */    
     public ObservableIntegerArray getFaces() {
@@ -148,7 +168,7 @@
      * between adjacent faces.
      *
      * <p> The face smoothing group is represented by an array of bits and up to
-     * 32 unique groups is possible; (1 <<  0) to (1 << 31). The face smoothing
+     * 32 unique groups is possible; (1 << 0) to (1 << 31). The face smoothing
      * group value can range from 0 (no smoothing group) to all 32 groups. A face
      * can belong to zero or more smoothing groups. A face is a member of group
      * N if bit N is set, for example, groups |= (1 << N). A value of 0 implies
--- a/prism-common/src/com/sun/prism/impl/BaseMesh.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-common/src/com/sun/prism/impl/BaseMesh.java	Tue May 21 17:30:13 2013 -0700
@@ -115,15 +115,15 @@
         }
     }
 
-    void copyIndices(int pi[]) {
+    void copyIndices(short pi[]) {
         int nf = meshNormal.getNumFaces();
         int face[] = new int[3];
         int index = 0;
         for (int i = 0; i != nf; ++i) {
             face = meshNormal.getFace(i, face);
-            pi[index++] = face[0];
-            pi[index++] = face[1];
-            pi[index++] = face[2];
+            pi[index++] = (short) face[0];
+            pi[index++] = (short) face[1];
+            pi[index++] = (short) face[2];
         }
     }
 
@@ -142,9 +142,9 @@
         return vertexBuffer;
     }
 
-    final protected int[] getIndexGM() {
+    final protected short[] getIndexGM() {
         int numIndices = getNIndicesGM();
-        int indexBuffer[] = new int[numIndices];
+        short indexBuffer[] = new short[numIndices];
         copyIndices(indexBuffer);
         return indexBuffer;
     }
--- a/prism-d3d-native/src/D3DContext.cc	Tue May 21 13:54:04 2013 -0700
+++ b/prism-d3d-native/src/D3DContext.cc	Tue May 21 17:30:13 2013 -0700
@@ -209,15 +209,15 @@
  * Signature: (JJ[F[I)Z
  */
 JNIEXPORT jboolean JNICALL Java_com_sun_prism_d3d_D3DContext_nBuildNativeGeometry
-  (JNIEnv *env, jclass, jlong ctx, jlong nativeMesh, jfloatArray vb, jintArray ib)
+  (JNIEnv *env, jclass, jlong ctx, jlong nativeMesh, jfloatArray vb, jshortArray ib)
 {
     TraceLn(NWT_TRACE_INFO, "D3DContext_nBuildNativeGeometry");
     D3DMesh *mesh = (D3DMesh *) jlong_to_ptr(nativeMesh);
 
     UINT vertexBufferSize = env->GetArrayLength(vb);
-    float *vertexBuffer = (jfloat*) (env->GetPrimitiveArrayCritical(vb, NULL));
+    float *vertexBuffer = (float *) (env->GetPrimitiveArrayCritical(vb, NULL));
     UINT indexBufferSize = env->GetArrayLength(ib);
-    UINT *indexBuffer = (UINT*) (env->GetPrimitiveArrayCritical(ib, NULL));
+    USHORT *indexBuffer = (USHORT *) (env->GetPrimitiveArrayCritical(ib, NULL));
 
     boolean result = mesh->buildBuffers(vertexBuffer, vertexBufferSize,
             indexBuffer, indexBufferSize);
--- a/prism-d3d-native/src/D3DMesh.cc	Tue May 21 13:54:04 2013 -0700
+++ b/prism-d3d-native/src/D3DMesh.cc	Tue May 21 17:30:13 2013 -0700
@@ -90,7 +90,7 @@
 
 }
 
-boolean D3DMesh::buildBuffers(float *vb, UINT vbSize, UINT *ib, UINT ibSize) {
+boolean D3DMesh::buildBuffers(float *vb, UINT vbSize, USHORT *ib, UINT ibSize) {
 //    cout << "D3DMesh::buildBuffers: vertexBufferSize = " << vbSize
 //            << ", indexBufferSize = " << ibSize << endl;
 
@@ -111,12 +111,11 @@
 //    printResult("D3DMesh.buildBuffers: VertexBuffer's result = ", result);
 
     if (SUCCEEDED(result)) {
-        size = ibSize * sizeof (UINT);
+        size = ibSize * sizeof (USHORT);
         result = device->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY,
-                sizeof (UINT) == 2 ? D3DFMT_INDEX16 : sizeof (UINT) == 4 ? D3DFMT_INDEX32 : D3DFMT_UNKNOWN,
-                D3DPOOL_DEFAULT, &indexBuffer, NULL);
+                D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, NULL);
         if (SUCCEEDED(result)) {
-            int *data;
+            USHORT *data;
             result = indexBuffer->Lock(0, size, (void **) &data, 0);
             if (SUCCEEDED(result)) {
                 memcpy_s(data, size, ib, size);
--- a/prism-d3d-native/src/D3DMesh.h	Tue May 21 13:54:04 2013 -0700
+++ b/prism-d3d-native/src/D3DMesh.h	Tue May 21 17:30:13 2013 -0700
@@ -40,7 +40,7 @@
     D3DMesh(D3DContext *pCtx);
     virtual ~D3DMesh();
     boolean buildBuffers(float *vertexBuffer, UINT vertexBufferSize,
-            UINT *indexBuffer, UINT indexBufferSize);
+            USHORT *indexBuffer, UINT indexBufferSize);
     DWORD getVertexFVF();
     IDirect3DIndexBuffer9 *getIndexBuffer();
     IDirect3DVertexBuffer9 *getVertexBuffer();
--- a/prism-d3d/src/com/sun/prism/d3d/D3DContext.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-d3d/src/com/sun/prism/d3d/D3DContext.java	Tue May 21 17:30:13 2013 -0700
@@ -358,7 +358,7 @@
     private static native long nCreateD3DMesh(long pContext);
     private static native void nReleaseD3DMesh(long pContext, long nativeHandle);
     private static native boolean nBuildNativeGeometry(long pContext, long nativeHandle,
-            float vertexBuffer[], int indexBuffer[]);
+            float vertexBuffer[], short indexBuffer[]);
     private static native long nCreateD3DPhongMaterial(long pContext);
     private static native void nReleaseD3DPhongMaterial(long pContext, long nativeHandle);
     private static native void nSetSolidColor(long pContext, long nativePhongMaterial,
@@ -424,7 +424,7 @@
     }
 
     boolean buildNativeGeometry(long nativeHandle, float vertexBuffer[],
-            int indexBuffer[]) {
+            short indexBuffer[]) {
         return nBuildNativeGeometry(pContext, nativeHandle, vertexBuffer, indexBuffer);
     }
 
--- a/prism-d3d/src/com/sun/prism/d3d/D3DMesh.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-d3d/src/com/sun/prism/d3d/D3DMesh.java	Tue May 21 17:30:13 2013 -0700
@@ -66,7 +66,7 @@
     @Override
     public boolean buildNativeGeometry() {
         float vertexBuffer[] = getVertsGM();
-        int indexBuffer[] = getIndexGM();
+        short indexBuffer[] = getIndexGM();
         return context.buildNativeGeometry(nativeHandle, vertexBuffer, indexBuffer);
 
     }
--- a/prism-es2-native/src/GLContext.c	Tue May 21 13:54:04 2013 -0700
+++ b/prism-es2-native/src/GLContext.c	Tue May 21 17:30:13 2013 -0700
@@ -1689,11 +1689,11 @@
  */
 JNIEXPORT jboolean JNICALL Java_com_sun_prism_es2_GLContext_nBuildNativeGeometry
   (JNIEnv *env, jclass class, jlong nativeCtxInfo, jlong nativeMeshInfo,
-        jfloatArray vbArray, jintArray ibArray)
+        jfloatArray vbArray, jshortArray ibArray)
 {
     GLuint vertexBufferSize;
     GLuint indexBufferSize;
-    GLuint *indexBuffer;
+    GLushort *indexBuffer;
     GLfloat *vertexBuffer;
     jboolean status = JNI_TRUE;
 
@@ -1710,7 +1710,7 @@
     vertexBuffer = (GLfloat *) ((*env)->GetPrimitiveArrayCritical(env, vbArray, NULL));
 
     indexBufferSize = (*env)->GetArrayLength(env, ibArray);
-    indexBuffer = (GLuint *) ((*env)->GetPrimitiveArrayCritical(env, ibArray, NULL));
+    indexBuffer = (GLushort *) ((*env)->GetPrimitiveArrayCritical(env, ibArray, NULL));
 
     if ((vertexBuffer == NULL ) || (vertexBufferSize == 0)
             || (indexBuffer == NULL) || (indexBufferSize == 0)) {
@@ -1729,7 +1729,7 @@
 
             // Initialize index buffer
             ctxInfo->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshInfo->vboIDArray[MESH_INDEXBUFFER]);
-            ctxInfo->glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSize * sizeof (GLuint),
+            ctxInfo->glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSize * sizeof (GLushort),
                     indexBuffer, GL_STATIC_DRAW);
             meshInfo->indexBufferSize = indexBufferSize;
 
@@ -2091,7 +2091,7 @@
             VERT_3D_STRIDE, (const void*) offset);
 
     glDrawElements(GL_TRIANGLES, mvInfo->meshInfo->indexBufferSize,
-            GL_UNSIGNED_INT, 0);
+            GL_UNSIGNED_SHORT, 0);
 
     // Reset states
     ctxInfo->glDisableVertexAttribArray(VC_3D_INDEX);
--- a/prism-es2/src/com/sun/prism/es2/ES2Context.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-es2/src/com/sun/prism/es2/ES2Context.java	Tue May 21 17:30:13 2013 -0700
@@ -411,7 +411,7 @@
         glContext.releaseES2Mesh(nativeHandle);
     }
 
-    boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int[] indexBuffer) {
+    boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, short[] indexBuffer) {
         return glContext.buildNativeGeometry(nativeHandle, vertexBuffer, indexBuffer);
     }
 
--- a/prism-es2/src/com/sun/prism/es2/ES2Mesh.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-es2/src/com/sun/prism/es2/ES2Mesh.java	Tue May 21 17:30:13 2013 -0700
@@ -66,7 +66,7 @@
     @Override
     public boolean buildNativeGeometry() {
         float vertexBuffer[] = getVertsGM();
-        int indexBuffer[] = getIndexGM();
+        short indexBuffer[] = getIndexGM();
         return context.buildNativeGeometry(nativeHandle, vertexBuffer, indexBuffer);
 
     }
--- a/prism-es2/src/com/sun/prism/es2/GLContext.java	Tue May 21 13:54:04 2013 -0700
+++ b/prism-es2/src/com/sun/prism/es2/GLContext.java	Tue May 21 17:30:13 2013 -0700
@@ -207,7 +207,7 @@
     private static native long nCreateES2Mesh(long nativeCtxInfo);
     private static native void nReleaseES2Mesh(long nativeCtxInfo, long nativeHandle);
     private static native boolean nBuildNativeGeometry(long nativeCtxInfo, long nativeHandle,
-            float vertexBuffer[], int indexBuffer[]);
+            float vertexBuffer[], short indexBuffer[]);
     private static native long nCreateES2PhongMaterial(long nativeCtxInfo);
     private static native void nReleaseES2PhongMaterial(long nativeCtxInfo, long nativeHandle);
     private static native void nSetSolidColor(long nativeCtxInfo, long nativePhongMaterial,
@@ -647,7 +647,7 @@
         nReleaseES2Mesh(nativeCtxInfo, nativeHandle);
     }
 
-    boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int[] indexBuffer) {
+    boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, short[] indexBuffer) {
         // See MeshVbIb.h : ctor()
         return nBuildNativeGeometry(nativeCtxInfo, nativeHandle, vertexBuffer, indexBuffer);
     }