Touch input jitter on Android |
Preet
Guest
|
I seem to be getting some kind of touch input lag / jitter using SDL with Android. It feels noticeably stuttery compared to just using the Android SDK. To create a minimal demo of the difference, I created two applications: one with SDL and one using the Android SDK.
Both these applications simply draw a square at the position touch input is received. On my device, the application written with the Android SDK feels much smoother. Source for Android SDK version: https://github.com/preet/scratch/tree/master/android/SmoothTouch APK for Android SDK version: [url=https://mega.nz/#!7NJgSLAS!cgdaRDVZz4pjIAtWdAwda-xMlTbkFT82o1hsl3_pcDM]https://mega.nz/#!7NJgSLAS!cgdaRDVZz4pjIAtWdAwda-xMlTbkFT82o1hsl3_pcDM[/url] Source for SDL version: https://gist.github.com/anonymous/b0b7ff7eefa3269fe55b1e01aa3fbb44 APK for SDL version: [url=https://mega.nz/#!aJRxSayK!Fjht0jFNjZWvf__aAg2cJg4iMVgXQxqrlhxDv2ZLM5A]https://mega.nz/#!aJRxSayK!Fjht0jFNjZWvf__aAg2cJg4iMVgXQxqrlhxDv2ZLM5A[/url] There is no input lag for SDL on the desktop. There is no lag or stutter when something unrelated to input position is animated so I don't think its a rendering issue, I think its just related to input position. Does anyone know why this might be happening? Am I handling the inputs in SDL incorrectly? I'd appreciate any advice. |
|||||||||||
|
AntTheAlchemist
|
Hi Preet, welcome.
SDL touch events are in the range of 0 to 1. https://wiki.libsdl.org/SDL_TouchFingerEvent And you will want to look at SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH Hope this helps. |
|||||||||||
|
Touch input jitter on Android |
Preet
Guest
|
On Wed, Apr 20, 2016 at 3:29 PM, AntTheAlchemist wrote:
Both of these are unrelated to the issue here. The problem is sort of obvious and I feel silly for wasting so much time on it. Input events can queue up. In my SDL example I only rendered the latest touch data, including batches of events that may have been sent between iterations of the event processing loop. If you instead render each input event position in a separate frame, the jitter is gone. It makes sense that the position would jump around if you ignore in-between events.   while(keep_running)   {     // drain all available events     while(SDL_PollEvent(&event) != 0) {       if(event.type == SDL_QUIT) {         keep_running=false;         break;       }       else if(event.type == SDL_WINDOWEVENT) {         if(event.window.event == SDL_WINDOWEVENT_RESIZED) {           g_win_width = event.window.data1;           g_win_height = event.window.data2;         }       }       else if(event.type == SDL_MOUSEMOTION)       {         input_x = event.motion.x;         input_y = event.motion.y;         break; // <--- BREAK HERE SO EACH TOUCH POSITION UPDATE IS RENDERED SEPARATELY       }     }     render(prog_id,vbo_id,attrib_loc_position);   } |
|||||||||||||
|
Touch input jitter on Android |
Preet
Guest
|
After messing with the result of rendering each touch position separately the output seems smooth but still slower some how than with the Android SDK
|
|||||||||||
|
Touch input jitter on Android |
Matthew Helsley
Guest
|
As best I can tell you aren't throttling how many frames per second you render in the SDL version. The Java SDK version probably manages that for you with its canvas widget. I suspect that's the main problem. To verify, count how many motion events you get per second and how many frames you render per second in each test. Then disable rendering entirely and see how many motion events you get. You might also calc min/max/avg frame times to see if you get any spikes -- they can significantly impact your sense of fluid responsiveness.
Also, you recreate the VBO every frame. That is a relatively expensive function -- can you find a way to reuse the VBO? Chances are this is not the problem but if you're going to do anything complex or latency sensitive you might consider addressing it. Cheers, Â Â Â Matt On Apr 20, 2016 15:07, "Preet" wrote:
|
|||||||||||||
|
Touch input jitter on Android |