From b5723c920939ec9051a0353150a490df940df599 Mon Sep 17 00:00:00 2001 From: fincs Date: Mon, 8 Dec 2014 15:57:39 +0100 Subject: [PATCH] Add gfxSetDoubleBuffering() for disabling double-buffering --- libctru/include/3ds/gfx.h | 1 + libctru/source/gfx.c | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 2965210..e7b33d3 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -22,6 +22,7 @@ void gfxExit(); //control stuff void gfxSet3D(bool enable); void gfxSetScreenFormat(gfxScreen_t screen, GSP_FramebufferFormats format); +void gfxSetDoubleBuffering(bool doubleBuffering); void gfxFlushBuffers(); void gfxSwapBuffers(); void gfxSwapBuffersGpu(); diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index 702051b..df99fcc 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -12,13 +12,14 @@ u8* gfxTopLeftFramebuffers[2]; u8* gfxTopRightFramebuffers[2]; u8* gfxBottomFramebuffers[2]; -u8 currentBuffer; -bool enable3d; +static u8 currentBuffer; +static bool enable3d; +static int doubleBuf = 1; Handle gspEvent, gspSharedMemHandle; -GSP_FramebufferFormats topFormat = GSP_BGR8_OES; -GSP_FramebufferFormats botFormat = GSP_BGR8_OES; +static GSP_FramebufferFormats topFormat = GSP_BGR8_OES; +static GSP_FramebufferFormats botFormat = GSP_BGR8_OES; void gfxSet3D(bool enable) { @@ -32,6 +33,10 @@ void gfxSetScreenFormat(gfxScreen_t screen, GSP_FramebufferFormats format) { botFormat = format; } +void gfxSetDoubleBuffering(bool doubleBuffering) { + doubleBuf = doubleBuffering ? 1 : 0; // make sure they're the integer values '1' and '0' +} + static u32 __get_bytes_per_pixel(GSP_FramebufferFormats format) { switch(format) { case GSP_RGBA8_OES: @@ -76,7 +81,7 @@ void gfxWriteFramebufferInfo(gfxScreen_t screen) u8* framebufferInfoHeader=gfxSharedMemory+0x200+gfxThreadID*0x80; if(screen==GFX_BOTTOM)framebufferInfoHeader+=0x40; GSP_FramebufferInfo* framebufferInfo=(GSP_FramebufferInfo*)&framebufferInfoHeader[0x4]; - framebufferInfoHeader[0x0]^=1; + framebufferInfoHeader[0x0]^=doubleBuf; framebufferInfo[framebufferInfoHeader[0x0]]=(screen==GFX_TOP)?(topFramebufferInfo):(bottomFramebufferInfo); framebufferInfoHeader[0x1]=1; } @@ -131,7 +136,7 @@ void gfxExit() // Exit event handler gspExitEventHandler(); - // Free framebuffers (let's pretend linearFree is actually implemented...) + // Free framebuffers linearFree(gfxTopRightFramebuffers[1]); linearFree(gfxTopRightFramebuffers[0]); linearFree(gfxBottomFramebuffers[1]); @@ -159,10 +164,10 @@ u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* hei if(screen==GFX_TOP) { if(height)*height=400; - return (side==GFX_LEFT || !enable3d)?(gfxTopLeftFramebuffers[currentBuffer^1]):(gfxTopRightFramebuffers[currentBuffer^1]); + return (side==GFX_LEFT || !enable3d)?(gfxTopLeftFramebuffers[currentBuffer^doubleBuf]):(gfxTopRightFramebuffers[currentBuffer^doubleBuf]); }else{ if(height)*height=320; - return gfxBottomFramebuffers[currentBuffer^1]; + return gfxBottomFramebuffers[currentBuffer^doubleBuf]; } } @@ -175,7 +180,7 @@ void gfxFlushBuffers() void gfxSwapBuffers() { - currentBuffer^=1; + currentBuffer^=doubleBuf; gfxSetFramebufferInfo(GFX_TOP, currentBuffer); gfxSetFramebufferInfo(GFX_BOTTOM, currentBuffer); GSPGPU_SetBufferSwap(NULL, GFX_TOP, &topFramebufferInfo); @@ -184,7 +189,7 @@ void gfxSwapBuffers() void gfxSwapBuffersGpu() { - currentBuffer^=1; + currentBuffer^=doubleBuf; gfxSetFramebufferInfo(GFX_TOP, currentBuffer); gfxSetFramebufferInfo(GFX_BOTTOM, currentBuffer); gfxWriteFramebufferInfo(GFX_TOP);