📄 terrrender.cc
字号:
mXFIndexBuffer[mXFIndexCount++] = p1;
for(i = 0; i < e1->pointCount; i++)
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex + i;
mXFIndexBuffer[mXFIndexCount++] = p2;
for(i = e2->pointCount - 1; i >= 0; i--)
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex + i;
mXFIndexBuffer[mXFIndexCount++] = p3;
for(i = e3->pointCount - 1; i >= 0; i--)
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex + i;
mXFIndexBuffer[mXFIndexCount++] = p0;
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
if(chunk->clip)
clip(indexStart - 1);
}
else
{
if(chunk->subDivLevel == 0)
{
U32 ip1 = interpPoint(p0, ip0, chunk->x + 1, chunk->y + 3, growFactor);
U32 ip2 = interpPoint(p1, ip0, chunk->x + 3, chunk->y + 3, growFactor);
U32 ip3 = interpPoint(p2, ip0, chunk->x + 3, chunk->y + 1, growFactor);
U32 ip4 = interpPoint(p3, ip0, chunk->x + 1, chunk->y + 1, growFactor);
// emit the 4 fans:
U32 indexStart;
if((chunk->emptyFlags & CornerEmpty_0_1) != CornerEmpty_0_1)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLE_FAN;
indexStart = mXFIndexCount++;
mXFIndexBuffer[mXFIndexCount++] = ip1;
mXFIndexBuffer[mXFIndexCount++] = p0;
if(e0->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex;
else // has to be 3:
{
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex;
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex + 1;
}
mXFIndexBuffer[mXFIndexCount++] = ip0;
if(e3->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex + 1;
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex;
}
mXFIndexBuffer[mXFIndexCount++] = p0;
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
if(chunk->clip)
clip(indexStart - 1);
}
if((chunk->emptyFlags & CornerEmpty_1_1) != CornerEmpty_1_1)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLE_FAN;
indexStart = mXFIndexCount++;
mXFIndexBuffer[mXFIndexCount++] = ip2;
mXFIndexBuffer[mXFIndexCount++] = p1;
if(e1->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex;
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex + 1;
}
mXFIndexBuffer[mXFIndexCount++] = ip0;
if(e0->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex + 1;
mXFIndexBuffer[mXFIndexCount++] = e0->pointIndex + 2;
}
mXFIndexBuffer[mXFIndexCount++] = p1;
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
if(chunk->clip)
clip(indexStart - 1);
}
if((chunk->emptyFlags & CornerEmpty_1_0) != CornerEmpty_1_0)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLE_FAN;
indexStart = mXFIndexCount++;
mXFIndexBuffer[mXFIndexCount++] = ip3;
mXFIndexBuffer[mXFIndexCount++] = p2;
if(e2->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex + 2;
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex + 1;
}
mXFIndexBuffer[mXFIndexCount++] = ip0;
if(e1->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex + 1;
mXFIndexBuffer[mXFIndexCount++] = e1->pointIndex + 2;
}
mXFIndexBuffer[mXFIndexCount++] = p2;
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
if(chunk->clip)
clip(indexStart - 1);
}
if((chunk->emptyFlags & CornerEmpty_0_0) != CornerEmpty_0_0)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLE_FAN;
indexStart = mXFIndexCount++;
mXFIndexBuffer[mXFIndexCount++] = ip4;
mXFIndexBuffer[mXFIndexCount++] = p3;
if(e3->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex + 2;
mXFIndexBuffer[mXFIndexCount++] = e3->pointIndex + 1;
}
mXFIndexBuffer[mXFIndexCount++] = ip0;
if(e2->pointCount == 1)
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex;
else
{
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex + 1;
mXFIndexBuffer[mXFIndexCount++] = e2->pointIndex;
}
mXFIndexBuffer[mXFIndexCount++] = p3;
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
if(chunk->clip)
clip(indexStart - 1);
}
}
else
{
// subDiv == -1
U32 ip1 = constructPoint(chunk->x + 1, chunk->y + 3);
U32 ip2 = constructPoint(chunk->x + 3, chunk->y + 3);
U32 ip3 = constructPoint(chunk->x + 3, chunk->y + 1);
U32 ip4 = constructPoint(chunk->x + 1, chunk->y + 1);
U32 ip5 = interpPoint(e0->pointIndex + 1, ip0, chunk->x + 2, chunk->y + 3, growFactor);
U32 ip6 = interpPoint(e1->pointIndex + 1, ip0, chunk->x + 3, chunk->y + 2, growFactor);
U32 ip7 = interpPoint(e2->pointIndex + 1, ip0, chunk->x + 2, chunk->y + 1, growFactor);
U32 ip8 = interpPoint(e3->pointIndex + 1, ip0, chunk->x + 1, chunk->y + 2, growFactor);
// now do the squares:
U16 *ib;
if(chunk->emptyFlags & CornerEmpty_0_1)
{
if((chunk->emptyFlags & CornerEmpty_0_1) != CornerEmpty_0_1)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLES;
U32 indexStart = mXFIndexCount++;
if(!(chunk->emptyFlags & SquareEmpty_0_3))
{
emitTri(ip1, e3->pointIndex, p0);
emitTri(ip1, p0, e0->pointIndex);
}
if(!(chunk->emptyFlags & SquareEmpty_1_3))
{
emitTri(ip1, e0->pointIndex, e0->pointIndex + 1);
emitTri(ip1, e0->pointIndex + 1, ip5);
}
if(!(chunk->emptyFlags & SquareEmpty_1_2))
{
emitTri(ip1, ip5, ip0);
emitTri(ip1, ip0, ip8);
}
if(!(chunk->emptyFlags & SquareEmpty_0_2))
{
emitTri(ip1, ip8, e3->pointIndex + 1);
emitTri(ip1, e3->pointIndex + 1, e3->pointIndex);
}
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
}
}
else
{
ib = mXFIndexBuffer + mXFIndexCount + 1;
ib[-1] = GL_TRIANGLE_FAN;
ib[0] = 10;
ib[1] = ip1;
ib[2] = p0;
ib[3] = e0->pointIndex;
ib[4] = e0->pointIndex + 1;
ib[5] = ip5;
ib[6] = ip0;
ib[7] = ip8;
ib[8] = e3->pointIndex + 1;
ib[9] = e3->pointIndex;
ib[10] = ib[2];
mXFIndexCount += 12;
if(chunk->clip)
clip(mXFIndexCount - 12);
}
if(chunk->emptyFlags & CornerEmpty_1_1)
{
if((chunk->emptyFlags & CornerEmpty_1_1) != CornerEmpty_1_1)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLES;
U32 indexStart = mXFIndexCount++;
if(!(chunk->emptyFlags & SquareEmpty_3_3))
{
emitTri(ip2, e0->pointIndex + 2, p1);
emitTri(ip2, p1, e1->pointIndex);
}
if(!(chunk->emptyFlags & SquareEmpty_3_2))
{
emitTri(ip2, e1->pointIndex, e1->pointIndex + 1);
emitTri(ip2, e1->pointIndex + 1, ip6);
}
if(!(chunk->emptyFlags & SquareEmpty_2_2))
{
emitTri(ip2, ip6, ip0);
emitTri(ip2, ip0, ip5);
}
if(!(chunk->emptyFlags & SquareEmpty_2_3))
{
emitTri(ip2, ip5, e0->pointIndex + 1);
emitTri(ip2, e0->pointIndex + 1, e0->pointIndex + 2);
}
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
}
}
else
{
ib = mXFIndexBuffer + mXFIndexCount + 1;
ib[-1] = GL_TRIANGLE_FAN;
ib[0] = 10;
ib[1] = ip2;
ib[2] = p1;
ib[3] = e1->pointIndex;
ib[4] = e1->pointIndex + 1;
ib[5] = ip6;
ib[6] = ip0;
ib[7] = ip5;
ib[8] = e0->pointIndex + 1;
ib[9] = e0->pointIndex + 2;
ib[10] = ib[2];
mXFIndexCount += 12;
if(chunk->clip)
clip(mXFIndexCount - 12);
}
if(chunk->emptyFlags & CornerEmpty_1_0)
{
if((chunk->emptyFlags & CornerEmpty_1_0) != CornerEmpty_1_0)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLES;
U32 indexStart = mXFIndexCount++;
if(!(chunk->emptyFlags & SquareEmpty_3_0))
{
emitTri(ip3, e1->pointIndex + 2, p2);
emitTri(ip3, p2, e2->pointIndex + 2);
}
if(!(chunk->emptyFlags & SquareEmpty_2_0))
{
emitTri(ip3, e2->pointIndex + 2, e2->pointIndex + 1);
emitTri(ip3, e2->pointIndex + 1, ip7);
}
if(!(chunk->emptyFlags & SquareEmpty_2_1))
{
emitTri(ip3, ip7, ip0);
emitTri(ip3, ip0, ip6);
}
if(!(chunk->emptyFlags & SquareEmpty_3_1))
{
emitTri(ip3, ip6, e1->pointIndex + 1);
emitTri(ip3, e1->pointIndex + 1, e1->pointIndex + 2);
}
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
}
}
else
{
ib = mXFIndexBuffer + mXFIndexCount + 1;
ib[-1] = GL_TRIANGLE_FAN;
ib[0] = 10;
ib[1] = ip3;
ib[2] = p2;
ib[3] = e2->pointIndex + 2;
ib[4] = e2->pointIndex + 1;
ib[5] = ip7;
ib[6] = ip0;
ib[7] = ip6;
ib[8] = e1->pointIndex + 1;
ib[9] = e1->pointIndex + 2;
ib[10] = ib[2];
mXFIndexCount += 12;
if(chunk->clip)
clip(mXFIndexCount - 12);
}
if(chunk->emptyFlags & CornerEmpty_0_0)
{
if((chunk->emptyFlags & CornerEmpty_0_0) != CornerEmpty_0_0)
{
mXFIndexBuffer[mXFIndexCount++] = GL_TRIANGLES;
U32 indexStart = mXFIndexCount++;
if(!(chunk->emptyFlags & SquareEmpty_0_0))
{
emitTri(ip4, e2->pointIndex, p3);
emitTri(ip4, p3, e3->pointIndex + 2);
}
if(!(chunk->emptyFlags & SquareEmpty_0_1))
{
emitTri(ip4, e3->pointIndex + 2, e3->pointIndex + 1);
emitTri(ip4, e3->pointIndex + 1, ip8);
}
if(!(chunk->emptyFlags & SquareEmpty_1_1))
{
emitTri(ip4, ip8, ip0);
emitTri(ip4, ip0, ip7);
}
if(!(chunk->emptyFlags & SquareEmpty_1_0))
{
emitTri(ip4, ip7, e2->pointIndex + 1);
emitTri(ip4, e2->pointIndex + 1, e2->pointIndex);
}
mXFIndexBuffer[indexStart] = mXFIndexCount - indexStart - 1;
}
}
else
{
ib = mXFIndexBuffer + mXFIndexCount + 1;
ib[-1] = GL_TRIANGLE_FAN;
ib[0] = 10;
ib[1] = ip4;
ib[2] = p3;
ib[3] = e3->pointIndex + 2;
ib[4] = e3->pointIndex + 1;
ib[5] = ip8;
ib[6] = ip0;
ib[7] = ip7;
ib[8] = e2->pointIndex + 1;
ib[9] = e2->pointIndex;
ib[10] = ib[2];
mXFIndexCount += 12;
if(chunk->clip)
clip(mXFIndexCount - 12);
}
}
}
// Do dynamic lighting here...
if (mEnableTerrainDynLights && chunk->lightMask != 0) {
for (U32 i = 0; i < 32; i++) {
if ((chunk->lightMask & (1 << i)) == 0)
continue;
for (U32 start = startXFIndex; start < mXFIndexCount; start++) {
if (mXFIndexBuffer[start] == GL_TRIANGLE_FAN) {
start++;
U32 count = mXFIndexBuffer[start];
U32 triCount = count - 2;
LightTriangle* lightTris = (LightTriangle*)FrameAllocator::alloc(sizeof(LightTriangle) * triCount);
U32 j;
for (j = 0; j < (triCount-1); j++)
lightTris[j].next = &lightTris[j+1];
lightTris[triCount-1].next = sgCurrLightTris;
sgCurrLightTris = lightTris;
// Copy out tri data here...
for (j = 0; j < triCount; j++) {
lightTris[j].point1 = mXFVertices[mXFIndexBuffer[start + 1 + 0]];
lightTris[j].point2 = mXFVertices[mXFIndexBuffer[start + 1 + j + 1]];
lightTris[j].point3 = mXFVertices[mXFIndexBuffer[start + 1 + j + 2]];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -