コード例 #1
0
ファイル: TextureUtils.cs プロジェクト: mechaz/vvvv-sdk
 /// <summary>
 /// Fill a 32 bit texture in parallel with values retrieved from the function fillFunc.
 /// </summary>
 /// <param name="tex">The texture to fill.</param>
 /// <param name="oldData">Array to fill with the old data</param>
 /// <param name="fillFunc">The function used to fill the texture.</param>
 public unsafe static void Fill32BitTexParallel(Texture tex, uint[] oldData, TextureFillFunction fillFunc)
 {
     Fill32BitTexParallel(tex, oldData, 0, (od, data, row, col, width, height, metadata) => fillFunc(od, data, row, col, width, height));
 }
コード例 #2
0
ファイル: TextureUtils.cs プロジェクト: mechaz/vvvv-sdk
        /// <summary>
        /// Fill a 32 bit texture in parallel with values retrieved from the function fillFunc.
        /// </summary>
        /// <param name="tex">The texture to fill.</param>
        /// <param name="oldData">Array to fill with the old data</param>
        /// <param name="metadata">User defined metadata to hand over to the fillFunc.</param>
        /// <param name="fillFunc">The function used to fill the texture.</param>
        public unsafe static void Fill32BitTexParallel <TMetadata>(Texture tex, uint[] oldData, TMetadata metadata, TextureFillFunction <TMetadata> fillFunc)
        {
            //lock the texture pixel data
            var rect = tex.LockRectangle(0, LockFlags.None);

            //calculate sizes
            var byteLenght = (int)rect.Data.Length;
            var pixelCount = byteLenght / 4;
            var width      = rect.Pitch / 4;
            var height     = byteLenght / rect.Pitch;

            //get the pointer to the data
            var data = (uint *)rect.Data.DataPointer.ToPointer();

            //copy data to array, that we can replace the data
            Copy32BitTexToArray(rect.Data.DataPointer, oldData, pixelCount);

            //call the given function for each pixel
            Parallel.For(0, height, i =>
            {
                for (int j = 0; j < width; j++)
                {
                    fillFunc(oldData, data, i, j, width, height, metadata);
                }
            });

            //unlock texture
            tex.UnlockRectangle(0);
        }