mirror of
https://github.com/xemu-project/imgui.git
synced 2024-11-23 10:19:46 +00:00
ImDrawList: Tweaks to make style consistent (using pointers, same local names). Added comments. Should be no-op.
This commit is contained in:
parent
e22e3f300a
commit
003153b3ac
@ -4077,15 +4077,15 @@ static void AddWindowToSortBuffer(ImVector<ImGuiWindow*>* out_sorted_windows, Im
|
||||
|
||||
static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* draw_list)
|
||||
{
|
||||
if (draw_list->CmdBuffer.empty())
|
||||
if (draw_list->CmdBuffer.Size == 0)
|
||||
return;
|
||||
|
||||
// Remove trailing command if unused
|
||||
ImDrawCmd& last_cmd = draw_list->CmdBuffer.back();
|
||||
if (last_cmd.ElemCount == 0 && last_cmd.UserCallback == NULL)
|
||||
ImDrawCmd* curr_cmd = &draw_list->CmdBuffer.back();
|
||||
if (curr_cmd->ElemCount == 0 && curr_cmd->UserCallback == NULL)
|
||||
{
|
||||
draw_list->CmdBuffer.pop_back();
|
||||
if (draw_list->CmdBuffer.empty())
|
||||
if (draw_list->CmdBuffer.Size == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
|
20
imgui.h
20
imgui.h
@ -1878,13 +1878,13 @@ typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* c
|
||||
// is enabled, those fields allow us to render meshes larger than 64K vertices while keeping 16-bit indices.
|
||||
struct ImDrawCmd
|
||||
{
|
||||
unsigned int ElemCount; // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[].
|
||||
ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates
|
||||
ImTextureID TextureId; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
|
||||
unsigned int VtxOffset; // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0. With ImGuiBackendFlags_RendererHasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bit indices.
|
||||
unsigned int IdxOffset; // Start offset in index buffer. Always equal to sum of ElemCount drawn so far.
|
||||
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
||||
void* UserCallbackData; // The draw callback code can access this.
|
||||
unsigned int ElemCount; // 4 // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[].
|
||||
ImVec4 ClipRect; // 4*4 // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates
|
||||
ImTextureID TextureId; // 4-8 // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
|
||||
unsigned int VtxOffset; // 4 // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0. With ImGuiBackendFlags_RendererHasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bit indices.
|
||||
unsigned int IdxOffset; // 4 // Start offset in index buffer. Always equal to sum of ElemCount drawn so far.
|
||||
ImDrawCallback UserCallback; // 4-8 // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
||||
void* UserCallbackData; // 4-8 // The draw callback code can access this.
|
||||
|
||||
ImDrawCmd() { ElemCount = 0; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; }
|
||||
};
|
||||
@ -1984,7 +1984,7 @@ struct ImDrawList
|
||||
ImVector<ImVec4> _ClipRectStack; // [Internal]
|
||||
ImVector<ImTextureID> _TextureIdStack; // [Internal]
|
||||
ImVector<ImVec2> _Path; // [Internal] current path building
|
||||
ImDrawListSplitter _Splitter; // [Internal] for channels api
|
||||
ImDrawListSplitter _Splitter; // [Internal] for channels api (note: prefer using your own persistent instance of ImDrawListSplitter!)
|
||||
|
||||
// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui)
|
||||
ImDrawList(const ImDrawListSharedData* shared_data) { _Data = shared_data; _OwnerName = NULL; Clear(); }
|
||||
@ -2048,13 +2048,13 @@ struct ImDrawList
|
||||
// - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit FG primitives before BG primitives)
|
||||
// - Use to minimize draw calls (e.g. if going back-and-forth between multiple clipping rectangles, prefer to append into separate channels then merge at the end)
|
||||
// - FIXME-OBSOLETE: This API shouldn't have been in ImDrawList in the first place!
|
||||
// Prefer using your own persistent copy of ImDrawListSplitter as you can stack them.
|
||||
// Prefer using your own persistent instance of ImDrawListSplitter as you can stack them.
|
||||
// Using the ImDrawList::ChannelsXXXX you cannot stack a split over another.
|
||||
inline void ChannelsSplit(int count) { _Splitter.Split(this, count); }
|
||||
inline void ChannelsMerge() { _Splitter.Merge(this); }
|
||||
inline void ChannelsSetCurrent(int n) { _Splitter.SetCurrentChannel(this, n); }
|
||||
|
||||
// Internal helpers
|
||||
// [Internal helpers]
|
||||
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
|
||||
IMGUI_API void Clear();
|
||||
IMGUI_API void ClearFreeMemory();
|
||||
|
@ -434,14 +434,14 @@ void ImDrawList::AddDrawCmd()
|
||||
|
||||
void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
|
||||
{
|
||||
ImDrawCmd* current_cmd = CmdBuffer.Size ? &CmdBuffer.back() : NULL;
|
||||
if (!current_cmd || current_cmd->ElemCount != 0 || current_cmd->UserCallback != NULL)
|
||||
ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size - 1] : NULL;
|
||||
if (!curr_cmd || curr_cmd->ElemCount != 0 || curr_cmd->UserCallback != NULL)
|
||||
{
|
||||
AddDrawCmd();
|
||||
current_cmd = &CmdBuffer.back();
|
||||
curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
}
|
||||
current_cmd->UserCallback = callback;
|
||||
current_cmd->UserCallbackData = callback_data;
|
||||
curr_cmd->UserCallback = callback;
|
||||
curr_cmd->UserCallbackData = callback_data;
|
||||
|
||||
AddDrawCmd(); // Force a new command after us (see comment below)
|
||||
}
|
||||
@ -452,7 +452,7 @@ void ImDrawList::UpdateClipRect()
|
||||
{
|
||||
// If current command is used with different settings we need to add a new command
|
||||
const ImVec4 curr_clip_rect = GetCurrentClipRect();
|
||||
ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size-1] : NULL;
|
||||
ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size - 1] : NULL;
|
||||
if (!curr_cmd || (curr_cmd->ElemCount != 0 && memcmp(&curr_cmd->ClipRect, &curr_clip_rect, sizeof(ImVec4)) != 0) || curr_cmd->UserCallback != NULL)
|
||||
{
|
||||
AddDrawCmd();
|
||||
@ -477,7 +477,7 @@ void ImDrawList::UpdateTextureID()
|
||||
{
|
||||
// If current command is used with different settings we need to add a new command
|
||||
const ImTextureID curr_texture_id = GetCurrentTextureId();
|
||||
ImDrawCmd* curr_cmd = CmdBuffer.Size ? &CmdBuffer.back() : NULL;
|
||||
ImDrawCmd* curr_cmd = CmdBuffer.Size > 0 ? &CmdBuffer.Data[CmdBuffer.Size - 1] : NULL;
|
||||
if (!curr_cmd || (curr_cmd->ElemCount != 0 && curr_cmd->TextureId != curr_texture_id) || curr_cmd->UserCallback != NULL)
|
||||
{
|
||||
AddDrawCmd();
|
||||
@ -559,8 +559,8 @@ void ImDrawList::PrimReserve(int idx_count, int vtx_count)
|
||||
AddDrawCmd();
|
||||
}
|
||||
|
||||
ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
draw_cmd.ElemCount += idx_count;
|
||||
ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
draw_cmd->ElemCount += idx_count;
|
||||
|
||||
int vtx_buffer_old_size = VtxBuffer.Size;
|
||||
VtxBuffer.resize(vtx_buffer_old_size + vtx_count);
|
||||
@ -576,8 +576,8 @@ void ImDrawList::PrimUnreserve(int idx_count, int vtx_count)
|
||||
{
|
||||
IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0);
|
||||
|
||||
ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
draw_cmd.ElemCount -= idx_count;
|
||||
ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
draw_cmd->ElemCount -= idx_count;
|
||||
VtxBuffer.shrink(VtxBuffer.Size - vtx_count);
|
||||
IdxBuffer.shrink(IdxBuffer.Size - idx_count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user