/// <summary> /// Copies pixels from an address in memory into a mip level of Texture2D, converting them from one format to another if necessary. /// </summary> /// <param name="texture">The texture to copy to.</param> /// <param name="level">The index into the texture's mip levels.</param> /// <param name="pData">The address of the pixel data.</param> /// <param name="destRect">The destination rectangle.</param> /// <param name="pitch">The number of bytes occupied by a single row of the pixel data (including padding at the end of rows).</param> /// <param name="sourceRect">The source rectangle.</param> /// <param name="pixelFormat">The format of the pixel data.</param> public static unsafe void SetData( this Texture2D texture, void* pSurface, void* pData, ref RECT destRect, uint pitch, ref RECT sourceRect, D3DFORMAT pixelFormat ) { fixed (RECT* pDestRect = &destRect) fixed (RECT* pSourceRect = &sourceRect) { var rv = D3DXLoadSurfaceFromMemory(pSurface, null, pDestRect, pData, pixelFormat, pitch, null, pSourceRect, D3DX_FILTER.NONE, 0); if (rv != 0) throw new COMException("D3DXLoadSurfaceFromMemory failed", rv); } }
private static unsafe extern int D3DXLoadSurfaceFromMemory( void* pDestSurface, void* pDestPalette, RECT* pDestRect, void* pSrcMemory, D3DFORMAT srcFormat, uint srcPitch, void* pSrcPalette, RECT* pSrcRect, D3DX_FILTER filter, uint colorKey );
/// <summary> /// Copies pixels from an address in memory into a mip level of Texture2D, converting them from one format to another if necessary. /// </summary> /// <param name="texture">The texture to copy to.</param> /// <param name="level">The index into the texture's mip levels.</param> /// <param name="pData">The address of the pixel data.</param> /// <param name="width">The width of the pixel data (in pixels).</param> /// <param name="height">The height of the pixel data (in pixels).</param> /// <param name="pitch">The number of bytes occupied by a single row of the pixel data (including padding at the end of rows).</param> /// <param name="pixelFormat">The format of the pixel data.</param> public static unsafe void SetData( this Texture2D texture, void* pSurface, void* pData, int width, int height, uint pitch, D3DFORMAT pixelFormat ) { var rect = new RECT { Top = 0, Left = 0, Right = width, Bottom = height }; SetData(texture, pSurface, pData, ref rect, pitch, ref rect, pixelFormat); }