(WIIU) shader: use a single attribute stream.

This commit is contained in:
aliaspider 2017-12-31 14:06:49 +01:00
parent 601fda9784
commit 0a32642f17
6 changed files with 157 additions and 209 deletions

View File

@ -18,7 +18,7 @@
#define GX2_COMP_SEL(c0, c1, c2, c3) (((c0) << 24) | ((c1) << 16) | ((c2) << 8) | (c3)) #define GX2_COMP_SEL(c0, c1, c2, c3) (((c0) << 24) | ((c1) << 16) | ((c2) << 8) | (c3))
#define COLOR_ABGR(r, g, b, a) (((u32)(a) << 24) | ((u32)(b) << 16) | ((u32)(g) << 8) | ((u32)(r) << 0)) #define COLOR_ABGR(r, g, b, a) (((u32)(a) << 24) | ((u32)(b) << 16) | ((u32)(g) << 8) | ((u32)(r) << 0))
#define COLOR_RGBA(r, g, b, a) (((u32)(a) << 24) | ((u32)(r) << 16) | ((u32)(g) << 8) | ((u32)(b) << 0)) #define COLOR_ARGB(r, g, b, a) (((u32)(a) << 24) | ((u32)(r) << 16) | ((u32)(g) << 8) | ((u32)(b) << 0))
#define COLOR_RGBA(r, g, b, a) (((u32)(r) << 24) | ((u32)(g) << 16) | ((u32)(b) << 8) | ((u32)(a) << 0)) #define COLOR_RGBA(r, g, b, a) (((u32)(r) << 24) | ((u32)(g) << 16) | ((u32)(b) << 8) | ((u32)(a) << 0))
//#define GX2_CAN_ACCESS_DATA_SECTION //#define GX2_CAN_ACCESS_DATA_SECTION
@ -30,24 +30,10 @@ typedef struct
GX2TVRenderMode mode; GX2TVRenderMode mode;
} wiiu_render_mode_t; } wiiu_render_mode_t;
typedef struct
{
float x;
float y;
} position_t;
typedef struct
{
float u;
float v;
} tex_coord_t;
struct gx2_overlay_data struct gx2_overlay_data
{ {
GX2Texture tex; GX2Texture tex;
float tex_coord[8]; tex_shader_vertex_t v[4];
float vertex_coord[8];
u32 color[4];
float alpha_mod; float alpha_mod;
}; };
@ -60,9 +46,7 @@ typedef struct
int width; int width;
int height; int height;
bool enable; bool enable;
position_t* position; tex_shader_vertex_t* v;
tex_coord_t* tex_coord;
u32* color;
} menu; } menu;
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
@ -75,17 +59,13 @@ typedef struct
GX2Sampler sampler_nearest; GX2Sampler sampler_nearest;
GX2Sampler sampler_linear; GX2Sampler sampler_linear;
GX2Texture texture; GX2Texture texture;
position_t* position; tex_shader_vertex_t* v;
tex_coord_t* tex_coord;
u32* color;
int width; int width;
int height; int height;
struct struct
{ {
position_t* positions; tex_shader_vertex_t* v;
tex_coord_t* tex_coords;
u32* colors;
int size; int size;
int current; int current;
} vertex_cache; } vertex_cache;

View File

@ -51,31 +51,28 @@ static const wiiu_render_mode_t wiiu_render_mode_map[] =
{1920, 1080, GX2_TV_RENDER_MODE_WIDE_1080P} /* GX2_TV_SCAN_MODE_1080P */ {1920, 1080, GX2_TV_RENDER_MODE_WIDE_1080P} /* GX2_TV_SCAN_MODE_1080P */
}; };
static void wiiu_set_position(position_t* position, GX2ColorBuffer* draw_buffer, float x0, float y0, float x1, float y1) static void wiiu_set_position(tex_shader_vertex_t* v, GX2ColorBuffer* draw_buffer, float x0, float y0, float x1, float y1)
{ {
position[0].x = (2.0f * x0 / draw_buffer->surface.width) - 1.0f; v[0].pos.x = (2.0f * x0 / draw_buffer->surface.width) - 1.0f;
position[0].y = (2.0f * y0 / draw_buffer->surface.height) - 1.0f; v[0].pos.y = (2.0f * y0 / draw_buffer->surface.height) - 1.0f;
position[1].x = (2.0f * x1 / draw_buffer->surface.width) - 1.0f;; v[1].pos.x = (2.0f * x1 / draw_buffer->surface.width) - 1.0f;;
position[1].y = (2.0f * y0 / draw_buffer->surface.height) - 1.0f; v[1].pos.y = (2.0f * y0 / draw_buffer->surface.height) - 1.0f;
position[2].x = (2.0f * x1 / draw_buffer->surface.width) - 1.0f;; v[2].pos.x = (2.0f * x1 / draw_buffer->surface.width) - 1.0f;;
position[2].y = (2.0f * y1 / draw_buffer->surface.height) - 1.0f; v[2].pos.y = (2.0f * y1 / draw_buffer->surface.height) - 1.0f;
position[3].x = (2.0f * x0 / draw_buffer->surface.width) - 1.0f;; v[3].pos.x = (2.0f * x0 / draw_buffer->surface.width) - 1.0f;;
position[3].y = (2.0f * y1 / draw_buffer->surface.height) - 1.0f; v[3].pos.y = (2.0f * y1 / draw_buffer->surface.height) - 1.0f;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, position, 4 * sizeof(*position));
} }
static void wiiu_set_tex_coords(tex_coord_t* tex_coord, GX2Texture* texture, float u0, float v0, float u1, float v1, unsigned rotation) static void wiiu_set_tex_coords(tex_shader_vertex_t* v, GX2Texture* texture, float u0, float v0, float u1, float v1, unsigned rotation)
{ {
tex_coord[((0 + rotation) % 4)].u = u0 / texture->surface.width; v[((0 + rotation) % 4)].coord.u = u0 / texture->surface.width;
tex_coord[((0 + rotation) % 4)].v = (v1 / texture->surface.height); v[((0 + rotation) % 4)].coord.v = (v1 / texture->surface.height);
tex_coord[((1 + rotation) % 4)].u = u1 / texture->surface.width; v[((1 + rotation) % 4)].coord.u = u1 / texture->surface.width;
tex_coord[((1 + rotation) % 4)].v = (v1 / texture->surface.height); v[((1 + rotation) % 4)].coord.v = (v1 / texture->surface.height);
tex_coord[((2 + rotation) % 4)].u = u1 / texture->surface.width; v[((2 + rotation) % 4)].coord.u = u1 / texture->surface.width;
tex_coord[((2 + rotation) % 4)].v = (v0 / texture->surface.height); v[((2 + rotation) % 4)].coord.v = (v0 / texture->surface.height);
tex_coord[((3 + rotation) % 4)].u = u0 / texture->surface.width; v[((3 + rotation) % 4)].coord.u = u0 / texture->surface.width;
tex_coord[((3 + rotation) % 4)].v = (v0 / texture->surface.height); v[((3 + rotation) % 4)].coord.v = (v0 / texture->surface.height);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, tex_coord, 4 * sizeof(*tex_coord));
} }
static void wiiu_gfx_update_viewport(wiiu_video_t* wiiu) static void wiiu_gfx_update_viewport(wiiu_video_t* wiiu)
@ -151,7 +148,7 @@ static void wiiu_gfx_update_viewport(wiiu_video_t* wiiu)
float scale_w = wiiu->color_buffer.surface.width / wiiu->render_mode.width; float scale_w = wiiu->color_buffer.surface.width / wiiu->render_mode.width;
float scale_h = wiiu->color_buffer.surface.height / wiiu->render_mode.height; float scale_h = wiiu->color_buffer.surface.height / wiiu->render_mode.height;
wiiu_set_position(wiiu->position, &wiiu->color_buffer, wiiu_set_position(wiiu->v, &wiiu->color_buffer,
wiiu->vp.x * scale_w, wiiu->vp.x * scale_w,
wiiu->vp.y * scale_h, wiiu->vp.y * scale_h,
(wiiu->vp.x + wiiu->vp.width) * scale_w, (wiiu->vp.x + wiiu->vp.width) * scale_w,
@ -316,39 +313,32 @@ static void* wiiu_gfx_init(const video_info_t* video,
GX2SetPixelShader(&wiiu->shader->ps); GX2SetPixelShader(&wiiu->shader->ps);
GX2SetFetchShader(&wiiu->shader->fs); GX2SetFetchShader(&wiiu->shader->fs);
wiiu->position = MEM2_alloc(4 * sizeof(*wiiu->position), GX2_VERTEX_BUFFER_ALIGNMENT); wiiu->v = MEM2_alloc(4 * sizeof(*wiiu->v), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu_set_position(wiiu->position, &wiiu->color_buffer, 0, 0, wiiu_set_position(wiiu->v, &wiiu->color_buffer, 0, 0,
wiiu->color_buffer.surface.width, wiiu->color_buffer.surface.height); wiiu->color_buffer.surface.width, wiiu->color_buffer.surface.height);
wiiu_set_tex_coords(wiiu->v, &wiiu->texture, 0, 0,
wiiu->tex_coord = MEM2_alloc(4 * sizeof(*wiiu->tex_coord), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu_set_tex_coords(wiiu->tex_coord, &wiiu->texture, 0, 0,
wiiu->texture.surface.width, wiiu->texture.surface.height, wiiu->rotation); wiiu->texture.surface.width, wiiu->texture.surface.height, wiiu->rotation);
wiiu->color = MEM2_alloc(4 * sizeof(*wiiu->color), GX2_VERTEX_BUFFER_ALIGNMENT); wiiu->v[0].color = 0xFFFFFFFF;
wiiu->color[0] = 0xFFFFFFFF; wiiu->v[1].color = 0xFFFFFFFF;
wiiu->color[1] = 0xFFFFFFFF; wiiu->v[2].color = 0xFFFFFFFF;
wiiu->color[2] = 0xFFFFFFFF; wiiu->v[3].color = 0xFFFFFFFF;
wiiu->color[3] = 0xFFFFFFFF;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->color, 4 * sizeof(*wiiu->color));
GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->position), sizeof(*wiiu->position), wiiu->position); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->v, 4 * sizeof(*wiiu->v));
GX2SetAttribBuffer(1, 4 * sizeof(*wiiu->tex_coord), sizeof(*wiiu->tex_coord), wiiu->tex_coord);
GX2SetAttribBuffer(2, 4 * sizeof(*wiiu->color), sizeof(*wiiu->color), wiiu->color);
wiiu->menu.position = MEM2_alloc(4 * sizeof(*wiiu->menu.position), GX2_VERTEX_BUFFER_ALIGNMENT); GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->v), sizeof(*wiiu->v), wiiu->v);
wiiu_set_position(wiiu->menu.position, &wiiu->color_buffer, 0, 0,
wiiu->menu.v = MEM2_alloc(4 * sizeof(*wiiu->menu.v), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu_set_position(wiiu->menu.v, &wiiu->color_buffer, 0, 0,
wiiu->color_buffer.surface.width, wiiu->color_buffer.surface.height); wiiu->color_buffer.surface.width, wiiu->color_buffer.surface.height);
wiiu_set_tex_coords(wiiu->menu.v, &wiiu->menu.texture, 0, 0,
wiiu->menu.tex_coord = MEM2_alloc(4 * sizeof(*wiiu->menu.tex_coord), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu_set_tex_coords(wiiu->menu.tex_coord, &wiiu->menu.texture, 0, 0,
wiiu->menu.texture.surface.width, wiiu->menu.texture.surface.height, 0); wiiu->menu.texture.surface.width, wiiu->menu.texture.surface.height, 0);
wiiu->menu.color = MEM2_alloc(4 * sizeof(*wiiu->menu.color), GX2_VERTEX_BUFFER_ALIGNMENT); wiiu->menu.v[0].color = 0xFFFFFF80;
wiiu->menu.color[0] = 0xFFFFFF80; wiiu->menu.v[1].color = 0xFFFFFF80;
wiiu->menu.color[1] = 0xFFFFFF80; wiiu->menu.v[2].color = 0xFFFFFF80;
wiiu->menu.color[2] = 0xFFFFFF80; wiiu->menu.v[3].color = 0xFFFFFF80;
wiiu->menu.color[3] = 0xFFFFFF80; GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->menu.v, 4 * sizeof(*wiiu->menu.v));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->menu.color, 4 * sizeof(*wiiu->menu.color));
/* Initialize frame texture */ /* Initialize frame texture */
memset(&wiiu->texture, 0, sizeof(GX2Texture)); memset(&wiiu->texture, 0, sizeof(GX2Texture));
@ -401,12 +391,8 @@ static void* wiiu_gfx_init(const video_info_t* video,
wiiu->vertex_cache.size = 0x1000; wiiu->vertex_cache.size = 0x1000;
wiiu->vertex_cache.current = 0; wiiu->vertex_cache.current = 0;
wiiu->vertex_cache.positions = MEM2_alloc(wiiu->vertex_cache.size wiiu->vertex_cache.v = MEM2_alloc(wiiu->vertex_cache.size
* sizeof(position_t), GX2_VERTEX_BUFFER_ALIGNMENT); * sizeof(*wiiu->vertex_cache.v), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu->vertex_cache.tex_coords = MEM2_alloc(wiiu->vertex_cache.size
* sizeof(tex_coord_t), GX2_VERTEX_BUFFER_ALIGNMENT);
wiiu->vertex_cache.colors = MEM2_alloc(wiiu->vertex_cache.size
* sizeof(u32), GX2_VERTEX_BUFFER_ALIGNMENT);
/* Initialize samplers */ /* Initialize samplers */
GX2InitSampler(&wiiu->sampler_nearest, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_POINT); GX2InitSampler(&wiiu->sampler_nearest, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_POINT);
@ -464,15 +450,15 @@ static void gx2_overlay_tex_geom(void *data, unsigned image,
if (!o) if (!o)
return; return;
o->tex_coord[0] = x; o->v[0].coord.u = x;
o->tex_coord[1] = y; o->v[0].coord.v = y;
o->tex_coord[2] = x + w; o->v[1].coord.u = x + w;
o->tex_coord[3] = y; o->v[1].coord.v = y;
o->tex_coord[4] = x + w; o->v[2].coord.u = x + w;
o->tex_coord[5] = y + h; o->v[2].coord.v = y + h;
o->tex_coord[6] = x ; o->v[3].coord.u = x ;
o->tex_coord[7] = y + h; o->v[3].coord.v = y + h;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->tex_coord, sizeof(o->tex_coord)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->v, sizeof(o->v));
} }
static void gx2_overlay_vertex_geom(void *data, unsigned image, static void gx2_overlay_vertex_geom(void *data, unsigned image,
@ -497,19 +483,19 @@ static void gx2_overlay_vertex_geom(void *data, unsigned image,
if (!o) if (!o)
return; return;
o->vertex_coord[0] = x; o->v[0].pos.x = x;
o->vertex_coord[1] = y; o->v[0].pos.y = y;
o->vertex_coord[2] = x + w; o->v[1].pos.x = x + w;
o->vertex_coord[3] = y; o->v[1].pos.y = y;
o->vertex_coord[4] = x + w; o->v[2].pos.x = x + w;
o->vertex_coord[5] = y + h; o->v[2].pos.y = y + h;
o->vertex_coord[6] = x ; o->v[3].pos.x = x ;
o->vertex_coord[7] = y + h; o->v[3].pos.y = y + h;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->vertex_coord,sizeof(o->vertex_coord)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->v,sizeof(o->v));
} }
static void gx2_free_overlay(wiiu_video_t *gx2) static void gx2_free_overlay(wiiu_video_t *gx2)
@ -569,15 +555,13 @@ static bool gx2_overlay_load(void *data,
gx2_overlay_tex_geom(gx2, i, 0, 0, 1, 1); gx2_overlay_tex_geom(gx2, i, 0, 0, 1, 1);
gx2_overlay_vertex_geom(gx2, i, 0, 0, 1, 1); gx2_overlay_vertex_geom(gx2, i, 0, 0, 1, 1);
gx2->overlay[i].alpha_mod = 1.0f; gx2->overlay[i].alpha_mod = 1.0f;
gx2->overlay[i].color[0] = 0xFFFFFFFF; gx2->overlay[i].v[0].color = 0xFFFFFFFF;
gx2->overlay[i].color[1] = 0xFFFFFFFF; gx2->overlay[i].v[1].color = 0xFFFFFFFF;
gx2->overlay[i].color[2] = 0xFFFFFFFF; gx2->overlay[i].v[2].color = 0xFFFFFFFF;
gx2->overlay[i].color[3] = 0xFFFFFFFF; gx2->overlay[i].v[3].color = 0xFFFFFFFF;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->vertex_coord,sizeof(o->vertex_coord)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->v,sizeof(o->v));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->tex_coord, sizeof(o->tex_coord));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, o->color, sizeof(o->color));
} }
@ -604,11 +588,11 @@ static void gx2_overlay_set_alpha(void *data, unsigned image, float mod)
if (gx2) if (gx2)
{ {
gx2->overlay[image].alpha_mod = mod; gx2->overlay[image].alpha_mod = mod;
gx2->overlay[image].color[0] = COLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF * gx2->overlay[image].alpha_mod); gx2->overlay[image].v[0].color = COLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF * gx2->overlay[image].alpha_mod);
gx2->overlay[image].color[1] = gx2->overlay[image].color[0]; gx2->overlay[image].v[1].color = gx2->overlay[image].v[0].color;
gx2->overlay[image].color[2] = gx2->overlay[image].color[0]; gx2->overlay[image].v[2].color = gx2->overlay[image].v[0].color;
gx2->overlay[image].color[3] = gx2->overlay[image].color[0]; gx2->overlay[image].v[3].color = gx2->overlay[image].v[0].color;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, gx2->overlay[image].color, sizeof(gx2->overlay[image].color)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, gx2->overlay[image].v, sizeof(gx2->overlay[image].v));
} }
} }
@ -620,12 +604,7 @@ static void gx2_render_overlay(void *data)
for (i = 0; i < gx2->overlays; i++){ for (i = 0; i < gx2->overlays; i++){
GX2SetAttribBuffer(0, 8 * sizeof(float), GX2SetAttribBuffer(0, sizeof(gx2->overlay[i].v), sizeof(*gx2->overlay[i].v), gx2->overlay[i].v);
2*sizeof(float), gx2->overlay[i].vertex_coord);
GX2SetAttribBuffer(1, 8 * sizeof(float),
2*sizeof(float), gx2->overlay[i].tex_coord);
GX2SetAttribBuffer(2, 4 * sizeof(u32),
sizeof(u32), gx2->overlay[i].color);
GX2SetPixelTexture(&gx2->overlay[i].tex, gx2->shader->sampler.location); GX2SetPixelTexture(&gx2->overlay[i].tex, gx2->shader->sampler.location);
GX2SetPixelSampler(&gx2->sampler_linear, gx2->shader->sampler.location); GX2SetPixelSampler(&gx2->sampler_linear, gx2->shader->sampler.location);
@ -682,9 +661,7 @@ static void wiiu_gfx_free(void* data)
MEM2_free(wiiu->cmd_buffer); MEM2_free(wiiu->cmd_buffer);
MEM2_free(wiiu->texture.surface.image); MEM2_free(wiiu->texture.surface.image);
MEM2_free(wiiu->menu.texture.surface.image); MEM2_free(wiiu->menu.texture.surface.image);
MEM2_free(wiiu->vertex_cache.positions); MEM2_free(wiiu->vertex_cache.v);
MEM2_free(wiiu->vertex_cache.tex_coords);
MEM2_free(wiiu->vertex_cache.colors);
MEM1_free(wiiu->color_buffer.surface.image); MEM1_free(wiiu->color_buffer.surface.image);
@ -702,13 +679,8 @@ static void wiiu_gfx_free(void* data)
MEM2_free(wiiu->shader); MEM2_free(wiiu->shader);
#endif #endif
MEM2_free(wiiu->position); MEM2_free(wiiu->v);
MEM2_free(wiiu->tex_coord); MEM2_free(wiiu->menu.v);
MEM2_free(wiiu->color);
MEM2_free(wiiu->menu.position);
MEM2_free(wiiu->menu.tex_coord);
MEM2_free(wiiu->menu.color);
free(wiiu); free(wiiu);
} }
@ -822,15 +794,10 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->texture.surface.image, GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->texture.surface.image,
wiiu->texture.surface.imageSize); wiiu->texture.surface.imageSize);
wiiu_set_tex_coords(wiiu->tex_coord, &wiiu->texture, 0, 0, width, height, wiiu->rotation); wiiu_set_tex_coords(wiiu->v, &wiiu->texture, 0, 0, width, height, wiiu->rotation);
} }
GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->position), GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->v), sizeof(*wiiu->v), wiiu->v);
sizeof(*wiiu->position), wiiu->position);
GX2SetAttribBuffer(1, 4 * sizeof(*wiiu->tex_coord),
sizeof(*wiiu->tex_coord), wiiu->tex_coord);
GX2SetAttribBuffer(2, 4 * sizeof(*wiiu->color),
sizeof(*wiiu->color), wiiu->color);
GX2SetPixelTexture(&wiiu->texture, wiiu->shader->sampler.location); GX2SetPixelTexture(&wiiu->texture, wiiu->shader->sampler.location);
GX2SetPixelSampler(wiiu->smooth? &wiiu->sampler_linear : &wiiu->sampler_nearest, GX2SetPixelSampler(wiiu->smooth? &wiiu->sampler_linear : &wiiu->sampler_nearest,
@ -845,12 +812,7 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
if (wiiu->menu.enable) if (wiiu->menu.enable)
{ {
GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->menu.position), GX2SetAttribBuffer(0, 4 * sizeof(*wiiu->menu.v), sizeof(*wiiu->menu.v), wiiu->menu.v);
sizeof(*wiiu->menu.position), wiiu->menu.position);
GX2SetAttribBuffer(1, 4 * sizeof(*wiiu->menu.tex_coord),
sizeof(*wiiu->menu.tex_coord), wiiu->menu.tex_coord);
GX2SetAttribBuffer(2, 4 * sizeof(*wiiu->menu.color),
sizeof(*wiiu->menu.color), wiiu->menu.color);
GX2SetPixelTexture(&wiiu->menu.texture, wiiu->shader->sampler.location); GX2SetPixelTexture(&wiiu->menu.texture, wiiu->shader->sampler.location);
GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location); GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location);
@ -859,12 +821,8 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
} }
wiiu->vertex_cache.current = 0; wiiu->vertex_cache.current = 0;
GX2SetAttribBuffer(0, wiiu->vertex_cache.size * sizeof(position_t), GX2SetAttribBuffer(0, wiiu->vertex_cache.size * sizeof(*wiiu->vertex_cache.v),
sizeof(position_t), wiiu->vertex_cache.positions); sizeof(*wiiu->vertex_cache.v), wiiu->vertex_cache.v);
GX2SetAttribBuffer(1, wiiu->vertex_cache.size * sizeof(tex_coord_t),
sizeof(tex_coord_t), wiiu->vertex_cache.tex_coords);
GX2SetAttribBuffer(2, wiiu->vertex_cache.size * sizeof(u32),
sizeof(u32), wiiu->vertex_cache.colors);
GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location); GX2SetPixelSampler(&wiiu->sampler_linear, wiiu->shader->sampler.location);
wiiu->render_msg_enabled = true; wiiu->render_msg_enabled = true;
@ -878,11 +836,7 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
wiiu->render_msg_enabled = false; wiiu->render_msg_enabled = false;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER,
wiiu->vertex_cache.positions, wiiu->vertex_cache.current * sizeof(position_t)); wiiu->vertex_cache.v, wiiu->vertex_cache.current * sizeof(*wiiu->vertex_cache.v));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER,
wiiu->vertex_cache.tex_coords, wiiu->vertex_cache.current * sizeof(tex_coord_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER,
wiiu->vertex_cache.colors, wiiu->vertex_cache.current * sizeof(u32));
if (wiiu->menu.enable) if (wiiu->menu.enable)
GX2DrawDone(); GX2DrawDone();
@ -1056,7 +1010,7 @@ static void wiiu_gfx_set_texture_frame(void* data, const void* frame, bool rgb32
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image, GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image,
wiiu->menu.texture.surface.imageSize); wiiu->menu.texture.surface.imageSize);
wiiu_set_tex_coords(wiiu->menu.tex_coord, &wiiu->menu.texture, 0, 0, width, height, 0); wiiu_set_tex_coords(wiiu->menu.v, &wiiu->menu.texture, 0, 0, width, height, 0);
} }
static void wiiu_gfx_set_texture_enable(void* data, bool state, bool full_screen) static void wiiu_gfx_set_texture_enable(void* data, bool state, bool full_screen)

View File

@ -160,9 +160,7 @@ static void wiiu_font_render_line(
break; break;
} }
position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current; tex_shader_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current;
u32* col = wiiu->vertex_cache.colors + wiiu->vertex_cache.current;
for (i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
{ {
@ -200,45 +198,42 @@ static void wiiu_font_render_line(
float u1 = u0 + width; float u1 = u0 + width;
float v1 = v0 + height; float v1 = v0 + height;
pos[0].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f; v[0].pos.x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;
pos[0].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f; v[0].pos.y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f;
pos[1].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; v[1].pos.x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[1].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f; v[1].pos.y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f;
pos[2].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; v[2].pos.x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[2].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f; v[2].pos.y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f;
pos[3].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;; v[3].pos.x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[3].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f; v[3].pos.y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f;
pos += 4;
coord[0].u = u0 / font->texture.surface.width; v[0].coord.u = u0 / font->texture.surface.width;
coord[0].v = v1 / font->texture.surface.height; v[0].coord.v = v1 / font->texture.surface.height;
coord[1].u = u1 / font->texture.surface.width; v[1].coord.u = u1 / font->texture.surface.width;
coord[1].v = v1 / font->texture.surface.height; v[1].coord.v = v1 / font->texture.surface.height;
coord[2].u = u1 / font->texture.surface.width; v[2].coord.u = u1 / font->texture.surface.width;
coord[2].v = v0 / font->texture.surface.height; v[2].coord.v = v0 / font->texture.surface.height;
coord[3].u = u0 / font->texture.surface.width; v[3].coord.u = u0 / font->texture.surface.width;
coord[3].v = v0 / font->texture.surface.height; v[3].coord.v = v0 / font->texture.surface.height;
coord += 4;
col[0] = color; v[0].color = color;
col[1] = color; v[1].color = color;
col[2] = color; v[2].color = color;
col[3] = color; v[3].color = color;
col += 4;
v += 4;
delta_x += glyph->advance_x; delta_x += glyph->advance_x;
delta_y += glyph->advance_y; delta_y += glyph->advance_y;
} }
int count = pos - wiiu->vertex_cache.positions - wiiu->vertex_cache.current; int count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current;
if (!count) if (!count)
return; return;
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.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current, count * sizeof(tex_coord_t));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.colors + wiiu->vertex_cache.current, count * sizeof(u32));
if(font->atlas->dirty) if(font->atlas->dirty)
{ {
@ -261,7 +256,7 @@ static void wiiu_font_render_line(
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, wiiu->vertex_cache.current, 1); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, wiiu->vertex_cache.current, 1);
wiiu->vertex_cache.current = pos - wiiu->vertex_cache.positions; wiiu->vertex_cache.current = v - wiiu->vertex_cache.v;
} }
static void wiiu_font_render_message( static void wiiu_font_render_message(

View File

@ -77,9 +77,7 @@ static void menu_display_wiiu_draw(void *data)
if (wiiu->vertex_cache.current + 4 > wiiu->vertex_cache.size) if (wiiu->vertex_cache.current + 4 > wiiu->vertex_cache.size)
return; return;
position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current; tex_shader_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current;
u32* col = wiiu->vertex_cache.colors + wiiu->vertex_cache.current;
float x0 = draw->x; float x0 = draw->x;
float y0 = draw->y; float y0 = draw->y;
@ -90,43 +88,47 @@ static void menu_display_wiiu_draw(void *data)
{ {
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
pos[i].x = draw->coords->vertex[i << 1] * 2.0f - 1.0f; v[i].pos.x = draw->coords->vertex[i << 1] * 2.0f - 1.0f;
pos[i].y = draw->coords->vertex[(i << 1) + 1] * 2.0f - 1.0f; v[i].pos.y = draw->coords->vertex[(i << 1) + 1] * 2.0f - 1.0f;
} }
} }
else else
{ {
pos[0].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f; v[0].pos.x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;
pos[0].y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f; v[0].pos.y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f;
pos[1].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; v[1].pos.x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[1].y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f; v[1].pos.y = (2.0f * y0 / wiiu->color_buffer.surface.height) - 1.0f;
pos[2].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;; v[2].pos.x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[2].y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f; v[2].pos.y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f;
pos[3].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;; v[3].pos.x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;;
pos[3].y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f; v[3].pos.y = (2.0f * y1 / wiiu->color_buffer.surface.height) - 1.0f;
} }
if(draw->coords->tex_coord && draw->coords->vertices == 4) if(draw->coords->tex_coord && draw->coords->vertices == 4)
{ {
memcpy(coord, draw->coords->tex_coord, 8 * sizeof(float)); for(int i = 0; i < 4; i++)
{
v[i].coord.u = draw->coords->tex_coord[i << 1];
v[i].coord.v = draw->coords->tex_coord[(i << 1) + 1];
}
} }
else else
{ {
coord[0].u = 0.0f; v[0].coord.u = 0.0f;
coord[0].v = 1.0f; v[0].coord.v = 1.0f;
coord[1].u = 1.0f; v[1].coord.u = 1.0f;
coord[1].v = 1.0f; v[1].coord.v = 1.0f;
coord[2].u = 1.0f; v[2].coord.u = 1.0f;
coord[2].v = 0.0f; v[2].coord.v = 0.0f;
coord[3].u = 0.0f; v[3].coord.u = 0.0f;
coord[3].v = 0.0f; v[3].coord.v = 0.0f;
} }
col[0] = COLOR_RGBA(0xFF * draw->coords->color[0], 0xFF * draw->coords->color[1], v[0].color = COLOR_RGBA(0xFF * draw->coords->color[0], 0xFF * draw->coords->color[1],
0xFF * draw->coords->color[2], 0xFF * draw->coords->color[3]); 0xFF * draw->coords->color[2], 0xFF * draw->coords->color[3]);
col[1] = col[0]; v[1].color = v[0].color;
col[2] = col[0]; v[2].color = v[0].color;
col[3] = col[0]; v[3].color = v[0].color;
// printf("color : %f, %f, %f, %f --> 0x%08X\n", draw->coords->color[0], draw->coords->color[1], draw->coords->color[2], draw->coords->color[3], col[0]); // printf("color : %f, %f, %f, %f --> 0x%08X\n", draw->coords->color[0], draw->coords->color[1], draw->coords->color[2], draw->coords->color[3], col[0]);

View File

@ -190,15 +190,15 @@ tex_shader_t tex_shader =
}, },
.attribute_stream = { .attribute_stream = {
.color = { .color = {
0, 2, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8, 0, 0, offsetof(tex_shader_vertex_t, color), GX2_ATTRIB_FORMAT_UNORM_8_8_8_8,
GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _Z, _W), GX2_ENDIAN_SWAP_DEFAULT GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _Z, _W), GX2_ENDIAN_SWAP_DEFAULT
}, },
.position = { .position = {
1, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32, 1, 0, offsetof(tex_shader_vertex_t, pos), GX2_ATTRIB_FORMAT_FLOAT_32_32,
GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _0, _1), GX2_ENDIAN_SWAP_DEFAULT GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _0, _1), GX2_ENDIAN_SWAP_DEFAULT
}, },
.tex_coord = { .tex_coord = {
2, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32, 2, 0, offsetof(tex_shader_vertex_t, coord), GX2_ATTRIB_FORMAT_FLOAT_32_32,
GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _0, _1), GX2_ENDIAN_SWAP_DEFAULT GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_X, _Y, _0, _1), GX2_ENDIAN_SWAP_DEFAULT
} }
}, },

View File

@ -41,6 +41,23 @@ typedef struct __attribute__((aligned(GX2_VERTEX_BUFFER_ALIGNMENT)))
GX2FetchShader fs; GX2FetchShader fs;
}tex_shader_t; }tex_shader_t;
typedef struct
{
struct
{
float x;
float y;
}pos;
struct
{
float u;
float v;
}coord;
u32 color;
}tex_shader_vertex_t;
extern tex_shader_t tex_shader; extern tex_shader_t tex_shader;
#ifdef __cplusplus #ifdef __cplusplus