From e654d1e7e9457bdf48e125f48498efc60c55d27a Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 16 Aug 2020 19:38:58 -0400 Subject: [PATCH] winport - fix OamView bug (proper obj priority wasn't being used when rendering it, causing many composite sprites to be rendered more or less in the opposite Z-order due to LATER obj drawing on top (whereas lower obj are supposed to draw on top). fixes #358 --- desmume/src/GPU.cpp | 11 ++++++++++- desmume/src/GPU.h | 1 + desmume/src/frontend/windows/oamView.cpp | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 896f59f4a..095b62839 100755 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -4956,7 +4956,11 @@ FORCEINLINE void GPUEngineBase::_RenderSpriteUpdatePixel(GPUEngineCompositorInfo if (ISDEBUGRENDER) { + //sprites draw in order, so EQUAL priority also trumps later sprites + if(prioTab[frameX] <= prio) + return; dst[frameX] = (ISOBJMODEBITMAP) ? *srcPalette : LE_TO_LOCAL_16(srcPalette[palIndex]); + prioTab[frameX] = prio; return; } @@ -5164,6 +5168,11 @@ void GPUEngineBase::_SpriteRender(GPUEngineCompositorInfo &compInfo, u16 *__rest this->_SpriteRenderPerform(compInfo, dst, dst_alpha, typeTab, prioTab); } +void GPUEngineBase::SpritePrepareRenderDebug(u16 *dst) +{ + memset(this->_sprPrio, 0x7F, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT); +} + void GPUEngineBase::SpriteRenderDebug(const u16 lineIndex, u16 *dst) { GPUEngineCompositorInfo compInfo; @@ -5202,7 +5211,7 @@ void GPUEngineBase::SpriteRenderDebug(const u16 lineIndex, u16 *dst) compInfo.target.lineColor32 = (FragmentColor *)compInfo.target.lineColorHeadNative; compInfo.target.lineLayerID = NULL; - this->_SpriteRender(compInfo, dst, NULL, NULL, NULL); + this->_SpriteRender(compInfo, dst, NULL, NULL, &this->_sprPrio[lineIndex][0]); } template diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 37222b878..82d460578 100755 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -1637,6 +1637,7 @@ public: const BGLayerInfo& GetBGLayerInfoByID(const GPULayerID layerID); + void SpritePrepareRenderDebug(u16 *dst); void SpriteRenderDebug(const u16 lineIndex, u16 *dst); void RenderLayerBG(const GPULayerID layerID, u16 *dstLineColor); diff --git a/desmume/src/frontend/windows/oamView.cpp b/desmume/src/frontend/windows/oamView.cpp index b02e7cc29..b7d02107b 100644 --- a/desmume/src/frontend/windows/oamView.cpp +++ b/desmume/src/frontend/windows/oamView.cpp @@ -211,10 +211,11 @@ LRESULT OamView_OnPaint(HWND hwnd, oamview_struct *win, WPARAM wParam, LPARAM lP SetWindowText(GetDlgItem(hwnd, IDC_PROP1), ""); } - for(i = 0; i < 192; ++i) - { - win->gpu->SpriteRenderDebug(i, (u16*)(bitmap + i*256)); - } + win->gpu->SpritePrepareRenderDebug(bitmap); + for(i = 0; i < 192; ++i) + { + win->gpu->SpriteRenderDebug(i, (u16*)(bitmap + i * 256)); + } u32 width = dimm_int[(oam->attr1>>14)][(oam->attr0>>14)][0]; u32 height = dimm_int[(oam->attr1>>14)][(oam->attr0>>14)][1];