From 981fcca76d190e2fcf7c61000ded81b495dd6883 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 18 Feb 2022 12:54:54 +0900 Subject: [PATCH] [sw,sw32] Fix broken software skies All for an unfortunate unsigned promotion. I guess I just wasn't testing the software renderers enough. --- libs/video/renderer/sw/d_sky.c | 6 ++++-- libs/video/renderer/sw32/d_sky.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/video/renderer/sw/d_sky.c b/libs/video/renderer/sw/d_sky.c index 853a3e0e0..c6cd5832d 100644 --- a/libs/video/renderer/sw/d_sky.c +++ b/libs/video/renderer/sw/d_sky.c @@ -42,14 +42,16 @@ D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t) { float wu, wv, temp; vec3_t end; + int half_width = vid.width >> 1; + int half_height = vid.height >> 1; if (r_refdef.vrect.width >= r_refdef.vrect.height) temp = (float) r_refdef.vrect.width; else temp = (float) r_refdef.vrect.height; - wu = 8192.0 * (float) (u - (vid.width >> 1)) / temp; - wv = 8192.0 * (float) ((vid.height >> 1) - v) / temp; + wu = 8192.0 * (float) (u - half_width) / temp; + wv = 8192.0 * (float) (half_height - v) / temp; end[0] = 4096 * vpn[0] + wu * vright[0] + wv * vup[0]; end[1] = 4096 * vpn[1] + wu * vright[1] + wv * vup[1]; diff --git a/libs/video/renderer/sw32/d_sky.c b/libs/video/renderer/sw32/d_sky.c index 989fd4369..b9c03b5a0 100644 --- a/libs/video/renderer/sw32/d_sky.c +++ b/libs/video/renderer/sw32/d_sky.c @@ -47,14 +47,16 @@ D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t) { float wu, wv, temp; vec3_t end; + int half_width = vid.width >> 1; + int half_height = vid.height >> 1; if (r_refdef.vrect.width >= r_refdef.vrect.height) temp = (float) r_refdef.vrect.width; else temp = (float) r_refdef.vrect.height; - wu = 8192.0 * (float) (u - (vid.width >> 1)) / temp; - wv = 8192.0 * (float) ((vid.height >> 1) - v) / temp; + wu = 8192.0 * (float) (u - half_width) / temp; + wv = 8192.0 * (float) (half_height - v) / temp; end[0] = 4096 * vpn[0] + wu * vright[0] + wv * vup[0]; end[1] = 4096 * vpn[1] + wu * vright[1] + wv * vup[1];