Exemplo n.º 1
0
 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
     );
Exemplo n.º 2
0
        /// <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="updateRect">The dimension and position of the rectangle to paint.</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, int level, void* pData,
            Rectangle updateRect, uint pitch,
            D3DFORMAT pixelFormat
            )
        {
            var rect = new RECT
            {
                Top = updateRect.Y,
                Left = updateRect.X,
                Right = updateRect.Width,
                Bottom = updateRect.Height
            };

            void* pSurface = GetSurfaceLevel(texture, level);

            try
            {
                var rv = D3DXLoadSurfaceFromMemory(pSurface, null, &rect, pData, pixelFormat, pitch, null, &rect, D3DX_FILTER.NONE, 0);
                if (rv != 0)
                    throw new COMException("D3DXLoadSurfaceFromMemory failed", rv);
            }
            finally
            {
                Marshal.Release(new IntPtr(pSurface));
            }
        }