Axiom.SceneManagers.Bsp.BspSceneManager.CacheGeometry C# (CSharp) Method

CacheGeometry() protected method

Caches a face group for imminent rendering.
protected CacheGeometry ( IntPtr indexes, BspStaticFaceGroup faceGroup ) : int
indexes System.IntPtr
faceGroup BspStaticFaceGroup
return int
		protected int CacheGeometry( IntPtr indexes, BspStaticFaceGroup faceGroup )
		{
			// Skip sky always
			if ( faceGroup.isSky )
				return 0;

			int idxStart = 0;
			int numIdx = 0;
			int vertexStart = 0;

			if ( faceGroup.type == FaceGroup.FaceList )
			{
				idxStart = faceGroup.elementStart;
				numIdx = faceGroup.numElements;
				vertexStart = faceGroup.vertexStart;
			}
			else if ( faceGroup.type == FaceGroup.Patch )
			{
				idxStart = faceGroup.patchSurf.IndexOffset;
				numIdx = faceGroup.patchSurf.CurrentIndexCount;
				vertexStart = faceGroup.patchSurf.VertexOffset;
			}
			else
			{
				// Unsupported face type
				return 0;
			}

			unsafe
			{
				uint* src = (uint*)level.Indexes.Lock(
					idxStart * sizeof( uint ),
					numIdx * sizeof( uint ),
					BufferLocking.ReadOnly );
				uint* pIndexes = (uint*)indexes;

				// Offset the indexes here
				// we have to do this now rather than up-front because the
				// indexes are sometimes reused to address different vertex chunks
				for ( int i = 0; i < numIdx; i++ )
					*pIndexes++ = (uint)( *src++ + vertexStart );

				level.Indexes.Unlock();
			}

			// return number of elements
			return numIdx;
		}