diff options
author | Oxore <oxore@protonmail.com> | 2023-05-07 21:20:47 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-05-07 21:20:47 +0300 |
commit | fdd4189bfc4244cd6eabdfef6fd044ddb1236656 (patch) | |
tree | 3b3186493f22b11470feca5c607d2da8b99f8ce1 /graphics.cpp | |
parent | f8a56f3c99fda938550ba6a1616c2fa4b41c19e9 (diff) |
Optimize rendering and enable VSync
Diffstat (limited to 'graphics.cpp')
-rw-r--r-- | graphics.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/graphics.cpp b/graphics.cpp index afcd3b2..56d0532 100644 --- a/graphics.cpp +++ b/graphics.cpp @@ -5,6 +5,7 @@ #include "vdp.hpp" #include <cstdlib> +#include <cassert> static size_t kIntegerScaling = 2; @@ -45,6 +46,14 @@ Graphics::Graphics() SDL_Quit(); return; } + if (SDL_GL_SetSwapInterval(-1)) { + printf("Couldn't set adaptive VSync: falling back to hard VSync\n"); + if (SDL_GL_SetSwapInterval(1)) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set up VSync: %s\n", SDL_GetError()); + SDL_Quit(); + return; + } + } #endif _initialized_ok = true; } @@ -76,10 +85,9 @@ void Graphics::Render(const VDP& vdp) // TODO probably should return and propagate error abort(); } - for (size_t row = 0; row < VDP().kRenderHeight; row++) { - uint32_t *dst = (uint32_t*)((uint8_t*)pixels + row * pitch); - memcpy(dst, buffer + row * VDP().kRenderWidth, VDP().kRenderWidth * sizeof(*dst)); - } + assert(pitch == VDP().kRenderWidth * sizeof(*buffer)); + (void) pitch; + memcpy(pixels, buffer, VDP().kRenderWidth * VDP().kRenderHeight * sizeof(*buffer)); SDL_UnlockTexture(_render_texture); SDL_RenderClear(_renderer); SDL_RenderCopy(_renderer, _render_texture, NULL, NULL); |