From 7383e90c19d2d2450a481479c5d826320e39b12e Mon Sep 17 00:00:00 2001 From: weihuoya Date: Thu, 23 Aug 2018 12:46:09 +0800 Subject: [PATCH] handle cullface, help to #10597 --- GPU/Common/DrawEngineCommon.cpp | 8 ++++---- GPU/GPUCommon.cpp | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 95d6d5ad2eb4..809811bc303a 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -522,7 +522,7 @@ void DrawEngineCommon::DecodeVertsStep(u8 *dest, int &i, int &decodedVerts) { decodedVerts += indexUpperBound - indexLowerBound + 1; bool clockwise = true; - if (dc.cullMode != -1 && gstate.isCullEnabled() && gstate.getCullMode() != dc.cullMode) { + if (gstate.isCullEnabled() && gstate.getCullMode() != dc.cullMode) { clockwise = false; } indexGen.AddPrim(dc.prim, dc.vertexCount, clockwise); @@ -550,7 +550,7 @@ void DrawEngineCommon::DecodeVertsStep(u8 *dest, int &i, int &decodedVerts) { case GE_VTYPE_IDX_8BIT >> GE_VTYPE_IDX_SHIFT: for (int j = i; j <= lastMatch; j++) { bool clockwise = true; - if (drawCalls[j].cullMode != -1 && gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { + if (gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { clockwise = false; } indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u8 *)drawCalls[j].inds, indexLowerBound, clockwise); @@ -559,7 +559,7 @@ void DrawEngineCommon::DecodeVertsStep(u8 *dest, int &i, int &decodedVerts) { case GE_VTYPE_IDX_16BIT >> GE_VTYPE_IDX_SHIFT: for (int j = i; j <= lastMatch; j++) { bool clockwise = true; - if (drawCalls[j].cullMode != -1 && gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { + if (gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { clockwise = false; } indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u16_le *)drawCalls[j].inds, indexLowerBound, clockwise); @@ -568,7 +568,7 @@ void DrawEngineCommon::DecodeVertsStep(u8 *dest, int &i, int &decodedVerts) { case GE_VTYPE_IDX_32BIT >> GE_VTYPE_IDX_SHIFT: for (int j = i; j <= lastMatch; j++) { bool clockwise = true; - if (drawCalls[j].cullMode != -1 && gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { + if (gstate.isCullEnabled() && gstate.getCullMode() != drawCalls[j].cullMode) { clockwise = false; } indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u32_le *)drawCalls[j].inds, indexLowerBound, clockwise); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 6339504d0d09..2474cda3626b 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1533,7 +1533,7 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) { UpdateUVScaleOffset(); // cull mode - int cullMode = gstate.isCullEnabled() ? gstate.getCullMode() : -1; + int cullMode = gstate.getCullMode(); uint32_t vertTypeID = GetVertTypeID(vertexType, gstate.getUVGenMode()); drawEngineCommon_->SubmitPrim(verts, inds, prim, count, vertTypeID, cullMode, &bytesRead); @@ -1582,13 +1582,6 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) { inds = Memory::GetPointerUnchecked(gstate_c.indexAddr); } - if (newPrim != GE_PRIM_TRIANGLE_STRIP && cullMode != -1 && cullMode != gstate.getCullMode()) { - DEBUG_LOG(G3D, "flush cull mode before prim: %d", newPrim); - drawEngineCommon_->DispatchFlush(); - gstate.cmdmem[GE_CMD_CULL] ^= 1; - gstate_c.Dirty(DIRTY_RASTER_STATE); - } - drawEngineCommon_->SubmitPrim(verts, inds, newPrim, count, vertTypeID, cullMode, &bytesRead); AdvanceVerts(vertexType, count, bytesRead); totalVertCount += count; @@ -1616,8 +1609,14 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) { case GE_CMD_BASE: gstate.cmdmem[GE_CMD_BASE] = data; break; + case GE_CMD_CULLFACEENABLE: + // Earth Defence Force 2 + if (gstate.cmdmem[GE_CMD_CULLFACEENABLE] != data) { + goto bail; + } + break; case GE_CMD_CULL: - // flip face by indices for GE_PRIM_TRIANGLE_STRIP + // flip face by indices for triangles cullMode = data & 1; break; case GE_CMD_NOP: @@ -1679,10 +1678,10 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) { UpdatePC(currentList->pc, currentList->pc + cmdCount * 4); currentList->pc += cmdCount * 4; // flush back cull mode - if (cullMode != -1 && cullMode != gstate.getCullMode()) { - drawEngineCommon_->DispatchFlush(); + if (cullMode != gstate.getCullMode()) { gstate.cmdmem[GE_CMD_CULL] ^= 1; gstate_c.Dirty(DIRTY_RASTER_STATE); + drawEngineCommon_->DispatchFlush(); } }