From 90c8b3370a0e0915e512705c5752e734c2b05eb5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 3 Nov 2016 12:51:07 +0100 Subject: [PATCH] Fix mipmap sampling bug --- src/r_draw.cpp | 2 +- src/r_segs.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 45758ee61..0a2c8553e 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -1073,7 +1073,7 @@ extern "C" BYTE *ds_curcolormap, *ds_cursource, *ds_curtiltedsource; void R_SetSpanSource(FTexture *tex) { ds_source = r_swtruecolor ? (const BYTE*)tex->GetPixelsBgra() : tex->GetPixels(); - ds_source_mipmapped = tex->Mipmapped(); + ds_source_mipmapped = tex->Mipmapped() && tex->GetWidth() > 1 && tex->GetHeight() > 1; #ifdef X86_ASM if (!r_swtruecolor && ds_cursource != ds_source) { diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 108463e38..a8267a663 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1159,12 +1159,12 @@ WallscanSampler::WallscanSampler(int y1, float swal, double yrepeat, fixed_t xof int mipmap_offset = 0; int mip_width = texture->GetWidth(); int mip_height = texture->GetHeight(); - if (r_mipmap && texture->Mipmapped()) + if (r_mipmap && texture->Mipmapped() && mip_width > 1 && mip_height > 1) { uint32_t xpos = (uint32_t)((((uint64_t)xoffset) << FRACBITS) / mip_width); double texture_bias = 1.7f; double level = MAX(magnitude - 3.0, 0.0); - while (level > texture_bias) + while (level > texture_bias && mip_width > 1 && mip_height > 1) { mipmap_offset += mip_width * mip_height; level *= 0.5f;