Skip to content

Commit

Permalink
[spline/bezier]Make a function to build indices.
Browse files Browse the repository at this point in the history
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 7cbc97f commit 30c3c87
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions GPU/Common/SplineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ static void CopyQuadIndex(u16 *&indices, GEPatchPrimType type, const int idx0, c
*(indices++) = idx3;
*(indices++) = idx1;
*(indices++) = idx2;
}
else {
} else {
*(indices++) = idx0;
*(indices++) = idx2;
*(indices++) = idx1;
Expand All @@ -111,6 +110,17 @@ static void CopyQuadIndex(u16 *&indices, GEPatchPrimType type, const int idx0, c
}
}

static void BuildIndex(u16 *indices, int &count, int num_u, int num_v, GEPatchPrimType prim_type, int total = 0) {
for (int v = 0; v < num_v; ++v) {
for (int u = 0; u < num_u; ++u) {
int idx0 = v * (num_u + 1) + u + total; // Top left
int idx2 = (v + 1) * (num_u + 1) + u + total; // Bottom left

CopyQuadIndex(indices, prim_type, idx0, idx0 + 1, idx2, idx2 + 1);
count += 6;
}
}
}

// Bernstein basis functions
inline float bern0(float x) { return (1 - x) * (1 - x) * (1 - x); }
Expand Down Expand Up @@ -283,18 +293,7 @@ static void TessellateSplinePatchHardware(u8 *&dest, u16 *indices, int &count, c
}
}

// Combine the vertices into triangles.
for (int tile_v = 0; tile_v < spatch.tess_v; ++tile_v) {
for (int tile_u = 0; tile_u < spatch.tess_u; ++tile_u) {
int idx0 = tile_v * (spatch.tess_u + 1) + tile_u;
int idx1 = tile_v * (spatch.tess_u + 1) + tile_u + 1;
int idx2 = (tile_v + 1) * (spatch.tess_u + 1) + tile_u;
int idx3 = (tile_v + 1) * (spatch.tess_u + 1) + tile_u + 1;

CopyQuadIndex(indices, spatch.primType, idx0, idx1, idx2, idx3);
count += 6;
}
}
BuildIndex(indices, count, spatch.tess_u, spatch.tess_v, spatch.primType);
}

static void _SplinePatchLowQuality(u8 *&dest, u16 *indices, int &count, const SplinePatchLocal &spatch, u32 origVertType) {
Expand Down Expand Up @@ -546,19 +545,7 @@ static void SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const Sp
delete[] divs_u;
delete[] divs_v;

GEPatchPrimType prim_type = spatch.primType;
// Tessellate.
for (int tile_v = 0; tile_v < patch_div_t; ++tile_v) {
for (int tile_u = 0; tile_u < patch_div_s; ++tile_u) {
int idx0 = tile_v * (patch_div_s + 1) + tile_u;
int idx1 = tile_v * (patch_div_s + 1) + tile_u + 1;
int idx2 = (tile_v + 1) * (patch_div_s + 1) + tile_u;
int idx3 = (tile_v + 1) * (patch_div_s + 1) + tile_u + 1;

CopyQuadIndex(indices, prim_type, idx0, idx1, idx2, idx3);
count += 6;
}
}
BuildIndex(indices, count, patch_div_s, patch_div_t, spatch.primType);
}

template <bool origNrm, bool origCol, bool origTc>
Expand Down Expand Up @@ -817,18 +804,7 @@ static void TessellateBezierPatchHardware(u8 *&dest, u16 *indices, int &count, i
}
}

// Combine the vertices into triangles.
for (int tile_v = 0; tile_v < tess_v; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u; ++tile_u) {
int idx0 = tile_v * (tess_u + 1) + tile_u;
int idx1 = tile_v * (tess_u + 1) + tile_u + 1;
int idx2 = (tile_v + 1) * (tess_u + 1) + tile_u;
int idx3 = (tile_v + 1) * (tess_u + 1) + tile_u + 1;

CopyQuadIndex(indices, primType, idx0, idx1, idx2, idx3);
count += 6;
}
}
BuildIndex(indices, count, tess_u, tess_v, primType);
}

void TessellateBezierPatch(u8 *&dest, u16 *&indices, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
Expand Down

0 comments on commit 30c3c87

Please sign in to comment.