Skip to content

Commit

Permalink
generic ui, add basic GLES support
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Sep 17, 2022
1 parent 7c6f791 commit 23e4719
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ OBJS += platform/linux/emu.o platform/linux/blit.o # FIXME
OBJS += platform/common/plat_sdl.o platform/common/input_sdlkbd.o
OBJS += platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
OBJS += platform/libpicofe/plat_dummy.o platform/libpicofe/linux/plat.o
OBJS += platform/libpicofe/gl.o
OBJS += platform/libpicofe/gl_platform.o
USE_FRONTEND = 1
endif
ifeq "$(PLATFORM)" "generic"
#ifeq (y,$(shell echo "\#include <GLES/gl.h>" | $(CC) -E -xc - >/dev/null 2>&1 && echo y))
ifeq "$(HAVE_GLES)" "1"
CFLAGS += -DHAVE_GLES -DSDL_REDRAW_EVT
LDFLAGS += -lEGL -lGLESv1_CM
endif
CFLAGS += -DSDL_OVERLAY_2X -DSDL_BUFFER_3X
OBJS += platform/linux/emu.o platform/linux/blit.o # FIXME
ifeq "$(use_inputmap)" "1"
Expand Down Expand Up @@ -254,6 +257,9 @@ OBJS += platform/common/main.o platform/common/emu.o platform/common/upscale.o \
# libpicofe
OBJS += platform/libpicofe/input.o platform/libpicofe/readpng.o \
platform/libpicofe/fonts.o
ifneq (,$(filter %HAVE_GLES, $(CFLAGS)))
OBJS += platform/libpicofe/gl.o platform/libpicofe/gl_platform.o
endif

# libpicofe - sound
OBJS += platform/libpicofe/sndout.o
Expand Down
9 changes: 9 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ have_arm_oabi=""
have_arm_neon=""
have_libavcodec=""
have_libchdr=""
have_gles="no"
need_sdl="no"
need_zlib="no"

Expand All @@ -74,9 +75,11 @@ set_platform()
case "$platform" in
rpi1)
MFLAGS="mcpu=arm1176jzf-s -mfpu=vfp"
have_gles="yes"
;;
rpi2)
MFLAGS="mcpu=cortex-a7 -mfpu=neon"
have_gles="yes"
;;
generic)
;;
Expand Down Expand Up @@ -155,6 +158,8 @@ for opt do
;;
--with-libavcodec=*) have_libavcodec="$optarg"
;;
--with-sdl-gles=*) have_gles="$optarg"
;;
*) echo "ERROR: unknown option $opt"; show_help="yes"
;;
esac
Expand All @@ -168,6 +173,7 @@ if [ "$show_help" = "yes" ]; then
echo " --sound-drivers=LIST sound output drivers [guessed]"
echo " available: $sound_driver_list"
echo " --with-libavcodec=yes|no use libavcodec for mp3 decoding"
echo " --with-sdl-gles=yes|no enable GLES usage for SDL"
echo "influential environment variables:"
echo " CROSS_COMPILE CC CXX AS STRIP CFLAGS ASFLAGS LDFLAGS LDLIBS"
exit 1
Expand Down Expand Up @@ -447,6 +453,9 @@ echo >> $config_mak
echo "ARCH = $ARCH" >> $config_mak
echo "PLATFORM = $platform" >> $config_mak
echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
if [ "$have_gles" = "yes" ]; then
echo "HAVE_GLES = 1" >> $config_mak
fi
if [ "$have_libavcodec" = "yes" ]; then
echo "HAVE_LIBAVCODEC = 1" >> $config_mak
fi
Expand Down
40 changes: 25 additions & 15 deletions platform/common/menu_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static unsigned short fname2color(const char *fname)
#include <platform/libpicofe/menu.c>

static const char *men_dummy[] = { NULL };
static int menu_w, menu_h;

/* platform specific options and handlers */
#if defined(__GP2X__)
Expand Down Expand Up @@ -147,7 +148,17 @@ static void copy_bg(int dir)

static void menu_enter(int is_rom_loaded)
{
if (is_rom_loaded)
plat_video_menu_enter(is_rom_loaded);
menu_w = menu_h = 0;
}

