Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the content of a FloatBuffer, keeping performance?

i've tried using

floatbuffer.put(float[]);

but as i am handling more than 200 squares, all with diferent texture coordinates that are updated each frame, my fps drop drastically, and the game becomes too far to be fluid.

y thought the method mentioned on badlogicgames.com, about of, instead use floatbuffer, use a intbuffer but, is the same thing, equal of slow at the moment of the method "put" of the buffer.

so, how i could update all my floatbuffers with a best performance?

EDIT: i've solved my problem, the "put" method itself is not slow, the problem is when a new float is initialized for each floatbuffer, instead of that, i just change the value of each element contained in the floatarray and that avoids many GC activity.. well i think.

like image 505
Jose Avatar asked May 18 '12 02:05

Jose


1 Answers

There are a number of ways to improve performance. Briefly, here are a few:

1) Initialize the floatbuffer and an apply a transformation each each frame: - If your squares are moving across the screen, place them once in a floatbuffer, and then apply a separate matrix transformation to each one. In this method, you fill the floatbuffer once, and just update the transformations each turn.

2) Put only unique shapes in the floatbuffer - If any of your squares are duplicates of each other, call the same buffer each frame to conserve memory.

3) Use Vertex Buffer Objects and Index Buffer Objects - It sounds like you might have done this, but store the data in a vertex buffer, and call the vertices using the indices of the array.

If you are still having issues, I recommend taking a look at this tutorial: http://www.learnopengles.com/android-lesson-one-getting-started/

like image 146
Fridiculous Avatar answered Oct 31 '22 23:10

Fridiculous