From 35b642d43444c435094b9c7238c9c94b325d6ca0 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 22 May 2020 09:00:48 +0100 Subject: [PATCH] Added rencache invalidation on window-exposed event Fixes #63 --- src/api/system.c | 5 ++++- src/rencache.c | 7 ++++++- src/rencache.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index 0215a564..35843a00 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -6,6 +6,7 @@ #include #include #include "api.h" +#include "rencache.h" #ifdef _WIN32 #include #endif @@ -56,7 +57,9 @@ top: lua_pushnumber(L, e.window.data2); return 3; } else if (e.window.event == SDL_WINDOWEVENT_EXPOSED) { - SDL_UpdateWindowSurface(window); + rencache_invalidate(); + lua_pushstring(L, "exposed"); + return 1; } /* on some systems, when alt-tabbing to the window SDL will queue up ** several KEYDOWN events for the `tab` key; we flush all keydown diff --git a/src/rencache.c b/src/rencache.c index 5ab1ff2d..b0b06cf9 100644 --- a/src/rencache.c +++ b/src/rencache.c @@ -150,6 +150,11 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c } +void rencache_invalidate(void) { + memset(cells_prev, 0xff, sizeof(cells_buf1)); +} + + void rencache_begin_frame(void) { /* reset all cells if the screen width/height has changed */ int w, h; @@ -157,7 +162,7 @@ void rencache_begin_frame(void) { if (screen_rect.width != w || h != screen_rect.height) { screen_rect.width = w; screen_rect.height = h; - memset(cells_prev, 0xff, sizeof(cells_buf1)); + rencache_invalidate(); } } diff --git a/src/rencache.h b/src/rencache.h index 4407e8d5..c5fa80f4 100644 --- a/src/rencache.h +++ b/src/rencache.h @@ -9,6 +9,7 @@ void rencache_free_font(RenFont *font); void rencache_set_clip_rect(RenRect rect); void rencache_draw_rect(RenRect rect, RenColor color); int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor color); +void rencache_invalidate(void); void rencache_begin_frame(void); void rencache_end_frame(void);