static void menu_draw_prep(void)
{
if (menu_w == g_menuscreen_w && menu_h == g_menuscreen_h)
return;
menu_w = g_menuscreen_w, menu_h = g_menuscreen_h;

if (PicoGameLoaded)
{
make_bg(0, 0);
}
Expand All @@ -159,12 +170,11 @@ static void menu_enter(int is_rom_loaded)
strcpy(buff + pos, "background.png");

// should really only happen once, on startup..
memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
if (readpng(g_menubg_ptr, buff, READPNG_BG,
g_menuscreen_w, g_menuscreen_h) < 0)
memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
}

plat_video_menu_enter(is_rom_loaded);
}

static void draw_savestate_bg(int slot)
Expand Down Expand Up @@ -436,7 +446,7 @@ static int menu_loop_keyconfig(int id, int keys)
static int sel = 0;

me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
me_loop(e_menu_keyconfig, &sel);
me_loop_d(e_menu_keyconfig, &sel, menu_draw_prep, NULL);

PicoSetInputDevice(0, currentConfig.input_dev0);
PicoSetInputDevice(1, currentConfig.input_dev1);
Expand All @@ -461,7 +471,7 @@ static int menu_loop_md_options(int id, int keys)
static int sel = 0;

me_enable(e_menu_md_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
me_loop(e_menu_md_options, &sel);
me_loop_d(e_menu_md_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand Down Expand Up @@ -489,7 +499,7 @@ static menu_entry e_menu_cd_options[] =
static int menu_loop_cd_options(int id, int keys)
{
static int sel = 0;
me_loop(e_menu_cd_options, &sel);
me_loop_d(e_menu_cd_options, &sel, menu_draw_prep, NULL);
return 0;
}

Expand Down Expand Up @@ -548,7 +558,7 @@ static int menu_loop_32x_options(int id, int keys)
static int sel = 0;

me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
me_loop(e_menu_32x_options, &sel);
me_loop_d(e_menu_32x_options, &sel, menu_draw_prep, NULL);

Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);

Expand Down Expand Up @@ -580,7 +590,7 @@ static int menu_loop_sms_options(int id, int keys)
{
static int sel = 0;

me_loop(e_menu_sms_options, &sel);
me_loop_d(e_menu_sms_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand Down Expand Up @@ -612,7 +622,7 @@ static int menu_loop_adv_options(int id, int keys)
{
static int sel = 0;

me_loop(e_menu_adv_options, &sel);
me_loop_d(e_menu_adv_options, &sel, menu_draw_prep, NULL);
PicoIn.overclockM68k = currentConfig.overclock_68k; // int vs short

return 0;
Expand Down Expand Up @@ -701,7 +711,7 @@ static int menu_loop_snd_options(int id, int keys)

if (PicoIn.sndRate > 52000 && PicoIn.sndRate < 54000)
PicoIn.sndRate = 53000;
me_loop(e_menu_snd_options, &sel);
me_loop_d(e_menu_snd_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand Down Expand Up @@ -739,7 +749,7 @@ static int menu_loop_gfx_options(int id, int keys)
{
static int sel = 0;

me_loop(e_menu_gfx_options, &sel);
me_loop_d(e_menu_gfx_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand All @@ -762,7 +772,7 @@ static int menu_loop_ui_options(int id, int keys)
{
static int sel = 0;

me_loop(e_menu_ui_options, &sel);
me_loop_d(e_menu_ui_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand Down Expand Up @@ -916,7 +926,7 @@ static int menu_loop_options(int id, int keys)
me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);

me_loop(e_menu_options, &sel);
me_loop_d(e_menu_options, &sel, menu_draw_prep, NULL);

return 0;
}
Expand Down Expand Up @@ -1265,7 +1275,7 @@ void menu_loop(void)

menu_enter(PicoGameLoaded);
in_set_config_int(0, IN_CFG_BLOCKING, 1);
me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
me_loop_d(e_menu_main, &sel, menu_draw_prep, menu_main_draw_status);

if (PicoGameLoaded) {
if (engineState == PGS_Menu)
Expand Down Expand Up @@ -1318,7 +1328,7 @@ int menu_loop_tray(void)
menu_enter(PicoGameLoaded);

in_set_config_int(0, IN_CFG_BLOCKING, 1);
me_loop(e_menu_tray, &sel);
me_loop_d(e_menu_tray, &sel, menu_draw_prep, NULL);

if (engineState != PGS_RestartRun) {
engineState = PGS_RestartRun;
Expand Down
11 changes: 5 additions & 6 deletions platform/common/plat_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,11 @@ void plat_video_menu_enter(int is_rom_loaded)
{
if (SDL_MUSTLOCK(plat_sdl_screen))
SDL_UnlockSurface(plat_sdl_screen);
plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 1);
resize_buffers();
}

void plat_video_menu_begin(void)
{
plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 1);
resize_buffers();
if (plat_sdl_overlay || plat_sdl_gl_active) {
g_menuscreen_pp = g_menuscreen_w;
Expand Down Expand Up @@ -318,10 +317,10 @@ void plat_early_init(void)
static void plat_sdl_resize(int w, int h)
{
// take over new settings
g_menuscreen_h = (plat_sdl_screen->h < 480 ? plat_sdl_screen->h : 480);
if (!plat_sdl_overlay && !plat_sdl_gl_active)
g_menuscreen_h = plat_sdl_screen->h;
g_menuscreen_w = g_menuscreen_h * plat_sdl_screen->w/plat_sdl_screen->h;
g_menuscreen_h = plat_sdl_screen->h;
g_menuscreen_w = plat_sdl_screen->w;
resize_buffers();
rendstatus_old = -1;
}

static void plat_sdl_quit(void)
Expand Down
1 change: 1 addition & 0 deletions platform/gp2x/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const char *men_scaling_opts[] = { "OFF", "software", "hardware", NULL };

static menu_entry e_menu_adv_options[];
static menu_entry e_menu_gfx_options[];
static menu_entry e_menu_sms_options[];
static menu_entry e_menu_options[];
static menu_entry e_menu_keyconfig[];

Expand Down
2 changes: 1 addition & 1 deletion platform/libpicofe
Submodule libpicofe updated 7 files
+20 −10 gl.c
+2 −2 gl.h
+32 −4 in_sdl.c
+3 −0 input.c
+1 −0 input.h
+1 −2 menu.c
+13 −10 plat_sdl.c
7 changes: 5 additions & 2 deletions platform/linux/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ void pemu_forced_frame(int no_scale, int do_emu)
emu_cmn_forced_frame(no_scale, do_emu, screen_buffer(g_screen_ptr));
render_bg = 0;

g_menubg_src_ptr = g_screen_ptr;
g_menubg_src_ptr = realloc(g_menubg_src_ptr, g_screen_height * g_screen_ppitch * 2);
memcpy(g_menubg_src_ptr, g_screen_ptr, g_screen_height * g_screen_ppitch * 2);
currentConfig.scaling = hs, currentConfig.vscaling = vs;
}

Expand Down Expand Up @@ -365,6 +366,7 @@ void emu_video_mode_change(int start_line, int line_count, int start_col, int co
out_y = start_line; out_x = start_col;
out_h = line_count; out_w = col_count;

plat_video_loop_prepare(); // recalculates g_screen_w/h
PicoDrawSetCallbacks(NULL, NULL);
// center output in screen
screen_w = g_screen_width, screen_x = (screen_w - out_w)/2;
Expand Down Expand Up @@ -402,7 +404,6 @@ void emu_video_mode_change(int start_line, int line_count, int start_col, int co
}

plat_video_set_size(screen_w, screen_h);
plat_video_set_buffer(g_screen_ptr);

if (screen_w < g_screen_width)
screen_x = (g_screen_width - screen_w)/2;
Expand All @@ -413,6 +414,8 @@ void emu_video_mode_change(int start_line, int line_count, int start_col, int co
screen_y += (224 - out_h)/2;
}

plat_video_set_buffer(g_screen_ptr);

// create a backing buffer for emulating the bad GG lcd display
if (currentConfig.ghosting && out_h == 144) {
int h = currentConfig.vscaling == EOPT_SCALE_SW ? 240:out_h;
Expand Down

0 comments on commit 23e4719

Please sign in to comment.