]> Chaos Git - corbenik/ctrulib.git/commitdiff
Add gfxSetDoubleBuffering() for disabling double-buffering
authorfincs <fincs.alt1@gmail.com>
Mon, 8 Dec 2014 14:57:39 +0000 (15:57 +0100)
committerfincs <fincs.alt1@gmail.com>
Mon, 8 Dec 2014 14:57:39 +0000 (15:57 +0100)
libctru/include/3ds/gfx.h
libctru/source/gfx.c

index 29652107da3126023acac7c35953bf799db93080..e7b33d3943f531bfed997e0baafd76bd9d1a8444 100644 (file)
@@ -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();
index 702051b803a98c4552c557d07c4ec4ec9650f035..df99fcc7195bf6c100ce2334ac2deeccf9e2f1bc 100644 (file)
@@ -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);