Skip to content

Commit

Permalink
Merge pull request #213 from Jezze/vertexloader-cleanups
Browse files Browse the repository at this point in the history
Vertexloader cleanups
  • Loading branch information
neobrain committed Apr 10, 2014
2 parents 4deb8f4 + 73176d0 commit cdf6172
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 43 deletions.
66 changes: 30 additions & 36 deletions Source/Core/VideoCommon/VertexLoader.cpp
Expand Up @@ -307,22 +307,18 @@ void LOADERDECL UpdateBoundingBox()
// If the polygon is inside viewport, let's update the bounding box and be done with it
if ((b0 == 3) && (b0 == b1) && (b0 == b2))
{
// Line
if (numPoints == 2)
{
left = (p0.x < p1.x) ? p0.x : p1.x;
top = (p0.y < p1.y) ? p0.y : p1.y;
right = (p0.x > p1.x) ? p0.x : p1.x;
bottom = (p0.y > p1.y) ? p0.y : p1.y;
}
left = std::min(p0.x, p1.x);
top = std::min(p0.y, p1.y);
right = std::max(p0.x, p1.x);
bottom = std::max(p0.y, p1.y);

// Triangle
else
if (numPoints == 3)
{
left = (p0.x < p1.x) ? (p0.x < p2.x) ? p0.x : p2.x : (p1.x < p2.x) ? p1.x : p2.x;
top = (p0.y < p1.y) ? (p0.y < p2.y) ? p0.y : p2.y : (p1.y < p2.y) ? p1.y : p2.y;
right = (p0.x > p1.x) ? (p0.x > p2.x) ? p0.x : p2.x : (p1.x > p2.x) ? p1.x : p2.x;
bottom = (p0.y > p1.y) ? (p0.y > p2.y) ? p0.y : p2.y : (p1.y > p2.y) ? p1.y : p2.y;
left = std::min(left, p2.x);
top = std::min(top, p2.y);
right = std::max(right, p2.x);
bottom = std::max(bottom, p2.y);
}

// Update bounding box
Expand Down Expand Up @@ -356,19 +352,19 @@ void LOADERDECL UpdateBoundingBox()
// Second point inside
if (b1 == 3)
{
left = (p1.x < left) ? p1.x : left;
top = (p1.y < top) ? p1.y : top;
right = (p1.x > right) ? p1.x : right;
bottom = (p1.y > bottom) ? p1.y : bottom;
left = std::min(p1.x, left);
top = std::min(p1.y, top);
right = std::max(p1.x, right);
bottom = std::max(p1.y, bottom);
}

// Third point inside
if ((b2 == 3) && (numPoints == 3))
{
left = (p2.x < left) ? p2.x : left;
top = (p2.y < top) ? p2.y : top;
right = (p2.x > right) ? p2.x : right;
bottom = (p2.y > bottom) ? p2.y : bottom;
left = std::min(p2.x, left);
top = std::min(p2.y, top);
right = std::max(p2.x, right);
bottom = std::max(p2.y, bottom);
}

// Triangle equation vars
Expand All @@ -386,10 +382,10 @@ void LOADERDECL UpdateBoundingBox()
{
m = (p1.x - p0.x) ? ((p1.y - p0.y) / (p1.x - p0.x)) : highNum;
c = p0.y - (m * p0.x);
if (i0 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i0 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i0 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i0 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i0 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i0 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); }
if (i0 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i0 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); }
}

// Only check other lines if we are dealing with a triangle
Expand All @@ -400,21 +396,21 @@ void LOADERDECL UpdateBoundingBox()
{
m = (p2.x - p1.x) ? ((p2.y - p1.y) / (p2.x - p1.x)) : highNum;
c = p1.y - (m * p1.x);
if (i1 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i1 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i1 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i1 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i1 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i1 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); }
if (i1 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i1 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); }
}

// Third line intersects
if (i2)
{
m = (p2.x - p0.x) ? ((p2.y - p0.y) / (p2.x - p0.x)) : highNum;
c = p0.y - (m * p0.x);
if (i2 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i2 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i2 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
if (i2 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = (s < left) ? s : left; right = (s > right) ? s : right; }
if (i2 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i2 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); }
if (i2 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); }
if (i2 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); }
}
}

Expand Down Expand Up @@ -613,10 +609,8 @@ void VertexLoader::CompileVertexTranslator()
nat_offset += 12;
}

int numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE;
components |= VB_HAS_NRM0;

if (numNormals == NRM_THREE)
if (m_VtxAttr.NormalElements == 1)
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
}

Expand Down
7 changes: 0 additions & 7 deletions Source/Core/VideoCommon/VertexLoader.h
Expand Up @@ -107,13 +107,6 @@ class VertexLoader
int GetNumLoadedVerts() const { return m_numLoadedVertices; }

private:
enum
{
NRM_ZERO = 0,
NRM_ONE = 1,
NRM_THREE = 3,
};

int m_VertexSize; // number of bytes of a raw GC vertex. Computed by CompileVertexTranslator.

// GC vertex format
Expand Down

0 comments on commit cdf6172

Please sign in to comment.