Skip to content

Commit 885d78a

Browse files
mardyWinterMute
authored andcommitted
ogc: remove sub-pixel adjustment when drawing triangles and quads
The adjustment is not needed, since the drawn geometries are exactly delimited by their vertices. The only adjustment that needs to be made is when drawing lines and point, due to the fact that in these cases the vertices do not really delimit the geometry, which is instead drawn around them.
1 parent d62ce9d commit 885d78a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/render/ogc/SDL_render_ogc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ int OGC_RenderPrimitive(SDL_Renderer *renderer, u8 primitive,
554554
OGC_RenderData *data = renderer->driverdata;
555555
size_t count = cmd->data.draw.count;
556556
const SDL_FPoint *verts = (SDL_FPoint *)(vertices + cmd->data.draw.first);
557+
Mtx mv;
558+
bool did_change_matrix = false;
557559
GXColor c = {
558560
cmd->data.draw.r,
559561
cmd->data.draw.g,
@@ -564,6 +566,14 @@ int OGC_RenderPrimitive(SDL_Renderer *renderer, u8 primitive,
564566
data->ops_after_present++;
565567
OGC_SetBlendMode(renderer, cmd->data.draw.blend);
566568

569+
if (primitive == GX_LINESTRIP || primitive == GX_POINTS) {
570+
float adjustment = 0.5;
571+
guMtxIdentity(mv);
572+
guMtxTransApply(mv, mv, adjustment, adjustment, 0);
573+
GX_LoadPosMtxImm(mv, GX_PNMTX0);
574+
did_change_matrix = true;
575+
}
576+
567577
/* TODO: optimize state changes. */
568578
GX_SetTevColor(GX_TEVREG0, c);
569579
GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO);
@@ -592,6 +602,11 @@ int OGC_RenderPrimitive(SDL_Renderer *renderer, u8 primitive,
592602
GX_End();
593603
}
594604

605+
if (did_change_matrix) {
606+
guMtxIdentity(mv);
607+
GX_LoadPosMtxImm(mv, GX_PNMTX0);
608+
}
609+
595610
return 0;
596611
}
597612

src/video/ogc/SDL_ogcgxcommon.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,8 @@ void OGC_set_viewport(int x, int y, int w, int h)
5454

5555
void OGC_draw_init(int w, int h)
5656
{
57-
Mtx mv;
58-
5957
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "OGC_draw_init called with %d, %d", w, h);
6058

61-
guMtxIdentity(mv);
62-
/* Ideally we would use 0.5 to center the coordinates on the pixels, but
63-
* this causes some visual artifacts due to rounding: in the VVVVVV game,
64-
* all 8x8 pixel textures lose their rightmost column and bottom row,
65-
* except when they are drawn on the bottom-right quadrant of the screen.
66-
* Values from 0.1 to 0.4 fix this issue, while preserving pixel accuracy
67-
* on drawing operations. */
68-
guMtxTransApply(mv, mv, 0.4, 0.4, 0);
69-
GX_LoadPosMtxImm(mv, GX_PNMTX0);
70-
7159
GX_ClearVtxDesc();
7260
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
7361
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);

0 commit comments

Comments
 (0)