SDL2 + Mac + OpenGL slow unless SDL_GetWindowSurface'd

Hello,

I have a (not that) small GL code that displays a circle around the cursor. The circle regularly hangs when moving the mouse, unless I request a surface, in which case, it’s completely smooth, no lag/hangs/stops whatsoever.

    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
    
    _sdl_window = SDL_CreateWindow (
        _window->title ()->get_value ().c_str(), 
        (int) (_window->x ()->get_value ()),
        (int) (_window->y ()->get_value ()),
        (int) (_window->width ()->get_value ()),
        (int) (_window->height ()->get_value ()),
        SDL_WINDOW_SHOWN
        | SDL_WINDOW_ALLOW_HIGHDPI
        | SDL_WINDOW_RESIZABLE
        | SDL_WINDOW_OPENGL
        );

    if( _sdl_window == NULL ) {
      std::cerr <<  "Window could not be created! SDL_Error:" << SDL_GetError() << std::endl;
      return;
    }

    SDL_GLContext context = SDL_GL_CreateContext(_sdl_window);
    if (!context) {
      fprintf(stderr, "Couldn't create context: %s\n", SDL_GetError());
      return;
    }

    //does not change anything
    //SDL_GL_SetSwapInterval(1);
    
    //Get window surface: commenting it make it run slow
    _sdl_surface = SDL_GetWindowSurface( sdl_window() ); // necessary for the remaining (renderer)
    assert(_sdl_surface);

The drawing part uses VBOs and array buffers.
The OpenGL renderer is: NVIDIA Corporation 2.1 NVIDIA-10.32.0 355.11.10.10.40.102

Similar topics in the forum did not enlighten me… maybe this one:

Did I miss something?

Best,

Stéphane

This probably isn’t helpful, but I use SDL 2.0.5 with SDL2_gfx and the OpenGL driver (in Windows), and everything works as I would expect: it doesn’t run unduly slowly and it doesn’t hang.

Richard.

@rtrussel I did not answer because as you recognized, it was not helpful. Still, I should have said ‘thank you’ in a first place.

anyway I found my culprit, and it wasn’t related to SDL_GetWindowSurface. Actually, my code was flooding the pipeline with way too many redisplay orders. I slowed it down according to the screen refresh rate, and it’s working fine now.

Best, Stéphane

1 Like