Skip to content

Commit

Permalink
[Vulkan] Don't skip drawing when there's no vertexes to ensure that u…
Browse files Browse the repository at this point in the history
…ser callbacks are still processed.
  • Loading branch information
kudaba committed Sep 17, 2019
1 parent 8478cc6 commit 4fb09ae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/imgui_impl_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkCommandBu
}

// Bind Vertex And Index Buffer:
if (draw_data->TotalVtxCount > 0)
{
VkBuffer vertex_buffers[1] = { rb->VertexBuffer };
VkDeviceSize vertex_offset[1] = { 0 };
Expand Down Expand Up @@ -320,7 +321,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount == 0)
if (fb_width <= 0 || fb_height <= 0)
return;

ImGuiIO& io = ImGui::GetIO();
Expand All @@ -344,12 +345,14 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
// Create or resize the vertex/index buffers
size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);

if (rb->VertexBuffer == VK_NULL_HANDLE || rb->VertexBufferSize < vertex_size)
CreateOrResizeBuffer(rb->VertexBuffer, rb->VertexBufferMemory, rb->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
if (rb->IndexBuffer == VK_NULL_HANDLE || rb->IndexBufferSize < index_size)
CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);

// Upload vertex/index data into a single contiguous GPU buffer
if (vertex_size)
{
ImDrawVert* vtx_dst = NULL;
ImDrawIdx* idx_dst = NULL;
Expand Down

0 comments on commit 4fb09ae

Please sign in to comment.