简体   繁体   中英

Android Opengl ES 2 Lag when application initially starts

The problem is, once the application starts, there will be a period of time (and this time is not consistent) where the application will appear to be lagging. For example, when navigating the menu the navigation animations will be very choppy. However this lag only normally lasts for about 2-3 seconds. This problem also seems to occur for the first 2-3 seconds once the player has entered the game.

I have ruled out the GC as a possible cause of this lag as everything is preloaded and all memory allocations is done once, when the game first loads and anytime the player starts a new round of the game.

I am running these tests on an Archos 43 running Android 2.2. The device can handle 3d games and I've tried several and non of those games lagged so it must be a problem with my code. I use 3 threads in my game, 2 of which are not created by me (the render thread and the event thread), and the third is the game update thread.

Also this is just a hypothesis, but it feels as though the game only lags when it has to draw a new texture (one that has not been drawn before) even though the textures are preloaded with GLES20.glGenTextures , GLES20.glBindTexture and GLUtils.texImage2D .

I can provide sources if needed.

Sounds like you might be doing a lot of work on the UI thread such as loading models or textures, and this type of work should be done elsewhere. Take a look here at the android developer page to see how to avoid this scenario, particularly the heading "Handling Expensive Operations in the UI Thread". http://developer.android.com/resources/faq/commontasks.html#progressbar

In one of my current projects, rendering a teapot with 1200ish vertexes and having to calculate the per vertex-normals after reading the file, I will have a sluggish app for a few seconds until all the background work is complete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM