/// <summary> /// Fill a 32 bit texture parallel in place with values retrieved from the function fillFunc. /// </summary> /// <param name="tex">The texture to fill.</param> /// <param name="fillFunc">The function used to fill the texture.</param> public unsafe static void Fill32BitTexInPlaceParallel(Texture tex, TextureFillFunctionInPlace fillFunc) { Fill32BitTexInPlaceParallel(tex, 0, (data, row, col, width, height, metadata) => fillFunc(data, row, col, width, height)); }
/// <summary> /// Fill a 32 bit texture parallel in place with values retrieved from the function fillFunc. /// </summary> /// <param name="tex">The texture to fill.</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 Fill32BitTexInPlaceParallel <TMetadata>(Texture tex, TMetadata metadata, TextureFillFunctionInPlace <TMetadata> fillFunc) { //lock the texture pixel data var rect = tex.LockRectangle(0, LockFlags.None); //calculate sizes var byteLenght = (int)rect.Data.Length; var width = rect.Pitch / 4; var height = byteLenght / rect.Pitch; //get the pointer to the data var data = (uint *)rect.Data.DataPointer.ToPointer(); //call the given function for each pixel Parallel.For(0, height, i => { for (int j = 0; j < width; j++) { fillFunc(data, i, j, width, height, metadata); } }); //unlock texture tex.UnlockRectangle(0); }