fredsa / playn

Cross platform game library for N≥4 platforms
0 stars 1 forks source link

Performance Improvements for Android Backend #156

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Purpose of code changes on this branch:
Rendering with OpenGL is slow because each time a sprite/object is rendered on 
the screen a flush (a.k.a gl20.glDrawElements) will take place. I have modified 
the code for the Android backend to increase the buffer sizes (max. 512 
sprites/objects) and only render when the byte buffer is full or when the 
render loop is finished. I have increase rendering performance by 50 times 
(before: 5000ms to render 2000 sprites -> after: 110ms to render 2000 sprites).

Limitations:
1. I had to resort to GL_TRIANGLES (instead of GL_TRIANGLE_STRIP). It's not 
possible to render independent sprites with GL_TRIANGLE_STRIP. 
2. Using GL_TRIANGLE_STRIP I had to override some methods in GLContext as 6 
instead of 4 index points are needed (in AndroidGLContext.java). My tests 
showed no noticeable difference in rendering using GL_TRIANGLES, so 
GL_TRIANGLE_STRIP can be replaced without taking a performance hit.
3. drawTexture works (drawRect should work too - not tested)
4. drawPoly will need rework (seems it's worked on anyway?)

Comments:
A) This should be applied to the WebGL backend too. Ditto for a future upcoming 
LWJGL integration (in the works?). The backends for AndroidGL, WebGL and LWJGL 
should be combined to remove code duplication and ease maintenance.
B) one of the fillRect methods looks very much like a duplicate of drawTexture.
C) there was no noticeable difference in rendering speed disabling OpenGL error 
check.
D) there was no noticeable difference in rendering speed disabling the depth 
test.
E) the index buffer can be kept fixed when rendering sprites/rectangles. It 
might give another performance improvements by pre-calculating & setting the 
index buffer in the constructor.

Questions:
I believe the proper draw method to use is GL_DYNAMIC_DRAW (instead of 
GL_STREAM_DRAW)? Performance did not change though? What benefits does 
GL_STREAM_DRAW offer over GL_DYNAMIC_DRAW?

Please note, this will need some rework.

When reviewing my code changes, please focus on:
http://code.google.com/r/xtophenator-playn/source/detail?r=fc4928fb68f39cf0ad8bd
114af2a6a0a4e7b3143

After the review, I'll merge this branch into:
/trunk

Original issue reported on code.google.com by xtophena...@gmail.com on 31 Mar 2012 at 4:15

GoogleCodeExporter commented 9 years ago
Oh pants. I have already revamped all of the OpenGL backends and made this same 
change already. I need to merge all those changes back upstream.

Original comment by m...@samskivert.com on 31 Mar 2012 at 3:28

GoogleCodeExporter commented 9 years ago
oh boy... http://dilbert.com/strips/comic/2008-05-15/

Original comment by xtophena...@gmail.com on 1 Apr 2012 at 2:54

GoogleCodeExporter commented 9 years ago

Original comment by m...@samskivert.com on 22 May 2012 at 6:14