|
|
@ -568,12 +568,12 @@ VkResult find_depth_format(VkPhysicalDevice physical_device, VkImageTiling tilin
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult create_render_pass(VkDevice device, VkSurfaceFormatKHR format, VkFormat depth_format, VkRenderPass* render_pass) {
|
|
|
|
VkResult create_render_pass(VkDevice device, VkSurfaceFormatKHR format, VkFormat depth_format, VkRenderPass* render_pass, VkAttachmentLoadOp color_load_op) {
|
|
|
|
VkAttachmentDescription attachments[] = {
|
|
|
|
VkAttachmentDescription attachments[] = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.format = format.format,
|
|
|
|
.format = format.format,
|
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
.loadOp = color_load_op,
|
|
|
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
@ -924,7 +924,17 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = create_render_pass(context->device, context->swapchain_format, context->depth_format, &context->render_pass);
|
|
|
|
result = create_render_pass(context->device, context->swapchain_format, context->depth_format, &context->world_render_pass, VK_ATTACHMENT_LOAD_OP_CLEAR);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = create_render_pass(context->device, context->swapchain_format, context->depth_format, &context->ui_render_pass, VK_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = create_render_pass(context->device, context->swapchain_format, context->depth_format, &context->ui_objects_render_pass, VK_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -934,7 +944,7 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = create_swapchain_framebuffers(context->device, context->swapchain_image_count, context->swapchain_image_views, context->depth_image_view, context->render_pass, context->swapchain_extent, &context->swapchain_framebuffers);
|
|
|
|
result = create_swapchain_framebuffers(context->device, context->swapchain_image_count, context->swapchain_image_views, context->depth_image_view, context->world_render_pass, context->swapchain_extent, &context->swapchain_framebuffers);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -944,7 +954,7 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = create_ui_polygon_pipeline(context->device, context->render_pass, context->ui_descriptor_layout, &context->ui_pipeline_polygon);
|
|
|
|
result = create_ui_polygon_pipeline(context->device, context->world_render_pass, context->ui_descriptor_layout, &context->ui_pipeline_polygon);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -988,16 +998,30 @@ VkResult draw_frame(RenderContext* context, struct UIPolygon polygon, VkBuffer u
|
|
|
|
|
|
|
|
|
|
|
|
VkClearValue clear_values[2] = {{.color={{0.0f, 0.0f, 0.0f, 1.0f}}}, {.depthStencil={1.0f, 0.0f}}};
|
|
|
|
VkClearValue clear_values[2] = {{.color={{0.0f, 0.0f, 0.0f, 1.0f}}}, {.depthStencil={1.0f, 0.0f}}};
|
|
|
|
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo render_pass_begin = {
|
|
|
|
// World Render Pass
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo world_render_pass_begin = {
|
|
|
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
|
|
|
|
.renderPass = context->world_render_pass,
|
|
|
|
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
|
|
|
|
.clearValueCount = 2,
|
|
|
|
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &world_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UI Render Pass
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo ui_render_pass_begin = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
.renderPass = context->render_pass,
|
|
|
|
.renderPass = context->ui_render_pass,
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &ui_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
|
|
|
|
|
|
// Draw UI polygons
|
|
|
|
// Draw UI polygons
|
|
|
|
vkCmdBindPipeline(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, context->ui_pipeline_polygon.pipeline);
|
|
|
|
vkCmdBindPipeline(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, context->ui_pipeline_polygon.pipeline);
|
|
|
@ -1009,7 +1033,19 @@ VkResult draw_frame(RenderContext* context, struct UIPolygon polygon, VkBuffer u
|
|
|
|
vkCmdBindVertexBuffers(context->swapchain_command_buffers[context->current_frame], 1, 1, &ui_polygons, &offset);
|
|
|
|
vkCmdBindVertexBuffers(context->swapchain_command_buffers[context->current_frame], 1, 1, &ui_polygons, &offset);
|
|
|
|
vkCmdDrawIndexed(context->swapchain_command_buffers[context->current_frame], polygon.indices, ui_polygon_count, 0, 0, 0);
|
|
|
|
vkCmdDrawIndexed(context->swapchain_command_buffers[context->current_frame], polygon.indices, ui_polygon_count, 0, 0, 0);
|
|
|
|
// End Draw UI polygons
|
|
|
|
// End Draw UI polygons
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// World Render Pass
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo ui_objects_render_pass_begin = {
|
|
|
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
|
|
|
|
.renderPass = context->ui_objects_render_pass,
|
|
|
|
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
|
|
|
|
.clearValueCount = 2,
|
|
|
|
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &ui_objects_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
|
|
|
|
|
|
|
|
result = vkEndCommandBuffer(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
result = vkEndCommandBuffer(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|