|
|
|
@ -1,68 +1,8 @@
|
|
|
|
|
#include "draw.h"
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(
|
|
|
|
|
RenderContext* context,
|
|
|
|
|
UIContextStorage* ui_context) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = vkResetFences(context->device, 1, &context->in_flight_fences[context->current_frame]);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = vkResetCommandBuffer(command_buffer, 0);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
|
};
|
|
|
|
|
result = vkBeginCommandBuffer(command_buffer, &begin_info);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkViewport viewport = {
|
|
|
|
|
.width = context->swapchain_extent.width,
|
|
|
|
|
.height = context->swapchain_extent.height,
|
|
|
|
|
.maxDepth = 1.0f,
|
|
|
|
|
.minDepth = 0.0f,
|
|
|
|
|
};
|
|
|
|
|
vkCmdSetViewport(command_buffer, 0, 1, &viewport);
|
|
|
|
|
|
|
|
|
|
VkRect2D scissor = {
|
|
|
|
|
.extent = context->swapchain_extent,
|
|
|
|
|
};
|
|
|
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
VkClearValue clear_values[2] = {{.color={{0.0f, 0.0f, 0.0f, 0.0f}}}, {.depthStencil={1.0f, 0.0f}}};
|
|
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo render_pass_begin = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
|
.renderPass = context->render_pass,
|
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
|
.clearValueCount = 2,
|
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkResult record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
|
|
|
|
|
|
// Compute Pass
|
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, ui_context->string_pipeline.pipeline);
|
|
|
|
|
for(uint32_t i = 0; i < ui_context->max_containers; i++) {
|
|
|
|
|
if(ui_context->containers[i].id != 0x00000000) {
|
|
|
|
@ -112,12 +52,12 @@ VkResult draw_frame(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult record_ui_draw(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
|
|
|
|
|
|
// Render Pass
|
|
|
|
|
vkCmdBeginRenderPass(command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
// World subpass
|
|
|
|
|
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
// UI subpass
|
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.pipeline);
|
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 0, 1, &ui_context->font_samplers, 0, NULL);
|
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 1, 1, &ui_context->font_textures, 0, NULL);
|
|
|
|
@ -133,6 +73,74 @@ VkResult draw_frame(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(
|
|
|
|
|
RenderContext* context,
|
|
|
|
|
UIContextStorage* ui_context) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = vkResetFences(context->device, 1, &context->in_flight_fences[context->current_frame]);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = vkResetCommandBuffer(command_buffer, 0);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
|
};
|
|
|
|
|
result = vkBeginCommandBuffer(command_buffer, &begin_info);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkViewport viewport = {
|
|
|
|
|
.width = context->swapchain_extent.width,
|
|
|
|
|
.height = context->swapchain_extent.height,
|
|
|
|
|
.maxDepth = 1.0f,
|
|
|
|
|
.minDepth = 0.0f,
|
|
|
|
|
};
|
|
|
|
|
vkCmdSetViewport(command_buffer, 0, 1, &viewport);
|
|
|
|
|
|
|
|
|
|
VkRect2D scissor = {
|
|
|
|
|
.extent = context->swapchain_extent,
|
|
|
|
|
};
|
|
|
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
VkClearValue clear_values[2] = {{.color={{0.0f, 0.0f, 0.0f, 0.0f}}}, {.depthStencil={1.0f, 0.0f}}};
|
|
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo render_pass_begin = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
|
.renderPass = context->render_pass,
|
|
|
|
|
.framebuffer = context->swapchain_framebuffers[image_index],
|
|
|
|
|
.renderArea.offset = {0, 0},
|
|
|
|
|
.renderArea.extent = context->swapchain_extent,
|
|
|
|
|
.clearValueCount = 2,
|
|
|
|
|
.pClearValues = clear_values,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
record_ui_compute(command_buffer, ui_context);
|
|
|
|
|
vkCmdBeginRenderPass(command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
record_ui_draw(command_buffer, ui_context);
|
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
|
|
|
|
|
|
result = vkEndCommandBuffer(command_buffer);
|
|
|
|
|