From 44035df446d55f4dba7c4043539b82c4ce298a53 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Tue, 23 Jul 2013 20:15:30 +0200 Subject: [PATCH] SoftGpu: Add support for triangle fans. --- GPU/Software/SoftGpu.cpp | 5 +++-- GPU/Software/TransformUnit.cpp | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 716fa28cb4..39d53f4b4a 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -276,9 +276,10 @@ void SoftGPU::ExecuteOp(u32 op, u32 diff) "RECTANGLES=6,", }; - if (type != GE_PRIM_TRIANGLES && type != GE_PRIM_TRIANGLE_STRIP && type != GE_PRIM_RECTANGLES) + if (type != GE_PRIM_TRIANGLES && type != GE_PRIM_TRIANGLE_STRIP && type != GE_PRIM_TRIANGLE_FAN && type != GE_PRIM_RECTANGLES) { + ERROR_LOG(G3D, "DL DrawPrim type: %s count: %i vaddr= %08x, iaddr= %08x", type<7 ? types[type] : "INVALID", count, gstate_c.vertexAddr, gstate_c.indexAddr); break; -// ERROR_LOG(G3D, "DL DrawPrim type: %s count: %i vaddr= %08x, iaddr= %08x", type<7 ? types[type] : "INVALID", count, gstate_c.vertexAddr, gstate_c.indexAddr); + } void *verts = Memory::GetPointer(gstate_c.vertexAddr); void *indices = NULL; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index ee608cdb9b..527cf0ac92 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -225,6 +225,42 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type continue; } + // We need to reverse the vertex order for each second primitive, + // but we additionally need to do that for every primitive if CCW cullmode is used. + if ((!gstate.getCullMode()) ^ (vtx % 2)) + Clipper::ProcessTriangle(data[2], data[1], data[0]); + else + Clipper::ProcessTriangle(data[0], data[1], data[2]); + } + } else if (prim_type == GE_PRIM_TRIANGLE_FAN) { + VertexData data[3]; + unsigned int skip_count = 1; // Don't draw a triangle when loading the first two vertices + + if (indices) + vreader.Goto(indices_16bit ? indices16[0] : indices8[0]); + else + vreader.Goto(0); + data[0] = ReadVertex(vreader); + + for (int vtx = 1; vtx < vertex_count; ++vtx) { + if (indices) + vreader.Goto(indices_16bit ? indices16[vtx] : indices8[vtx]); + else + vreader.Goto(vtx); + + data[2 - (vtx % 2)] = ReadVertex(vreader); + if (outside_range_flag) { + // Drop all primitives containing the current vertex + skip_count = 2; + outside_range_flag = false; + continue; + } + + if (skip_count) { + --skip_count; + continue; + } + // We need to reverse the vertex order for each second primitive, // but we additionally need to do that for every primitive if CCW cullmode is used. if ((!gstate.getCullMode()) ^ (vtx % 2))