Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack. The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only.
| 449 | // Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack. |
| 450 | // The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only. |
| 451 | void ImDrawList::UpdateClipRect() |
| 452 | { |
| 453 | // If current command is used with different settings we need to add a new command |
| 454 | const ImVec4 curr_clip_rect = GetCurrentClipRect(); |
| 455 | ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size-1] : NULL; |
| 456 | if (!curr_cmd || (curr_cmd->ElemCount != 0 && memcmp(&curr_cmd->ClipRect, &curr_clip_rect, sizeof(ImVec4)) != 0) || curr_cmd->UserCallback != NULL) |
| 457 | { |
| 458 | AddDrawCmd(); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | // Try to merge with previous command if it matches, else use current command |
| 463 | ImDrawCmd* prev_cmd = CmdBuffer.Size > 1 ? curr_cmd - 1 : NULL; |
| 464 | if (curr_cmd->ElemCount == 0 && prev_cmd && memcmp(&prev_cmd->ClipRect, &curr_clip_rect, sizeof(ImVec4)) == 0 && prev_cmd->TextureId == GetCurrentTextureId() && prev_cmd->UserCallback == NULL) |
| 465 | CmdBuffer.pop_back(); |
| 466 | else |
| 467 | curr_cmd->ClipRect = curr_clip_rect; |
| 468 | } |
| 469 | |
| 470 | void ImDrawList::UpdateTextureID() |
| 471 | { |