Skip to content

Commit d62ce9d

Browse files
mardyWinterMute
authored andcommitted
ogc, renderer: workaround missing pixels in linestrips
In addition to drawing the last point, we must draw all the other ones, too. The reason is that GX rendering of lines is a bit different than how SDL applications expect it, and there isn't a straightforward way to correct it in a way that is good for all cases. The problem is that GX draws a line (let's assume it's a horizontal one) between coordinates A and B like this: ┌────────────────────────────────────────────────────────┐ A B └────────────────────────────────────────────────────────┘ That is, the line is made as wide as needed, but the line caps are in "butt" style (using the HTML terminology), that is the line lenght is not increased by half width around the points A and B (which is what SDL seems to be doing on both the software and OpenGL renderer backends on the desktop). As a result, when drawing a linestrip as a rectangle with vertices A, B, C and D, the drawing that GX sets up is this: ┌────────────────────────────────────┐ ┌─A─┐ 1 ┌─B─┐ │ ├────────────────────────────────┤ │ │ 4 │ │ 2 │ │ │ │ │ │ ├────────────────────────────────┴─┐ │ └─D─┘ 3 C─┘ └────────────────────────────────────┘ If (like is the case with SDL) lines are only one pixel wide, the corner pixels will not be drawn if the positioning of the vertex is such that the GX engine decides the pixel is not covered enough. In practice, as can be tested with the sdl-subpixel program[1], it very often happens that at least one corner of the rectangle is not drawn. Since points are always drawn as a square around the given coordinates, adding squares at line vertices helps fixing this issue. [1]: https://github.com/mardy/sdl-subpixel
1 parent 0edb424 commit d62ce9d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/render/ogc/SDL_render_ogc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,10 @@ int OGC_RenderPrimitive(SDL_Renderer *renderer, u8 primitive,
585585

586586
/* The last point is not drawn */
587587
if (primitive == GX_LINESTRIP) {
588-
GX_Begin(GX_POINTS, GX_VTXFMT0, 1);
589-
GX_Position2f32(verts[count - 1].x, verts[count - 1].y);
588+
GX_Begin(GX_POINTS, GX_VTXFMT0, count);
589+
for (int i = 0; i < count; i++) {
590+
GX_Position2f32(verts[i].x, verts[i].y);
591+
}
590592
GX_End();
591593
}
592594

0 commit comments

Comments
 (0)