Added rencache invalidation on window-exposed event

Fixes #63
This commit is contained in:
rxi 2020-05-22 09:00:48 +01:00
parent 35ce3d32a9
commit 35b642d434
3 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "api.h" #include "api.h"
#include "rencache.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
@ -56,7 +57,9 @@ top:
lua_pushnumber(L, e.window.data2); lua_pushnumber(L, e.window.data2);
return 3; return 3;
} else if (e.window.event == SDL_WINDOWEVENT_EXPOSED) { } 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 /* on some systems, when alt-tabbing to the window SDL will queue up
** several KEYDOWN events for the `tab` key; we flush all keydown ** several KEYDOWN events for the `tab` key; we flush all keydown

View File

@ -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) { void rencache_begin_frame(void) {
/* reset all cells if the screen width/height has changed */ /* reset all cells if the screen width/height has changed */
int w, h; int w, h;
@ -157,7 +162,7 @@ void rencache_begin_frame(void) {
if (screen_rect.width != w || h != screen_rect.height) { if (screen_rect.width != w || h != screen_rect.height) {
screen_rect.width = w; screen_rect.width = w;
screen_rect.height = h; screen_rect.height = h;
memset(cells_prev, 0xff, sizeof(cells_buf1)); rencache_invalidate();
} }
} }

View File

@ -9,6 +9,7 @@ void rencache_free_font(RenFont *font);
void rencache_set_clip_rect(RenRect rect); void rencache_set_clip_rect(RenRect rect);
void rencache_draw_rect(RenRect rect, RenColor color); void rencache_draw_rect(RenRect rect, RenColor color);
int rencache_draw_text(RenFont *font, const char *text, int x, int y, 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_begin_frame(void);
void rencache_end_frame(void); void rencache_end_frame(void);