From 288de895db210ae581b9c5906214939441d141a9 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 28 Jun 2013 23:34:56 +0200 Subject: [PATCH] softgpu: Support indexed rendering. --- GPU/Software/SoftGpu.cpp | 6 +++--- GPU/Software/TransformUnit.cpp | 19 +++++++++++++++---- GPU/Software/TransformUnit.h | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 90b145bb54..af50470fd3 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -261,12 +261,12 @@ void SoftGPU::ExecuteOp(u32 op, u32 diff) 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; if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - // TODO: Index support... - ERROR_LOG(G3D, "Using indices... fail"); + indices = Memory::GetPointer(gstate_c.indexAddr); } - TransformUnit::SubmitPrimitive(verts, type, count, gstate.vertType); + TransformUnit::SubmitPrimitive(verts, indices, type, count, gstate.vertType); } break; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 088022ecee..f8d7a1e863 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -66,15 +66,23 @@ DrawingCoords TransformUnit::ScreenToDrawing(const ScreenCoords& coords) return ret; } -void TransformUnit::SubmitPrimitive(void* vertices, u32 prim_type, int vertex_count, u32 vertex_type) +void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type, int vertex_count, u32 vertex_type) { // TODO: Cache VertexDecoder objects VertexDecoder vdecoder; vdecoder.SetVertexType(vertex_type); const DecVtxFormat& vtxfmt = vdecoder.GetDecVtxFmt(); - static u8 buf[1024000]; // yolo - vdecoder.DecodeVerts(buf, vertices, 0, vertex_count - 1); + static u8 buf[65536 * 48]; // yolo + u16 index_lower_bound = 0; + u16 index_upper_bound = vertex_count - 1; + bool indices_8bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_8BIT; + bool indices_16bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT; + u8* indices8 = (u8*)indices; + u16* indices16 = (u16*)indices; + if (indices) + GetIndexBounds(indices, vertex_count, vertex_type, &index_lower_bound, &index_upper_bound); + vdecoder.DecodeVerts(buf, vertices, index_lower_bound, index_upper_bound); VertexReader vreader(buf, vtxfmt, vertex_type); @@ -95,7 +103,10 @@ void TransformUnit::SubmitPrimitive(void* vertices, u32 prim_type, int vertex_co for (unsigned int i = 0; i < vtcs_per_prim; ++i) { float pos[3]; - vreader.Goto(vtx+i); + if (indices) + vreader.Goto(indices_16bit ? indices16[vtx+i] : indices8[vtx+i]); + else + vreader.Goto(vtx+i); vreader.ReadPos(pos); if (!gstate.isModeClear() && gstate.textureMapEnable && vreader.hasUV()) { diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index 8094fc8167..95d9900ade 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -80,5 +80,5 @@ public: static ScreenCoords ClipToScreen(const ClipCoords& coords); static DrawingCoords ScreenToDrawing(const ScreenCoords& coords); - static void SubmitPrimitive(void* vertices, u32 prim_type, int vertex_count, u32 vertex_type); + static void SubmitPrimitive(void* vertices, void* indices, u32 prim_type, int vertex_count, u32 vertex_type); };