mirror of https://github.com/encounter/SDL.git
testgl2: Press 'o' or 'p' to decrease/increase OpenGL swap interval.
This commit is contained in:
parent
13869f194c
commit
c3e3503ee8
|
@ -218,6 +218,7 @@ main(int argc, char *argv[])
|
||||||
Uint32 then, now, frames;
|
Uint32 then, now, frames;
|
||||||
int status;
|
int status;
|
||||||
int dw, dh;
|
int dw, dh;
|
||||||
|
int swap_interval = 0;
|
||||||
|
|
||||||
/* Enable standard application logging */
|
/* Enable standard application logging */
|
||||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||||
|
@ -289,11 +290,15 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||||
/* try late-swap-tearing first. If not supported, try normal vsync. */
|
/* try late-swap-tearing first. If not supported, try normal vsync. */
|
||||||
if (SDL_GL_SetSwapInterval(-1) == -1) {
|
if (SDL_GL_SetSwapInterval(-1) == 0) {
|
||||||
|
swap_interval = -1;
|
||||||
|
} else {
|
||||||
SDL_GL_SetSwapInterval(1);
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
swap_interval = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDL_GL_SetSwapInterval(0); /* disable vsync. */
|
SDL_GL_SetSwapInterval(0); /* disable vsync. */
|
||||||
|
swap_interval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GetCurrentDisplayMode(0, &mode);
|
SDL_GetCurrentDisplayMode(0, &mode);
|
||||||
|
@ -377,16 +382,35 @@ main(int argc, char *argv[])
|
||||||
then = SDL_GetTicks();
|
then = SDL_GetTicks();
|
||||||
done = 0;
|
done = 0;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
SDL_bool update_swap_interval = SDL_FALSE;
|
||||||
|
|
||||||
/* Check for events */
|
/* Check for events */
|
||||||
++frames;
|
++frames;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
SDLTest_CommonEvent(state, &event, &done);
|
SDLTest_CommonEvent(state, &event, &done);
|
||||||
|
if (event.type == SDL_KEYDOWN) {
|
||||||
|
if (event.key.keysym.sym == SDLK_o) {
|
||||||
|
swap_interval--;
|
||||||
|
update_swap_interval = SDL_TRUE;
|
||||||
|
} else if (event.key.keysym.sym == SDLK_p) {
|
||||||
|
swap_interval++;
|
||||||
|
update_swap_interval = SDL_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (update_swap_interval) {
|
||||||
|
SDL_Log("Swap interval to be set to %d\n", swap_interval);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < state->num_windows; ++i) {
|
for (i = 0; i < state->num_windows; ++i) {
|
||||||
int w, h;
|
int w, h;
|
||||||
if (state->windows[i] == NULL)
|
if (state->windows[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
SDL_GL_MakeCurrent(state->windows[i], context);
|
SDL_GL_MakeCurrent(state->windows[i], context);
|
||||||
|
if (update_swap_interval) {
|
||||||
|
SDL_GL_SetSwapInterval(swap_interval);
|
||||||
|
}
|
||||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||||
ctx.glViewport(0, 0, w, h);
|
ctx.glViewport(0, 0, w, h);
|
||||||
Render();
|
Render();
|
||||||
|
|
Loading…
Reference in New Issue