MCPcopy Create free account
hub / github.com/RenderKit/embree / Merge

Method Merge

tutorials/common/imgui/imgui_draw.cpp:1710–1779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1708}
1709
1710void ImDrawListSplitter::Merge(ImDrawList* draw_list)
1711{
1712 // Note that we never use or rely on _Channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
1713 if (_Count <= 1)
1714 return;
1715
1716 SetCurrentChannel(draw_list, 0);
1717 draw_list->_PopUnusedDrawCmd();
1718
1719 // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
1720 int new_cmd_buffer_count = 0;
1721 int new_idx_buffer_count = 0;
1722 ImDrawCmd* last_cmd = (_Count > 0 && draw_list->CmdBuffer.Size > 0) ? &draw_list->CmdBuffer.back() : NULL;
1723 int idx_offset = last_cmd ? last_cmd->IdxOffset + last_cmd->ElemCount : 0;
1724 for (int i = 1; i < _Count; i++)
1725 {
1726 ImDrawChannel& ch = _Channels[i];
1727 if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0 && ch._CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd()
1728 ch._CmdBuffer.pop_back();
1729
1730 if (ch._CmdBuffer.Size > 0 && last_cmd != NULL)
1731 {
1732 // Do not include ImDrawCmd_AreSequentialIdxOffset() in the compare as we rebuild IdxOffset values ourselves.
1733 // Manipulating IdxOffset (e.g. by reordering draw commands like done by RenderDimmedBackgroundBehindWindow()) is not supported within a splitter.
1734 ImDrawCmd* next_cmd = &ch._CmdBuffer[0];
1735 if (ImDrawCmd_HeaderCompare(last_cmd, next_cmd) == 0 && last_cmd->UserCallback == NULL && next_cmd->UserCallback == NULL)
1736 {
1737 // Merge previous channel last draw command with current channel first draw command if matching.
1738 last_cmd->ElemCount += next_cmd->ElemCount;
1739 idx_offset += next_cmd->ElemCount;
1740 ch._CmdBuffer.erase(ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges.
1741 }
1742 }
1743 if (ch._CmdBuffer.Size > 0)
1744 last_cmd = &ch._CmdBuffer.back();
1745 new_cmd_buffer_count += ch._CmdBuffer.Size;
1746 new_idx_buffer_count += ch._IdxBuffer.Size;
1747 for (int cmd_n = 0; cmd_n < ch._CmdBuffer.Size; cmd_n++)
1748 {
1749 ch._CmdBuffer.Data[cmd_n].IdxOffset = idx_offset;
1750 idx_offset += ch._CmdBuffer.Data[cmd_n].ElemCount;
1751 }
1752 }
1753 draw_list->CmdBuffer.resize(draw_list->CmdBuffer.Size + new_cmd_buffer_count);
1754 draw_list->IdxBuffer.resize(draw_list->IdxBuffer.Size + new_idx_buffer_count);
1755
1756 // Write commands and indices in order (they are fairly small structures, we don't copy vertices only indices)
1757 ImDrawCmd* cmd_write = draw_list->CmdBuffer.Data + draw_list->CmdBuffer.Size - new_cmd_buffer_count;
1758 ImDrawIdx* idx_write = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size - new_idx_buffer_count;
1759 for (int i = 1; i < _Count; i++)
1760 {
1761 ImDrawChannel& ch = _Channels[i];
1762 if (int sz = ch._CmdBuffer.Size) { memcpy(cmd_write, ch._CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; }
1763 if (int sz = ch._IdxBuffer.Size) { memcpy(idx_write, ch._IdxBuffer.Data, sz * sizeof(ImDrawIdx)); idx_write += sz; }
1764 }
1765 draw_list->_IdxWritePtr = idx_write;
1766
1767 // Ensure there's always a non-callback draw command trailing the command-buffer

Callers 3

EndTableMethod · 0.80
EndColumnsMethod · 0.80
ChannelsMergeMethod · 0.80

Calls 4

_PopUnusedDrawCmdMethod · 0.80
AddDrawCmdMethod · 0.80
pop_backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected