I am making a Jni replacement method for FloatBuffer.put(), since on Android 2.x and below, the FloatBuffer.put() method is inefficiently implemented as stated here. However, I want to be able to able to put a given array of src floats to a specified offset in the dst floatbuffer, as I could with position() and put(). With this in mind, I implemented this JNI method.
JNIEXPORT void JNICALL Java_com_voidseer_voidengine_mesh_Vertices_PutFloatsJni
(JNIEnv *env, jclass, jfloatArray src, jobject dst, jint numFloats, jint dstOffset )
{
float* pDst = (float*)env->GetDirectBufferAddress( dst );
float* pSrc = (float*)env->GetPrimitiveArrayCritical(src, 0);
memcpy( pDst + (dstOffset << 2), pSrc, numFloats << 2 );
env->ReleasePrimitiveArrayCritical(src, pSrc, 0);
}
However, something seems wrong. My game engine does not draw my entities like it should. Can someone spot something wrong I am doing here in this function?
Thanks
EDIT:
Just got it to work with this code.
JNIEXPORT void JNICALL Java_com_voidseer_voidengine_mesh_Vertices_PutFloatsJni
(JNIEnv *env, jclass, jfloatArray src, jobject dst, jint numFloats, jint dstOffset )
{
float* pDst = (float*)env->GetDirectBufferAddress( dst );
float* pSrc = (float*)env->GetPrimitiveArrayCritical(src, 0);
memcpy( &pDst[dstOffset], pSrc, numFloats << 2 );
env->ReleasePrimitiveArrayCritical(src, pSrc, 0);
}
Got it to work with this code.