Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adapt to new libnx NWindow/Framebuffer API
  • Loading branch information
fincs committed Dec 19, 2018
1 parent d4af9cd commit 29caa76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
8 changes: 4 additions & 4 deletions common/common.h
Expand Up @@ -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++;
Expand All @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions common/menu.c
Expand Up @@ -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
Expand Down
37 changes: 16 additions & 21 deletions nx_main/main.c
Expand Up @@ -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

Expand Down Expand Up @@ -114,59 +119,49 @@ 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);
printf("%s\n", errormsg);
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 {
if (menuUpdateErrorScreen()) break;
}

if (!error_screen) {
gfxFlushBuffers();
framebufferEnd(&g_framebufObj);

#ifdef PERF_LOG
g_tickdiff_frame = svcGetSystemTick() - start_tick;
#endif

gfxSwapBuffers();
}
else {
consoleUpdate(NULL);
}
}

if (!error_screen) {
gfxExit();
framebufferClose(&g_framebufObj);
}
else {
consoleExit(NULL);
Expand Down

0 comments on commit 29caa76

Please sign in to comment.