Android, openGL lag in jni when touching the screen

I am currently testing all the functions that I need in my Android game. I just modified the hello-gl2 code sample and added some textures, VBO, FBO and simple shaders in two rendering passes.

The fact is that when I launch the application without touching the screen, I have about 35-45 frames per second. But if I start touching the screen all the time, the rendering will start to lag! So this is a problem, because the input and rendering are in the same thread (what does it think it is?), Can this be fixed? If I can't fix this lag, my game probably won't work well enough to play the bees. (Is has some hard rendering things)

//Thanks in advance!

+3
source share
1 answer

I am new to Android development, but found that the touch handler is also very concise. The default sample updates the object and does it quite a lot - this inevitably makes the garbage collector angry. I managed to get it to work less succinctly by calling "Thread.sleep (10);" inside the launch function.

I assume that replacing the “new Runnable” with a circular object buffer will improve performance, but I have not explored this yet. I think that touch events occur in a separate branch, and this can 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;
    }
+1
source

All Articles