diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index f60940b4f..e7521a57e 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -382,9 +382,8 @@ void gfx3d_glFogOffset (u32 v) void gfx3d_glClearDepth(u32 v) { - //formula from http://nocash.emubase.de/gbatek.htm#ds3drearplane v &= 0x7FFF; - gfx3d.clearDepth = (v*0x200)+((v+1)/0x8000)*0x01FF; + gfx3d.clearDepth = gfx3d_extendDepth_15_to_24(v); } void gfx3d_glMatrixMode(u32 v) diff --git a/desmume/src/gfx3d.h b/desmume/src/gfx3d.h index 54ba9aeb3..10823a71d 100644 --- a/desmume/src/gfx3d.h +++ b/desmume/src/gfx3d.h @@ -50,6 +50,11 @@ //produce a 15bpp color from individual 5bit components #define R5G5B5TORGB15(r,g,b) ((r)|((g)<<5)|((b)<<10)) +inline u32 gfx3d_extendDepth_15_to_24(u32 depth) +{ + //formula from http://nocash.emubase.de/gbatek.htm#ds3drearplane + return (depth*0x200)+((depth+1)>>15)*0x01FF; +} #define TEXMODE_NONE 0 #define TEXMODE_A3I5 1 diff --git a/desmume/src/rasterize.cpp b/desmume/src/rasterize.cpp index bd2b10ff4..bb161b5ff 100644 --- a/desmume/src/rasterize.cpp +++ b/desmume/src/rasterize.cpp @@ -467,10 +467,19 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo } else { - float test = -1.2f; - u32 test2 = u32floor(test); - //depth = u32floor(z*0x7FFF); //the traditional value - depth = u32floor(z*0xFFFFFF); //sonic chronicles uses depth clear and this makes it work + //the traditional value + depth = u32floor(z*0x7FFF); + + //this would work in sonic chronicles but break battles of prince of persia + //depth = u32floor(z*0xFFFFFF); + + //so we have this compromise: + depth = gfx3d_extendDepth_15_to_24(depth); + + //some contemplation on the matter: + //it seems that everything in the ds uses 15 bit depths + //except that thedepth buffer is 24 bit. but nothing ever uses 24 bits!!! + //this makes no sense. } if(polyAttr.decalMode) { @@ -481,7 +490,7 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo } else { - if(depth>=destFragment.depth) + if(depth>=destFragment.depth+1) { goto depth_fail; } @@ -599,6 +608,8 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo destFragment.stencil = 1; }*/ + int zzz=9; + rejected_fragment: done_with_pixel: ; @@ -1202,7 +1213,7 @@ static void SoftRastRender() //masking off fog for now depth &= 0x7FFF; //TODO - might consider a lookup table for this - dst->depth = (depth*0x200)+((depth+1)>>15)*0x01FF; + dst->depth = gfx3d_extendDepth_15_to_24(depth); clearDepth++; clearImage++;