1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "javax_microedition_m3g_MorphingMesh.h" |
|
19 |
|
20 JNIEXPORT void JNICALL Java_javax_microedition_m3g_MorphingMesh__1setWeights |
|
21 (JNIEnv* aEnv, jclass, jint aHandle, jfloatArray aWeightArray) |
|
22 { |
|
23 if (aWeightArray != NULL) |
|
24 { |
|
25 jfloat* weightArray = aEnv->GetFloatArrayElements(aWeightArray, NULL); |
|
26 if (weightArray == NULL) |
|
27 { |
|
28 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
29 return; |
|
30 } |
|
31 |
|
32 M3G_DO_LOCK |
|
33 m3gSetWeights((M3GMorphingMesh)aHandle, (M3Gfloat *)weightArray, aEnv->GetArrayLength(aWeightArray)); |
|
34 M3G_DO_UNLOCK(aEnv) |
|
35 |
|
36 if (weightArray) |
|
37 { |
|
38 aEnv->ReleaseFloatArrayElements(aWeightArray, weightArray, JNI_ABORT); |
|
39 } |
|
40 } |
|
41 else |
|
42 { |
|
43 M3G_RAISE_EXCEPTION(aEnv, "java/lang/NullPointerException"); |
|
44 } |
|
45 } |
|
46 |
|
47 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_MorphingMesh__1getMorphTargetCount |
|
48 (JNIEnv* aEnv, jclass, jint aHandle) |
|
49 { |
|
50 M3G_DO_LOCK |
|
51 jint count = (M3Guint)m3gGetMorphTargetCount((M3GMorphingMesh)aHandle); |
|
52 M3G_DO_UNLOCK(aEnv) |
|
53 return count; |
|
54 } |
|
55 |
|
56 JNIEXPORT void JNICALL Java_javax_microedition_m3g_MorphingMesh__1getWeights |
|
57 (JNIEnv* aEnv, jclass, jint aHandle, jfloatArray aWeightArray) |
|
58 { |
|
59 if (aWeightArray != NULL) |
|
60 { |
|
61 jfloat* weightArray = aEnv->GetFloatArrayElements(aWeightArray, NULL); |
|
62 if (weightArray == NULL) |
|
63 { |
|
64 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
65 return; |
|
66 } |
|
67 |
|
68 M3G_DO_LOCK |
|
69 m3gGetWeights((M3GMorphingMesh)aHandle, (M3Gfloat *)weightArray, aEnv->GetArrayLength(aWeightArray)); |
|
70 M3G_DO_UNLOCK(aEnv) |
|
71 |
|
72 if (weightArray) |
|
73 { |
|
74 aEnv->ReleaseFloatArrayElements(aWeightArray, weightArray, 0); |
|
75 } |
|
76 } |
|
77 else |
|
78 { |
|
79 M3G_RAISE_EXCEPTION(aEnv, "java/lang/NullPointerException"); |
|
80 } |
|
81 } |
|
82 |
|
83 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_MorphingMesh__1ctor |
|
84 (JNIEnv* aEnv, jclass, jint aM3g, jint aHVertices, jintArray aHTargets, jintArray aHTriangles, jintArray aHAppearances) |
|
85 { |
|
86 if (aHVertices == 0 || aHTargets == NULL || aHTriangles == NULL) |
|
87 { |
|
88 M3G_RAISE_EXCEPTION(aEnv, "java/lang/NullPointerException"); |
|
89 return 0; |
|
90 } |
|
91 |
|
92 int trianglesLen = aEnv->GetArrayLength(aHTriangles); |
|
93 int targetsLen = aEnv->GetArrayLength(aHTargets); |
|
94 |
|
95 if (trianglesLen == 0 || targetsLen == 0) |
|
96 { |
|
97 M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException"); |
|
98 return 0; |
|
99 } |
|
100 |
|
101 if (aHAppearances != NULL) |
|
102 { |
|
103 int appearancesLen = aEnv->GetArrayLength(aHAppearances); |
|
104 if (appearancesLen < trianglesLen) |
|
105 { |
|
106 M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException"); |
|
107 return 0; |
|
108 } |
|
109 } |
|
110 |
|
111 jint* targets = aEnv->GetIntArrayElements(aHTargets, NULL); |
|
112 if (targets == NULL) |
|
113 { |
|
114 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
115 return 0; |
|
116 } |
|
117 |
|
118 jint* triangles = aEnv->GetIntArrayElements(aHTriangles, NULL); |
|
119 if (triangles == NULL) |
|
120 { |
|
121 aEnv->ReleaseIntArrayElements(aHTargets, targets, JNI_ABORT); |
|
122 |
|
123 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
124 return 0; |
|
125 } |
|
126 |
|
127 jint* appearances = NULL; |
|
128 if (aHAppearances) |
|
129 { |
|
130 appearances = aEnv->GetIntArrayElements(aHAppearances, NULL); |
|
131 if (appearances == NULL) |
|
132 { |
|
133 aEnv->ReleaseIntArrayElements(aHTargets, targets, JNI_ABORT); |
|
134 aEnv->ReleaseIntArrayElements(aHTriangles, triangles, JNI_ABORT); |
|
135 |
|
136 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
137 return 0; |
|
138 } |
|
139 } |
|
140 |
|
141 M3G_DO_LOCK |
|
142 M3Guint ret = (M3Guint)m3gCreateMorphingMesh((M3GInterface)aM3g, |
|
143 (M3GVertexBuffer)aHVertices, |
|
144 (M3GVertexBuffer*)targets, |
|
145 (M3GIndexBuffer*)triangles, |
|
146 (M3GAppearance*)appearances, |
|
147 trianglesLen, |
|
148 targetsLen); |
|
149 M3G_DO_UNLOCK(aEnv) |
|
150 |
|
151 aEnv->ReleaseIntArrayElements(aHTargets, targets, JNI_ABORT); |
|
152 aEnv->ReleaseIntArrayElements(aHTriangles, triangles, JNI_ABORT); |
|
153 if (appearances) |
|
154 { |
|
155 aEnv->ReleaseIntArrayElements(aHAppearances, appearances, JNI_ABORT); |
|
156 } |
|
157 |
|
158 return ret; |
|
159 } |
|
160 |
|
161 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_MorphingMesh__1getMorphTarget |
|
162 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex) |
|
163 { |
|
164 M3G_DO_LOCK |
|
165 jint target = (M3Guint)m3gGetMorphTarget((M3GMorphingMesh)aHandle, aIndex); |
|
166 M3G_DO_UNLOCK(aEnv) |
|
167 return target; |
|
168 } |
|