improve SDL2 render code, remove flickering
commit37b7989ed84e0152aedf927b01f4fe9223b07449
authorrofl0r <rofl0r@users.noreply.github.com>
Sat, 28 Aug 2021 22:17:58 +0000 (28 22:17 +0000)
committerrofl0r <rofl0r@users.noreply.github.com>
Sat, 28 Aug 2021 22:32:16 +0000 (28 22:32 +0000)
tree8a1454a0c1fe944b7ecb61c5786e827dd011ef50
parente4fe528fe06cc82943a16dd9c2871635bf111be7
improve SDL2 render code, remove flickering

- remove unnecessary copy between SDL_Surface and SDL_Texture,
  using SDL_LockTexture we can access its pixel memory directly.

- remove unnecessary SDL_RenderClear() - the engine always writes
  an entire frame, so there's no need to explicitly clear the
  buffer.

- use platform independent pixel format SDL_PIXELFORMAT_BGRA32
  instead of SDL_PIXELFORMAT_ARGB8888. the latter is endian
  specific and what SDL_PIXELFORMAT_BGRA32 translates to
  for little endian.

- use vsync by default, which removes flickering (very noticeable
  e.g. in the "MAIN MENU" scroller of Mario Tennis).
  unfortunately it comes at a cost; without vsync CPU usage
  in powersave governor is around 6-7% for gnuboy and 3-5% for
  Xorg, with vsync it's about 8% for gnuboy and 15-20% for Xorg.
  the game still runs sufficiently fast though not to introduce
  audio stuttering even at high scale settings.

  if the additional load is considered unreasonable, it can be
  turned off by exporting environment variable SDL_RENDER_VSYNC=0,
  which activates SDL_HINT_RENDER_VSYNC, overriding the code.
sys/sdl2/sdl2.c