int CScape::RenderPatch(
int i )
{
int FacesRendered =
0;
static unsigned short Indices[INDICES_LOD_HIGH];
ScapePatch* Patch = &m_Patches[i];
unsigned short* IndexPtr;
glVertexPointer(
3, GL_FLOAT,
sizeof(ScapeVertex), m_Buffer->GetPointer() + (PATCH_VERTS * i *
sizeof(ScapeVertex)) );
int CurIndices;
if( Patch->LoD == SCAPE_LOD_HIGH )
{
CurIndices = INDICES_LOD_HIGH;
IndexPtr = m_Indices[
0];
}
else if( Patch->LoD == SCAPE_LOD_MED )
{
CurIndices = INDICES_LOD_MED;
IndexPtr = m_Indices[
1];
}
else if( Patch->LoD == SCAPE_LOD_LOW )
{
CurIndices = INDICES_LOD_LOW;
IndexPtr = m_Indices[
2];
}
else if( Patch->LoD == SCAPE_LOD_XTRALOW )
{
CurIndices = INDICES_LOD_XTRALOW;
IndexPtr = m_Indices[
3];
}
else if( Patch->LoD == SCAPE_LOD_MIN )
{
CurIndices = INDICES_LOD_MIN;
IndexPtr = m_Indices[
4];
}
memcpy( Indices, IndexPtr, CurIndices *
sizeof(
unsigned short) );
ScapePatch* Other;
if( i >= m_HeightPatches )
{
Other = &m_Patches[i-m_HeightPatches];
if( Other->LoD > Patch->LoD )
{
for(
int n =
0; n < CurIndices; ++n )
{
if( (Indices[n] < (PATCH_SIZE+
1)) && (Indices[n] % Other->LoD) !=
0 )
{
Indices[n] -= Indices[n] % Other->LoD;
}
}
}
}
if( i <= m_NumPatches - m_HeightPatches )
{
Other = &m_Patches[i+m_HeightPatches];
if( Other->LoD > Patch->LoD )
{
for(
int n =
0; n < CurIndices; ++n )
{
if( (Indices[n] > ((PATCH_SIZE+
1)*PATCH_SIZE) ) && (Indices[n] % Other->LoD) !=
0 )
{
Indices[n] -= Indices[n] % Other->LoD;
}
}
}
}
if( i % m_HeightPatches )
{
Other = &m_Patches[i-
1];
if( Other->LoD > Patch->LoD )
{
for(
int n =
0; n < CurIndices; ++n )
{
if( (Indices[n] % (PATCH_SIZE+
1) ==
0) && (Indices[n] % (Other->LoD * (PATCH_SIZE+
1))) !=
0)
{
Indices[n] -= (PATCH_SIZE+
1) * Indices[n] % (Other->LoD * (PATCH_SIZE+
1));
}
}
}
}
if( (i +
1) % m_HeightPatches )
{
Other = &m_Patches[i+
1];
if( Other->LoD > Patch->LoD )
{
for(
int n =
0; n < CurIndices; ++n )
{
if( ((Indices[n] +
1) % (PATCH_SIZE+
1) ==
0) && (Indices[n] % (Other->LoD * (PATCH_SIZE+
1))) !=
0)
{
Indices[n] -= (PATCH_SIZE+
1) * Indices[n] % (Other->LoD * (PATCH_SIZE+
1));
}
}
}
}
glDrawElements( GL_TRIANGLES, CurIndices, GL_UNSIGNED_SHORT, Indices );
FacesRendered = CurIndices /
3;
return FacesRendered;
}