Merge pull request #213 from Jezze/vertexloader-cleanups
Vertexloader cleanups
This commit is contained in:
commit
cdf6172348
|
@ -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 the polygon is inside viewport, let's update the bounding box and be done with it
|
||||||
if ((b0 == 3) && (b0 == b1) && (b0 == b2))
|
if ((b0 == 3) && (b0 == b1) && (b0 == b2))
|
||||||
{
|
{
|
||||||
// Line
|
left = std::min(p0.x, p1.x);
|
||||||
if (numPoints == 2)
|
top = std::min(p0.y, p1.y);
|
||||||
{
|
right = std::max(p0.x, p1.x);
|
||||||
left = (p0.x < p1.x) ? p0.x : p1.x;
|
bottom = std::max(p0.y, p1.y);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Triangle
|
// 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;
|
left = std::min(left, p2.x);
|
||||||
top = (p0.y < p1.y) ? (p0.y < p2.y) ? p0.y : p2.y : (p1.y < p2.y) ? p1.y : p2.y;
|
top = std::min(top, p2.y);
|
||||||
right = (p0.x > p1.x) ? (p0.x > p2.x) ? p0.x : p2.x : (p1.x > p2.x) ? p1.x : p2.x;
|
right = std::max(right, p2.x);
|
||||||
bottom = (p0.y > p1.y) ? (p0.y > p2.y) ? p0.y : p2.y : (p1.y > p2.y) ? p1.y : p2.y;
|
bottom = std::max(bottom, p2.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update bounding box
|
// Update bounding box
|
||||||
|
@ -356,19 +352,19 @@ void LOADERDECL UpdateBoundingBox()
|
||||||
// Second point inside
|
// Second point inside
|
||||||
if (b1 == 3)
|
if (b1 == 3)
|
||||||
{
|
{
|
||||||
left = (p1.x < left) ? p1.x : left;
|
left = std::min(p1.x, left);
|
||||||
top = (p1.y < top) ? p1.y : top;
|
top = std::min(p1.y, top);
|
||||||
right = (p1.x > right) ? p1.x : right;
|
right = std::max(p1.x, right);
|
||||||
bottom = (p1.y > bottom) ? p1.y : bottom;
|
bottom = std::max(p1.y, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third point inside
|
// Third point inside
|
||||||
if ((b2 == 3) && (numPoints == 3))
|
if ((b2 == 3) && (numPoints == 3))
|
||||||
{
|
{
|
||||||
left = (p2.x < left) ? p2.x : left;
|
left = std::min(p2.x, left);
|
||||||
top = (p2.y < top) ? p2.y : top;
|
top = std::min(p2.y, top);
|
||||||
right = (p2.x > right) ? p2.x : right;
|
right = std::max(p2.x, right);
|
||||||
bottom = (p2.y > bottom) ? p2.y : bottom;
|
bottom = std::max(p2.y, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triangle equation vars
|
// Triangle equation vars
|
||||||
|
@ -386,10 +382,10 @@ void LOADERDECL UpdateBoundingBox()
|
||||||
{
|
{
|
||||||
m = (p1.x - p0.x) ? ((p1.y - p0.y) / (p1.x - p0.x)) : highNum;
|
m = (p1.x - p0.x) ? ((p1.y - p0.y) / (p1.x - p0.x)) : highNum;
|
||||||
c = p0.y - (m * p0.x);
|
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 & 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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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 = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
|
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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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
|
// Only check other lines if we are dealing with a triangle
|
||||||
|
@ -400,10 +396,10 @@ void LOADERDECL UpdateBoundingBox()
|
||||||
{
|
{
|
||||||
m = (p2.x - p1.x) ? ((p2.y - p1.y) / (p2.x - p1.x)) : highNum;
|
m = (p2.x - p1.x) ? ((p2.y - p1.y) / (p2.x - p1.x)) : highNum;
|
||||||
c = p1.y - (m * p1.x);
|
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 & 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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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 = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
|
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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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
|
// Third line intersects
|
||||||
|
@ -411,10 +407,10 @@ void LOADERDECL UpdateBoundingBox()
|
||||||
{
|
{
|
||||||
m = (p2.x - p0.x) ? ((p2.y - p0.y) / (p2.x - p0.x)) : highNum;
|
m = (p2.x - p0.x) ? ((p2.y - p0.y) / (p2.x - p0.x)) : highNum;
|
||||||
c = p0.y - (m * p0.x);
|
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 & 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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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 = (s < top) ? s : top; bottom = (s > bottom) ? s : bottom; }
|
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 = (s < left) ? s : left; right = (s > right) ? s : right; }
|
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); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,10 +609,8 @@ void VertexLoader::CompileVertexTranslator()
|
||||||
nat_offset += 12;
|
nat_offset += 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numNormals = (m_VtxAttr.NormalElements == 1) ? NRM_THREE : NRM_ONE;
|
|
||||||
components |= VB_HAS_NRM0;
|
components |= VB_HAS_NRM0;
|
||||||
|
if (m_VtxAttr.NormalElements == 1)
|
||||||
if (numNormals == NRM_THREE)
|
|
||||||
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
|
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,13 +107,6 @@ public:
|
||||||
int GetNumLoadedVerts() const { return m_numLoadedVertices; }
|
int GetNumLoadedVerts() const { return m_numLoadedVertices; }
|
||||||
|
|
||||||
private:
|
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.
|
int m_VertexSize; // number of bytes of a raw GC vertex. Computed by CompileVertexTranslator.
|
||||||
|
|
||||||
// GC vertex format
|
// GC vertex format
|
||||||
|
|
Loading…
Reference in New Issue