android spritebatch issue

Started by
0 comments, last by Daivuk 14 years, 2 months ago
Hi, I tried google around, but there is not much information about this problem on Android. The problem comes from Java. I am allocating my vertex buffer this way:

ByteBuffer vbb = ByteBuffer.allocateDirect(CAPACITY * 8 * 4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asFloatBuffer();
No choice to use allocateDirect here, to avoid Java to fragment or move around that memory. What i am triying to do, is a sprite batch class. I am used to do this one in Cpp, where you can access the float array directly (Like on iPhone for example). The problem is writing to that ByteBuffer in java is extremely slow. I can render statically 100 sprites with 60 fps, but if I write to the buffer I get 21 FPS. I update the buffer once per sprite, OR once at the end for all sprites at once. Same result. Using FloatBuffer.put(float [], float offset, float lenght) Is there a way around this? Is there a way to create a fast sprite batch, like on the iPhone. The problem really comes from Java, not the device's capabilities to render. But I am not a Guru of Java, so I am probably missing something! Thanks for any help
Advertisement
The solution -> NDK

Doing it in C++, everything is way faster now.

This topic is closed to new replies.

Advertisement