Merge branch 'gx-overlays'

Conflicts:
	Makefile.wii
	gx/gx_video.c
This commit is contained in:
Toad King 2014-02-20 19:46:43 -05:00
commit 041ec45132
6 changed files with 311 additions and 12 deletions

View File

@ -87,6 +87,8 @@ endif
HAVE_RSOUND := 1
HAVE_LIBRETRO_MANAGEMENT := 1
HAVE_ZLIB := 1
HAVE_RPNG := 1
HAVE_OVERLAY := 1
else ifeq ($(platform), psp1)
CC = psp-gcc$(EXE_EXT)
CXX = psp-g++$(EXE_EXT)
@ -139,6 +141,10 @@ ifeq ($(HAVE_ZLIB), 1)
CFLAGS += -DHAVE_ZLIB -DWANT_MINIZ
endif
ifeq ($(HAVE_OVERLAY), 1)
CFLAGS += -DHAVE_OVERLAY
endif
CFLAGS += -std=gnu99 -DSINC_LOWER_QUALITY -DHAVE_RGUI -DHAVE_MENU -DRARCH_CONSOLE -DHAVE_GRIFFIN=1 -DHAVE_SCREENSHOTS -Wno-char-subscripts -DRARCH_INTERNAL
ifeq ($(HAVE_THREADS), 1)

View File

