Implement RenderLines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c
index 25c4949..f4d5743 100644
--- a/src/render/ps2/SDL_render_ps2.c
+++ b/src/render/ps2/SDL_render_ps2.c
@@ -210,6 +210,30 @@ PS2_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
}
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)
{
clear_vertex *verts = (clear_vertex *) SDL_AllocateRenderVertices(renderer, count * sizeof (clear_vertex), 4, &cmd->data.draw.first);
@@ -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;