示例#1
0
        /// <summary>
        /// Load bitmap into Image with stagging and mipmap generation if necessary
        /// and usage.
        /// </summary>
        public static Image Load(Device dev, Queue staggingQ, CommandPool staggingCmdPool,
                                 string path, VkFormat format      = VkFormat.Undefined,
                                 VkMemoryPropertyFlags memoryProps = VkMemoryPropertyFlags.DeviceLocal,
                                 VkImageTiling tiling    = VkImageTiling.Optimal, bool generateMipmaps = true,
                                 VkImageType imageType   = VkImageType.Image2D,
                                 VkImageUsageFlags usage = VkImageUsageFlags.Sampled | VkImageUsageFlags.TransferSrc | VkImageUsageFlags.TransferDst)
        {
            if (format == VkFormat.Undefined)
            {
                format = DefaultTextureFormat;
            }
            if (tiling == VkImageTiling.Optimal)
            {
                usage |= VkImageUsageFlags.TransferDst;
            }
            if (generateMipmaps)
            {
                usage |= (VkImageUsageFlags.TransferSrc | VkImageUsageFlags.TransferDst);
            }

            using (StbImage stbi = new StbImage(path)) {
                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.load(staggingQ, staggingCmdPool, stbi.Handle, generateMipmaps);

                return(img);
            }
        }