Permalink
Browse files

Fix winding issues with various ui draw methods. Face culling is actu…

…ally disabled during ui rendering, but it's still good to do winding correctly regardless. Also automated tri strip batching.
  • Loading branch information...
Shyotl committed Feb 24, 2017
1 parent d39ad79 commit 5d96bd8966a27eb4c17b44df1ad0aa185d1d0af1
Showing with 144 additions and 76 deletions.
  1. +100 −5 indra/llrender/llrender.cpp
  2. +2 −0 indra/llrender/llrender.h
  3. +42 −71 indra/llrender/llrender2dutils.cpp
View
@@ -1043,7 +1043,8 @@ LLRender::LLRender()
mCount(0),
mMode(LLRender::TRIANGLES),
mCurrTextureUnitIndex(0),
mMaxAnisotropy(0.f)
mMaxAnisotropy(0.f),
mPrimitiveReset(false)
{
mTexUnits.reserve(LL_NUM_TEXTURE_LAYERS);
for (U32 i = 0; i < LL_NUM_TEXTURE_LAYERS; i++)
@@ -2056,7 +2057,8 @@ void LLRender::begin(const GLuint& mode)
{
if (mMode == LLRender::LINES ||
mMode == LLRender::TRIANGLES ||
mMode == LLRender::POINTS)
mMode == LLRender::POINTS ||
mMode == LLRender::TRIANGLE_STRIP )
{
flush();
}
@@ -2079,11 +2081,16 @@ void LLRender::end()
if ((mMode != LLRender::LINES &&
mMode != LLRender::TRIANGLES &&
mMode != LLRender::POINTS) ||
mMode != LLRender::POINTS &&
mMode != LLRender::TRIANGLE_STRIP) ||
mCount > 2048)
{
flush();
}
else if (mMode == LLRender::TRIANGLE_STRIP)
{
mPrimitiveReset = true;
}
}
void LLRender::flush()
{
@@ -2177,6 +2184,7 @@ void LLRender::flush()
mColorsp[0] = mColorsp[count];
mCount = 0;
mPrimitiveReset = false;
}
}
@@ -2190,6 +2198,21 @@ void LLRender::vertex4a(const LLVector4a& vertex)
case LLRender::POINTS: flush(); break;
case LLRender::TRIANGLES: if (mCount%3==0) flush(); break;
case LLRender::LINES: if (mCount%2 == 0) flush(); break;
case LLRender::TRIANGLE_STRIP:
{
LLVector4a vert[] = { mVerticesp[mCount - 2], mVerticesp[mCount - 1], mVerticesp[mCount] };
LLColor4U col[] = { mColorsp[mCount - 2], mColorsp[mCount - 1], mColorsp[mCount] };
LLVector2 tc[] = { mTexcoordsp[mCount - 2], mTexcoordsp[mCount - 1], mTexcoordsp[mCount] };
flush();
for (int i = 0; i < LL_ARRAY_SIZE(vert); ++i)
{
mVerticesp[i] = vert[i];
mColorsp[i] = col[i];
mTexcoordsp[i] = tc[i];
}
mCount = 2;
break;
}
}
}
@@ -2199,6 +2222,18 @@ void LLRender::vertex4a(const LLVector4a& vertex)
return;
}
if (mPrimitiveReset && mCount)
{
// Insert degenerate
++mCount;
mVerticesp[mCount] = mVerticesp[mCount - 1];
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
mColorsp[mCount - 1] = mColorsp[mCount - 2];
mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
}
if (mUIOffset.empty())
{
mVerticesp[mCount]=vertex;
@@ -2213,7 +2248,17 @@ void LLRender::vertex4a(const LLVector4a& vertex)
mCount++;
mVerticesp[mCount] = mVerticesp[mCount-1];
mColorsp[mCount] = mColorsp[mCount-1];
mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
if (mPrimitiveReset && mCount)
{
mCount++;
mVerticesp[mCount] = mVerticesp[mCount - 1];
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
}
mPrimitiveReset = false;
}
void LLRender::vertexBatchPreTransformed(LLVector4a* verts, S32 vert_count)
@@ -2224,6 +2269,21 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, S32 vert_count)
return;
}
if (mPrimitiveReset && mCount)
{
// Insert degenerate
++mCount;
mVerticesp[mCount] = verts[0];
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
mColorsp[mCount - 1] = mColorsp[mCount - 2];
mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
++mCount;
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
}
for (S32 i = 0; i < vert_count; i++)
{
mVerticesp[mCount] = verts[i];
@@ -2234,6 +2294,8 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, S32 vert_count)
}
mVerticesp[mCount] = mVerticesp[mCount-1];
mPrimitiveReset = false;
}
void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, S32 vert_count)
@@ -2244,6 +2306,21 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, S32
return;
}
if (mPrimitiveReset && mCount)
{
// Insert degenerate
++mCount;
mVerticesp[mCount] = verts[0];
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = uvs[0];
mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
mColorsp[mCount - 1] = mColorsp[mCount - 2];
mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
++mCount;
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
}
for (S32 i = 0; i < vert_count; i++)
{
mVerticesp[mCount] = verts[i];
@@ -2255,6 +2332,8 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, S32
mVerticesp[mCount] = mVerticesp[mCount-1];
mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
mPrimitiveReset = false;
}
void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, LLColor4U* colors, S32 vert_count)
@@ -2265,7 +2344,21 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, LLCo
return;
}
if (mPrimitiveReset && mCount)
{
// Insert degenerate
++mCount;
mVerticesp[mCount] = verts[0];
mColorsp[mCount] = colors[mCount - 1];
mTexcoordsp[mCount] = uvs[0];
mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
mColorsp[mCount - 1] = mColorsp[mCount - 2];
mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
++mCount;
mColorsp[mCount] = mColorsp[mCount - 1];
mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
}
for (S32 i = 0; i < vert_count; i++)
{
mVerticesp[mCount] = verts[i];
@@ -2278,6 +2371,8 @@ void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, LLCo
mVerticesp[mCount] = mVerticesp[mCount-1];
mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
mColorsp[mCount] = mColorsp[mCount-1];
mPrimitiveReset = false;
}
void LLRender::texCoord2f(const GLfloat& x, const GLfloat& y)
@@ -493,6 +493,8 @@ class LLRender
std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 64> > mUIOffset;
std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 64> > mUIScale;
bool mPrimitiveReset;
} LL_ALIGN_POSTFIX(16);
Oops, something went wrong.

0 comments on commit 5d96bd8

Please sign in to comment.