Got the triangle working! It only took 10 hours.
This commit is contained in:
parent
3d36517b4f
commit
10fc100e2b
11 changed files with 352 additions and 4 deletions
|
|
@ -144,8 +144,12 @@ void VulkanEngine::draw()
|
|||
|
||||
draw_background(t.cmd);
|
||||
|
||||
vkutil::transition_image(t.cmd, _drawImage.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
|
||||
draw_geometry(t.cmd);
|
||||
|
||||
// ZED: ?
|
||||
vkutil::transition_image(t.cmd, _drawImage.image, VK_IMAGE_LAYOUT_GENERAL,
|
||||
vkutil::transition_image(t.cmd, _drawImage.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
|
||||
// ZED: ?
|
||||
|
|
@ -159,15 +163,47 @@ void VulkanEngine::draw()
|
|||
// ZED: ?
|
||||
vkutil::transition_image(t.cmd, _swapchainImages[t.swapchainImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
|
||||
_gui.draw_imgui(_swapchainExtent, t.cmd, _swapchainImageViews[t.swapchainImageIndex]);
|
||||
// ZED: end drawing the things
|
||||
_gui.draw_imgui(_swapchainExtent, t.cmd, _swapchainImageViews[t.swapchainImageIndex]);
|
||||
|
||||
// ZED: finalize image and commit command buffer
|
||||
vkutil::transition_image(t.cmd, _swapchainImages[t.swapchainImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
vkutil::transition_image(t.cmd, _swapchainImages[t.swapchainImageIndex], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
|
||||
commit_transaction(t);
|
||||
}
|
||||
|
||||
void VulkanEngine::draw_geometry(VkCommandBuffer cmd)
|
||||
{
|
||||
VkRenderingAttachmentInfo colorAttachment = vkinit::attachment_info(_drawImage.imageView, nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
|
||||
VkRenderingInfo renderInfo = vkinit::rendering_info(_drawExtent, &colorAttachment, nullptr);
|
||||
vkCmdBeginRendering(cmd, &renderInfo);
|
||||
|
||||
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, _trianglePipeline);
|
||||
|
||||
VkViewport viewport{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = (float)_drawExtent.width,
|
||||
.height = (float)_drawExtent.height,
|
||||
.minDepth = 0.0f,
|
||||
.maxDepth = 1.0f,
|
||||
};
|
||||
|
||||
vkCmdSetViewport(cmd, 0, 1, &viewport);
|
||||
|
||||
VkRect2D scissor{
|
||||
.offset = { .x = 0, .y = 0, },
|
||||
.extent = _drawExtent
|
||||
};
|
||||
|
||||
vkCmdSetScissor(cmd, 0, 1, &scissor);
|
||||
|
||||
vkCmdDraw(cmd, 3, 1, 0, 0);
|
||||
|
||||
vkCmdEndRendering(cmd);
|
||||
}
|
||||
|
||||
void VulkanEngine::run()
|
||||
{
|
||||
//main loop
|
||||
|
|
@ -428,6 +464,7 @@ void VulkanEngine::init_descriptors() {
|
|||
void VulkanEngine::init_pipelines()
|
||||
{
|
||||
init_background_pipelines();
|
||||
init_triangle_pipelines();
|
||||
init_shaders();
|
||||
}
|
||||
|
||||
|
|
@ -530,4 +567,49 @@ void VulkanEngine::immediate_submit(std::function<void(VkCommandBuffer cmd)>&& f
|
|||
}
|
||||
|
||||
|
||||
void VulkanEngine::init_triangle_pipelines()
|
||||
{
|
||||
VkShaderModule triangleFragShader;
|
||||
|
||||
if(!vkutil::load_shader_module("colored_triangle.frag.spv",_device, &triangleFragShader)) {
|
||||
std::print("Error when building the triangle fragment shaders module");
|
||||
} else {
|
||||
std::print("Triangle fragment shader successfully loaded");
|
||||
}
|
||||
|
||||
VkShaderModule triangleVertexShader;
|
||||
if(!vkutil::load_shader_module("colored_triangle.vert.spv", _device, &triangleVertexShader)) {
|
||||
std::println("Error when building the triangle, vertex shader module");
|
||||
} else {
|
||||
std::println("Triangle vertex shader successfully loaded");
|
||||
}
|
||||
|
||||
VkPipelineLayoutCreateInfo pipeline_layout_info = vkinit::pipeline_layout_create_info();
|
||||
|
||||
VK_CHECK(vkCreatePipelineLayout(_device, &pipeline_layout_info, nullptr, &_trianglePipelineLayout));
|
||||
|
||||
PipelineBuilder pipelineBuilder;
|
||||
|
||||
pipelineBuilder._pipelineLayout = _trianglePipelineLayout;
|
||||
pipelineBuilder.set_shaders(triangleVertexShader, triangleFragShader);
|
||||
pipelineBuilder.set_input_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
|
||||
pipelineBuilder.set_polygon_mode(VK_POLYGON_MODE_FILL);
|
||||
pipelineBuilder.set_cull_mode(VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE);
|
||||
pipelineBuilder.set_multisampling_none();
|
||||
pipelineBuilder.disable_blending();
|
||||
pipelineBuilder.disable_depthtest();
|
||||
|
||||
// connect the image format we will drw into, from draw image
|
||||
pipelineBuilder.set_color_attachment_format(_drawImage.imageFormat);
|
||||
pipelineBuilder.set_depth_format(VK_FORMAT_UNDEFINED);
|
||||
|
||||
_trianglePipeline = pipelineBuilder.build_pipeline(_device);
|
||||
|
||||
vkDestroyShaderModule(_device, triangleFragShader, nullptr);
|
||||
vkDestroyShaderModule(_device, triangleVertexShader, nullptr);
|
||||
|
||||
_mainDeletionQueue.push_function([&]() {
|
||||
vkDestroyPipelineLayout(_device, _trianglePipelineLayout, nullptr);
|
||||
vkDestroyPipeline(_device, _trianglePipeline, nullptr);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue