/// <summary>Create a texture with initial content from system RAM, with 1 subresource.</summary> public static ITexture CreateTexture <T>(this IRenderDevice device, ref TextureDesc desc, T[] array, int stride, string name = null) where T : unmanaged { TextureSubResData[] srd = new TextureSubResData[1]; srd[0].Stride = stride; unsafe { fixed(T *sourceData = array) { srd[0].pData = (IntPtr)sourceData; return(device.CreateTexture(ref desc, srd, 1, name)); } } }
/// <summary>Overwrite a box of 2D texture with supplied data in system RAM</summary> public static void updateTexture <T>(this IDeviceContext context, ITexture texture, ReadOnlySpan <T> source, ref CRect destBox) where T : unmanaged { CSize boxSize = destBox.size; Debug.Assert(boxSize.cx * boxSize.cy == source.Length); TextureSubResData tsrd = new TextureSubResData(false); tsrd.Stride = Marshal.SizeOf <T>() * boxSize.cx; Box box = createBox(ref destBox); unsafe { fixed(T *pointer = source) { tsrd.pData = (IntPtr)pointer; context.UpdateTexture(texture, 0, 0, ref box, ref tsrd); } } }