Create Font driver for PS2

This commit is contained in:
Francisco Javier Trujillo Mata 2019-01-07 21:49:55 +01:00
parent aa231dca10
commit 26ce69694f
7 changed files with 202 additions and 8 deletions

View File

@ -40,7 +40,7 @@ RARCH_DEFINES += -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -
LIBDIR =
LDFLAGS += -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ee/lib -L.
LIBS += -lretro_ps2 -lgskit -ldmakit -laudsrv -lpad -lmc -lhdd -lsdl -lfileXio -lpatches -lpoweroff
LIBS += -lretro_ps2 -lgskit -ldmakit -lgskit_toolkit -laudsrv -lpad -lmc -lhdd -lsdl -lfileXio -lpatches -lpoweroff
#IRX modules
# IRX modules - modules have to be in IRX_DIR
@ -73,6 +73,7 @@ EE_OBJS += ps2/compat_files/compat_ctype.o ps2/compat_files/time.o
EE_OBJS += griffin/griffin.o
EE_CFLAGS = $(CFLAGS)
EE_CXXFLAGS = $(CFLAGS)
EE_LDFLAGS = $(LDFLAGS)
EE_LIBS = $(LIBS)
EE_ASFLAGS = $(ASFLAGS)

View File

@ -196,6 +196,9 @@ static void *ps2_gfx_init(const video_info_t *video,
return NULL;
init_ps2_video(ps2);
if (video->font_enable) {
font_driver_init_osd(ps2, false, video->is_threaded, FONT_DRIVER_RENDER_PS2);
}
ps2->rgb32 = video->rgb32;
ps2->fullscreen = video->fullscreen;
ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST;
@ -223,7 +226,6 @@ static bool ps2_gfx_frame(void *data, const void *frame,
static float fps = 0.0;
#endif
ps2_video_t *ps2 = (ps2_video_t*)data;
bool texture_empty = true;
if (!width || !height)
return false;
@ -241,11 +243,25 @@ static bool ps2_gfx_frame(void *data, const void *frame,
prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect);
}
texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
if (ps2->menuVisible && !texture_empty) {
vram_alloc(ps2->gsGlobal, ps2->menuTexture);
gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture);
prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen);
if (ps2->menuVisible) {
bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
if (!texture_empty) {
vram_alloc(ps2->gsGlobal, ps2->menuTexture);
gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture);
prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen);
}
} else if (video_info->statistics_show) {
struct font_params *osd_params = (struct font_params*)
&video_info->osd_stat_params;
if (osd_params) {
font_driver_render_msg(video_info, NULL, video_info->stat_text,
(const struct font_params*)&video_info->osd_stat_params);
}
}
if(!string_is_empty(msg)) {
font_driver_render_msg(video_info, NULL, msg, NULL);
}
gsKit_sync_flip(ps2->gsGlobal);
@ -292,6 +308,8 @@ static void ps2_gfx_free(void *data)
gsKit_clear(ps2->gsGlobal, GS_BLACK);
gsKit_vram_clear(ps2->gsGlobal);
font_driver_free_osd();
deinitTexture(ps2->menuTexture);
deinitTexture(ps2->coreTexture);
@ -364,6 +382,14 @@ static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen)
ps2->fullscreen = fullscreen;
}
static void ps2_set_osd_msg(void *data,
video_frame_info_t *video_info,
const char *msg,
const void *params, void *font)
{
font_driver_render_msg(video_info, font, msg, params);
}
static const video_poke_interface_t ps2_poke_interface = {
NULL, /* get_flags */
NULL, /* set_coords */
@ -382,7 +408,7 @@ static const video_poke_interface_t ps2_poke_interface = {
ps2_apply_state_changes,
ps2_set_texture_frame,
ps2_set_texture_enable,
NULL, /* set_osd_msg */
ps2_set_osd_msg, /* set_osd_msg */
NULL, /* show_mouse */
NULL, /* grab_mouse_toggle */
NULL, /* get_current_shader */

126
gfx/drivers_font/ps2_font.c Normal file
View File

@ -0,0 +1,126 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2019 - Francisco Javier Trujillo Mata
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <gsKit.h>
#include <dmaKit.h>
#include <gsToolkit.h>
#include "../font_driver.h"
#define FONTM_VRAM_SIZE 4096
#define FONTM_TEXTURE_COLOR GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00)
#define FONTM_TEXTURE_WIDTH 52
#define FONTM_TEXTURE_HEIGHT 832
#define FONTM_TEXTURE_SPACING 1.0f
#define FONTM_TEXTURE_SCALED 0.5f
#define FONTM_TEXTURE_LEFT_MARGIN 0
#define FONTM_TEXTURE_BOTTOM_MARGIN 15
#define FONTM_TEXTURE_ZPOSITION 3
typedef struct ps2_font_info
{
GSGLOBAL *gsGlobal;
GSFONTM *gsFontM;
} ps2_font_info_t;
/* Copied from GSKIT FONTM CLUT
FONTM Textures are GS_PSM_T4, and need a 16x16 CLUT
This is a greyscale ramp CLUT, with linear alpha. */
static u32 gsKit_fontm_clut[16] = { 0x00000000, 0x11111111, 0x22222222, 0x33333333, \
0x44444444, 0x55555555, 0x66666666, 0x77777777, \
0x80888888, 0x80999999, 0x80AAAAAA, 0x80BBBBBB, \
0x80CCCCCC, 0x80DDDDDD, 0x80EEEEEE, 0x80FFFFFF };
static void ps2_prepare_font(GSGLOBAL *gsGlobal, GSFONTM *gsFontM) {
if(gsKit_fontm_unpack(gsFontM) == 0) {
gsFontM->Texture->Width = FONTM_TEXTURE_WIDTH;
gsFontM->Texture->Height = FONTM_TEXTURE_HEIGHT;
gsFontM->Texture->PSM = GS_PSM_T4;
gsFontM->Texture->ClutPSM = GS_PSM_CT32;
gsFontM->Texture->Filter = GS_FILTER_LINEAR;
gsKit_setup_tbw(gsFontM->Texture);
}
}
static void ps2_upload_font(GSGLOBAL *gsGlobal, GSFONTM *gsFontM) {
int pgindx;
int TexSize = gsKit_texture_size(gsFontM->Texture->Width, gsFontM->Texture->Height, gsFontM->Texture->PSM);
free(gsFontM->Texture->VramClut);
gsFontM->Texture->VramClut = gsKit_vram_alloc(gsGlobal, FONTM_VRAM_SIZE, GSKIT_ALLOC_USERBUFFER);
for (pgindx = 0; pgindx < GS_FONTM_PAGE_COUNT; ++pgindx) {
free(gsFontM->Vram[pgindx]);
gsFontM->Vram[pgindx] = gsKit_vram_alloc(gsGlobal, TexSize, GSKIT_ALLOC_USERBUFFER);
gsFontM->LastPage[pgindx] = (u32) -1;
}
gsFontM->Texture->Vram = gsFontM->Vram[0];
gsFontM->VramIdx = 0;
gsFontM->Spacing = FONTM_TEXTURE_SPACING;
gsFontM->Align = GSKIT_FALIGN_LEFT;
gsFontM->Texture->Clut = memalign(GS_VRAM_TBWALIGN_CLUT, GS_VRAM_TBWALIGN);
memcpy(gsFontM->Texture->Clut, gsKit_fontm_clut, GS_VRAM_TBWALIGN);
gsKit_texture_send(gsFontM->Texture->Clut, 8, 2, gsFontM->Texture->VramClut, gsFontM->Texture->ClutPSM, 1, GS_CLUT_PALLETE);
free(gsFontM->Texture->Clut);
}
static void *ps2_font_init_font(void *gl_data, const char *font_path,
float font_size, bool is_threaded)
{
ps2_font_info_t *ps2 = (ps2_font_info_t*)calloc(1, sizeof(ps2_font_info_t));
ps2_video_t *ps2_video = (ps2_video_t *)gl_data;
ps2->gsGlobal = ps2_video->gsGlobal;
ps2->gsFontM = gsKit_init_fontm();
ps2_prepare_font(ps2->gsGlobal, ps2->gsFontM);
return ps2;
}
static void ps2_font_free_font(void *data, bool is_threaded)
{
ps2_font_info_t *ps2 = (ps2_font_info_t *)data;
free(ps2->gsFontM);
free(ps2);
}
static void ps2_font_render_msg(
video_frame_info_t *video_info,
void *data, const char *msg,
const struct font_params *params)
{
ps2_font_info_t *ps2 = (ps2_font_info_t *)data;
if (ps2) {
int x = FONTM_TEXTURE_LEFT_MARGIN;
int y = ps2->gsGlobal->Height - FONTM_TEXTURE_BOTTOM_MARGIN;
ps2_upload_font(ps2->gsGlobal, ps2->gsFontM);
gsKit_fontm_print_scaled(ps2->gsGlobal, ps2->gsFontM, x, y, FONTM_TEXTURE_ZPOSITION,
FONTM_TEXTURE_SCALED , FONTM_TEXTURE_COLOR, msg);
}
}
font_renderer_t ps2_font = {
ps2_font_init_font,
ps2_font_free_font,
ps2_font_render_msg,
"PS2 font",
NULL, /* get_glyph */
NULL, /* bind_block */
NULL, /* flush */
NULL, /* get_message_width */
};

View File

@ -464,6 +464,36 @@ static bool d3d12_font_init_first(
}
#endif
#ifdef PS2
static const font_renderer_t *ps2_font_backends[] = {
&ps2_font
};
static bool ps2_font_init_first(
const void **font_driver, void **font_handle,
void *video_data, const char *font_path,
float font_size, bool is_threaded)
{
unsigned i;
for (i = 0; ps2_font_backends[i]; i++)
{
void *data = ps2_font_backends[i]->init(
video_data, font_path, font_size,
is_threaded);
if (!data)
continue;
*font_driver = ps2_font_backends[i];
*font_handle = data;
return true;
}
return false;
}
#endif
#ifdef HAVE_VITA2D
static const font_renderer_t *vita2d_font_backends[] = {
&vita2d_vita_font
@ -641,6 +671,11 @@ static bool font_init_first(
return vita2d_font_init_first(font_driver, font_handle,
video_data, font_path, font_size, is_threaded);
#endif
#ifdef PS2
case FONT_DRIVER_RENDER_PS2:
return ps2_font_init_first(font_driver, font_handle,
video_data, font_path, font_size, is_threaded);
#endif
#ifdef _3DS
case FONT_DRIVER_RENDER_CTR:
return ctr_font_init_first(font_driver, font_handle,

View File

@ -161,6 +161,7 @@ extern font_renderer_t libdbg_font;
extern font_renderer_t d3d_xbox360_font;
extern font_renderer_t d3d_xdk1_font;
extern font_renderer_t d3d_win32_font;
extern font_renderer_t ps2_font;
extern font_renderer_t vita2d_vita_font;
extern font_renderer_t ctr_font;
extern font_renderer_t wiiu_font;

View File

@ -88,6 +88,7 @@ enum font_driver_render_api
FONT_DRIVER_RENDER_D3D10_API,
FONT_DRIVER_RENDER_D3D11_API,
FONT_DRIVER_RENDER_D3D12_API,
FONT_DRIVER_RENDER_PS2,
FONT_DRIVER_RENDER_VITA2D,
FONT_DRIVER_RENDER_CTR,
FONT_DRIVER_RENDER_WIIU,

View File

@ -498,6 +498,10 @@ FONTS
#include "../gfx/drivers_font/xdk1_xfonts.c"
#endif
#if defined(PS2)
#include "../gfx/drivers_font/ps2_font.c"
#endif
#if defined(VITA)
#include "../gfx/drivers_font/vita2d_font.c"
#endif