test/testgl2.c
changeset 12478 b801d44da5dc
parent 11811 5d94cb6b24d3
child 12503 806492103856
     1.1 --- a/test/testgl2.c	Sun Dec 16 01:03:17 2018 -0500
     1.2 +++ b/test/testgl2.c	Sun Dec 16 01:04:07 2018 -0500
     1.3 @@ -218,6 +218,7 @@
     1.4      Uint32 then, now, frames;
     1.5      int status;
     1.6      int dw, dh;
     1.7 +    int swap_interval = 0;
     1.8  
     1.9      /* Enable standard application logging */
    1.10      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.11 @@ -289,11 +290,15 @@
    1.12  
    1.13      if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
    1.14          /* try late-swap-tearing first. If not supported, try normal vsync. */
    1.15 -        if (SDL_GL_SetSwapInterval(-1) == -1) {
    1.16 +        if (SDL_GL_SetSwapInterval(-1) == 0) {
    1.17 +            swap_interval = -1;
    1.18 +        } else {
    1.19              SDL_GL_SetSwapInterval(1);
    1.20 +            swap_interval = 1;
    1.21          }
    1.22      } else {
    1.23          SDL_GL_SetSwapInterval(0);  /* disable vsync. */
    1.24 +        swap_interval = 0;
    1.25      }
    1.26  
    1.27      SDL_GetCurrentDisplayMode(0, &mode);
    1.28 @@ -377,16 +382,35 @@
    1.29      then = SDL_GetTicks();
    1.30      done = 0;
    1.31      while (!done) {
    1.32 +        SDL_bool update_swap_interval = SDL_FALSE;
    1.33 +
    1.34          /* Check for events */
    1.35          ++frames;
    1.36          while (SDL_PollEvent(&event)) {
    1.37              SDLTest_CommonEvent(state, &event, &done);
    1.38 +            if (event.type == SDL_KEYDOWN) {
    1.39 +                if (event.key.keysym.sym == SDLK_o) {
    1.40 +                    swap_interval--;
    1.41 +                    update_swap_interval = SDL_TRUE;
    1.42 +                } else if (event.key.keysym.sym == SDLK_p) {
    1.43 +                    swap_interval++;
    1.44 +                    update_swap_interval = SDL_TRUE;
    1.45 +                }
    1.46 +            }
    1.47          }
    1.48 +
    1.49 +        if (update_swap_interval) {
    1.50 +            SDL_Log("Swap interval to be set to %d\n", swap_interval);
    1.51 +        }
    1.52 +
    1.53          for (i = 0; i < state->num_windows; ++i) {
    1.54              int w, h;
    1.55              if (state->windows[i] == NULL)
    1.56                  continue;
    1.57              SDL_GL_MakeCurrent(state->windows[i], context);
    1.58 +            if (update_swap_interval) {
    1.59 +                SDL_GL_SetSwapInterval(swap_interval);
    1.60 +            }
    1.61              SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
    1.62              ctx.glViewport(0, 0, w, h);
    1.63              Render();