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 #include "javax_microedition_m3g_TriangleStripArray.h" |
|
18 |
|
19 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_TriangleStripArray__1createImplicit |
|
20 (JNIEnv* aEnv, jclass, jint aM3g, jint first, jintArray aLengthArray) |
|
21 { |
|
22 M3GIndexBuffer buffer; |
|
23 |
|
24 int *lengths = NULL; |
|
25 if (aLengthArray) |
|
26 { |
|
27 lengths = (int *)(aEnv->GetIntArrayElements(aLengthArray, NULL)); |
|
28 if (lengths == NULL) |
|
29 { |
|
30 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
31 return 0; |
|
32 } |
|
33 } |
|
34 int count = aLengthArray != NULL ? aEnv->GetArrayLength(aLengthArray) : 0; |
|
35 |
|
36 M3G_DO_LOCK |
|
37 buffer = m3gCreateImplicitStripBuffer((M3GInterface)aM3g, |
|
38 count, |
|
39 lengths, |
|
40 first); |
|
41 M3G_DO_UNLOCK(aEnv) |
|
42 |
|
43 if (lengths) |
|
44 { |
|
45 aEnv->ReleaseIntArrayElements(aLengthArray, lengths, JNI_ABORT); |
|
46 } |
|
47 |
|
48 return (M3Guint) buffer; |
|
49 } |
|
50 |
|
51 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_TriangleStripArray__1createExplicit |
|
52 (JNIEnv* aEnv, jclass, jint aM3g, jintArray aIndices, jintArray aLengths) |
|
53 { |
|
54 M3GIndexBuffer buffer; |
|
55 |
|
56 |
|
57 jint* lengths = NULL; |
|
58 jint* indices = NULL; |
|
59 if (aLengths) |
|
60 { |
|
61 lengths = aEnv->GetIntArrayElements(aLengths, NULL); |
|
62 if (lengths == NULL) |
|
63 { |
|
64 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
65 return 0; |
|
66 } |
|
67 } |
|
68 if (aIndices) |
|
69 { |
|
70 indices = aEnv->GetIntArrayElements(aIndices, NULL); |
|
71 if (indices == NULL) |
|
72 { |
|
73 if (lengths) |
|
74 { |
|
75 aEnv->ReleaseIntArrayElements(aLengths, lengths, JNI_ABORT); |
|
76 } |
|
77 |
|
78 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
79 return 0; |
|
80 } |
|
81 } |
|
82 M3G_DO_LOCK |
|
83 buffer = m3gCreateStripBuffer((M3GInterface)aM3g, |
|
84 M3G_TRIANGLE_STRIPS, |
|
85 aLengths != NULL ? aEnv->GetArrayLength(aLengths) : 0, |
|
86 (M3Gsizei *)lengths, |
|
87 M3G_INT, |
|
88 aIndices != NULL ? aEnv->GetArrayLength(aIndices) : 0, |
|
89 (void *)indices); |
|
90 M3G_DO_UNLOCK(aEnv) |
|
91 |
|
92 if (indices) |
|
93 { |
|
94 aEnv->ReleaseIntArrayElements(aIndices, indices, JNI_ABORT); |
|
95 } |
|
96 if (lengths) |
|
97 { |
|
98 aEnv->ReleaseIntArrayElements(aLengths, lengths, JNI_ABORT); |
|
99 } |
|
100 |
|
101 return (M3Guint) buffer; |
|
102 } |
|
103 |
|
104 /* M3G 1.1 JNI Calls */ |
|
105 |
|
106 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_TriangleStripArray__1getIndexCount |
|
107 (JNIEnv* aEnv, jclass, jint aHTsa) |
|
108 { |
|
109 M3G_DO_LOCK |
|
110 jint size = (jint)m3gGetBatchSize((M3GIndexBuffer)aHTsa, 0); |
|
111 M3G_DO_UNLOCK(aEnv) |
|
112 return size; |
|
113 } |
|
114 |
|
115 JNIEXPORT void JNICALL Java_javax_microedition_m3g_TriangleStripArray__1getIndices |
|
116 (JNIEnv* aEnv, jclass, jint aHTsa, jintArray aIndices) |
|
117 { |
|
118 jint* indices = NULL; |
|
119 |
|
120 if (aIndices) |
|
121 { |
|
122 indices = aEnv->GetIntArrayElements(aIndices, NULL); |
|
123 if (indices == NULL) |
|
124 { |
|
125 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
126 return; |
|
127 } |
|
128 } |
|
129 M3G_DO_LOCK |
|
130 m3gGetBatchIndices((M3GIndexBuffer)aHTsa, 0, indices); |
|
131 M3G_DO_UNLOCK(aEnv) |
|
132 |
|
133 if (indices) |
|
134 { |
|
135 aEnv->ReleaseIntArrayElements(aIndices, indices, 0); |
|
136 } |
|
137 } |
|