Skip to content

Commit

Permalink
Imgui fixes (bkaradzic#2720)
Browse files Browse the repository at this point in the history
* Pass Meta key modifier to ImGui

* Use index offset provided by ImGui

* Use vertex offset provided by ImGui

We need to tell ImGui we can support per-draw vertex offsets. Useful for
complex widgets like implot.
  • Loading branch information
pezcode authored and Michael Pekar committed Mar 2, 2024
1 parent b1288c1 commit 36a797c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/common/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ struct OcornutImguiContext

bgfx::Encoder* encoder = bgfx::begin();

uint32_t offset = 0;
for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd)
{
if (cmd->UserCallback)
Expand Down Expand Up @@ -176,13 +175,11 @@ struct OcornutImguiContext

encoder->setState(state);
encoder->setTexture(0, s_tex, th);
encoder->setVertexBuffer(0, &tvb, 0, numVertices);
encoder->setIndexBuffer(&tib, offset, cmd->ElemCount);
encoder->setVertexBuffer(0, &tvb, cmd->VtxOffset, numVertices);
encoder->setIndexBuffer(&tib, cmd->IdxOffset, cmd->ElemCount);
encoder->submit(m_viewId, program);
}
}

offset += cmd->ElemCount;
}

bgfx::end(encoder);
Expand Down Expand Up @@ -215,6 +212,8 @@ struct OcornutImguiContext

setupStyle(true);

io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;

#if USE_ENTRY
io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab;
io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left;
Expand Down Expand Up @@ -400,6 +399,7 @@ struct OcornutImguiContext
io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) );
io.KeySuper = 0 != (modifiers & (entry::Modifier::LeftMeta | entry::Modifier::RightMeta ) );
for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
{
io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
Expand Down

0 comments on commit 36a797c

Please sign in to comment.