Axiom.Core.PatchSurface.DistributeControlPoints C# (CSharp) Method

DistributeControlPoints() protected method

protected DistributeControlPoints ( IntPtr lockedBuffer ) : void
lockedBuffer System.IntPtr
return void
		protected unsafe void DistributeControlPoints( IntPtr lockedBuffer )
		{
			// Insert original control points into expanded mesh
			int uStep = 1 << uLevel;
			int vStep = 1 << vLevel;


			VertexElement elemPos = declaration.FindElementBySemantic( VertexElementSemantic.Position );
			VertexElement elemNorm = declaration.FindElementBySemantic( VertexElementSemantic.Normal );
			VertexElement elemTex0 = declaration.FindElementBySemantic( VertexElementSemantic.TexCoords, 0 );
			VertexElement elemTex1 = declaration.FindElementBySemantic( VertexElementSemantic.TexCoords, 1 );
			VertexElement elemDiffuse = declaration.FindElementBySemantic( VertexElementSemantic.Diffuse );

			byte* pSrc = (byte*)controlPointBuffer;
			byte* pDest;
			int vertexSize = declaration.GetVertexSize( 0 );
			float* pSrcReal, pDestReal;
			int* pSrcRGBA, pDestRGBA;

			for ( int v = 0; v < meshHeight; v += vStep )
			{
				// set dest by v from base
				pDest = (byte*)( lockedBuffer ) + ( vertexSize * meshWidth * v );

				for ( int u = 0; u < meshWidth; u += uStep )
				{
					// Copy Position
					pSrcReal = (float*)( (byte*)pSrc + elemPos.Offset );
					pDestReal = (float*)( (byte*)pDest + elemPos.Offset );
					*pDestReal++ = *pSrcReal++;
					*pDestReal++ = *pSrcReal++;
					*pDestReal++ = *pSrcReal++;

					// Copy Normals
					if ( elemNorm != null )
					{
						pSrcReal = (float*)( (byte*)pSrc + elemNorm.Offset );
						pDestReal = (float*)( (byte*)pDest + elemNorm.Offset );
						*pDestReal++ = *pSrcReal++;
						*pDestReal++ = *pSrcReal++;
						*pDestReal++ = *pSrcReal++;
					}

					// Copy Diffuse
					if ( elemDiffuse != null )
					{
						pSrcRGBA = (int*)( (byte*)pSrc + elemDiffuse.Offset );
						pDestRGBA = (int*)( (byte*)pDest + elemDiffuse.Offset );
						*pDestRGBA++ = *pSrcRGBA++;
					}

					// Copy texture coords
					if ( elemTex0 != null )
					{
						pSrcReal = (float*)( (byte*)pSrc + elemTex0.Offset );
						pDestReal = (float*)( (byte*)pDest + elemTex0.Offset );
						for ( int dim = 0; dim < VertexElement.GetTypeCount( elemTex0.Type ); dim++ )
						{
							*pDestReal++ = *pSrcReal++;
						}
					}
					if ( elemTex1 != null )
					{
						pSrcReal = (float*)( (byte*)pSrc + elemTex1.Offset );
						pDestReal = (float*)( (byte*)pDest + elemTex1.Offset );
						for ( int dim = 0; dim < VertexElement.GetTypeCount( elemTex1.Type ); dim++ )
						{
							*pDestReal++ = *pSrcReal++;
						}
					}

					// Increment source by one vertex
					pSrc += vertexSize;
					// Increment dest by 1 vertex * uStep
					pDest += vertexSize * uStep;
				} // u
			} // v
		}