2017-05-22 01:45:40 +01:00
|
|
|
/* 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
|
2021-08-18 14:19:48 -04:00
|
|
|
#include "../../config.h"
|
2017-05-22 01:45:40 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
#include "../gfx_display.h"
|
2019-06-17 15:10:22 +02:00
|
|
|
|
|
|
|
#include "../../retroarch.h"
|
2020-02-16 15:26:58 +01:00
|
|
|
#include "../font_driver.h"
|
|
|
|
#include "../common/gx2_common.h"
|
2019-06-17 15:10:22 +02:00
|
|
|
#include "../../wiiu/system/memory.h"
|
|
|
|
#include "../../wiiu/wiiu_dbg.h"
|
2017-05-22 01:45:40 +01:00
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static void gfx_display_wiiu_draw(gfx_display_ctx_draw_t *draw,
|
2020-03-08 22:05:51 +01:00
|
|
|
void *data, unsigned video_width, unsigned video_height)
|
2017-05-22 01:45:40 +01:00
|
|
|
{
|
2020-03-08 22:05:51 +01:00
|
|
|
wiiu_video_t *wiiu = (wiiu_video_t*)data;
|
2017-05-22 01:45:40 +01:00
|
|
|
|
|
|
|
if (!wiiu || !draw)
|
|
|
|
return;
|
|
|
|
|
2020-08-14 15:58:43 +02:00
|
|
|
if (draw->pipeline_id)
|
2018-01-11 02:09:03 +01:00
|
|
|
{
|
|
|
|
GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK);
|
|
|
|
|
2020-08-14 15:58:43 +02:00
|
|
|
switch(draw->pipeline_id)
|
2018-01-12 02:54:45 +01:00
|
|
|
{
|
2020-09-26 23:31:12 +02:00
|
|
|
case VIDEO_SHADER_MENU:
|
|
|
|
GX2SetShader(&ribbon_shader);
|
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_2:
|
|
|
|
GX2SetShader(&ribbon_simple_shader);
|
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_3:
|
|
|
|
GX2SetShader(&snow_simple_shader);
|
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_4:
|
|
|
|
GX2SetShader(&snow_shader);
|
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_5:
|
|
|
|
GX2SetShader(&bokeh_shader);
|
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_6:
|
|
|
|
GX2SetShader(&snowflake_shader);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-01-12 02:54:45 +01:00
|
|
|
}
|
|
|
|
|
2020-08-14 15:58:43 +02:00
|
|
|
switch(draw->pipeline_id)
|
2018-01-12 02:54:45 +01:00
|
|
|
{
|
2020-09-26 23:31:12 +02:00
|
|
|
case VIDEO_SHADER_MENU:
|
|
|
|
case VIDEO_SHADER_MENU_2:
|
|
|
|
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_STRIP, draw->coords->vertices, 0, 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);
|
|
|
|
case VIDEO_SHADER_MENU_3:
|
|
|
|
case VIDEO_SHADER_MENU_4:
|
|
|
|
case VIDEO_SHADER_MENU_5:
|
|
|
|
case VIDEO_SHADER_MENU_6:
|
|
|
|
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1);
|
|
|
|
break;
|
2018-01-12 02:54:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 02:09:03 +01:00
|
|
|
}
|
2020-04-22 23:35:46 +10:00
|
|
|
/* TODO come up with a better check for "not all vertexes are the same color" */
|
2020-02-10 13:18:27 +01:00
|
|
|
else if (draw->coords->vertex || draw->coords->color[0] != draw->coords->color[12])
|
2017-12-30 23:21:32 +01:00
|
|
|
{
|
2020-08-19 03:06:22 +02:00
|
|
|
int i;
|
2018-01-11 02:09:03 +01:00
|
|
|
if (wiiu->vertex_cache_tex.current + 4 > wiiu->vertex_cache_tex.size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tex_shader_vertex_t* v = wiiu->vertex_cache_tex.v + wiiu->vertex_cache_tex.current;
|
|
|
|
|
|
|
|
GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK);
|
|
|
|
GX2SetShader(&tex_shader);
|
|
|
|
GX2SetVertexUniformBlock(tex_shader.vs.uniformBlocks[0].offset,
|
2020-09-26 23:31:12 +02:00
|
|
|
tex_shader.vs.uniformBlocks[0].size,
|
|
|
|
wiiu->ubo_mvp);
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetAttribBuffer(0, wiiu->vertex_cache_tex.size * sizeof(*wiiu->vertex_cache_tex.v),
|
2020-09-26 23:31:12 +02:00
|
|
|
sizeof(*wiiu->vertex_cache_tex.v), wiiu->vertex_cache_tex.v);
|
2018-01-11 02:09:03 +01:00
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
if (!draw->coords->vertex)
|
2018-01-11 02:09:03 +01:00
|
|
|
{
|
2020-04-22 23:35:46 +10:00
|
|
|
/* Convert the libretro bottom-up coordinate system to GX2 - low y at
|
|
|
|
the top of the screen, large y at the bottom
|
|
|
|
The compiler will optimise 90% of this out anyway */
|
|
|
|
float y = -(draw->y + draw->height - video_height);
|
|
|
|
/* Remember: this is a triangle strip, not a quad, draw in a Z shape
|
|
|
|
Bottom-left, right, top-left, right */
|
|
|
|
v[0].pos.x = (draw->x ) / video_width;
|
|
|
|
v[0].pos.y = (y + draw->height) / video_height;
|
|
|
|
v[1].pos.x = (draw->x + draw->width ) / video_width;
|
|
|
|
v[1].pos.y = (y + draw->height) / video_height;
|
|
|
|
v[2].pos.x = (draw->x ) / video_width;
|
|
|
|
v[2].pos.y = (y ) / video_height;
|
|
|
|
v[3].pos.x = (draw->x + draw->width ) / video_width;
|
|
|
|
v[3].pos.y = (y ) / video_height;
|
2018-01-11 02:09:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v[0].pos.x = draw->coords->vertex[0];
|
|
|
|
v[0].pos.y = 1.0 - draw->coords->vertex[1];
|
|
|
|
v[1].pos.x = draw->coords->vertex[2];
|
|
|
|
v[1].pos.y = 1.0 - draw->coords->vertex[3];
|
|
|
|
v[2].pos.x = draw->coords->vertex[4];
|
|
|
|
v[2].pos.y = 1.0 - draw->coords->vertex[5];
|
|
|
|
v[3].pos.x = draw->coords->vertex[6];
|
|
|
|
v[3].pos.y = 1.0 - draw->coords->vertex[7];
|
|
|
|
}
|
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
if (!draw->coords->tex_coord)
|
2018-01-11 02:09:03 +01:00
|
|
|
{
|
|
|
|
v[0].coord.u = 0.0f;
|
|
|
|
v[0].coord.v = 1.0f;
|
|
|
|
v[1].coord.u = 1.0f;
|
|
|
|
v[1].coord.v = 1.0f;
|
|
|
|
v[2].coord.u = 0.0f;
|
|
|
|
v[2].coord.v = 0.0f;
|
|
|
|
v[3].coord.u = 1.0f;
|
|
|
|
v[3].coord.v = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v[0].coord.u = draw->coords->tex_coord[0];
|
|
|
|
v[0].coord.v = draw->coords->tex_coord[1];
|
|
|
|
v[1].coord.u = draw->coords->tex_coord[2];
|
|
|
|
v[1].coord.v = draw->coords->tex_coord[3];
|
|
|
|
v[2].coord.u = draw->coords->tex_coord[4];
|
|
|
|
v[2].coord.v = draw->coords->tex_coord[5];
|
|
|
|
v[3].coord.u = draw->coords->tex_coord[6];
|
|
|
|
v[3].coord.v = draw->coords->tex_coord[7];
|
|
|
|
}
|
|
|
|
|
2020-08-19 03:06:22 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
2018-01-11 02:09:03 +01:00
|
|
|
{
|
|
|
|
v[i].color.r = draw->coords->color[(i << 2) + 0];
|
|
|
|
v[i].color.g = draw->coords->color[(i << 2) + 1];
|
|
|
|
v[i].color.b = draw->coords->color[(i << 2) + 2];
|
|
|
|
v[i].color.a = draw->coords->color[(i << 2) + 3];
|
|
|
|
}
|
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
if (draw->texture)
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetPixelTexture((GX2Texture*)draw->texture, tex_shader.ps.samplerVars[0].location);
|
|
|
|
|
|
|
|
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_STRIP, 4, wiiu->vertex_cache_tex.current, 1);
|
|
|
|
wiiu->vertex_cache_tex.current += 4;
|
2017-12-30 23:21:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-11 02:09:03 +01:00
|
|
|
if (wiiu->vertex_cache.current + 1 > wiiu->vertex_cache.size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sprite_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
|
2018-01-04 17:38:04 +01:00
|
|
|
v->pos.x = draw->x;
|
|
|
|
v->pos.y = wiiu->color_buffer.surface.height - draw->y - draw->height;
|
|
|
|
v->pos.width = draw->width;
|
|
|
|
v->pos.height = draw->height;
|
|
|
|
v->coord.u = 0.0f;
|
|
|
|
v->coord.v = 0.0f;
|
|
|
|
v->coord.width = 1.0f;
|
|
|
|
v->coord.height = 1.0f;
|
2017-12-30 23:21:32 +01:00
|
|
|
|
2018-01-11 02:09:03 +01:00
|
|
|
v->color = COLOR_RGBA(0xFF * draw->coords->color[0], 0xFF * draw->coords->color[1],
|
2020-09-26 23:31:12 +02:00
|
|
|
0xFF * draw->coords->color[2], 0xFF * draw->coords->color[3]);
|
2017-12-30 23:21:32 +01:00
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
if (draw->texture)
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetPixelTexture((GX2Texture*)draw->texture, sprite_shader.ps.samplerVars[0].location);
|
2017-05-22 01:45:40 +01:00
|
|
|
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, 1, wiiu->vertex_cache.current, 1);
|
|
|
|
wiiu->vertex_cache.current ++;
|
|
|
|
return;
|
|
|
|
}
|
2017-05-22 01:45:40 +01:00
|
|
|
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetShaderMode(GX2_SHADER_MODE_GEOMETRY_SHADER);
|
|
|
|
GX2SetShader(&sprite_shader);
|
2020-09-26 23:31:12 +02:00
|
|
|
#if 0
|
|
|
|
GX2SetGeometryShaderInputRingBuffer(wiiu->input_ring_buffer, wiiu->input_ring_buffer_size);
|
|
|
|
GX2SetGeometryShaderOutputRingBuffer(wiiu->output_ring_buffer, wiiu->output_ring_buffer_size);
|
|
|
|
#endif
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[0].offset,
|
2020-09-26 23:31:12 +02:00
|
|
|
sprite_shader.vs.uniformBlocks[0].size,
|
|
|
|
wiiu->ubo_vp);
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset,
|
2020-09-26 23:31:12 +02:00
|
|
|
sprite_shader.vs.uniformBlocks[1].size,
|
|
|
|
wiiu->ubo_tex);
|
2018-01-11 02:09:03 +01:00
|
|
|
GX2SetAttribBuffer(0, wiiu->vertex_cache.size * sizeof(*wiiu->vertex_cache.v),
|
2020-09-26 23:31:12 +02:00
|
|
|
sizeof(*wiiu->vertex_cache.v), wiiu->vertex_cache.v);
|
2017-05-22 01:45:40 +01:00
|
|
|
}
|
|
|
|
|
2021-04-08 00:38:24 +02:00
|
|
|
static void gfx_display_wiiu_draw_pipeline(
|
|
|
|
gfx_display_ctx_draw_t *draw,
|
|
|
|
gfx_display_t *p_disp,
|
2020-03-08 22:05:51 +01:00
|
|
|
void *data, unsigned video_width, unsigned video_height)
|
2017-05-22 01:45:40 +01:00
|
|
|
{
|
2018-02-16 19:08:16 +01:00
|
|
|
video_coord_array_t *ca = NULL;
|
2020-03-08 22:05:51 +01:00
|
|
|
wiiu_video_t *wiiu = (wiiu_video_t*)data;
|
2018-01-11 02:09:03 +01:00
|
|
|
|
2018-01-12 02:54:45 +01:00
|
|
|
if (!wiiu || !draw)
|
2018-01-11 02:09:03 +01:00
|
|
|
return;
|
|
|
|
|
2020-08-14 15:58:43 +02:00
|
|
|
switch(draw->pipeline_id)
|
2018-01-11 02:09:03 +01:00
|
|
|
{
|
2018-05-13 14:15:04 +02:00
|
|
|
case VIDEO_SHADER_MENU:
|
|
|
|
case VIDEO_SHADER_MENU_2:
|
2020-09-25 10:31:07 +02:00
|
|
|
ca = &p_disp->dispca;
|
2020-02-10 13:18:27 +01:00
|
|
|
if (!wiiu->menu_shader_vbo)
|
2018-05-13 14:15:04 +02:00
|
|
|
{
|
|
|
|
wiiu->menu_shader_vbo = MEM2_alloc(ca->coords.vertices * 2 * sizeof(float), GX2_VERTEX_BUFFER_ALIGNMENT);
|
|
|
|
memcpy(wiiu->menu_shader_vbo, ca->coords.vertex, ca->coords.vertices * 2 * sizeof(float));
|
|
|
|
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->menu_shader_vbo, ca->coords.vertices * 2 * sizeof(float));
|
|
|
|
}
|
|
|
|
|
|
|
|
draw->coords->vertex = wiiu->menu_shader_vbo;
|
|
|
|
draw->coords->vertices = ca->coords.vertices;
|
|
|
|
GX2SetAttribBuffer(0, draw->coords->vertices * 2 * sizeof(float), 2 * sizeof(float), wiiu->menu_shader_vbo);
|
|
|
|
GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_ONE,
|
|
|
|
GX2_BLEND_COMBINE_MODE_ADD, GX2_DISABLE, 0, 0, 0);
|
2018-01-12 02:54:45 +01:00
|
|
|
|
2018-05-13 14:15:04 +02:00
|
|
|
break;
|
|
|
|
case VIDEO_SHADER_MENU_3:
|
|
|
|
case VIDEO_SHADER_MENU_4:
|
|
|
|
case VIDEO_SHADER_MENU_5:
|
|
|
|
case VIDEO_SHADER_MENU_6:
|
|
|
|
GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->v), sizeof(*wiiu->v), wiiu->v);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2018-01-11 02:09:03 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 13:18:27 +01:00
|
|
|
if (!wiiu->menu_shader_ubo)
|
2018-01-12 02:54:45 +01:00
|
|
|
{
|
|
|
|
wiiu->menu_shader_ubo = MEM2_alloc(sizeof(*wiiu->menu_shader_ubo), GX2_UNIFORM_BLOCK_ALIGNMENT);
|
|
|
|
matrix_4x4_ortho(wiiu->menu_shader_ubo->mvp, 0, 1, 1, 0, -1, 1);
|
|
|
|
wiiu->menu_shader_ubo->OutputSize.width = wiiu->color_buffer.surface.width;
|
|
|
|
wiiu->menu_shader_ubo->OutputSize.height = wiiu->color_buffer.surface.height;
|
|
|
|
wiiu->menu_shader_ubo->time = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wiiu->menu_shader_ubo->time += 0.01f;
|
2018-01-11 02:09:03 +01:00
|
|
|
|
2018-01-12 02:54:45 +01:00
|
|
|
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->menu_shader_ubo, sizeof(*wiiu->menu_shader_ubo));
|
|
|
|
GX2SetVertexUniformBlock(1, sizeof(*wiiu->menu_shader_ubo), wiiu->menu_shader_ubo);
|
|
|
|
GX2SetPixelUniformBlock(1, sizeof(*wiiu->menu_shader_ubo), wiiu->menu_shader_ubo);
|
2017-05-22 01:45:40 +01:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
static bool gfx_display_wiiu_font_init_first(
|
2017-05-22 01:45:40 +01:00
|
|
|
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;
|
2020-09-26 23:31:12 +02:00
|
|
|
*handle = font_driver_init_first(video_data,
|
2017-05-22 01:45:40 +01:00
|
|
|
font_path, font_size, true,
|
|
|
|
is_threaded,
|
|
|
|
FONT_DRIVER_RENDER_WIIU);
|
|
|
|
return *handle;
|
|
|
|
}
|
|
|
|
|
2020-03-07 21:18:12 +01:00
|
|
|
static void gfx_display_wiiu_scissor_begin(
|
2020-03-08 21:46:52 +01:00
|
|
|
void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height,
|
|
|
|
int x, int y,
|
2018-09-28 22:33:58 +02:00
|
|
|
unsigned width, unsigned height)
|
|
|
|
{
|
2021-07-20 18:51:53 +10:00
|
|
|
GX2SetScissor(MAX(x, 0), MAX(y, 0), MIN(width, video_width), MIN(height, video_height));
|
2018-09-28 22:33:58 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 21:46:52 +01:00
|
|
|
static void gfx_display_wiiu_scissor_end(
|
|
|
|
void *data,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height
|
|
|
|
)
|
2018-09-28 22:33:58 +02:00
|
|
|
{
|
2020-03-07 21:18:12 +01:00
|
|
|
GX2SetScissor(0, 0, video_width, video_height);
|
2018-09-28 22:33:58 +02:00
|
|
|
}
|
|
|
|
|
2020-02-16 15:10:07 +01:00
|
|
|
gfx_display_ctx_driver_t gfx_display_ctx_wiiu = {
|
|
|
|
gfx_display_wiiu_draw,
|
|
|
|
gfx_display_wiiu_draw_pipeline,
|
2020-09-26 23:31:12 +02:00
|
|
|
NULL, /* blend_begin */
|
|
|
|
NULL, /* blend_end */
|
2020-09-26 21:40:16 +02:00
|
|
|
NULL, /* get_default_mvp */
|
|
|
|
NULL, /* get_default_vertices */
|
|
|
|
NULL, /* get_default_tex_coords */
|
2020-02-16 15:10:07 +01:00
|
|
|
gfx_display_wiiu_font_init_first,
|
|
|
|
GFX_VIDEO_DRIVER_WIIU,
|
2018-10-09 01:03:29 +02:00
|
|
|
"gx2",
|
2018-09-20 14:48:07 +02:00
|
|
|
true,
|
2020-02-16 15:10:07 +01:00
|
|
|
gfx_display_wiiu_scissor_begin,
|
|
|
|
gfx_display_wiiu_scissor_end
|
2017-05-22 01:45:40 +01:00
|
|
|
};
|