(Vita) Add Overlays

This commit is contained in:
Francisco José García García 2015-09-29 20:01:13 +02:00
parent 1f1d58bf61
commit 4f7be65f32

View File

@ -31,6 +31,24 @@ typedef struct vita_menu_frame
vita2d_texture *texture;
} vita_menu_t;
#ifdef HAVE_OVERLAY
struct vita_overlay_data
{
vita2d_texture *tex;
float x;
float y;
float w;
float h;
float tex_x;
float tex_y;
float tex_w;
float tex_h;
float alpha_mod;
float width;
float height;
};
#endif
typedef struct vita_video
{
vita2d_texture *texture;
@ -51,6 +69,14 @@ typedef struct vita_video
bool should_resize;
vita_menu_t menu;
#ifdef HAVE_OVERLAY
struct vita_overlay_data *overlay;
unsigned overlays;
bool overlay_enable;
bool overlay_full_screen;
#endif
} vita_video_t;
static void *vita2d_gfx_init(const video_info_t *video,
@ -105,10 +131,27 @@ static void *vita2d_gfx_init(const video_info_t *video,
vita->keep_aspect = true;
vita->should_resize = true;
#ifdef HAVE_OVERLAY
vita->overlay_enable = false;
#endif
return vita;
}
#ifdef HAVE_OVERLAY
static void vita2d_render_overlay(void *data);
static void vita2d_free_overlay(vita_video_t *vita)
{
for (unsigned i = 0; i < vita->overlays; i++)
{
vita2d_free_texture(vita->overlay[i].tex);
}
free(vita->overlay);
vita->overlay = NULL;
vita->overlays = 0;
//GX_InvalidateTexAll();
}
#endif
static void vita2d_gfx_update_viewport(vita_video_t* vita);
static bool vita2d_gfx_frame(void *data, const void *frame,
@ -221,6 +264,11 @@ static bool vita2d_gfx_frame(void *data, const void *frame,
}
}
}
#ifdef HAVE_OVERLAY
if (vita->overlay_enable)
vita2d_render_overlay(vita);
#endif
vita2d_end_drawing();
vita2d_swap_buffers();
@ -561,6 +609,146 @@ static void vita2d_gfx_get_poke_interface(void *data,
*iface = &vita_poke_interface;
}
#ifdef HAVE_OVERLAY
static void vita2d_overlay_tex_geom(void *data, unsigned image, float x, float y, float w, float h);
static void vita2d_overlay_vertex_geom(void *data, unsigned image, float x, float y, float w, float h);
static bool vita2d_overlay_load(void *data, const void *image_data, unsigned num_images)
{
unsigned i,j,k;
unsigned int stride, pitch;
vita_video_t *vita = (vita_video_t*)data;
const struct texture_image *images = (const struct texture_image*)image_data;
vita2d_free_overlay(vita);
vita->overlay = (struct vita_overlay_data*)calloc(num_images, sizeof(*vita->overlay));
if (!vita->overlay)
return false;
vita->overlays = num_images;
for (i = 0; i < num_images; i++)
{
struct vita_overlay_data *o = (struct vita_overlay_data*)&vita->overlay[i];
o->width = images[i].width;
o->height = images[i].height;
o->tex = vita2d_create_empty_texture_format(o->width , o->height, SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB);
vita2d_texture_set_filters(o->tex,SCE_GXM_TEXTURE_FILTER_LINEAR,SCE_GXM_TEXTURE_FILTER_LINEAR);
stride = vita2d_texture_get_stride(o->tex);
stride /= 4;
uint32_t *tex32 = vita2d_texture_get_datap(o->tex);
const uint32_t *frame32 = images[i].pixels;
pitch = o->width;
for (j = 0; j < o->height; j++)
for (k = 0; k < o->width; k++)
tex32[k + j*stride] = frame32[k + j*pitch];
vita2d_overlay_tex_geom(vita, i, 0, 0, 1, 1); /* Default. Stretch to whole screen. */
vita2d_overlay_vertex_geom(vita, i, 0, 0, 1, 1);
vita->overlay[i].alpha_mod = 1.0f;
}
return true;
}
static void vita2d_overlay_tex_geom(void *data, unsigned image,
float x, float y, float w, float h)
{
vita_video_t *vita = (vita_video_t*)data;
struct vita_overlay_data *o;
o = NULL;
if (vita)
o = (struct vita_overlay_data*)&vita->overlay[image];
if (o)
{
o->tex_x = x;
o->tex_y = y;
o->tex_w = w*o->width;
o->tex_h = h*o->height;
}
}
static void vita2d_overlay_vertex_geom(void *data, unsigned image,
float x, float y, float w, float h)
{
vita_video_t *vita = (vita_video_t*)data;
struct vita_overlay_data *o;
o = NULL;
/* Flipped, so we preserve top-down semantics. */
/*y = 1.0f - y;
h = -h;*/
if (vita)
o = (struct vita_overlay_data*)&vita->overlay[image];
if (o)
{
o->w = w*PSP_FB_WIDTH/o->width;
o->h = h*PSP_FB_HEIGHT/o->height;
o->x = PSP_FB_WIDTH*(1-w)/2+x;
o->y = PSP_FB_HEIGHT*(1-h)/2+y;
}
}
static void vita2d_overlay_enable(void *data, bool state)
{
vita_video_t *vita = (vita_video_t*)data;
vita->overlay_enable = state;
}
static void vita2d_overlay_full_screen(void *data, bool enable)
{
vita_video_t *vita = (vita_video_t*)data;
vita->overlay_full_screen = enable;
}
static void vita2d_overlay_set_alpha(void *data, unsigned image, float mod)
{
vita_video_t *vita = (vita_video_t*)data;
vita->overlay[image].alpha_mod = mod;
}
static void vita2d_render_overlay(void *data)
{
vita_video_t *vita = (vita_video_t*)data;
for (unsigned i = 0; i < vita->overlays; i++)
{
vita2d_draw_texture_tint_part_scale(vita->overlay[i].tex,
vita->overlay[i].x,
vita->overlay[i].y,
vita->overlay[i].tex_x,
vita->overlay[i].tex_y,
vita->overlay[i].tex_w,
vita->overlay[i].tex_h,
vita->overlay[i].w,
vita->overlay[i].h,
RGBA8(0xFF,0xFF,0xFF,(uint8_t)(vita->overlay[i].alpha_mod * 255.0f)));
//RGBA8(0x00, 0x00, 0x00, (uint8_t)(vita->overlay[i].alpha_mod * 255.0f)));
}
}
static const video_overlay_interface_t vita2d_overlay_interface = {
vita2d_overlay_enable,
vita2d_overlay_load,
vita2d_overlay_tex_geom,
vita2d_overlay_vertex_geom,
vita2d_overlay_full_screen,
vita2d_overlay_set_alpha,
};
static void vita2d_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
{
(void)data;
*iface = &vita2d_overlay_interface;
}
#endif
video_driver_t video_vita2d = {
vita2d_gfx_init,
vita2d_gfx_frame,
@ -577,9 +765,8 @@ video_driver_t video_vita2d = {
vita2d_gfx_viewport_info,
vita2d_gfx_read_viewport,
NULL, /* read_frame_raw */
#ifdef HAVE_OVERLAY
NULL, /* overlay_interface */
vita2d_get_overlay_interface,
#endif
vita2d_gfx_get_poke_interface,
};