2
\$\begingroup\$

I have an SDL_Renderer which I set to use or not use vSync depending on the user). In my options menu I have an option for enabling/disabling vSync. Can I edit my renderer to update the vSync preferences so that I don't have to destroy and recreate it? Doing so would invalidate a lot of renderer pointers in my game, so I would like to find an alternative solution.

\$\endgroup\$
0
\$\begingroup\$

EDIT: The following only works when executed before calling SDL_CreateRenderer. Seems like SDL has made a simple and trivial task quite hard.

SDL wiki suggests that calling SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1" or "0"); should do the trick. You might also want to try SDL_SetHintWithPriority, which will override any possible environment variables that have been set that could prevent that value passed in to SDL_SetHint to have an effect.

\$\endgroup\$
  • \$\begingroup\$ Here says that this hint is used in SDL_CreateRenderer() if SDL_RENDERER_PRESENTVSYNC isn't passed. Btw, is there any way to test if vSync is being effectively active? \$\endgroup\$ – Xriuk Dec 27 '15 at 11:58
  • 1
    \$\begingroup\$ You should be able to see whether VSYNC is active by disabling your framerate limiting code and then calculating your framerate. With VSYNC on, the framerate should be ~60, and without it much higher. I'll see if I can get this working on my game. \$\endgroup\$ – Tyyppi_77 Dec 27 '15 at 12:01
  • \$\begingroup\$ Could you drop by the chat so we could discuss this better there? \$\endgroup\$ – Tyyppi_77 Dec 27 '15 at 12:06
  • 1
    \$\begingroup\$ Tested it right now, not working. :( \$\endgroup\$ – Xriuk Dec 27 '15 at 12:06
0
\$\begingroup\$

Ok, I asked on the SDL Forums too:

  • There is no way to edit vSync settings after renderer creation without using OpenGL.
  • Destroying the renderer and re-creating it, is not an option because it will destroy every texture created with it.

So vSync shouldn't be an user-editable setting (at least for now).

\$\endgroup\$
  • \$\begingroup\$ Why not just reload textures with the new renderer? \$\endgroup\$ – Tyyppi_77 Jan 4 '16 at 13:39
  • \$\begingroup\$ @Tyyppi_77 That would be hell of a work, updating EVERY pointer, plus not worth it. \$\endgroup\$ – Xriuk Jan 4 '16 at 14:33
  • \$\begingroup\$ That just depends on your architecture, in some cases (like in my game) textures are stored in a single place, and updating them would be really easy. \$\endgroup\$ – Tyyppi_77 Jan 4 '16 at 14:41
  • 1
    \$\begingroup\$ Not useless; you could make VSync toggleable. \$\endgroup\$ – Tyyppi_77 Jan 4 '16 at 17:48
  • 1
    \$\begingroup\$ I don't know why this answer got a minus one. It explains quite clearly that it can't be done unless the renderer is destroyed. Why the OP decided not to do it shouldn't change the quality of that answer. Plus one from me. \$\endgroup\$ – Martin Véronneau Oct 2 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.