From 167f501a1ac1a41a44882b8414058b0b7f150022 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Jul 2025 23:09:30 +1000 Subject: [PATCH] N64: Still enable Z when depth write is enabled --- misc/n64/gpu.c | 2 +- src/Graphics_N64.c | 15 +++++++++++---- src/Graphics_SoftGPU.c | 2 +- src/_GraphicsBase.h | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/misc/n64/gpu.c b/misc/n64/gpu.c index b65fd63e1..eb5b33ec5 100644 --- a/misc/n64/gpu.c +++ b/misc/n64/gpu.c @@ -95,7 +95,7 @@ static int gpu_stride; #define GPU_ATTR_TEX (1 << 9) #define GPU_ATTR_SHADE (1 << 10) #define GPU_ATTR_EDGE (1 << 11) -static bool gpu_attr_z, gpu_attr_tex; +static uint8_t gpu_attr_z, gpu_attr_tex; static void gpuUpdateFormat(void) { diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 6b7a9061e..1ea54c9d8 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -19,8 +19,8 @@ void Gfx_Create(void) { rspq_init(); //rspq_profile_start(); rdpq_init(); - //rdpq_debug_start(); // TODO debug - //rdpq_debug_log(true); + //rdpq_debug_start(); // TODO debug + //rdpq_debug_log(true); rdpq_set_mode_standard(); __rdpq_mode_change_som(SOM_TEXTURE_PERSP, SOM_TEXTURE_PERSP); @@ -96,7 +96,7 @@ void Gfx_BeginFrame(void) { surface_t* disp = display_get(); rdpq_attach(disp, &zbuffer); - Platform_LogConst("== BEGIN frame"); + //Platform_LogConst("== BEGIN frame"); } extern void __rdpq_autosync_change(int mode); @@ -251,14 +251,21 @@ static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) { //gpuColorMask(r, g, b, a); TODO } +#define FLAG_Z_WRITE 0x02 void Gfx_SetDepthWrite(cc_bool enabled) { __rdpq_mode_change_som(SOM_Z_WRITE, enabled ? SOM_Z_WRITE : 0); + + gpu_attr_z &= ~FLAG_Z_WRITE; + gpu_attr_z |= enabled ? FLAG_Z_WRITE : 0; + gpuUpdateFormat(); } +#define FLAG_Z_READ 0x01 void Gfx_SetDepthTest(cc_bool enabled) { __rdpq_mode_change_som(SOM_Z_COMPARE, enabled ? SOM_Z_COMPARE : 0); - gpu_attr_z = enabled; + gpu_attr_z &= ~FLAG_Z_READ; + gpu_attr_z |= enabled ? FLAG_Z_READ : 0; gpuUpdateFormat(); } diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index ded68ac82..54c3cc413 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -119,7 +119,7 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i CopyPixels(dst, tex->width * BITMAPCOLOR_SIZE, part->scan0, rowWidth * BITMAPCOLOR_SIZE, - bmp->width, bmp->height); + part->width, part->height); } void Gfx_EnableMipmaps(void) { } diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index a4b404196..7ad71ab29 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -332,7 +332,8 @@ static CC_INLINE void CopyPixels(void* dst, int dstStride, Mem_Copy(dst_, src_, Bitmap_DataSize(pixelsPerRow, rows)); } else { /* Have to copy scanline by scanline */ - for (y = 0; y < rows; y++) { + for (y = 0; y < rows; y++) + { Mem_Copy(dst_, src_, pixelsPerRow * BITMAPCOLOR_SIZE); src_ += srcStride; dst_ += dstStride;