Added ImDrawList::SplitDrawCmd() to force multiple draw calls for depending rendering/blending + Comments

This commit is contained in:
ocornut 2015-01-31 09:51:25 +00:00
parent 64679a0b03
commit 4437293b79
2 changed files with 22 additions and 9 deletions

View File

@ -6039,6 +6039,17 @@ void ImDrawList::Clear()
texture_id_stack.resize(0); texture_id_stack.resize(0);
} }
// This is useful if you need to force-create a new draw call (to allow for depending rendering / blending).
// Otherwise primitives are merged into the same draw-call as much as possible.
void ImDrawList::SplitDrawCmd()
{
ImDrawCmd draw_cmd;
draw_cmd.vtx_count = 0;
draw_cmd.clip_rect = clip_rect_stack.back();
draw_cmd.texture_id = texture_id_stack.back();
commands.push_back(draw_cmd);
}
void ImDrawList::SetClipRect(const ImVec4& clip_rect) void ImDrawList::SetClipRect(const ImVec4& clip_rect)
{ {
ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back(); ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
@ -6060,8 +6071,8 @@ void ImDrawList::SetClipRect(const ImVec4& clip_rect)
void ImDrawList::PushClipRect(const ImVec4& clip_rect) void ImDrawList::PushClipRect(const ImVec4& clip_rect)
{ {
SetClipRect(clip_rect);
clip_rect_stack.push_back(clip_rect); clip_rect_stack.push_back(clip_rect);
SetClipRect(clip_rect);
} }
void ImDrawList::PopClipRect() void ImDrawList::PopClipRect()
@ -6093,8 +6104,8 @@ void ImDrawList::SetTextureID(const ImTextureID& texture_id)
void ImDrawList::PushTextureID(const ImTextureID& texture_id) void ImDrawList::PushTextureID(const ImTextureID& texture_id)
{ {
SetTextureID(texture_id);
texture_id_stack.push_back(texture_id); texture_id_stack.push_back(texture_id);
SetTextureID(texture_id);
} }
void ImDrawList::PopTextureID() void ImDrawList::PopTextureID()

16
imgui.h
View File

@ -696,11 +696,12 @@ struct ImGuiTextEditCallbackData
// Hold a series of drawing commands. The user provides a renderer for ImDrawList // Hold a series of drawing commands. The user provides a renderer for ImDrawList
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Typically, One ImDrawCmd = One GPU draw call
struct ImDrawCmd struct ImDrawCmd
{ {
unsigned int vtx_count; unsigned int vtx_count; // Number of vertices (multiple of 3) to be drawn. The vertices are stored in the callee ImDrawList's vtx_buffer[] array
ImVec4 clip_rect; ImVec4 clip_rect; // Clipping rectangle (x1, y1, x2, y2)
ImTextureID texture_id; // Copy of user-provided 'TexID' from ImFont or passed to Image*() functions. Ignore if not using images or multiple fonts. ImTextureID texture_id; // Copy of user-provided 'TexID' from ImFont or passed to Image*() functions. Ignore if not using images or multiple fonts
}; };
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT #ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
@ -719,16 +720,16 @@ IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
#endif #endif
// Draw command list // Draw command list
// This is the low-level list of polygon that ImGui:: functions are creating. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering. // This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged. // At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
// If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives. // If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
// You can interleave normal ImGui:: calls and adding primitives to the current draw list. // You can interleave normal ImGui:: calls and adding primitives to the current draw list.
// Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl // Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
struct ImDrawList struct ImDrawList
{ {
// This is what you have to render // This is what you have to render
ImVector<ImDrawCmd> commands; // commands ImVector<ImDrawCmd> commands; // Commands. Typically 1 command = 1 draw call.
ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those ImVector<ImDrawVert> vtx_buffer; // Vertex buffer. Each command consume ImDrawCmd::vtx_count of those
// [Internal to ImGui] // [Internal to ImGui]
ImVector<ImVec4> clip_rect_stack; // [internal] ImVector<ImVec4> clip_rect_stack; // [internal]
@ -748,6 +749,7 @@ struct ImDrawList
IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col); IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv); IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col); IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
IMGUI_API void SplitDrawCmd(); // This is useful if you need to force-create a new draw call (to allow for depending rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
// Primitives // Primitives
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);