javauis/m3g_qt/src/jni/mesh.inl
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     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_Mesh.h"
       
    19 
       
    20 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Mesh__1getIndexBuffer
       
    21 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex)
       
    22 {
       
    23     M3G_DO_LOCK
       
    24     jint buffer = (M3Guint)m3gGetIndexBuffer((M3GMesh)aHandle, aIndex);
       
    25     M3G_DO_UNLOCK(aEnv)
       
    26     return buffer;
       
    27 }
       
    28 
       
    29 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Mesh__1getSubmeshCount
       
    30 (JNIEnv* aEnv, jclass, jint aHandle)
       
    31 {
       
    32     M3G_DO_LOCK
       
    33     jint count = (M3Guint)m3gGetSubmeshCount((M3GMesh)aHandle);
       
    34     M3G_DO_UNLOCK(aEnv)
       
    35     return count;
       
    36 }
       
    37 
       
    38 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Mesh__1ctor
       
    39 (JNIEnv* aEnv, jclass, jint aM3g, jint aHVertices, jintArray aHTriangles, jintArray aHAppearances)
       
    40 {
       
    41     if (aHVertices == 0 || aHTriangles == NULL)
       
    42     {
       
    43         M3G_RAISE_EXCEPTION(aEnv, "java/lang/NullPointerException");
       
    44         return 0;
       
    45     }
       
    46 
       
    47     int trianglesLen = aEnv->GetArrayLength(aHTriangles);
       
    48     int appearancesLen = aHAppearances ? aEnv->GetArrayLength(aHAppearances) : 0;
       
    49     if (trianglesLen == 0 || (aHAppearances != NULL && appearancesLen < trianglesLen))
       
    50     {
       
    51         M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException");
       
    52         return 0;
       
    53     }
       
    54 
       
    55     jint* triangle = aEnv->GetIntArrayElements(aHTriangles, NULL);
       
    56     if (triangle == NULL)
       
    57     {
       
    58         M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    59         return 0;
       
    60     }
       
    61 
       
    62     jint* appearance = NULL;
       
    63     if (aHAppearances)
       
    64     {
       
    65         appearance = aEnv->GetIntArrayElements(aHAppearances, NULL);
       
    66         if (appearance == NULL)
       
    67         {
       
    68             aEnv->ReleaseIntArrayElements(aHTriangles, triangle, JNI_ABORT);
       
    69 
       
    70             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    71             return 0;
       
    72         }
       
    73     }
       
    74     M3G_DO_LOCK
       
    75     M3Guint ret = (M3Guint)m3gCreateMesh((M3GInterface)aM3g,
       
    76                                          (M3GVertexBuffer)aHVertices,
       
    77                                          (M3GIndexBuffer*)triangle,
       
    78                                          (M3GAppearance*)appearance,
       
    79                                          trianglesLen);
       
    80     M3G_DO_UNLOCK(aEnv)
       
    81 
       
    82     if (triangle)
       
    83     {
       
    84         aEnv->ReleaseIntArrayElements(aHTriangles, triangle, JNI_ABORT);
       
    85     }
       
    86     if (appearance)
       
    87     {
       
    88         aEnv->ReleaseIntArrayElements(aHAppearances, appearance, JNI_ABORT);
       
    89     }
       
    90 
       
    91     return ret;
       
    92 }
       
    93 
       
    94 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Mesh__1getVertexBuffer
       
    95 (JNIEnv* aEnv, jclass, jint aHandle)
       
    96 {
       
    97     M3G_DO_LOCK
       
    98     jint vBuffer = (M3Guint)m3gGetVertexBuffer((M3GMesh)aHandle);
       
    99     M3G_DO_UNLOCK(aEnv)
       
   100     return vBuffer;
       
   101 }
       
   102 
       
   103 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Mesh__1getAppearance
       
   104 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex)
       
   105 {
       
   106     M3G_DO_LOCK
       
   107     jint appearence = (M3Guint)m3gGetAppearance((M3GMesh)aHandle, aIndex);
       
   108     M3G_DO_UNLOCK(aEnv)
       
   109     return appearence;
       
   110 }
       
   111 
       
   112 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Mesh__1setAppearance
       
   113 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex, jint aHAppearance)
       
   114 {
       
   115     M3G_DO_LOCK
       
   116     m3gSetAppearance((M3GMesh)aHandle, aIndex, (M3GAppearance)aHAppearance);
       
   117     M3G_DO_UNLOCK(aEnv)
       
   118 }