コード例 #1
0
        /// <summary>
        /// load bitmap from pointer
        /// </summary>
        void load(Queue staggingQ, CommandPool staggingCmdPool, IntPtr bitmap, bool generateMipmaps = true)
        {
            long size = info.extent.width * info.extent.height * 4 * info.extent.depth;

            if (MemoryFlags.HasFlag(VkMemoryPropertyFlags.HostVisible))
            {
                Map();
                unsafe {
                    System.Buffer.MemoryCopy(bitmap.ToPointer(), MappedData.ToPointer(), size, size);
                }
                Unmap();

                if (generateMipmaps)
                {
                    BuildMipmaps(staggingQ, staggingCmdPool);
                }
            }
            else
            {
                using (HostBuffer stagging = new HostBuffer(Dev, VkBufferUsageFlags.TransferSrc, (UInt64)size, bitmap)) {
                    PrimaryCommandBuffer cmd = staggingCmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit);

                    stagging.CopyTo(cmd, this);
                    if (generateMipmaps)
                    {
                        BuildMipmaps(cmd);
                    }

                    cmd.End();
                    staggingQ.Submit(cmd);
                    staggingQ.WaitIdle();
                    cmd.Free();
                }
            }
        }