mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
SoftGPU: Simplify index conversion.
This commit is contained in:
parent
65439b8e96
commit
ede9025447
3 changed files with 37 additions and 66 deletions
|
@ -841,31 +841,6 @@ void TessellateBezierPatch(u8 *&dest, u16 *&indices, int &count, int tess_u, int
|
|||
}
|
||||
}
|
||||
|
||||
class IndexConverter {
|
||||
private:
|
||||
union {
|
||||
const void *indices;
|
||||
const u8 *indices8;
|
||||
const u16 *indices16;
|
||||
const u32 *indices32;
|
||||
};
|
||||
u32 indexType;
|
||||
public:
|
||||
IndexConverter(u32 vertType, const void *indices) : indices(indices), indexType(vertType & GE_VTYPE_IDX_MASK) {}
|
||||
|
||||
inline u32 convert(u32 index) const {
|
||||
switch (indexType) {
|
||||
case GE_VTYPE_IDX_8BIT:
|
||||
return indices8[index];
|
||||
case GE_VTYPE_IDX_16BIT:
|
||||
return indices16[index];
|
||||
case GE_VTYPE_IDX_32BIT:
|
||||
return indices32[index];
|
||||
}
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
// This maps GEPatchPrimType to GEPrimitiveType.
|
||||
const GEPrimitiveType primType[] = { GE_PRIM_TRIANGLES, GE_PRIM_LINES, GE_PRIM_POINTS, GE_PRIM_POINTS };
|
||||
|
||||
|
|
|
@ -106,6 +106,35 @@ inline int RoundUp4(int x) {
|
|||
return (x + 3) & ~3;
|
||||
}
|
||||
|
||||
class IndexConverter {
|
||||
private:
|
||||
union {
|
||||
const void *indices;
|
||||
const u8 *indices8;
|
||||
const u16 *indices16;
|
||||
const u32 *indices32;
|
||||
};
|
||||
u32 indexType;
|
||||
|
||||
public:
|
||||
IndexConverter(u32 vertType, const void *indices)
|
||||
: indices(indices), indexType(vertType & GE_VTYPE_IDX_MASK) {
|
||||
}
|
||||
|
||||
inline u32 convert(u32 index) const {
|
||||
switch (indexType) {
|
||||
case GE_VTYPE_IDX_8BIT:
|
||||
return indices8[index];
|
||||
case GE_VTYPE_IDX_16BIT:
|
||||
return indices16[index];
|
||||
case GE_VTYPE_IDX_32BIT:
|
||||
return indices32[index];
|
||||
default:
|
||||
return index;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Reads decoded vertex formats in a convenient way. For software transform and debugging.
|
||||
class VertexReader {
|
||||
public:
|
||||
|
|
|
@ -322,11 +322,8 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
|
||||
u16 index_lower_bound = 0;
|
||||
u16 index_upper_bound = vertex_count - 1;
|
||||
bool indices_16bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT;
|
||||
bool indices_32bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT;
|
||||
u8 *indices8 = (u8 *)indices;
|
||||
u16 *indices16 = (u16 *)indices;
|
||||
u32 *indices32 = (u32 *)indices;
|
||||
IndexConverter idxConv(vertex_type, 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);
|
||||
|
@ -357,15 +354,9 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
for (int vtx = 0; vtx < vertex_count; vtx += vtcs_per_prim) {
|
||||
for (int i = 0; i < vtcs_per_prim; ++i) {
|
||||
if (indices) {
|
||||
if (indices_32bit) {
|
||||
vreader.Goto(indices32[vtx + i] - index_lower_bound);
|
||||
} else if (indices_16bit) {
|
||||
vreader.Goto(indices16[vtx + i] - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(indices8[vtx + i] - index_lower_bound);
|
||||
}
|
||||
vreader.Goto(idxConv.convert(vtx + i) - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(vtx+i);
|
||||
vreader.Goto(vtx + i);
|
||||
}
|
||||
|
||||
data[i] = ReadVertex(vreader);
|
||||
|
@ -411,13 +402,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
int skip_count = 1; // Don't draw a line when loading the first vertex
|
||||
for (int vtx = 0; vtx < vertex_count; ++vtx) {
|
||||
if (indices) {
|
||||
if (indices_32bit) {
|
||||
vreader.Goto(indices32[vtx] - index_lower_bound);
|
||||
} else if (indices_16bit) {
|
||||
vreader.Goto(indices16[vtx] - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(indices8[vtx] - index_lower_bound);
|
||||
}
|
||||
vreader.Goto(idxConv.convert(vtx) - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(vtx);
|
||||
}
|
||||
|
@ -445,13 +430,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
|
||||
for (int vtx = 0; vtx < vertex_count; ++vtx) {
|
||||
if (indices) {
|
||||
if (indices_32bit) {
|
||||
vreader.Goto(indices32[vtx] - index_lower_bound);
|
||||
} else if (indices_16bit) {
|
||||
vreader.Goto(indices16[vtx] - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(indices8[vtx] - index_lower_bound);
|
||||
}
|
||||
vreader.Goto(idxConv.convert(vtx) - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(vtx);
|
||||
}
|
||||
|
@ -488,13 +467,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
unsigned int skip_count = 1; // Don't draw a triangle when loading the first two vertices
|
||||
|
||||
if (indices) {
|
||||
if (indices_32bit) {
|
||||
vreader.Goto(indices32[0] - index_lower_bound);
|
||||
} else if (indices_16bit) {
|
||||
vreader.Goto(indices16[0] - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(indices8[0] - index_lower_bound);
|
||||
}
|
||||
vreader.Goto(idxConv.convert(0) - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(0);
|
||||
}
|
||||
|
@ -502,13 +475,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, u32 prim_type
|
|||
|
||||
for (int vtx = 1; vtx < vertex_count; ++vtx) {
|
||||
if (indices) {
|
||||
if (indices_32bit) {
|
||||
vreader.Goto(indices32[vtx] - index_lower_bound);
|
||||
} else if (indices_16bit) {
|
||||
vreader.Goto(indices16[vtx] - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(indices8[vtx] - index_lower_bound);
|
||||
}
|
||||
vreader.Goto(idxConv.convert(vtx) - index_lower_bound);
|
||||
} else {
|
||||
vreader.Goto(vtx);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue