Axiom.RenderSystems.Xna.XnaHardwarePixelBuffer.BlitFromMemory C# (CSharp) Method

BlitFromMemory() public method

Copies a region from normal memory to a region of this pixelbuffer. The source image can be in any pixel format supported by Axiom, and in any size.
The source and destination regions dimensions don't have to match, in which case scaling is done. This scaling is generally done using a bilinear filter in hardware, but it is faster to pass the source image in the right dimensions. Only call this function when both buffers are unlocked.
public BlitFromMemory ( PixelBox src, BasicBox dstBox ) : void
src Axiom.Media.PixelBox PixelBox containing the source pixels and format in memory
dstBox Axiom.Media.BasicBox Image.BasicBox describing the destination region in this buffer
return void
		public override void BlitFromMemory( PixelBox src, BasicBox dstBox )
		{
			PixelBox converted = src;
			GCHandle bufGCHandle = new GCHandle();
			int bufSize = 0;

			// Get src.Data as byte[]
			bufSize = PixelUtil.GetMemorySize( src.Width, src.Height, src.Depth, Format );
			byte[] newBuffer = new byte[ bufSize ];
			bufGCHandle = GCHandle.Alloc( newBuffer, GCHandleType.Pinned );
            //XnaHelper.Convert(XFG.SurfaceFormat) would never have returned SurfaceFormat.Unknown anyway...
            //if ( XnaHelper.Convert( src.Format ) == XFG.SurfaceFormat.Unknown )
            //{
            //    converted = new PixelBox( src.Width, src.Height, src.Depth, Format, bufGCHandle.AddrOfPinnedObject() );
            //    PixelConverter.BulkPixelConversion( src, converted );
            //}
			//else
			{
				Memory.Copy( converted.Data, bufGCHandle.AddrOfPinnedObject(), bufSize );
			}

			if ( surface != null )
			{
				surface.SetData<byte>( mipLevel, XnaHelper.ToRectangle( dstBox ), newBuffer, 0, bufSize );
			}
			else
			{
				throw new NotSupportedException( "BlitFromMemory on Volume Textures not supported." );
			}

			// If we allocated a buffer for the temporary conversion, free it here
			if ( bufGCHandle.IsAllocated )
				bufGCHandle.Free();

			if ( doMipmapGen )
				GenMipmaps();
		}