Exemple #1
0
        private void createCommandBuffers()
        {
            int commandBuffersCount = swapChainFramebuffers.Length;

            commandBuffers = new VkCommandBuffer[commandBuffersCount];

            VkCommandBufferAllocateInfo allocInfo = new VkCommandBufferAllocateInfo();

            allocInfo.sType              = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
            allocInfo.commandPool        = commandPool;
            allocInfo.level              = VkCommandBufferLevel.VK_COMMAND_BUFFER_LEVEL_PRIMARY;
            allocInfo.commandBufferCount = commandBuffersCount;

            VkResult result = Vulkan.vkAllocateCommandBuffers(device, allocInfo, commandBuffers);

            if (result != VkResult.VK_SUCCESS)
            {
                throw Program.Throw("failed to allocate command buffers!", result);
            }

            for (int i = 0; i < commandBuffersCount; i++)
            {
                VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo();
                beginInfo.sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
                beginInfo.flags = VkCommandBufferUsageFlagBits.VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;

                Vulkan.vkBeginCommandBuffer(commandBuffers[i], beginInfo);

                VkRenderPassBeginInfo renderPassInfo = new VkRenderPassBeginInfo();
                renderPassInfo.sType             = VkStructureType.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
                renderPassInfo.renderPass        = renderPass;
                renderPassInfo.framebuffer       = swapChainFramebuffers[i];
                renderPassInfo.renderArea.offset = VkOffset2D.Create(0, 0);
                renderPassInfo.renderArea.extent = swapChainExtent;

                VkClearValue clearColor = VkClearValue.Create(0.01f, 0.03f, 0.01f, 1.0f);
                renderPassInfo.clearValueCount = 1;
                renderPassInfo.pClearValues    = new VkClearValue[] { clearColor };

                Vulkan.vkCmdBeginRenderPass(commandBuffers[i], renderPassInfo, VkSubpassContents.VK_SUBPASS_CONTENTS_INLINE);

                Vulkan.vkCmdBindPipeline(commandBuffers[i], VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);

                VkBuffer[] vertexBuffers = new VkBuffer[] { vertexBuffer };
                int[]      offsets       = new int[] { 0 };
                Vulkan.vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);

                Vulkan.vkCmdDraw(commandBuffers[i], vertices.Length, 1, 0, 0);

                Vulkan.vkCmdEndRenderPass(commandBuffers[i]);

                result = Vulkan.vkEndCommandBuffer(commandBuffers[i]);
                if (result != VkResult.VK_SUCCESS)
                {
                    throw Program.Throw("failed to record command buffer!", result);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="x">The X component of the offset.</param>
 /// <param name="y">The Y component of the offset.</param>
 /// <param name="width">The width component of the extent.</param>
 /// <param name="height">The height component of the extent.</param>
 public VkRect2D(int x, int y, int width, int height)
 {
     offset = new VkOffset2D(x, y);
     extent = new VkExtent2D(width, height);
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="offset">The offset component of the rectangle.</param>
 /// <param name="extent">The extent component of the rectangle.</param>
 public VkRect2D(VkOffset2D offset, VkExtent2D extent)
 {
     this.offset = offset;
     this.extent = extent;
 }