/// <summary> /// create host visible linear image without command from data pointed by IntPtr pointer containing full image file (jpg, png,...) /// </summary> public static Image Load(Device dev, IntPtr bitmap, ulong bitmapByteCount, VkImageUsageFlags usage = VkImageUsageFlags.TransferSrc, VkFormat format = VkFormat.Undefined, VkMemoryPropertyFlags memoryProps = VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent, VkImageTiling tiling = VkImageTiling.Linear, bool generateMipmaps = false, VkImageType imageType = VkImageType.Image2D) { if (format == VkFormat.Undefined) { format = DefaultTextureFormat; } if (generateMipmaps) { usage |= (VkImageUsageFlags.TransferSrc | VkImageUsageFlags.TransferDst); } using (StbImage stbi = new StbImage(bitmap, bitmapByteCount)) { uint mipLevels = generateMipmaps ? ComputeMipLevels(stbi.Width, stbi.Height) : 1; Image img = new Image(dev, format, usage, memoryProps, (uint)stbi.Width, (uint)stbi.Height, imageType, VkSampleCountFlags.SampleCount1, tiling, mipLevels); img.Map(); stbi.CoptyTo(img.MappedData); img.Unmap(); return(img); } }
/// <summary> /// create host visible linear image without command from path /// </summary> public static Image Load(Device dev, string path, VkImageUsageFlags usage = VkImageUsageFlags.Sampled, bool reserveSpaceForMipmaps = true, VkFormat format = VkFormat.Undefined, VkMemoryPropertyFlags memoryProps = VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent, VkImageTiling tiling = VkImageTiling.Linear, VkImageType imageType = VkImageType.Image2D) { if (format == VkFormat.Undefined) { format = DefaultTextureFormat; } using (StbImage stbi = new StbImage(path)) { uint mipLevels = reserveSpaceForMipmaps ? ComputeMipLevels(stbi.Width, stbi.Height) : 1; Image img = new Image(dev, format, usage, memoryProps, (uint)stbi.Width, (uint)stbi.Height, imageType, VkSampleCountFlags.SampleCount1, tiling, mipLevels); img.Map(); stbi.CoptyTo(img.MappedData); img.Unmap(); return(img); } }