(WiiU) add a menu display driver. enable MATERIALUI and XMB.

This commit is contained in:
aliaspider 2017-05-22 01:45:40 +01:00
parent 0b1716650b
commit db490a69a3
9 changed files with 266 additions and 40 deletions

View File

@ -39,7 +39,7 @@ ifeq ($(GRIFFIN_BUILD), 1)
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DWANT_ZLIB -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_STB_FONT -DHAVE_LANGEXTRA
# DEFINES += -DHAVE_FREETYPE
# DEFINES += -DHAVE_XMB -DHAVE_MATERIALUI
DEFINES += -DHAVE_XMB -DHAVE_MATERIALUI
else
HAVE_MENU_COMMON = 1
HAVE_RTGA = 1
@ -52,8 +52,8 @@ else
HAVE_BUILTINZLIB = 1
HAVE_LIBRETRODB = 1
HAVE_ZARCH = 0
HAVE_MATERIALUI = 0
HAVE_XMB = 0
HAVE_MATERIALUI = 1
HAVE_XMB = 1
HAVE_STB_FONT = 1
# HAVE_FREETYPE = 1
HAVE_LANGEXTRA = 1
@ -66,7 +66,7 @@ else
OBJ += gfx/drivers/wiiu_gfx.o
OBJ += gfx/drivers_font/wiiu_font.o
# OBJ += menu/drivers_display/menu_display_wiiu.o
OBJ += menu/drivers_display/menu_display_wiiu.o
OBJ += input/drivers/wiiu_input.o
OBJ += input/drivers_joypad/wiiu_joypad.o
OBJ += audio/drivers/wiiu_audio.o

View File

@ -64,6 +64,13 @@ typedef struct
int width;
int height;
struct
{
position_t* positions;
tex_coord_t* tex_coords;
int size;
int current;
}vertex_cache;
void* drc_scan_buffer;
void* tv_scan_buffer;

View File

