Browse files

SoftRasterizer: Fix Z-depth calculations when compiling on MSVC. Fixe…

…s the overworld map in Dragon Quest IV. (Regression from commit d81a75c.)

- Apparently, MSVC has a more strict implementation of IEEE-754 single-precision floats (with 23-bit significands) than Clang and GCC, and so we going to drop 2 LSBs during the calculation so that we're multiplying z by a 22-bit significand. Coincidentally, this now matches what we're doing with the OpenGL renderer, so this tends to better code consistency.
  • Loading branch information...
rogerman committed Nov 22, 2018
1 parent f03a880 commit d410b5c195903e01d2023cf3d8a8e6f53097dcff
Showing with 4 additions and 1 deletion.
  1. +4 −1 desmume/src/rasterize.cpp
5 desmume/src/rasterize.cpp 100644 → 100755
@@ -517,7 +517,10 @@ FORCEINLINE void RasterizerUnit<RENDERER>::_pixel(const POLYGON_ATTR polyAttr, c
// When using z-depth, be sure to test against the following test cases:
// - The drawing of the overworld map in Dragon Quest IV
// - The drawing of all units on the map in Advance Wars: Days of Ruin
const u32 newDepth = (gfx3d.renderState.wbuffer) ? u32floor(w * 4096.0f) : u32floor(z * 16777215.0f);
// Note that an IEEE-754 single-precision float uses a 23-bit significand. Therefore, we will multiply the
// Z-depth by a 22-bit significand for safety.
const u32 newDepth = (gfx3d.renderState.wbuffer) ? u32floor(w * 4096.0f) : u32floor(z * 4194303.0f) << 2;
// run the depth test
bool depthFail = false;

0 comments on commit d410b5c

Please sign in to comment.