get rid of current frame global
now I feel dirty because this feels like oop
This commit is contained in:
parent
ccf0e1481b
commit
44fe0c5f7d
3 changed files with 18 additions and 17 deletions
|
@ -11,25 +11,27 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
// TODO: clean up globals here
|
||||
|
||||
bool m_framebuffer_resized = false;
|
||||
uint32_t g_current_frame = 0;
|
||||
uint32_t m_current_frame = 0;
|
||||
|
||||
void vk_framebuffer_resized(GLFWwindow *window, int width, int height) {
|
||||
(void)window; (void)width; (void)height;
|
||||
m_framebuffer_resized = true;
|
||||
}
|
||||
|
||||
uint32_t vk_current_frame(void) {
|
||||
return m_current_frame;
|
||||
}
|
||||
|
||||
bool vk_draw_frame(void) {
|
||||
vkWaitForFences(g_dev, 1, &g_in_flight_fences.data[g_current_frame], VK_TRUE, UINT64_MAX);
|
||||
vkWaitForFences(g_dev, 1, &g_in_flight_fences.data[m_current_frame], VK_TRUE, UINT64_MAX);
|
||||
|
||||
uint32_t image_index;
|
||||
const VkResult acquire_next_image_result = vkAcquireNextImageKHR(
|
||||
g_dev,
|
||||
g_swapchain,
|
||||
UINT64_MAX,
|
||||
g_image_available_semaphores.data[g_current_frame],
|
||||
g_image_available_semaphores.data[m_current_frame],
|
||||
VK_NULL_HANDLE,
|
||||
&image_index
|
||||
);
|
||||
|
@ -44,17 +46,17 @@ bool vk_draw_frame(void) {
|
|||
return false;
|
||||
}
|
||||
|
||||
vk_update_uniform_buffer(g_current_frame);
|
||||
vk_update_uniform_buffer(m_current_frame);
|
||||
|
||||
vkResetFences(g_dev, 1, &g_in_flight_fences.data[g_current_frame]);
|
||||
vkResetFences(g_dev, 1, &g_in_flight_fences.data[m_current_frame]);
|
||||
|
||||
vkResetCommandBuffer(g_command_buffers.data[g_current_frame], 0);
|
||||
if (!vk_record_command_buffer(g_command_buffers.data[g_current_frame], image_index)) {
|
||||
vkResetCommandBuffer(g_command_buffers.data[m_current_frame], 0);
|
||||
if (!vk_record_command_buffer(g_command_buffers.data[m_current_frame], image_index)) {
|
||||
PTK_ERR("failed recording command buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
const VkSemaphore signal_semaphores[] = {g_render_finished_semaphores.data[g_current_frame]};
|
||||
const VkSemaphore signal_semaphores[] = {g_render_finished_semaphores.data[m_current_frame]};
|
||||
|
||||
VK_TRY(false,
|
||||
vkQueueSubmit(
|
||||
|
@ -64,14 +66,14 @@ bool vk_draw_frame(void) {
|
|||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||
.pNext = NULL,
|
||||
.waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &g_image_available_semaphores.data[g_current_frame],
|
||||
.pWaitSemaphores = &g_image_available_semaphores.data[m_current_frame],
|
||||
.pWaitDstStageMask = &(VkPipelineStageFlags){VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT},
|
||||
.commandBufferCount = 1,
|
||||
.pCommandBuffers = &g_command_buffers.data[g_current_frame],
|
||||
.pCommandBuffers = &g_command_buffers.data[m_current_frame],
|
||||
.signalSemaphoreCount = 1,
|
||||
.pSignalSemaphores = signal_semaphores,
|
||||
},
|
||||
g_in_flight_fences.data[g_current_frame]
|
||||
g_in_flight_fences.data[m_current_frame]
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -101,7 +103,7 @@ bool vk_draw_frame(void) {
|
|||
return false;
|
||||
}
|
||||
|
||||
g_current_frame = (g_current_frame + 1) % g_max_frames_in_flight;
|
||||
m_current_frame = (m_current_frame + 1) % g_max_frames_in_flight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
#endif
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
extern uint32_t g_current_frame;
|
||||
|
||||
void vk_framebuffer_resized(GLFWwindow *window, int width, int height);
|
||||
uint32_t vk_current_frame(void);
|
||||
|
||||
bool vk_draw_frame(void);
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ bool vk_record_command_buffer(const VkCommandBuffer command_buffer, const uint32
|
|||
|
||||
vkCmdBindIndexBuffer(command_buffer, m_index_buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
|
||||
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline_layout, 0, 1, &m_descriptor_sets.data[g_current_frame], 0, NULL);
|
||||
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline_layout, 0, 1, &m_descriptor_sets.data[vk_current_frame()], 0, NULL);
|
||||
|
||||
vkCmdDrawIndexed(command_buffer, g_indices.size, 1, 0, 0, 0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue