Implement FillRect

This commit is contained in:
Daniel Santos 2022-07-07 14:10:37 -03:00 committed by Sam Lantinga
parent a152e467b1
commit df6ebc2562
1 changed files with 53 additions and 1 deletions

View File

@ -35,6 +35,11 @@
/* turn black GS Screen */
#define GS_BLACK GS_SETREG_RGBA(0x00, 0x00, 0x00, 0x80)
typedef struct clear_vertex {
float x;
float y;
} clear_vertex;
typedef struct texture_vertex {
float x;
float y;
@ -209,6 +214,22 @@ PS2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
static int
PS2_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 4, &cmd->data.draw.first);
int i;
if (!verts) {
return -1;
}
cmd->data.draw.count = count;
for (i = 0; i < count; i++, verts++, rects++) {
verts->x = (int)rects->x;
verts->y = (int)rects->y;
verts->w = rects->w + 0.5f;
verts->h = rects->h + 0.5f;
}
return 0;
}
@ -424,6 +445,35 @@ PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cm
return 0;
}
int
PS2_FillRects(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * cmd)
{
PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata;
const SDL_Rect* rect;
uint64_t color;
int i;
const size_t count = cmd->data.draw.count;
const uint8_t ColorR = cmd->data.draw.r >> 1;
const uint8_t ColorG = cmd->data.draw.g >> 1;
const uint8_t ColorB = cmd->data.draw.b >> 1;
const uint8_t ColorA = cmd->data.draw.a >> 1;
color = GS_SETREG_RGBAQ(ColorR, ColorG, ColorB, ColorA, 0x00);
SDL_Rect *rects = (SDL_Rect *) (vertices + cmd->data.draw.first);
for (i = 0; i < count; i++) {
rect = &rects[i];
gsKit_prim_sprite(data->gsGlobal, rect->x, rect->y, rect->w, rect->h, 0, color);
}
/* We're done! */
return 0;
}
static int
PS2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
@ -437,8 +487,10 @@ PS2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
PS2_RenderClear(renderer, cmd);
break;
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
case SDL_RENDERCMD_FILL_RECTS: {
PS2_FillRects(renderer, vertices, cmd);
break;
}
case SDL_RENDERCMD_COPY: /* unused */
break;