diff --git a/port/include/video.h b/port/include/video.h index c99655110..0e4b242e2 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -45,6 +45,7 @@ s32 videoGetDisplayMode(displaymode *out, const s32 index); s32 videoGetNumDisplayModes(void); s32 videoGetVsync(void); s32 videoGetFramerateLimit(void); +s32 videoGetMSAA(void); void videoSetWindowOffset(s32 x, s32 y); void videoSetFullscreen(s32 fs); @@ -55,6 +56,7 @@ void videoSetDetailTextures(s32 detail); void videoSetDisplayMode(const s32 index); void videoSetVsync(const s32 vsync); void videoSetFramerateLimit(const s32 limit); +void videoSetMSAA(const s32 msaa); s32 videoCreateFramebuffer(u32 w, u32 h, s32 upscale, s32 autoresize); void videoSetFramebuffer(s32 target); diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 022e1e802..dfc12c97b 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -790,6 +790,44 @@ static MenuItemHandlerResult menuhandlerFramerateLimit(s32 operation, struct men return 0; } +static MenuItemHandlerResult menuhandlerMSAA(s32 operation, struct menuitem *item, union handlerdata *data) +{ + s32 msaa; + static const char *opts[] = { + "Off", + "2x", + "4x", + "8x", + "16x" + }; + + switch (operation) { + case MENUOP_GETOPTIONCOUNT: + data->dropdown.value = ARRAYCOUNT(opts); + break; + case MENUOP_GETOPTIONTEXT: + return (intptr_t)opts[data->dropdown.value]; + case MENUOP_SET: + videoSetMSAA(1 << data->dropdown.value); + break; + case MENUOP_GETSELECTEDINDEX: + msaa = videoGetMSAA(); + if (msaa < 2) { + data->dropdown.value = 0; + } else if (msaa < 4) { + data->dropdown.value = 1; + } else if (msaa < 8) { + data->dropdown.value = 2; + } else if (msaa < 16) { + data->dropdown.value = 3; + } else { + data->dropdown.value = 4; + } + } + + return 0; +} + static MenuItemHandlerResult menuhandlerResolution(s32 operation, struct menuitem *item, union handlerdata *data) { static char resstring[32]; @@ -999,6 +1037,14 @@ struct menuitem g_ExtendedVideoMenuItems[] = { VIDEO_MAX_FPS, menuhandlerFramerateLimit, }, + { + MENUITEMTYPE_DROPDOWN, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Anti-aliasing (MSAA)", + 0, + menuhandlerMSAA, + }, { MENUITEMTYPE_CHECKBOX, 0, diff --git a/port/src/video.c b/port/src/video.c index cd1f6288d..0a84df49b 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -217,6 +217,12 @@ s32 videoGetDisplayModeIndex(void) return 0; } +s32 videoGetMSAA(void) +{ + vidMSAA = (s32)gfx_msaa_level; + return vidMSAA; +} + s32 videoGetVsync(void) { vidVsync = wmAPI->get_swap_interval(); @@ -414,6 +420,12 @@ s32 videoCreateFramebuffer(u32 w, u32 h, s32 upscale, s32 autoresize) return gfx_create_framebuffer(w, h, upscale, autoresize); } +void videoSetMSAA(const s32 msaa) +{ + vidMSAA = msaa; + gfx_msaa_level = (u32)vidMSAA; +} + void videoSetVsync(const s32 vsync) { vidVsync = wmAPI->set_swap_interval(vsync) ? vsync : 0;