SDL2 Application slow over x11 Forwarding

Hi everyone.

I’ve created a simple SDL2 application following LazyFoo’s tutorial on frame rate capping:

The application actually works great on Linux (CentOS 7). The application runs at the frame rate I specify. When I uncap the frame rate I get FPS measurement in the thousands of frames per second (of course it’s not actually rendering anything but an blank window and a textured string).

The problem is that when I forward the application’s X11 display to my Windows 7 PC (Running Xming-Mesa) the framerate of the application drops to like 5 or 6 FPS. I tried running ‘glxgears’ through x11 forwarding and found that it too was getting a very low framerate compared to when it was run as a native X11 app. I tried running export LIBGL_ALWAYS_INDIRECT=1 which did result in a very substantial speedup for glxgears (it was now getting thousands of FPS over x11 forwarding). The SDL2 application is still apparently not being rendered indirectly as it’s FPS remains unaffected and is still 4-5 FPS when forwarded.

I’m using SDL 2.0.3 (that’s what comes with CentOS 7) and am creating my renderer with:
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
My Windows 7 PC has Xming (I’ve also tried Xming-Mesa but haven’t noticed a difference, I’m pretty sure they are actually the same thing).

Hey! I think I figured this out!

  1. So what I did was first upgrade my version of Xming to which has support for AIGLX (-wgl). *

  2. Next I changed my code for creating the window to:
    (I believe the SDL_WINDOW_OPENGL flag was the key!)

  3. I also had to add:
    setenv("LIBGL_ALWAYS_INDIRECT","1", 1);
    setenv("SDL_VIDEO_X11_VISUALID", "", 1);
    to the top of my int main(..) function.

After doing this my application now renders at roughly ~ 180 FPS using x11 forwarding with AIGLX. I’m curious as to why my solution fixes the issue though as I thought that when I had SDL_RENDERER_ACCELERATED it would have been using hardware acceleration (OpenGL) anyways?

*I do believe that Xming-Mesa would probably also work if you didn’t feel like sending ~$16 CAD to support the developer of Xming.