From fdd4189bfc4244cd6eabdfef6fd044ddb1236656 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 7 May 2023 21:20:47 +0300 Subject: Optimize rendering and enable VSync --- graphics.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'graphics.cpp') 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 +#include 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); -- cgit v1.2.3