@ -225,13 +225,105 @@ bool texture_image_load_argb_shift(const char *path, struct texture_image *out_i
#endif
#ifdef GEKKO
#define GX_BLIT_LINE_32(off) \
{ \
const uint16_t *tmp_src = src; \
uint16_t *tmp_dst = dst; \
for (unsigned x = 0; x < width2 >> 2; x += 8, tmp_src += 32, tmp_dst += 128) \
{ \
tmp_dst[ 0 + off] = tmp_src[0]; \
tmp_dst[ 16 + off] = tmp_src[1]; \
tmp_dst[ 1 + off] = tmp_src[2]; \
tmp_dst[ 17 + off] = tmp_src[3]; \
tmp_dst[ 2 + off] = tmp_src[4]; \
tmp_dst[ 18 + off] = tmp_src[5]; \
tmp_dst[ 3 + off] = tmp_src[6]; \
tmp_dst[ 19 + off] = tmp_src[7]; \
tmp_dst[ 32 + off] = tmp_src[8]; \
tmp_dst[ 48 + off] = tmp_src[9]; \
tmp_dst[ 33 + off] = tmp_src[10]; \
tmp_dst[ 49 + off] = tmp_src[11]; \
tmp_dst[ 34 + off] = tmp_src[12]; \
tmp_dst[ 50 + off] = tmp_src[13]; \
tmp_dst[ 35 + off] = tmp_src[14]; \
tmp_dst[ 51 + off] = tmp_src[15]; \
tmp_dst[ 64 + off] = tmp_src[16]; \
tmp_dst[ 80 + off] = tmp_src[17]; \
tmp_dst[ 65 + off] = tmp_src[18]; \
tmp_dst[ 81 + off] = tmp_src[19]; \
tmp_dst[ 66 + off] = tmp_src[20]; \
tmp_dst[ 82 + off] = tmp_src[21]; \
tmp_dst[ 67 + off] = tmp_src[22]; \
tmp_dst[ 83 + off] = tmp_src[23]; \
tmp_dst[ 96 + off] = tmp_src[24]; \
tmp_dst[112 + off] = tmp_src[25]; \
tmp_dst[ 97 + off] = tmp_src[26]; \
tmp_dst[113 + off] = tmp_src[27]; \
tmp_dst[ 98 + off] = tmp_src[28]; \
tmp_dst[114 + off] = tmp_src[29]; \
tmp_dst[ 99 + off] = tmp_src[30]; \
tmp_dst[115 + off] = tmp_src[31]; \
} \
src += tmp_pitch; \
}
static bool gx_convert_texture32(struct texture_image *image)
{
// memory allocation in libogc is extremely primitive so try to avoid gaps in memory when converting
// by copying over to temp buffer first then converting over into main buffer again
void *tmp = malloc(image->width * image->height * sizeof(uint32_t));
if (!tmp)
{
RARCH_ERR("Failed to create temp buffer for conversion.\n");
return false;
}
memcpy(tmp, image->pixels, image->width * image->height * sizeof(uint32_t));
unsigned tmp_pitch = (image->width * sizeof(uint32_t)) >> 1;
image->width &= ~3;
image->height &= ~3;
unsigned width2 = image->width << 1;
const uint16_t *src = (uint16_t *) tmp;
uint16_t *dst = (uint16_t *) image->pixels;
for (unsigned i = 0; i < image->height; i += 4, dst += 4 * width2)
{
GX_BLIT_LINE_32(0)
GX_BLIT_LINE_32(4)
GX_BLIT_LINE_32(8)
GX_BLIT_LINE_32(12)
}
free(tmp);
return true;
}
#endif
bool texture_image_load(const char *path, struct texture_image *out_img)
{
bool ret;
// This interface "leak" is very ugly. FIXME: Fix this properly ...
if (driver.gfx_use_rgba)
return texture_image_load_argb_shift(path, out_img, 24, 0, 8, 16);
ret = texture_image_load_argb_shift(path, out_img, 24, 0, 8, 16);
else
return texture_image_load_argb_shift(path, out_img, 24, 16, 8, 0);
ret = texture_image_load_argb_shift(path, out_img, 24, 16, 8, 0);
#ifdef GEKKO
if (ret)
{
if (!gx_convert_texture32(out_img))
{
texture_image_free(out_img);
ret = false;
}
}
#endif
return ret;
}
void texture_image_free(struct texture_image *img)

View File

@ -21,6 +21,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef GEKKO
#include <malloc.h>
#endif
#ifdef RARCH_INTERNAL
#include "../../hash.h"
#else
@ -709,7 +713,12 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un
*width = ihdr.width;
*height = ihdr.height;
#ifdef GEKKO
// we often use these in textures, make sure they're 32-byte aligned
*data = (uint32_t*)memalign(32, ihdr.width * ihdr.height * sizeof(uint32_t));
#else
*data = (uint32_t*)malloc(ihdr.width * ihdr.height * sizeof(uint32_t));
#endif
if (!*data)
GOTO_END_ERROR();

View File

@ -66,16 +66,23 @@ unsigned gx_old_width, gx_old_height;
float verts[16] ATTRIBUTE_ALIGN(32) = {
-1, 1, -0.5,
1, 1, -0.5,
-1, -1, -0.5,
1, -1, -0.5,
1, 1, -0.5,
};
float vertex_ptr[8] ATTRIBUTE_ALIGN(32) = {
0, 0,
1, 0,
0, 1,
1, 1,
1, 0,
};
u8 color_ptr[16] ATTRIBUTE_ALIGN(32) = {
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
};
static void retrace_callback(u32 retrace_count)
@ -87,6 +94,21 @@ static void retrace_callback(u32 retrace_count)
extern rgui_handle_t *rgui;
#ifdef HAVE_OVERLAY
static void gx_render_overlay(void *data);
static void gx_free_overlay(gx_video_t *gx)
{
#ifdef GX_OPTS
struct __gx_regdef *__gx = (struct __gx_regdef*)__gxregs;
#endif
free(gx->overlay);
gx->overlay = NULL;
gx->overlays = 0;
GX_InvalidateTexAll();
}
#endif
void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines)
{
unsigned modetype, level, viHeightMultiplier, viWidth, tvmode,
@ -360,20 +382,23 @@ static void init_vtx(struct __gx_regdef *__gx, void *data)
__GX_ClearVtxDesc(__gx);
__GX_SetVtxDesc(__gx, GX_VA_POS, GX_INDEX8);
__GX_SetVtxDesc(__gx, GX_VA_TEX0, GX_INDEX8);
__GX_SetVtxDesc(__gx, GX_VA_CLR0, GX_INDEX8);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
GX_SetArray(GX_VA_POS, verts, 3 * sizeof(float));
GX_SetArray(GX_VA_TEX0, vertex_ptr, 2 * sizeof(float));
GX_SetArray(GX_VA_CLR0, color_ptr, 4 * sizeof(u8));
__GX_SetNumTexGens(__gx, 1);
__GX_SetNumChans(__gx, 0);
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL);
__GX_SetNumChans(__gx, 1);
GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE);
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
__GX_InvVtxCache();
__GX_SetBlendMode(__gx, GX_BM_BLEND, GX_BL_ONE, GX_BL_INVSRCALPHA, 0);
__GX_SetBlendMode(__gx, GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
g_tex.data = memalign(32, 4 * 4 * 4);
memset(g_tex.data, 0, 4 * 4 * 4);
memset(&g_tex.obj, 0, sizeof(GXTexObj));
@ -388,10 +413,11 @@ static void build_disp_list(struct __gx_regdef *__gx)
{
DCInvalidateRange(display_list, sizeof(display_list));
GX_BeginDispList(display_list, sizeof(display_list));
__GX_Begin(__gx, GX_QUADS, GX_VTXFMT0, 4);
__GX_Begin(__gx, GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
for (unsigned i = 0; i < 4; i++)
{
__GX_Position1x8(i);
__GX_Color1x8(i);
__GX_TexCoord1x8(i);
}
GX_End();
@ -943,16 +969,21 @@ static bool gx_frame(void *data, const void *frame,
__GX_SetCurrentMtx(__gx, GX_PNMTX0);
GX_LoadTexObj(&g_tex.obj, GX_TEXMAP0);
__GX_CallDispList(__gx, display_list, display_list_size);
GX_DrawDone();
if (gx->rgui_texture_enable)
{
__GX_SetCurrentMtx(__gx, GX_PNMTX1);
GX_LoadTexObj(&menu_tex.obj, GX_TEXMAP0);
__GX_CallDispList(__gx, display_list, display_list_size);
GX_DrawDone();
}
#ifdef HAVE_OVERLAY
if (gx->overlay_enable)
gx_render_overlay(gx);
#endif
GX_DrawDone();
char fps_txt[128], fps_text_buf[128];
bool fps_draw = g_settings.fps_show;
gfx_get_fps(fps_txt, sizeof(fps_txt), fps_draw ? fps_text_buf : NULL, sizeof(fps_text_buf));
@ -1014,6 +1045,10 @@ static bool gx_focus(void *data)
static void gx_free(void *data)
{
(void)data;
#ifdef HAVE_OVERLAY
gx_video_t *gx = (gx_video_t*)driver.video_data;
gx_free_overlay(gx);
#endif
}
static void gx_set_rotation(void *data, unsigned orientation)
@ -1070,6 +1105,145 @@ static void gx_get_poke_interface(void *data, const video_poke_interface_t **ifa
*iface = &gx_poke_interface;
}
#ifdef HAVE_OVERLAY
static void gx_overlay_tex_geom(void *data, unsigned image, float x, float y, float w, float h);
static void gx_overlay_vertex_geom(void *data, unsigned image, float x, float y, float w, float h);
static bool gx_overlay_load(void *data, const struct texture_image *images, unsigned num_images)
{
unsigned i;
gx_video_t *gx = (gx_video_t*)data;
#ifdef GX_OPTS
struct __gx_regdef *__gx = (struct __gx_regdef*)__gxregs;
#endif
gx_free_overlay(gx);
gx->overlay = (struct gx_overlay_data*)calloc(num_images, sizeof(*gx->overlay));
if (!gx->overlay)
return false;
gx->overlays = num_images;
for (i = 0; i < num_images; i++)
{
struct gx_overlay_data *o = &gx->overlay[i];
GX_InitTexObj(&o->tex, images[i].pixels, images[i].width, images[i].height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
GX_InitTexObjFilterMode(&g_tex.obj, GX_LINEAR, GX_LINEAR);
DCFlushRange(images[i].pixels, images[i].width * images[i].height * sizeof(uint32_t));
gx_overlay_tex_geom(gx, i, 0, 0, 1, 1); // Default. Stretch to whole screen.
gx_overlay_vertex_geom(gx, i, 0, 0, 1, 1);
gx->overlay[i].alpha_mod = 1.0f;
}
GX_InvalidateTexAll();
return true;
}
static void gx_overlay_tex_geom(void *data, unsigned image, float x, float y, float w, float h)
{
gx_video_t *gx = (gx_video_t*)data;
struct gx_overlay_data *o = &gx->overlay[image];
o->tex_coord[0] = x; o->tex_coord[1] = y;
o->tex_coord[2] = x + w; o->tex_coord[3] = y;
o->tex_coord[4] = x; o->tex_coord[5] = y + h;
o->tex_coord[6] = x + w; o->tex_coord[7] = y + h;
}
static void gx_overlay_vertex_geom(void *data, unsigned image, float x, float y, float w, float h)
{
gx_video_t *gx = (gx_video_t*)data;
struct gx_overlay_data *o = &gx->overlay[image];
// Flipped, so we preserve top-down semantics.
y = 1.0f - y;
h = -h;
// expand from 0 - 1 to -1 - 1
x = (x * 2.0f) - 1.0f;
y = (y * 2.0f) - 1.0f;
w = (w * 2.0f);
h = (h * 2.0f);
o->vertex_coord[0] = x; o->vertex_coord[1] = y;
o->vertex_coord[2] = x + w; o->vertex_coord[3] = y;
o->vertex_coord[4] = x; o->vertex_coord[5] = y + h;
o->vertex_coord[6] = x + w; o->vertex_coord[7] = y + h;
}
static void gx_overlay_enable(void *data, bool state)
{
gx_video_t *gx = (gx_video_t*)data;
gx->overlay_enable = state;
}
static void gx_overlay_full_screen(void *data, bool enable)
{
gx_video_t *gx = (gx_video_t*)data;
gx->overlay_full_screen = enable;
}
static void gx_overlay_set_alpha(void *data, unsigned image, float mod)
{
gx_video_t *gx = (gx_video_t*)data;
gx->overlay[image].alpha_mod = mod;
}
static void gx_render_overlay(void *data)
{
gx_video_t *gx = (gx_video_t*)data;
#ifdef GX_OPTS
struct __gx_regdef *__gx = (struct __gx_regdef*)__gxregs;
#endif
GX_SetCurrentMtx(GX_PNMTX1);
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
for (unsigned i = 0; i < gx->overlays; i++)
{
GX_LoadTexObj(&gx->overlay[i].tex, GX_TEXMAP0);
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
GX_Position3f32(gx->overlay[i].vertex_coord[0], gx->overlay[i].vertex_coord[1], -0.5);
GX_Color4u8(255, 255, 255, (u8)(gx->overlay[i].alpha_mod * 255.0f));
GX_TexCoord2f32(gx->overlay[i].tex_coord[0], gx->overlay[i].tex_coord[1]);
GX_Position3f32(gx->overlay[i].vertex_coord[2], gx->overlay[i].vertex_coord[3], -0.5);
GX_Color4u8(255, 255, 255, (u8)(gx->overlay[i].alpha_mod * 255.0f));
GX_TexCoord2f32(gx->overlay[i].tex_coord[2], gx->overlay[i].tex_coord[3]);
GX_Position3f32(gx->overlay[i].vertex_coord[4], gx->overlay[i].vertex_coord[5], -0.5);
GX_Color4u8(255, 255, 255, (u8)(gx->overlay[i].alpha_mod * 255.0f));
GX_TexCoord2f32(gx->overlay[i].tex_coord[4], gx->overlay[i].tex_coord[5]);
GX_Position3f32(gx->overlay[i].vertex_coord[6], gx->overlay[i].vertex_coord[7], -0.5);
GX_Color4u8(255, 255, 255, (u8)(gx->overlay[i].alpha_mod * 255.0f));
GX_TexCoord2f32(gx->overlay[i].tex_coord[6], gx->overlay[i].tex_coord[7]);
GX_End();
}
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
}
static const video_overlay_interface_t gx_overlay_interface = {
gx_overlay_enable,
gx_overlay_load,
gx_overlay_tex_geom,
gx_overlay_vertex_geom,
gx_overlay_full_screen,
gx_overlay_set_alpha,
};
static void gx_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
{
(void)data;
*iface = &gx_overlay_interface;
}
#endif
const video_driver_t video_gx = {
.init = gx_init,
.frame = gx_frame,
@ -1081,5 +1255,8 @@ const video_driver_t video_gx = {
.set_rotation = gx_set_rotation,
.viewport_info = gx_viewport_info,
.restart = gx_restart,
#ifdef HAVE_OVERLAY
.overlay_interface = gx_get_overlay_interface,
#endif
.poke_interface = gx_get_poke_interface,
};

View File

@ -18,6 +18,14 @@
#ifndef _GX_VIDEO_H__
#define _GX_VIDEO_H__
struct gx_overlay_data
{
GXTexObj tex;
float tex_coord[8];
float vertex_coord[8];
float alpha_mod;
};
typedef struct gx_video
{
bool should_resize;
@ -28,6 +36,12 @@ typedef struct gx_video
bool rgui_texture_enable;
rarch_viewport_t vp;
unsigned scale;
#ifdef HAVE_OVERLAY
struct gx_overlay_data *overlay;
unsigned overlays;
bool overlay_enable;
bool overlay_full_screen;
#endif
} gx_video_t;
void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines);

View File

@ -781,3 +781,4 @@ static void __GX_SetCopyFilter(u8 aa,u8 sample_pattern[12][2],u8 vf,u8 vfilter[7
#define __GX_Position1x8(index) FIFO_PUTU8(index)
#define __GX_TexCoord1x8(index) FIFO_PUTU8(index)
#define __GX_Color1x8(index) FIFO_PUTU8(index)