summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-05-07 21:20:47 +0300
committerOxore <oxore@protonmail.com>2023-05-07 21:20:47 +0300
commitfdd4189bfc4244cd6eabdfef6fd044ddb1236656 (patch)
tree3b3186493f22b11470feca5c607d2da8b99f8ce1
parentf8a56f3c99fda938550ba6a1616c2fa4b41c19e9 (diff)
Optimize rendering and enable VSync
-rw-r--r--.gitignore1
-rw-r--r--graphics.cpp16
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 <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);