How to change FloatBuffer content while maintaining performance?

I tried using

floatbuffer.put(float[]); 

but since I process more than 200 squares, all with different texture coordinates, which are updated every frame, my drops drop sharply and the game gets too far away for liquid.

y thought that the method mentioned on badlogicgames.com, oh, instead uses floatbuffer, uses intbuffer, but is the same as the slow one at the time of the put method from the buffer.

So how can I update all my floatbuffers with better performance?

EDIT: I solved the problem, the put method itself is not slow, the problem is that a new float is initialized for each floatbuffer, instead I just change the value of each element contained in the floatarray, and this avoids many GC actions. Well, I think.

+6
source share
1 answer

There are several ways to improve performance. In short, here are a few:

1) Initialize the floatbuffer and apply the conversion of each frame:. If your squares move around the screen, put them once in a floatbuffer and then apply a separate matrix transformation for each one. In this method, you populate the floatbuffer once and simply update the transforms at every step.

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

3) Use vertex buffer objects and index buffer objects . It looks like you did this, but save the data in the vertex buffer and call the vertices using the array indices.

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

+1
source

Source: https://habr.com/ru/post/916054/


All Articles