diff --git a/vtm/BUILD_JNI.txt b/vtm/BUILD_JNI.txt new file mode 100644 index 00000000..8291d06a --- /dev/null +++ b/vtm/BUILD_JNI.txt @@ -0,0 +1,20 @@ +Build native libraries: + +* modify jni/builder/JniBuilder.java for your platform. + +* get gdx-jnigen, then run: + +javac -cp gdx-jnigen.jar jni/builder/JniBuilder.java +java -cp gdx-jnigen.jar:jni/builder JniBuilder + +* to build android: +export NDK_HOME=/your_android_ndk_path + +* compile +cd jni +ant -v + +* copy vtm/libs/armeabi* to vtm-android/libs + + + diff --git a/vtm/jni/Android.mk b/vtm/jni/Android.mk deleted file mode 100644 index 3be634f1..00000000 --- a/vtm/jni/Android.mk +++ /dev/null @@ -1,17 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := vtm-jni -LOCAL_C_INCLUDES := . - -LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -DTRILIBRARY -DREDUCED -DCDT_ONLY -DNO_TIMER -LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -DTRILIBRARY -DREDUCED -DCDT_ONLY -DNO_TIMER -LOCAL_LDLIBS := -lm -llog -LOCAL_ARM_MODE := arm - -LOCAL_SRC_FILES := gl/utils.c\ - triangle/triangle_dbg.c\ - triangle/TriangleJni.c\ - triangle/triangle.c - -include $(BUILD_SHARED_LIBRARY) diff --git a/vtm/jni/Application.mk b/vtm/jni/Application.mk deleted file mode 100644 index d0a1e397..00000000 --- a/vtm/jni/Application.mk +++ /dev/null @@ -1 +0,0 @@ -APP_ABI := armeabi armeabi-v7a \ No newline at end of file diff --git a/vtm/jni/build-android32.xml b/vtm/jni/build-android32.xml deleted file mode 100644 index 4487f924..00000000 --- a/vtm/jni/build-android32.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - ndk_home: ${env.NDK_HOME} - - - - - - - - - - - - - - - - diff --git a/vtm/jni/build-linux64.xml b/vtm/jni/build-linux64.xml deleted file mode 100644 index f04435e0..00000000 --- a/vtm/jni/build-linux64.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vtm/jni/build.xml b/vtm/jni/build.xml deleted file mode 100644 index a4fe3ec1..00000000 --- a/vtm/jni/build.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vtm/jni/builder/org/oscim/jni/JniBuilder.java b/vtm/jni/builder/JniBuilder.java similarity index 80% rename from vtm/jni/builder/org/oscim/jni/JniBuilder.java rename to vtm/jni/builder/JniBuilder.java index db6da38f..fb938517 100644 --- a/vtm/jni/builder/org/oscim/jni/JniBuilder.java +++ b/vtm/jni/builder/JniBuilder.java @@ -1,4 +1,3 @@ -package org.oscim.jni; import com.badlogic.gdx.jnigen.AntScriptGenerator; @@ -9,8 +8,28 @@ import com.badlogic.gdx.jnigen.BuildTarget.TargetOs; public class JniBuilder { public static void main(String[] args) { String[] headers = { "." }; - String[] sources = { "gl/utils.c", "triangle/TriangleJni.c", "triangle/triangle.c", "triangle/triangle_dbg.c" }; - String cflags = " -Wall -std=c99 -O2 -DTRILIBRARY -DREDUCED -DCDT_ONLY -DNO_TIMER"; // -Werror"; + String[] sources = { + // Matrix stuff + "gl/utils.c", + // Triangle + "triangle/TriangleJni.c", + "triangle/triangle.c", + "triangle/triangle_dbg.c", + // libtessellate + "tessellate/dict.c", + "tessellate/mesh.c", + "tessellate/render.c", + "tessellate/tess.c", + "tessellate/geom.c", + "tessellate/memalloc.c", + "tessellate/normal.c", + "tessellate/priorityq.c", + "tessellate/sweep.c", + "tessellate/tessmono.c", + "tessellate/tessellate.c" + }; + + String cflags = " -Wall -std=c99 -O2 -ffast-math -DTRILIBRARY -DREDUCED -DCDT_ONLY -DNO_TIMER"; BuildTarget win32home = BuildTarget.newDefaultTarget(TargetOs.Windows, false); @@ -73,8 +92,13 @@ public class JniBuilder { new AntScriptGenerator().generate(new BuildConfig("vtm-jni"), //win32home, win32, win64, lin32, lin64, android); + // BuildExecutor.executeAnt("jni/build-windows32home.xml", "-v clean"); // BuildExecutor.executeAnt("jni/build-windows32home.xml", "-v"); // BuildExecutor.executeAnt("jni/build.xml", "pack-natives -v"); + + + + } } diff --git a/vtm/jni/tessellate/tessellate.c b/vtm/jni/tessellate/tessellate.c index d0e2d649..4d21e2dc 100644 --- a/vtm/jni/tessellate/tessellate.c +++ b/vtm/jni/tessellate/tessellate.c @@ -9,9 +9,10 @@ #include #endif -#ifndef uintptr_t -typedef unsigned long uintptr_t; -#endif +//#ifndef uintptr_t +//typedef unsigned long uintptr_t; +//#endif + /******************************************************************************/ typedef struct Triangle { @@ -167,7 +168,7 @@ void begin(GLenum which, void *poly_data) ctx->vertex_cb = &fan_vertex; break; default: - printf(stderr, "ERROR, can't handle %d\n", (int) which); + //printf(stderr, "ERROR, can't handle %d\n", (int) which); ctx->vertex_cb = &skip_vertex; break; } @@ -249,6 +250,46 @@ TessContext *tessellate( return ctx; } + +TessContext *tessellateD( + int *nverts, + int *ntris, + const double **contoursbegin, + const double **contoursend) +{ + const double *contourbegin, *contourend; + Vertex *current_vertex; + GLUtesselator *tess; + TessContext *ctx; + + tess = gluNewTess(); + ctx = new_tess_context(); + + gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLvoid (*)()) &vertex); + gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLvoid (*)()) &begin); + gluTessCallback(tess, GLU_TESS_COMBINE_DATA, (GLvoid (*)()) &combine); + + gluTessBeginPolygon(tess, ctx); + do { + contourbegin = *contoursbegin++; + contourend = *contoursbegin; + gluTessBeginContour(tess); + while (contourbegin != contourend) { + current_vertex = new_vertex(ctx, contourbegin[0], contourbegin[1]); + contourbegin += 2; + gluTessVertex(tess, current_vertex->pt, current_vertex); + } + gluTessEndContour(tess); + } while (contoursbegin != (contoursend - 1)); + gluTessEndPolygon(tess); + + //write_output(ctx, verts, tris, nverts, ntris); + //destroy_tess_context(ctx); + + gluDeleteTess(tess); + + return ctx; +} #ifdef __ANDROID__ #define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "Tesselate", __VA_ARGS__) #endif @@ -287,8 +328,8 @@ jint Java_org_oscim_renderer_sublayers_MeshLayer_tessGetCoordinates(JNIEnv *env, return 0; } - int n_verts = 1 + ctx->latest_v->index; - int n_tris_copy = ctx->n_tris; + //int n_verts = 1 + ctx->latest_v->index; + //int n_tris_copy = ctx->n_tris; int cnt = 0; for (; ctx->latest_v && cnt < length; cnt += 2) { @@ -303,6 +344,33 @@ jint Java_org_oscim_renderer_sublayers_MeshLayer_tessGetCoordinates(JNIEnv *env, return cnt; } +jint Java_org_oscim_renderer_sublayers_MeshLayer_tessGetCoordinatesD(JNIEnv *env, jclass c, + jlong ptr_context, jdoubleArray obj_coords) { + + TessContext *ctx = CAST_CTX(ptr_context); + + int length = (*env)->GetArrayLength(env, obj_coords); + + jdouble* coords = (jdouble*) (*env)->GetPrimitiveArrayCritical(env, obj_coords, 0); + if (coords == NULL) { + return 0; + } + + //int n_verts = 1 + ctx->latest_v->index; + //int n_tris_copy = ctx->n_tris; + + int cnt = 0; + for (; ctx->latest_v && cnt < length; cnt += 2) { + coords[cnt + 0] = ctx->latest_v->pt[0]; + coords[cnt + 1] = ctx->latest_v->pt[1]; + Vertex *prev = ctx->latest_v->prev; + free(ctx->latest_v); + ctx->latest_v = prev; + } + (*env)->ReleasePrimitiveArrayCritical(env, obj_coords, coords, JNI_ABORT); + + return cnt; +} jint Java_org_oscim_renderer_sublayers_MeshLayer_tessGetIndices(JNIEnv *env, jclass c, jlong ptr_context, jshortArray obj_indices) { @@ -380,3 +448,48 @@ jlong Java_org_oscim_renderer_sublayers_MeshLayer_tessellate(JNIEnv *env, jclass return (long) ctx; } + + +jlong Java_org_oscim_renderer_sublayers_MeshLayer_tessellateD(JNIEnv *env, jclass c, + jdoubleArray obj_points, jint pos, + jshortArray obj_index, jint ipos, + jint num_rings) { //, jintArray obj_out) { + + jboolean isCopy; + + printf("add %d %d %d\n", pos, ipos, num_rings); + + double* orig_points = (double*) (*env)->GetPrimitiveArrayCritical(env, obj_points, &isCopy); + if (orig_points == NULL) + return 0; + + const double *points = orig_points + pos; + + jshort* orig_indices = (jshort*) (*env)->GetPrimitiveArrayCritical(env, obj_index, &isCopy); + if (orig_indices == NULL) { + (*env)->ReleasePrimitiveArrayCritical(env, obj_points, orig_points, JNI_ABORT); + return 0; + } + + jshort* indices = orig_indices + ipos; + + const double **rings = malloc(sizeof(double*) * (num_rings + 1)); + int offset = 0; + for (int i = 0; i < num_rings; i++) { + rings[i] = points + offset; + offset += indices[i]; + } + rings[num_rings] = points + offset; + + int nverts, ntris; + + TessContext *ctx = tessellateD(&nverts, &ntris, + rings, rings + (num_rings + 1)); + + free(rings); + + (*env)->ReleasePrimitiveArrayCritical(env, obj_index, orig_indices, JNI_ABORT); + (*env)->ReleasePrimitiveArrayCritical(env, obj_points, orig_points, JNI_ABORT); + + return (long) ctx; +}