@ -17,6 +17,7 @@
#include <string.h>
#include <wiiu/os.h>
#include <wiiu/gx2.h>
#include <formats/image.h>
#include "../../driver.h"
#include "../../configuration.h"
@ -391,6 +392,11 @@ static void* wiiu_gfx_init(const video_info_t* video,
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image,
wiiu->menu.texture.surface.imageSize);
wiiu->vertex_cache.size = 0x1000;
wiiu->vertex_cache.current = 0;
wiiu->vertex_cache.positions = MEM2_alloc(wiiu->vertex_cache.size * sizeof(position_t), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu->vertex_cache.tex_coords = MEM2_alloc(wiiu->vertex_cache.size * sizeof(tex_coord_t), GX2_VERTEX_BUFFER_ALIGNMENT);
/* init samplers */
GX2InitSampler(&wiiu->sampler_nearest, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_POINT);
GX2InitSampler(&wiiu->sampler_linear, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_LINEAR);
@ -459,6 +465,8 @@ static void wiiu_gfx_free(void* data)
MEM2_free(wiiu->cmd_buffer);
MEM2_free(wiiu->texture.surface.image);
MEM2_free(wiiu->menu.texture.surface.image);
MEM2_free(wiiu->vertex_cache.positions);
MEM2_free(wiiu->vertex_cache.tex_coords);
MEM1_free(wiiu->color_buffer.surface.image);
@ -601,10 +609,6 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1);
#ifdef HAVE_MENU
menu_driver_frame(video_info);
#endif
if (wiiu->menu.enable)
{
GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->menu.position), sizeof(*wiiu->menu.position), wiiu->menu.position);
@ -616,9 +620,20 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1);
}
wiiu->vertex_cache.current = 0;
GX2SetAttribBuffer(0, wiiu->vertex_cache.size * sizeof(position_t), sizeof(position_t), wiiu->vertex_cache.positions);
GX2SetAttribBuffer(1, wiiu->vertex_cache.size * sizeof(tex_coord_t), sizeof(tex_coord_t), wiiu->vertex_cache.tex_coords);
GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location);
if (wiiu->menu.enable)
menu_driver_frame(video_info);
if (msg)
font_driver_render_msg(video_info, NULL, msg, NULL);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.positions, wiiu->vertex_cache.current * sizeof(position_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.tex_coords, wiiu->vertex_cache.current * sizeof(tex_coord_t));
if (wiiu->menu.enable)
GX2DrawDone();
@ -698,11 +713,46 @@ static bool wiiu_gfx_read_viewport(void* data, uint8_t* buffer, bool is_idle)
static uintptr_t wiiu_gfx_load_texture(void* video_data, void* data,
bool threaded, enum texture_filter_type filter_type)
{
return 0;
int i;
wiiu_video_t* wiiu = (wiiu_video_t*) video_data;
struct texture_image *image = (struct texture_image*)data;
if (!wiiu)
return 0;
GX2Texture* texture = calloc(1, sizeof(GX2Texture));
texture->surface.width = image->width;
texture->surface.height = image->height;
texture->surface.depth = 1;
texture->surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
texture->surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
texture->viewNumSlices = 1;
texture->surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
texture->compMap = GX2_COMP_SEL(_G, _B, _A, _R);
GX2CalcSurfaceSizeAndAlignment(&texture->surface);
GX2InitTextureRegs(texture);
texture->surface.image = MEM2_alloc(texture->surface.imageSize, texture->surface.alignment);
for (i = 0; (i < image->height) && (i < texture->surface.height); i++)
memcpy((uint32_t*)texture->surface.image + (i * texture->surface.pitch),
image->pixels + (i * image->width), image->width * sizeof(image->pixels));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, texture->surface.image, texture->surface.imageSize);
return (uintptr_t)texture;
}
static void wiiu_gfx_unload_texture(void* data, uintptr_t handle)
{
GX2Texture* texture = (GX2Texture*)handle;
if(!texture)
return;
MEM2_free(texture->surface.image);
free(texture);
}
static void wiiu_gfx_set_filtering(void* data, unsigned index, bool smooth)
{

View File

@ -35,13 +35,6 @@ typedef struct
const font_renderer_driver_t* font_driver;
void* font_data;
struct font_atlas* atlas;
struct
{
position_t* positions;
tex_coord_t* tex_coords;
int size;
int current;
}vertex_cache;
} wiiu_font_t;
static void* wiiu_font_init_font(void* data, const char* font_path,
@ -78,7 +71,7 @@ static void* wiiu_font_init_font(void* data, const char* font_path,
font->texture.surface.alignment);
for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),
memcpy((uint8_t*)font->texture.surface.image + (i * font->texture.surface.pitch),
font->atlas->buffer + (i * font->atlas->width), font->atlas->width);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image,
@ -86,10 +79,6 @@ static void* wiiu_font_init_font(void* data, const char* font_path,
font->atlas->dirty = false;
font->vertex_cache.size = 0x1000;
font->vertex_cache.positions = MEM2_alloc(font->vertex_cache.size * sizeof(position_t), GX2_VERTEX_BUFFER_ALIGNMENT);
font->vertex_cache.tex_coords = MEM2_alloc(font->vertex_cache.size * sizeof(tex_coord_t), GX2_VERTEX_BUFFER_ALIGNMENT);
return font;
}
@ -104,8 +93,6 @@ static void wiiu_font_free_font(void* data, bool is_threaded)
font->font_driver->free(font->font_data);
MEM1_free(font->texture.surface.image);
MEM2_free(font->vertex_cache.positions);
MEM2_free(font->vertex_cache.tex_coords);
free(font);
}
@ -159,7 +146,7 @@ static void wiiu_font_render_line(
int delta_x = 0;
int delta_y = 0;
if(font->vertex_cache.size < (msg_len * 4))
if(wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size)
return;
switch (text_align)
@ -173,11 +160,8 @@ static void wiiu_font_render_line(
break;
}
if ((font->vertex_cache.size - font->vertex_cache.current) < (msg_len * 4))
font->vertex_cache.current = 0;
position_t* pos = font->vertex_cache.positions + font->vertex_cache.current;
tex_coord_t* coord = font->vertex_cache.tex_coords + font->vertex_cache.current;
position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current;
tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current;
for (i = 0; i < msg_len; i++)
{
@ -239,13 +223,14 @@ static void wiiu_font_render_line(
delta_y += glyph->advance_y;
}
int count = pos - font->vertex_cache.positions - font->vertex_cache.current;
int count = pos - wiiu->vertex_cache.positions - wiiu->vertex_cache.current;
if (!count)
return;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, font->vertex_cache.positions + font->vertex_cache.current, count * sizeof(position_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, font->vertex_cache.tex_coords + font->vertex_cache.current, count * sizeof(tex_coord_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.positions + wiiu->vertex_cache.current, count * sizeof(position_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current, count * sizeof(tex_coord_t));
if(font->atlas->dirty)
{
@ -264,11 +249,7 @@ static void wiiu_font_render_line(
DEBUG_VAR(color);
#endif
GX2SetAttribBuffer(0, font->vertex_cache.size * sizeof(position_t), sizeof(position_t), font->vertex_cache.positions);
GX2SetAttribBuffer(1, font->vertex_cache.size * sizeof(tex_coord_t), sizeof(tex_coord_t), font->vertex_cache.tex_coords);
GX2SetPixelTexture(&font->texture, wiiu->shader->sampler.location);
GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location);
GX2SetBlendConstantColor(((color >> 0) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f,
((color >> 16) & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
@ -276,12 +257,12 @@ static void wiiu_font_render_line(
GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_BLEND_FACTOR, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD,
GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD);
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, font->vertex_cache.current, 1);
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, wiiu->vertex_cache.current, 1);
GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD,
GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD);
font->vertex_cache.current = pos - font->vertex_cache.positions;
wiiu->vertex_cache.current = pos - wiiu->vertex_cache.positions;
}
static void wiiu_font_render_message(

View File

@ -224,7 +224,7 @@ static void *font_renderer_stb_unicode_init(const char *font_path, float font_si
if(!*font_path)
{
uint32_t size = 0;
if (!OSGetSharedData(SHARED_FONT_DEFAULT, 0, &self->font_data, &size))
if (!OSGetSharedData(SHARED_FONT_DEFAULT, 0, (void**)&self->font_data, &size))
goto error;
}
else

View File

@ -1002,6 +1002,10 @@ MENU
#include "../menu/drivers_display/menu_display_ctr.c"
#endif
#ifdef WIIU
#include "../menu/drivers_display/menu_display_wiiu.c"
#endif
#ifdef HAVE_CACA
#include "../menu/drivers_display/menu_display_caca.c"
#endif

View File

@ -0,0 +1,175 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2017 - Ali Bouhlel
*
* 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 <wiiu/gx2.h>
#include <retro_miscellaneous.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "menu/menu_driver.h"
#include "retroarch.h"
#include "gfx/font_driver.h"
#include "gfx/video_driver.h"
#include "gfx/common/gx2_common.h"
#include "wiiu/wiiu_dbg.h"
static const float *menu_display_wiiu_get_default_vertices(void)
{
return NULL;
}
static const float *menu_display_wiiu_get_default_tex_coords(void)
{
return NULL;
}
static void *menu_display_wiiu_get_default_mvp(void)
{
return NULL;
}
static void menu_display_wiiu_blend_begin(void)
{
}
static void menu_display_wiiu_blend_end(void)
{
}
static void menu_display_wiiu_viewport(void *data)
{
}
static void menu_display_wiiu_draw(void *data)
{
GX2Texture *texture = NULL;
wiiu_video_t *wiiu = (wiiu_video_t*)video_driver_get_ptr(false);
menu_display_ctx_draw_t *draw = (menu_display_ctx_draw_t*)data;
if (!wiiu || !draw)
return;
texture = (GX2Texture*)draw->texture;
if (!texture)
return;
if (wiiu->vertex_cache.current + 4 > wiiu->vertex_cache.size)
return;
position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current;
tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current;
float x0 = draw->x;
float y0 = draw->y;
float x1 = x0 + draw->width;
float y1 = y0 + draw->height;
pos[0].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;
pos[0].y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f;
pos[1].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[1].y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f;
pos[2].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[2].y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f;
pos[3].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[3].y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f;
coord[0].u = 0.0f;
coord[0].v = 1.0f;
coord[1].u = 1.0f;
coord[1].v = 1.0f;
coord[2].u = 1.0f;
coord[2].v = 0.0f;
coord[3].u = 0.0f;
coord[3].v = 0.0f;
GX2SetPixelTexture(texture, wiiu->shader->sampler.location);
// GX2SetBlendConstantColor(draw->coords->color[3], draw->coords->color[2], draw->coords->color[1], draw->coords->color[0]);
// GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD,
// GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD);
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, wiiu->vertex_cache.current, 1);
#if 0
printf("(%i,%i,%i,%i) , (%i,%i)\n", (int)draw->x,
(int)draw->y, (int)draw->width, (int)draw->height,
texture->surface.width, texture->surface.height);
#endif
wiiu->vertex_cache.current += 4;
}
static void menu_display_wiiu_draw_pipeline(void *data)
{
}
static void menu_display_wiiu_restore_clear_color(void)
{
#if 0
wiiu_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
#endif
}
static void menu_display_wiiu_clear_color(menu_display_ctx_clearcolor_t *clearcolor)
{
if (!clearcolor)
return;
#if 0
wiiu_set_clear_color(RGBA8((int)(clearcolor->r*255.f),
(int)(clearcolor->g*255.f),
(int)(clearcolor->b*255.f),
(int)(clearcolor->a*255.f)));
wiiu_clear_screen();
#endif
}
static bool menu_display_wiiu_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size,
bool is_threaded)
{
font_data_t **handle = (font_data_t**)font_handle;
*handle = font_driver_init_first(video_data,
font_path, font_size, true,
is_threaded,
FONT_DRIVER_RENDER_WIIU);
return *handle;
}
menu_display_ctx_driver_t menu_display_ctx_wiiu = {
menu_display_wiiu_draw,
menu_display_wiiu_draw_pipeline,
menu_display_wiiu_viewport,
menu_display_wiiu_blend_begin,
menu_display_wiiu_blend_end,
menu_display_wiiu_restore_clear_color,
menu_display_wiiu_clear_color,
menu_display_wiiu_get_default_mvp,
menu_display_wiiu_get_default_vertices,
menu_display_wiiu_get_default_tex_coords,
menu_display_wiiu_font_init_first,
MENU_VIDEO_DRIVER_WIIU,
"menu_display_wiiu",
};

View File

@ -100,6 +100,9 @@ static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = {
#ifdef _3DS
&menu_display_ctx_ctr,
#endif
#ifdef WIIU
&menu_display_ctx_wiiu,
#endif
#ifdef HAVE_CACA
&menu_display_ctx_caca,
#endif
@ -205,6 +208,10 @@ static bool menu_display_check_compatibility(
if (string_is_equal_fast(video_driver, "ctr", 3))
return true;
break;
case MENU_VIDEO_DRIVER_WIIU:
if (string_is_equal_fast(video_driver, "gx2", 3))
return true;
break;
case MENU_VIDEO_DRIVER_CACA:
if (string_is_equal_fast(video_driver, "caca", 4))
return true;
@ -937,7 +944,7 @@ void menu_display_draw_texture_slice(
void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw)
{
#if !defined(VITA)
#if !defined(VITA) && !defined(_3DS) && !defined(WIIU)
math_matrix_4x4 matrix_rotated, matrix_scaled;
math_matrix_4x4 *b = NULL;

View File

@ -276,6 +276,7 @@ enum menu_display_driver_type
MENU_VIDEO_DRIVER_DIRECT3D,
MENU_VIDEO_DRIVER_VITA2D,
MENU_VIDEO_DRIVER_CTR,
MENU_VIDEO_DRIVER_WIIU,
MENU_VIDEO_DRIVER_CACA,
MENU_VIDEO_DRIVER_GDI,
MENU_VIDEO_DRIVER_VGA
@ -692,6 +693,7 @@ extern menu_display_ctx_driver_t menu_display_ctx_vulkan;
extern menu_display_ctx_driver_t menu_display_ctx_d3d;
extern menu_display_ctx_driver_t menu_display_ctx_vita2d;
extern menu_display_ctx_driver_t menu_display_ctx_ctr;
extern menu_display_ctx_driver_t menu_display_ctx_wiiu;
extern menu_display_ctx_driver_t menu_display_ctx_caca;
extern menu_display_ctx_driver_t menu_display_ctx_gdi;
extern menu_display_ctx_driver_t menu_display_ctx_vga;