Android, openGL lag in jni when touching screen

廉价感情. 提交于 2019-12-10 20:28:52

问题


I am currently testing out all the features that a need in my game on the Android platform. I have only modified the hello-gl2 sample code, and added some textures, VBO's, FBO's and simple shaders in two rendering passes.

The thing is that when I let the app run with out touching the screen, i have about 35-45 fps. But if I start touching the screen continuously, the rendering starts to lag! So is this a problem because input and rendering is in the same thread (as a thinks it is?), is it even possible to fix? If I can't fix that lag, my game is probably not going to run good enough to bee playable. (Is has some heavy rendering stuff)

//Thanks in advance!


回答1:


I'm fairly new to android development but found the touch handler to be very laggy also. The default sample is newing up an object and doing this quite a lot - this is bound to make the garbage collector angry. I managed to get it to perform in a less laggy way by calling 'Thread.sleep(10);' inside the run function.

I imagine that replacing the 'new Runnable' with a circular buffer of objects would improve performance but I haven't investigated this yet. I'm the touch events seem to occur on a seperate thread and this may cause complications.

Override public boolean onTouchEvent(final MotionEvent event)
    {
        queueEvent(


        new Runnable()
        {
            public void run()
            {

                int action = event.getAction();
                //do your handling here
                try
                {
                    Thread.sleep(10);
                } catch (InterruptedException e)
                {

                    e.printStackTrace();
                } 

            }
        });
        return true;
    }


来源:https://stackoverflow.com/questions/5237414/android-opengl-lag-in-jni-when-touching-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!