From 29caa7688443b18e5f9c5920ae74a577d733990f Mon Sep 17 00:00:00 2001 From: fincs Date: Wed, 19 Dec 2018 19:39:29 +0100 Subject: [PATCH] Adapt to new libnx NWindow/Framebuffer API --- common/common.h | 8 ++++---- common/menu.c | 4 ---- nx_main/main.c | 37 ++++++++++++++++--------------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/common/common.h b/common/common.h index a587dd6..37ad0e4 100644 --- a/common/common.h +++ b/common/common.h @@ -93,7 +93,7 @@ static inline void DrawPixel(uint32_t x, uint32_t y, color_t clr) { if (x >= 1280 || y >= 720) return; - u32 off = (y * g_framebuf_width + x)*4; + u32 off = y*g_framebuf_width + x*4; g_framebuf[off] = BlendColor(g_framebuf[off], clr.r, clr.a); off++; g_framebuf[off] = BlendColor(g_framebuf[off], clr.g, clr.a); off++; g_framebuf[off] = BlendColor(g_framebuf[off], clr.b, clr.a); off++; @@ -103,7 +103,7 @@ static inline void DrawPixelRaw(uint32_t x, uint32_t y, color_t clr) { if (x >= 1280 || y >= 720) return; - u32 off = (y * g_framebuf_width + x)*4; + u32 off = y*g_framebuf_width + x*4; *((u32*)&g_framebuf[off]) = clr.r | (clr.g<<8) | (clr.b<<16) | (0xff<<24); } static inline void Draw4PixelsRaw(uint32_t x, uint32_t y, color_t clr) @@ -113,12 +113,12 @@ static inline void Draw4PixelsRaw(uint32_t x, uint32_t y, color_t clr) u32 color = clr.r | (clr.g<<8) | (clr.b<<16) | (0xff<<24); u128 val = color | ((u128)color<<32) | ((u128)color<<64) | ((u128)color<<96); - u32 off = (y * g_framebuf_width + x)*4; + u32 off = y*g_framebuf_width + x*4; *((u128*)&g_framebuf[off]) = val; } static inline color_t FetchPixelColor(uint32_t x, uint32_t y) { - u32 off = (y * g_framebuf_width + x)*4; + u32 off = y*g_framebuf_width + x*4; u32 val = *((u32*)&g_framebuf[off]); u8 r = (u8)val; u8 g = (u8)(val>>8); diff --git a/common/menu.c b/common/menu.c index d7284f4..3a2dc90 100644 --- a/common/menu.c +++ b/common/menu.c @@ -545,14 +545,10 @@ void menuLoop(void) { DrawText(interuiregular14, 180, 46 + 18, themeCurrent.textColor, VERSION); #ifdef PERF_LOG_DRAW//Seperate from the PERF_LOG define since this might affect perf. - extern u64 g_tickdiff_vsync; extern u64 g_tickdiff_frame; char tmpstr[64]; - snprintf(tmpstr, sizeof(tmpstr)-1, "%lu", g_tickdiff_vsync); - DrawText(interuiregular14, 180 + 256, 46 + 18, themeCurrent.textColor, tmpstr); - snprintf(tmpstr, sizeof(tmpstr)-1, "%lu", g_tickdiff_frame); DrawText(interuiregular14, 180 + 256, 46 + 16 + 18, themeCurrent.textColor, tmpstr); #endif diff --git a/nx_main/main.c b/nx_main/main.c index 914a37f..cb2caf7 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -5,13 +5,18 @@ #include "../common/common.h" #include "nx_touch.h" +// Define the desired framebuffer resolution (here we set it to 720p). +#define FB_WIDTH 1280 +#define FB_HEIGHT 720 + +Framebuffer g_framebufObj; + uint8_t* g_framebuf; u32 g_framebuf_width; bool menuUpdateErrorScreen(void); #ifdef PERF_LOG -u64 g_tickdiff_vsync=0; u64 g_tickdiff_frame=0; #endif @@ -114,7 +119,8 @@ int main(int argc, char **argv) if (errormsg[0]) error_screen = 1; if (!error_screen) { - gfxInitDefault(); + framebufferCreate(&g_framebufObj, nwindowGetDefault(), FB_WIDTH, FB_HEIGHT, PIXEL_FORMAT_RGBA_8888, 2); + framebufferMakeLinear(&g_framebufObj); } else { consoleInit(NULL); @@ -122,29 +128,20 @@ int main(int argc, char **argv) printf("Press the + button to exit.\n"); } - #ifdef PERF_LOG - if (!error_screen) { - gfxWaitForVsync(); - - start_tick = svcGetSystemTick(); - gfxWaitForVsync(); - g_tickdiff_vsync = svcGetSystemTick() - start_tick; - } - #endif - while (appletMainLoop()) { - #ifdef PERF_LOG - if (!error_screen) start_tick = svcGetSystemTick(); - #endif + //Scan all the inputs. This should be done once for each frame hidScanInput(); if (!error_screen) { - g_framebuf = gfxGetFramebuffer(&g_framebuf_width, NULL); - memset(g_framebuf, 237, gfxGetFramebufferSize()); if (!uiUpdate()) break; + g_framebuf = framebufferBegin(&g_framebufObj, &g_framebuf_width); + #ifdef PERF_LOG + start_tick = svcGetSystemTick(); + #endif + memset(g_framebuf, 237, g_framebuf_width * FB_HEIGHT); menuLoop(); } else { @@ -152,13 +149,11 @@ int main(int argc, char **argv) } if (!error_screen) { - gfxFlushBuffers(); + framebufferEnd(&g_framebufObj); #ifdef PERF_LOG g_tickdiff_frame = svcGetSystemTick() - start_tick; #endif - - gfxSwapBuffers(); } else { consoleUpdate(NULL); @@ -166,7 +161,7 @@ int main(int argc, char **argv) } if (!error_screen) { - gfxExit(); + framebufferClose(&g_framebufObj); } else { consoleExit(NULL);