@ -437,6 +437,17 @@ void ImDrawList::AddDrawCmd()
CmdBuffer . push_back ( draw_cmd ) ;
CmdBuffer . push_back ( draw_cmd ) ;
}
}
// Pop trailing draw command (used before merging or presenting to user)
// Note that this leaves the ImDrawList in a state unfit for further commands, as most code assume that CmdBuffer.Size > 0 && CmdBuffer.back().UserCallback == NULL
void ImDrawList : : PopUnusedDrawCmd ( )
{
if ( CmdBuffer . Size = = 0 )
return ;
ImDrawCmd * curr_cmd = & CmdBuffer . Data [ CmdBuffer . Size - 1 ] ;
if ( curr_cmd - > ElemCount = = 0 & & curr_cmd - > UserCallback = = NULL )
CmdBuffer . pop_back ( ) ;
}
void ImDrawList : : AddCallback ( ImDrawCallback callback , void * callback_data )
void ImDrawList : : AddCallback ( ImDrawCallback callback , void * callback_data )
{
{
ImDrawCmd * curr_cmd = & CmdBuffer . Data [ CmdBuffer . Size - 1 ] ;
ImDrawCmd * curr_cmd = & CmdBuffer . Data [ CmdBuffer . Size - 1 ] ;
@ -1362,13 +1373,12 @@ void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
void ImDrawListSplitter : : Merge ( ImDrawList * draw_list )
void ImDrawListSplitter : : Merge ( ImDrawList * draw_list )
{
{
// Note that we never use or rely on c hannels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
// Note that we never use or rely on _C hannels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
if ( _Count < = 1 )
if ( _Count < = 1 )
return ;
return ;
SetCurrentChannel ( draw_list , 0 ) ;
SetCurrentChannel ( draw_list , 0 ) ;
if ( draw_list - > CmdBuffer . Size ! = 0 & & draw_list - > CmdBuffer . back ( ) . ElemCount = = 0 )
draw_list - > PopUnusedDrawCmd ( ) ;
draw_list - > CmdBuffer . pop_back ( ) ;
// Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
// Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
int new_cmd_buffer_count = 0 ;
int new_cmd_buffer_count = 0 ;
@ -1378,8 +1388,11 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list)
for ( int i = 1 ; i < _Count ; i + + )
for ( int i = 1 ; i < _Count ; i + + )
{
{
ImDrawChannel & ch = _Channels [ i ] ;
ImDrawChannel & ch = _Channels [ i ] ;
// Equivalent of PopUnusedDrawCmd() for this channel's cmdbuffer and except we don't need to test for UserCallback.
if ( ch . _CmdBuffer . Size > 0 & & ch . _CmdBuffer . back ( ) . ElemCount = = 0 )
if ( ch . _CmdBuffer . Size > 0 & & ch . _CmdBuffer . back ( ) . ElemCount = = 0 )
ch . _CmdBuffer . pop_back ( ) ;
ch . _CmdBuffer . pop_back ( ) ;
if ( ch . _CmdBuffer . Size > 0 & & last_cmd ! = NULL )
if ( ch . _CmdBuffer . Size > 0 & & last_cmd ! = NULL )
{
{
ImDrawCmd * next_cmd = & ch . _CmdBuffer [ 0 ] ;
ImDrawCmd * next_cmd = & ch . _CmdBuffer [ 0 ] ;