简体   繁体   English

应用程序最初启动时,Android Opengl ES 2延迟

[英]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. 但是,这种滞后通常仅持续约2-3秒。 This problem also seems to occur for the first 2-3 seconds once the player has entered the game. 玩家进入游戏后的最初2-3秒内似乎也会出现此问题。

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. 我已经排除了GC造成这种滞后的可能原因,因为在游戏首次加载时以及玩家开始新一轮游戏时,所有内容都已预加载,并且所有内存分配都执行一次。

I am running these tests on an Archos 43 running Android 2.2. 我正在运行Android 2.2的Archos 43上运行这些测试。 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. 该设备可以处理3d游戏,我尝试了几种游戏,但这些游戏都没有滞后,因此我的代码肯定有问题。 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. 我在游戏中使用3个线程,其中2个不是我创建的(渲染线程和事件线程),第三个是游戏更新线程。

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 . 同样,这只是一个假设,但感觉游戏似乎只有在必须绘制新纹理(之前未绘制过)时才会滞后,即使该纹理已预先加载了GLES20.glGenTexturesGLES20.glBindTextureGLUtils.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. 听起来您可能在UI线程上做了很多工作,例如加载模型或纹理,而这种工作应该在其他地方完成。 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". 在此处查看android开发人员页面,以了解如何避免这种情况,尤其是标题“在UI线程中处理昂贵的操作”。 http://developer.android.com/resources/faq/commontasks.html#progressbar 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. 在我当前的项目之一中,渲染一个具有1200ish顶点的茶壶,并且在读取文件后必须计算每个顶点法线,我将有一个缓慢的应用程序运行几秒钟,直到完成所有背景工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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