Copy a pointer to a static array
I'm developing an Android application with some native code (used to render with OpenGL ES 2.0).
I have the following method signature:
JNIEXPORT void JNICALL Java_com_xxxxxx_xxxx_ActivityRenderer_renderFrame
(JNIEnv *env, jobject obj,
jfloatArray vertices, jfloatArray normals,
jfloatArray texCoord, jintArray indices)
To get access to jfloatArray vertices, jfloatArray normals, jfloatArray texCoord, jintArray indices
elements I do the following:
jfloat *vertPos, *vertNorm, *vertTexC;
jint *indicesArray;
vertPos = env->GetFloatArrayElements(vertices, 0);
vertNorm = env->GetFloatArrayElements(normals开发者_运维问答, 0);
vertTexC = env->GetFloatArrayElements(texCoord, 0);
indicesArray = env->GetIntArrayElements(indices, 0);
And, after glDrawElements(...), at the end, I do the following:
env->ReleaseFloatArrayElements(vertices, vertPos, 0);
env->ReleaseFloatArrayElements(normals, vertNorm, 0);
env->ReleaseFloatArrayElements(texCoord, vertTexC, 0);
env->ReleaseIntArrayElements(indices, indicesArray, 0);
I'm not drawing the model that I want, probably, because I'm releasing pointers while they are still been using by glDrawElements. I'm not sure, but I want to check it before doing any other tests.
My question is how can I make an static array from a pointer?
I can get pointers' elements doing this:
jsize numVertices = env->GetArrayLength(vertices);
jsize numNormals = env->GetArrayLength(normals);
jsize numTexCoords = env->GetArrayLength(texCoord);
GLsizei numIndices = (GLsizei) env->GetArrayLength(indices);
But I don't know how to continue.
Any advice?
I'm searching the web to find how, and if I find something I will tell you.
Thanks.
Let me know if I'm misinterpreting what you're asking, but it sounds like you need to brush up on your C++. Static arrays in C++ have a fixed size at compile-time. You probably want to look into using new[]
, or malloc()
to achieve what you want.
精彩评论