diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | graphics.cpp | 16 |
2 files changed, 13 insertions, 4 deletions
@@ -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 <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); |