コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
ファイル: VkCrowWindow.cs プロジェクト: jpbruyere/vkvg.net
        void initUISurface()
        {
            iFace.surf?.Dispose();
            uiImage?.Dispose();

            uiImage = new Image(dev, VkFormat.B8g8r8a8Unorm, VkImageUsageFlags.Sampled,
                                VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent, Width, Height, VkImageType.Image2D,
                                VkSampleCountFlags.SampleCount1, VkImageTiling.Linear);
            uiImage.CreateView(VkImageViewType.ImageView2D, VkImageAspectFlags.Color);
            uiImage.CreateSampler(VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder);
            uiImage.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
            uiImage.Map();

            CommandBuffer cmd = cmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit);

            uiImage.SetLayout(cmd, VkImageAspectFlags.Color,
                              VkImageLayout.Undefined, VkImageLayout.ShaderReadOnlyOptimal);
            presentQueue.EndSubmitAndWait(cmd, true);

            NotifyValueChanged("uiImage", uiImage);

            uiImageUpdate?.Write(dev, uiImage.Descriptor);

            iFace.surf = new Crow.Cairo.ImageSurface(uiImage.MappedData, Crow.Cairo.Format.ARGB32,
                                                     (int)Width, (int)Height, (int)uiImage.GetSubresourceLayout().rowPitch);
        }
コード例 #3
0
        /// <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);
            }
        }