Android, openGL lag in jni when touching screen
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 th开发者_运维问答inks 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!
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;
}
精彩评论