假设Vulkan已经初始化,你正在录制到命令缓冲区,你有一个帧缓冲区和渲染通道,如何使用Vulkan绘制原始2D几何形状?
vkCmdBeginRenderPass(command_buffer, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
// Draw primitives here
vkCmdEndRenderPass(command_buffer);
答案 0 :(得分:3)
绘图设置非常复杂,但绘制所需的实际调用非常简单。从tri.c
(绘制2D三角形):
// ...
vkCmdBeginRenderPass(demo->draw_cmd, &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(demo->draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
demo->pipeline);
vkCmdBindDescriptorSets(demo->draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, demo->pipeline_layout,
0, 1, & demo->desc_set, 0, NULL);
VkViewport viewport = {};
viewport.height = (float) demo->height;
viewport.width = (float) demo->width;
viewport.minDepth = (float) 0.0f;
viewport.maxDepth = (float) 1.0f;
vkCmdSetViewport(demo->draw_cmd, 0, 1, &viewport);
VkRect2D scissor = {};
scissor.extent.width = demo->width;
scissor.extent.height = demo->height;
scissor.offset.x = 0;
scissor.offset.y = 0;
vkCmdSetScissor(demo->draw_cmd, 0, 1, &scissor);
VkDeviceSize offsets[1] = {0};
vkCmdBindVertexBuffers(demo->draw_cmd, VERTEX_BUFFER_BIND_ID, 1, &demo->vertices.buf, offsets);
vkCmdDraw(demo->draw_cmd, 3, 1, 0, 0);
vkCmdEndRenderPass(demo->draw_cmd);
// ...
此代码段假定您已经获得VkPipeline
(包括着色器等),VkBuffer
(对于顶点缓冲区)和VkCommandBuffer
处于适当状态。执行包含vkCmdDraw
后,实际发出绘制命令的VkCommandBuffer
。