GLSurfaceView lag/delay

Started by
5 comments, last by Pufixas 10 years, 8 months ago

Hello,

I tried asking this same question on Google groups, android developers section, but no one seems want to help me.

sSo I have this problem with galaxy S3 and OpenGL ES 1.0.

Here's little backstory:
I had LG P350 (600MHZ CPU, Adreno 200 GPU, 2.8 inch screen) for 2 years or so. And I was developing this little game framework which used OpenGL. My old LG handled it pretty well, good framerates, no lags, everything worked as expected. But few days ago I decided that I should get new phone, so I ordered Galaxy S3.

So after I got the phone (Android version 4.1.2) I installed my 2 games which used my framework and noticed that there is a delay between touching / moving finger on the screen and things appearing on screen. First I thought that this could be problem of my input handling system, so I did something like this to check if that was true:


    inputSystem.update();

    float x = inputSystem.getTouchX();
    float y = inputSystem.geTouchY();

    Log.d("Touch: ", "X: " + x + " Y: " + y);


Essentially I just touched my screen, and looked at the logcat to see if there is any delay in receiving data. And there was absolutely no delay! As soon as I touched the screen, coordinates on logcat appeared.

Then I thought to myself... OK, maybe my rendering system is messed up. To test if that was true I did exactly this:


    public void onDrawFrame(GL10 gl){
    FloatBuffer floatBuffer = buffer.asFloatBuffer();

    public void tempDraw(GL10 gl){
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        gl.glViewport(0,0,1280,720);
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0, 20, 14, 0, -1, 1);

        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(2,GL10.GL_FLOAT,0,floatBuffer);

        inputSystem.update();

        float x = inputSystem.getLastTouchEvent().position.x;
        float y = inputSystem.getLastTouchEvent().position.y;

        Log.d("Touch: ", "X: " + x + " Y: " + y);

        gl.glTranslatef(x,y,0);
        gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 6);
    }

This is as simple as it could be, I didn't use my render system for rendering, I just used this little piece of code which couldn't get any simpler. It just draws little rectangle on screen in the position of last touch event.

And guess what! This didn't do the trick either! It still has delay! Also in developer options I enabled "Show touches" function, so I could see in real time how much delay there is. After I scroll my finger through screen, I immediately can see output on logcat, but square on the screen still has huge delay.

Here's the video showing the delay: GLSurfaceView lag/delay on Galaxy S3

You can see that "Show touches" android function showing the white dot on screen, this is where I WANT my square to be, but my square just follows it with delay.
Just for comparison I will launch painting application which paint on EXACTLY the white dot. This is the performance I want in my game.

It can't be the problem of my phone, because other games and apps that I downloaded from google play doesn't have this lag/delay problem.

So can someone help me out please? What am I missing? Have any of you encountered this problem before?

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
Advertisement

I noticed the same thing (input lag when using GLSurfaceView) on a samsung galaxy s2 with android 2.3.3 or something around that weird version number.

If you use the Canvas element for painting instead you have less input lag, so it might be possible that the other apps you checked which didn't have input lag were not using OpenGL.

I suspect it's either double buffering or maybe I caught the touch events at the wrong place.

Anyway, I still have to check if this is still the case on non-stock android roms.

I noticed the same thing (input lag when using GLSurfaceView) on a samsung galaxy s2 with android 2.3.3 or something around that weird version number.

If you use the Canvas element for painting instead you have less input lag, so it might be possible that the other apps you checked which didn't have input lag were not using OpenGL.

I suspect it's either double buffering or maybe I caught the touch events at the wrong place.

Anyway, I still have to check if this is still the case on non-stock android roms.

I really believe that they ARE using OpenGL, because you see stuff you couldn't possibly do with canvas. Like shaders, and 3D stuff, and it runs very smoothly.

It's kind of bummer that I posted this question in multiple forums and only got one answer - yours. This is pretty serious problem, I wonder why no one has mentioned it before. I can't continue developing my game while this issue is not fixed, and it was already 2 days after I had this problem.

Though I will still try to research what the problem might be, if I will find the answer, I will surely post it here.

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh

I noticed that even the default CyanogenMod UI has some delay, so it either is a hardware issue or OS issue.

Further I found two more threads which appear to be about the same problem, no solution through:

http://stackoverflow.com/questions/8173284/android-touch-input-delay-problems-for-a-timing-critical-game-is-there-a-delay

http://stackoverflow.com/questions/16660485/android-moving-a-view-with-ontouch-has-definite-lag

It is mentioned that there should be less lag on HTC devices, and I read somewhere else that iphones should have less lag, too.

EDIT:

Seems like not even the developers are sure what the reason is.

https://plus.google.com/100838276097451809262/posts/VDkV9XaJRGS

Anyway, unless we hack into android we can't change it.

I noticed that even the default CyanogenMod UI has some delay, so it either is a hardware issue or OS issue.

Further I found two more threads which appear to be about the same problem, no solution through:

http://stackoverflow.com/questions/8173284/android-touch-input-delay-problems-for-a-timing-critical-game-is-there-a-delay

http://stackoverflow.com/questions/16660485/android-moving-a-view-wit h-ontouch-has-definite-lag

It is mentioned that there should be less lag on HTC devices, and I read somewhere else that iphones should have less lag, too.

EDIT:

Seems like not even the developers are sure what the reason is.

https://plus.google.com/100838276097451809262/posts/VDkV9XaJRGS

Anyway, unless we hack into android we can't change it.

Thank you very much. +1 for you.

I noticed that many people in the links you posted here think that this is actually input problem, which is not, as I tested it, it really is the OpenGL / Rendering problem.

It's like you render stuff, but OpenGL shows only what you rendered few frames before that.

It's so strange, the OS's UI itself doesn't have this delay. Maybe because it uses canvas for drawing. As EVIL_ENT pointed out, that canvas increases performance. But not only OS's UI that doesn't have the delay, even some games don't. For example, today I downloaded fruit ninja, and I can feel and see delay there, but Steal Bastard has absolutely no delay in input. It's so confusing, and annoying! Damn it!

I don't really care that I have the lag, but I do care that my players will have it. I think I should test it out on more devices, and see is it really android problem, or the devices problem. Well... There's much work for me to do.

Thank you everyone, and please, if someone has any fixes, or ideas. Please let me know here.

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh

Here's another lag video. The delay between OS (CyanogenMod) and app seems to be less than in your video.

Code:

https://dl.dropboxusercontent.com/u/54747914/share/MainActivity.java

App:

https://dl.dropboxusercontent.com/u/54747914/share/DelayTest.apk

You mentioned in your video that the second example would not have delay, but imho the black line is still way slower than your finger (and where did the touch position indicator go?). Also this app would be way easier to program with Canvas, because Paint supports antialiasing.

I can't check Stealh Bastard because I don't have the game, but it does not look very prone to delay.

Well yes it was LITTLE bit slower. But it was very good. It looked almost same as in your video.

Also, you call this delay? Haha. I wish my delay test on S3 would be running this smooth. I would be very happy with such "delay" and wouldn't even bother writing this post, haha :D

I have posted this same question to google groups and they told me that this may be because OpenGL 1.0 is too old. So I rewrote my framework in OpenGL ES 2.0, and I can't see any difference in performance.

Also, I installed your delay test thinking that it might be faster, but no. It's still the same.

What the hell could be wrong?! Now i'm completely lost! I somehow need to find open source android app that uses OpenGL and has not delay (if there is one)

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh

This topic is closed to new replies.

Advertisement