继续啊

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;
	//unsigned short* IndexPtr;
	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) );
	//GenIndices( Patch->LoD, Indices );

	ScapePatch* Other;

	//ok, now to work out some adjacency LoD issues
	//If an adjacent patch is at a lower LoD, shift indices around
	//to avoid cracks in the landscape.

	if( i >= m_HeightPatches )
	{
		Other = &m_Patches[i-m_HeightPatches];
		if( Other->LoD > Patch->LoD )
		{
			//the patch to the left is at a lower LoD
			//we need to reduce our left detail level
			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 )
		{
			//Patch to the right is at a lower LoD
			//reduce right edge detail
			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 )
		{
			//the patch to the top is at a lower LoD
			//we need to reduce our top detail level
			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 )
		{
			//the patch to the bottom is at a lower LoD
			//we need to reduce our bottom detail level
			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;
}

你可能感兴趣的:(继续啊)