Reputation: 1134
Would there be a performance increase if my app was to modifying the objects vertices instead of using glTranslatef
?
The vertices of the NPC object are set as the following; this allows them to be 1/10th of the screen width because of a previous call to gl.glScalef()
protected float[] vertices = {
0f, 0f, -1f, //Bottom Left
1f, 0f, -1f, //Bottom Right
0f, 1f, -1f, //Top Left
1f, 1f, -1f //Top Right
};
At the moment I have a collection of NPC objects which are drawn on the screen, when they move the X and Y values are updated, which my onDraw
accesses to draw the NPCs in the correct place.
onDraw(GL10 gl){
for(int i=0; i<npcs.size(); i++){
NPC npc = npcs.get(i);
npc.move();
translate(npc.x, npc.y);
npc.draw(gl);
}
}
translate(x,y)
- pushes and pops the matrix while calling the method gl.glTranslatef()
making calculations in relation to the screen size and ratio
npc.draw(gl)
- enables client state and draws arrays
Would there be an increase in performance if the move function changed the vertices and of the NPC object? for example;
move(){
// ... do normal movement calculations
float[] vewVertices = {
x, y, 0f,
x+npc.width, y, z,
x, y+npc.height, z,
x+npc.width, y+npc.height, z
}
vertexBuffer.put(newVertices);
vertexBuffer.position(0);
}
I am about to create a short test to see if I can see any performance increase, but I wanted to ask if anyone had any previous experience with this.
Upvotes: 2
Views: 2320
Reputation: 1882
Like Maurizio Benedetti pointed out, you will start to see a difference only when your vertex count is sufficiently large.
Upvotes: 0
Reputation: 1134
After creating a test state in my current Open GL app there seems to be no performance increase when changing the vertices directly, over using gl.glTranslatef()
Upvotes: 0
Reputation: 3577
The best way is simply to use the translate function since a transformation of the model view matrix during a translation consists in the manipulation of 3 float values while a change in the vertices information is directly proportional to the number of vertices you have.
With all the due respect, the way you proposed is very inconvenient and you should stick to matrix manipulation in place of vertices manipulation.
You can refer to this document for more information about matrix changes during translation operations:
http://www.songho.ca/opengl/gl_transform.html
Cheers Maurizio
Upvotes: 2