From 5bb965be3d92e36b0532cc1f7411ded5be2083fa Mon Sep 17 00:00:00 2001 From: Daniel Santos <47725160+DanielSant0s@users.noreply.github.com> Date: Fri, 8 Jul 2022 15:47:33 -0300 Subject: [PATCH] Implement RenderLines --- src/render/ps2/SDL_render_ps2.c | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c index 25c4949de..f4d57433a 100644 --- a/src/render/ps2/SDL_render_ps2.c +++ b/src/render/ps2/SDL_render_ps2.c @@ -209,6 +209,30 @@ PS2_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd) return 0; /* nothing to do in this backend. */ } +static int +PS2_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count) +{ + PS2_RenderData *data = (PS2_RenderData *) renderer->driverdata; + uint64_t color = data->drawColor; + color_vertex *vertex = (color_vertex *) SDL_AllocateRenderVertices(renderer, (count-1) * sizeof (color_vertex) * 2, 4, &cmd->data.draw.first); + + cmd->data.draw.first = (size_t)vertex; + cmd->data.draw.count = (count-1) * 2; + + for (int i = 0; i < count-1; i++) + { + vertex[i*2].x = points[i].x; + vertex[i*2].y = points[i].y; + vertex[i*2].color = color; + + vertex[i*2+1].x = points[i+1].x; + vertex[i*2+1].y = points[i+1].y; + vertex[i*2+1].color = color; + } + + return 0; +} + static int PS2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count) { @@ -440,6 +464,34 @@ PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cm return 0; } + +int +PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * cmd) +{ + PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata; + float x1, y1, x2, y2; + uint64_t c1, c2; + int i; + + const size_t count = cmd->data.draw.count; + + const color_vertex *verts = (color_vertex *) (vertices + cmd->data.draw.first); + + for (i = 0; i < count-1; i++, verts++) { + x1 = verts[i*2].x; + y1 = verts[i*2].y; + c1 = verts[i*2].color; + + x2 = verts[i*2+1].x; + y2 = verts[i*2+1].y; + c2 = verts[i*2+1].color; + gsKit_prim_line_goraud(data->gsGlobal, x1, y1, x2, y2, 0, c1, c2); + } + + /* We're done! */ + return 0; +} + int PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * cmd) { @@ -483,6 +535,10 @@ PS2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti PS2_RenderPoints(renderer, vertices, cmd); break; } + case SDL_RENDERCMD_DRAW_LINES: { + PS2_RenderLines(renderer, vertices, cmd); + break; + } case SDL_RENDERCMD_FILL_RECTS: /* unused */ break; case SDL_RENDERCMD_COPY: /* unused */ @@ -537,7 +593,6 @@ PS2_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) SDL_free(ps2_texture); } - static void PS2_DestroyRenderer(SDL_Renderer * renderer) { @@ -645,7 +700,7 @@ PS2_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->QueueSetViewport = PS2_QueueSetViewport; renderer->QueueSetDrawColor = PS2_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */ renderer->QueueDrawPoints = PS2_QueueDrawPoints; - renderer->QueueDrawLines = PS2_QueueDrawPoints; /* lines and points queue vertices the same way. */ + renderer->QueueDrawLines = PS2_QueueDrawLines; /* lines and points queue vertices the same way. */ renderer->QueueGeometry = PS2_QueueGeometry; renderer->RunCommandQueue = PS2_RunCommandQueue; renderer->RenderReadPixels = PS2_RenderReadPixels;