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 --- .gitignore | 1 + graphics.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index dfcdb04..512e1b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.o *.out +prof_out* sim cmake[-_]build* compile_commands.json 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