Commit 6ea7c51
iOS Metal port: half-pixel offset for DrawLine and DrawRect line endpoints
GPU line rasterisation snaps each line to the pixel grid. A horizontal
line at integer y (e.g. y=0) straddles the boundary between row -1 and
row 0; hardware antialiasing splits the coverage between the two rows
at half intensity each, so the line ends up looking 2 px wide and washed
out instead of crisp 1 px. The standard fix is to pass endpoints through
the pixel centre (y = N + 0.5) so the line sits inside a single row.
The GL ES2 path already does this -- DrawLine.m:122 emits
`x1+0.5, y1+0.5, x2+0.5, y2+0.5`, and DrawRect.m:122 mirrors the same
+0.5 on every vertex of the closed line strip. Mirror it in Metal's
CN1MetalDrawLine and CN1MetalDrawRect.
Visible victim: the graphics-draw-rect test draws hundreds of
concentric drawRect outlines with cycling colours. On GL each outline
is a distinct 1 px coloured stripe and the whole stack reads as a
moiré of stripes. On Metal pre-fix the lines smeared between adjacent
rows and the inner stripes blurred into a solid filled block.
graphics-draw-line had the analogous symptom on every line in the test.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 774eeb2 commit 6ea7c51
1 file changed
Lines changed: 21 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
285 | 295 | | |
286 | 296 | | |
287 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
288 | 301 | | |
289 | 302 | | |
290 | 303 | | |
291 | 304 | | |
292 | 305 | | |
293 | | - | |
| 306 | + | |
| 307 | + | |
294 | 308 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
300 | 314 | | |
301 | 315 | | |
302 | 316 | | |
| |||
0 commit comments