From a304c4170664d4f8da197da1b278ce28767c1a30 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Sun, 14 Jan 2024 11:23:05 +0300 Subject: [PATCH] ogc: implement double-buffering --- src/video/ogc/SDL_ogcvideo.c | 8 ++++++-- src/video/ogc/SDL_ogcvideo.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video/ogc/SDL_ogcvideo.c b/src/video/ogc/SDL_ogcvideo.c index 28e0cccb1b5ce..b86da4ec633a5 100644 --- a/src/video/ogc/SDL_ogcvideo.c +++ b/src/video/ogc/SDL_ogcvideo.c @@ -108,7 +108,7 @@ int OGC_VideoInit(_THIS) /* Allocate the XFB */ videodata->xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); - videodata->xfb[1] = NULL; /* We'll allocate this when double-buffering */ + videodata->xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); VIDEO_ClearFrameBuffer(vmode, videodata->xfb[0], COLOR_BLACK); VIDEO_SetNextFramebuffer(videodata->xfb[0]); @@ -172,20 +172,24 @@ void OGC_VideoQuit(_THIS) void *OGC_video_get_xfb(_THIS) { SDL_VideoData *videodata = _this->driverdata; - return videodata->xfb[0]; + return videodata->xfb[videodata->fb_index]; } void OGC_video_flip(_THIS, bool vsync) { + SDL_VideoData *videodata = _this->driverdata; void *xfb = OGC_video_get_xfb(_this); GX_CopyDisp(xfb, GX_TRUE); GX_DrawDone(); GX_Flush(); + VIDEO_SetNextFramebuffer(xfb); VIDEO_Flush(); if (vsync) { VIDEO_WaitVSync(); } + + videodata->fb_index ^= 1; } #endif /* SDL_VIDEO_DRIVER_OGC */ diff --git a/src/video/ogc/SDL_ogcvideo.h b/src/video/ogc/SDL_ogcvideo.h index 193d94e82f377..3821d1966c085 100644 --- a/src/video/ogc/SDL_ogcvideo.h +++ b/src/video/ogc/SDL_ogcvideo.h @@ -32,6 +32,7 @@ typedef struct SDL_VideoData GXRModeObj *vmode; u8 *gp_fifo; void *xfb[2]; + u8 fb_index; } SDL_VideoData; typedef struct SDL_WindowData