|
|
@ -969,13 +969,14 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t image_index;
|
|
|
|
uint32_t image_index;
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = context->swapchain_command_buffers[context->current_frame];
|
|
|
|
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index);
|
|
|
|
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = vkResetCommandBuffer(context->swapchain_command_buffers[context->current_frame], 0);
|
|
|
|
result = vkResetCommandBuffer(command_buffer, 0);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -983,7 +984,7 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vkBeginCommandBuffer(context->swapchain_command_buffers[context->current_frame], &begin_info);
|
|
|
|
result = vkBeginCommandBuffer(command_buffer, &begin_info);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -994,12 +995,12 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
.maxDepth = 1.0f,
|
|
|
|
.maxDepth = 1.0f,
|
|
|
|
.minDepth = 0.0f,
|
|
|
|
.minDepth = 0.0f,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdSetViewport(context->swapchain_command_buffers[context->current_frame], 0, 1, &viewport);
|
|
|
|
vkCmdSetViewport(command_buffer, 0, 1, &viewport);
|
|
|
|
|
|
|
|
|
|
|
|
VkRect2D scissor = {
|
|
|
|
VkRect2D scissor = {
|
|
|
|
.extent = context->swapchain_extent,
|
|
|
|
.extent = context->swapchain_extent,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdSetScissor(context->swapchain_command_buffers[context->current_frame], 0, 1, &scissor);
|
|
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
|
|
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}}};
|
|
|
|
VkDeviceSize offset = 0;
|
|
|
|
VkDeviceSize offset = 0;
|
|
|
@ -1014,8 +1015,8 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &world_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdBeginRenderPass(command_buffer, &world_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
// UI Render Pass
|
|
|
|
// UI Render Pass
|
|
|
|
VkRenderPassBeginInfo ui_render_pass_begin = {
|
|
|
|
VkRenderPassBeginInfo ui_render_pass_begin = {
|
|
|
@ -1027,36 +1028,36 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.clearValueCount = 2,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdBeginRenderPass(context->swapchain_command_buffers[context->current_frame], &ui_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdBeginRenderPass(command_buffer, &ui_render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
|
|
|
|
|
|
// Draw UI colored rects ////////////////////////////////
|
|
|
|
// Draw UI colored rects ////////////////////////////////
|
|
|
|
vkCmdBindPipeline(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_rect.pipeline);
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_rect.pipeline);
|
|
|
|
vkCmdBindDescriptorSets(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_rect.layout, 0, 1, &ui_context->ui_descriptor_set, 0, NULL);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_rect.layout, 0, 1, &ui_context->ui_descriptor_set, 0, NULL);
|
|
|
|
vkCmdBindVertexBuffers(context->swapchain_command_buffers[context->current_frame], 0, 1, &ui_context->ui_rect.vertex, &offset);
|
|
|
|
vkCmdBindVertexBuffers(command_buffer, 0, 1, &ui_context->ui_rect.vertex, &offset);
|
|
|
|
vkCmdBindIndexBuffer(context->swapchain_command_buffers[context->current_frame], ui_context->ui_rect.index, 0, VK_INDEX_TYPE_UINT32);
|
|
|
|
vkCmdBindIndexBuffer(command_buffer, ui_context->ui_rect.index, 0, VK_INDEX_TYPE_UINT32);
|
|
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < ui_layer_count; i++) {
|
|
|
|
for(uint32_t i = 0; i < ui_layer_count; i++) {
|
|
|
|
if(ui_layers[i].colored_rect_count > 0) {
|
|
|
|
if(ui_layers[i].colored_rect_count > 0) {
|
|
|
|
vkCmdBindVertexBuffers(context->swapchain_command_buffers[context->current_frame], 1, 1, &ui_layers[i].colored_rects, &offset);
|
|
|
|
vkCmdBindVertexBuffers(command_buffer, 1, 1, &ui_layers[i].colored_rects, &offset);
|
|
|
|
vkCmdDrawIndexed(context->swapchain_command_buffers[context->current_frame], 6, ui_layers[i].colored_rect_count, 0, 0, 0);
|
|
|
|
vkCmdDrawIndexed(command_buffer, 6, ui_layers[i].colored_rect_count, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// Draw UI text /////////////////////////////////////////
|
|
|
|
// Draw UI text /////////////////////////////////////////
|
|
|
|
vkCmdBindPipeline(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.pipeline);
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.pipeline);
|
|
|
|
vkCmdBindDescriptorSets(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.layout, 0, 1, &ui_context->ui_descriptor_set, 0, NULL);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.layout, 0, 1, &ui_context->ui_descriptor_set, 0, NULL);
|
|
|
|
for(uint32_t i = 0; i < ui_layer_count; i++) {
|
|
|
|
for(uint32_t i = 0; i < ui_layer_count; i++) {
|
|
|
|
if(ui_layers[i].text_count > 0) {
|
|
|
|
if(ui_layers[i].text_count > 0) {
|
|
|
|
vkCmdBindDescriptorSets(context->swapchain_command_buffers[context->current_frame], VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.layout, 1, 1, &ui_layers[i].font.set, 0, NULL);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->ui_pipeline_text.layout, 1, 1, &ui_layers[i].font.set, 0, NULL);
|
|
|
|
vkCmdBindVertexBuffers(context->swapchain_command_buffers[context->current_frame], 1, 1, &ui_layers[i].texts, &offset);
|
|
|
|
vkCmdPushConstants(command_buffer, ui_context->ui_pipeline_text.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, 8, &ui_layers[i].texts_address);
|
|
|
|
vkCmdDrawIndexed(context->swapchain_command_buffers[context->current_frame], 6, ui_layers[i].text_count, 0, 0, 0);
|
|
|
|
vkCmdDrawIndexed(command_buffer, 6, ui_layers[i].text_count, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
result = vkEndCommandBuffer(context->swapchain_command_buffers[context->current_frame]);
|
|
|
|
result = vkEndCommandBuffer(command_buffer);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1068,7 +1069,7 @@ VkResult draw_frame(RenderContext* context, UIContext* ui_context, UILayer* ui_l
|
|
|
|
.pWaitSemaphores = &context->image_available_semaphores[context->current_frame],
|
|
|
|
.pWaitSemaphores = &context->image_available_semaphores[context->current_frame],
|
|
|
|
.pWaitDstStageMask = wait_stages,
|
|
|
|
.pWaitDstStageMask = wait_stages,
|
|
|
|
.commandBufferCount = 1,
|
|
|
|
.commandBufferCount = 1,
|
|
|
|
.pCommandBuffers = &context->swapchain_command_buffers[context->current_frame],
|
|
|
|
.pCommandBuffers = &command_buffer,
|
|
|
|
.signalSemaphoreCount = 1,
|
|
|
|
.signalSemaphoreCount = 1,
|
|
|
|
.pSignalSemaphores = &context->render_finished_semaphores[context->current_frame],
|
|
|
|
.pSignalSemaphores = &context->render_finished_semaphores[context->current_frame],
|
|
|
|
};
|
|
|
|
};
|
|
|
|