shithub: qk1

Download patch

ref: 680760277c70d206be73825a4050235d535f7e58
parent: 6847239cc62b476b397eae0bcc672def968b0fa4
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Dec 18 02:36:09 EST 2023

fences (bsp20 and external textures): rescale from base as with premultiplied alpha and use other mip levels when rendering

--- a/d_edge.c
+++ b/d_edge.c
@@ -176,10 +176,7 @@
 			}
 
 			pface = s->data;
-			if(s->flags & SURF_FENCE)
-				miplevel = 0;
-			else
-				miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust);
+			miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust);
 
 			// FIXME: make this passed in to D_CacheSurface
 			pcurrentcache = D_CacheSurface(pface, miplevel);
--- a/i_external.c
+++ b/i_external.c
@@ -51,7 +51,8 @@
 			tx->pixels+tx->offsets[i],
 			tx->width, tx->height,
 			w, h,
-			premult
+			premult,
+			name[0] == '{'
 		);
 	}
 
--- a/i_resize.c
+++ b/i_resize.c
@@ -8,11 +8,11 @@
 #pragma GCC diagnostic pop
 
 void
-pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premulalpha)
+pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premul, bool fence)
 {
 	stbir_resize_uint8_srgb(
 		(byte*)in, iw, ih, iw*sizeof(pixel_t),
 		(byte*)out, ow, oh, ow*sizeof(pixel_t),
-		premulalpha ? STBIR_RGBA_PM : STBIR_RGBA
+		(premul || fence) ? STBIR_RGBA_PM : STBIR_RGBA
 	);
 }
--- a/i_wad.c
+++ b/i_wad.c
@@ -215,8 +215,24 @@
 	for(i = 0; i < nelem(t->offsets); i++)
 		t->offsets[i] = le32(p) - (16+2*4+4*4);
 	off = p - wad->in;
-	if((n = W_ReadPixelsAt(wad, name, off, lmp->off+lmp->sz-off, (pixel_t*)(t+1), n)) < 0)
+	if((n = W_ReadPixelsAt(wad, name, off, lmp->off+lmp->sz-off, t->pixels, n)) < 0)
 		werrstr("%s: %s", name, lerr());
+
+	// looks shit either way on cs_italy
+	if(0 && name[0] == '{'){
+		for(i = 1; i < MIPLEVELS; i++){
+			w /= 2;
+			h /= 2;
+			pixels_resize(
+				t->pixels+t->offsets[0],
+				t->pixels+t->offsets[i],
+				t->width, t->height,
+				w, h,
+				false,
+				true
+			);
+		}
+	}
 	return n;
 }
 
--- a/model_bsp.c
+++ b/model_bsp.c
@@ -133,6 +133,20 @@
 			tx->height = h;
 			// the pixels immediately follow the structures
 			torgbx(p, tx->pixels, pixels);
+			if(tx->name[0] == '{'){
+				for(j = 1; j < MIPLEVELS; j++){
+					w /= 2;
+					h /= 2;
+					pixels_resize(
+						tx->pixels+tx->offsets[0],
+						tx->pixels+tx->offsets[j],
+						tx->width, tx->height,
+						w, h,
+						false,
+						true
+					);
+				}
+			}
 		}
 		if(strncmp(tx->name, "sky", 3) == 0)
 			R_InitSky(tx);
--- a/quakedef.h
+++ b/quakedef.h
@@ -136,7 +136,7 @@
 	pixel_t pixels[];
 }qpic_t;
 
-void pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premulalpha);
+void pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premulalpha, bool fence);
 
 #include "i_tga.h"
 #include "i_wad.h"