]> Chaos Git - corbenik/ctrulib.git/commitdiff
added gfxSetScreenFormat
authorplutoo <plutoo@inbox.com>
Wed, 26 Nov 2014 00:32:47 +0000 (01:32 +0100)
committerplutoo <plutoo@inbox.com>
Wed, 26 Nov 2014 00:32:47 +0000 (01:32 +0100)
libctru/include/3ds/gfx.h
libctru/source/gfx.c

index 7953ca615e294f52a2c6a73440a18e8cfed24b3c..29652107da3126023acac7c35953bf799db93080 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 #include <3ds/types.h>
+#include <3ds/services/gsp.h>
 
 typedef enum
 {
@@ -20,6 +21,7 @@ void gfxExit();
 
 //control stuff
 void gfxSet3D(bool enable);
+void gfxSetScreenFormat(gfxScreen_t screen, GSP_FramebufferFormats format);
 void gfxFlushBuffers();
 void gfxSwapBuffers();
 void gfxSwapBuffersGpu();
index d32dcc6b03c87a0a17ea522511ae8cc684141e35..702051b803a98c4552c557d07c4ec4ec9650f035 100644 (file)
@@ -17,11 +17,36 @@ bool enable3d;
 
 Handle gspEvent, gspSharedMemHandle;
 
+GSP_FramebufferFormats topFormat = GSP_BGR8_OES;
+GSP_FramebufferFormats botFormat = GSP_BGR8_OES;
+
 void gfxSet3D(bool enable)
 {
        enable3d=enable;
 }
 
+void gfxSetScreenFormat(gfxScreen_t screen, GSP_FramebufferFormats format) {
+    if(screen==GFX_TOP)
+        topFormat = format;
+    else
+        botFormat = format;
+}
+
+static u32 __get_bytes_per_pixel(GSP_FramebufferFormats format) {
+    switch(format) {
+    case GSP_RGBA8_OES:
+        return 4;
+    case GSP_BGR8_OES:
+        return 3;
+    case GSP_RGB565_OES:
+    case GSP_RGB5_A1_OES:
+    case GSP_RGBA4_OES:
+        return 2;
+    }
+
+    return 3;
+}
+
 void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
 {
        if(screen==GFX_TOP)
@@ -30,17 +55,17 @@ void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
                topFramebufferInfo.framebuf0_vaddr=(u32*)gfxTopLeftFramebuffers[id];
                if(enable3d)topFramebufferInfo.framebuf1_vaddr=(u32*)gfxTopRightFramebuffers[id];
                else topFramebufferInfo.framebuf1_vaddr=topFramebufferInfo.framebuf0_vaddr;
-               topFramebufferInfo.framebuf_widthbytesize=240*3;
+               topFramebufferInfo.framebuf_widthbytesize=240*__get_bytes_per_pixel(topFormat);
                u8 bit5=(enable3d!=0);
-               topFramebufferInfo.format=((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES;
+               topFramebufferInfo.format=((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|topFormat;
                topFramebufferInfo.framebuf_dispselect=id;
                topFramebufferInfo.unk=0x00000000;
        }else{
                bottomFramebufferInfo.active_framebuf=id;
                bottomFramebufferInfo.framebuf0_vaddr=(u32*)gfxBottomFramebuffers[id];
                bottomFramebufferInfo.framebuf1_vaddr=0x00000000;
-               bottomFramebufferInfo.framebuf_widthbytesize=240*3;
-               bottomFramebufferInfo.format=GSP_BGR8_OES;
+               bottomFramebufferInfo.framebuf_widthbytesize=240*__get_bytes_per_pixel(botFormat);
+               bottomFramebufferInfo.format=botFormat;
                bottomFramebufferInfo.framebuf_dispselect=id;
                bottomFramebufferInfo.unk=0x00000000;
        }