You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bits indices. To enable the feature, the renderer back-end needs to set 'io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset' and honor the ImDrawCmd::VtxOffset field. Otherwise the value will always be zero. This has the advantage of preserving smaller index buffers and allowing to execute on hardware that do not support 32-bits indices.
ImDrawList: Added ImDrawCmd::IdxOffset value, equivalent to summing element count for each draw command. This is provided for convenience and consistency with VtxOffset. (#2591)
@@ -3774,19 +3780,28 @@ static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* d
3774
3780
return;
3775
3781
}
3776
3782
3777
-
// Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. May trigger for you if you are using PrimXXX functions incorrectly.
3783
+
// Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
3784
+
// May trigger for you if you are using PrimXXX functions incorrectly.
// Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window)
3783
3791
// If this assert triggers because you are drawing lots of stuff manually:
3784
-
// A) Make sure you are coarse clipping, because ImDrawList let all your vertices pass. You can use the Metrics window to inspect draw list contents.
3785
-
// B) If you need/want meshes with more than 64K vertices, uncomment the '#define ImDrawIdx unsigned int' line in imconfig.h to set the index size to 4 bytes.
3786
-
// You'll need to handle the 4-bytes indices to your renderer. For example, the OpenGL example code detect index size at compile-time by doing:
// Your own engine or render API may use different parameters or function calls to specify index sizes. 2 and 4 bytes indices are generally supported by most API.
3789
-
// C) If for some reason you cannot use 4 bytes indices or don't want to, a workaround is to call BeginChild()/EndChild() before reaching the 64K limit to split your draw commands in multiple draw lists.
3792
+
// - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds.
3793
+
// Be mindful that the ImDrawList API doesn't filter vertices. Use the Metrics window to inspect draw list contents.
3794
+
// - If you want large meshes with more than 64K vertices, you can either:
3795
+
// (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset'.
3796
+
// Most example back-ends already support this from 1.71. Pre-1.71 back-ends won't.
3797
+
// Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them.
3798
+
// (B) Or handle 32-bits indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
3799
+
// Most example back-ends already support this. For example, the OpenGL example code detect index size at compile-time:
Copy file name to clipboardExpand all lines: imgui.h
+18-9Lines changed: 18 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Index of this file:
47
47
// Version
48
48
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
// Define attributes of all API symbols declarations (e.g. for DLL under Windows)
@@ -1003,9 +1003,10 @@ enum ImGuiConfigFlags_
1003
1003
enum ImGuiBackendFlags_
1004
1004
{
1005
1005
ImGuiBackendFlags_None = 0,
1006
-
ImGuiBackendFlags_HasGamepad = 1 << 0, // Back-end supports gamepad and currently has one connected.
1007
-
ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Back-end supports honoring GetMouseCursor() value to change the OS cursor shape.
1008
-
ImGuiBackendFlags_HasSetMousePos = 1 << 2// Back-end supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
1006
+
ImGuiBackendFlags_HasGamepad = 1 << 0, // Platform Back-end supports gamepad and currently has one connected.
1007
+
ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Platform Back-end supports honoring GetMouseCursor() value to change the OS cursor shape.
1008
+
ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Platform Back-end supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
1009
+
ImGuiBackendFlags_HasVtxOffset = 1 << 3// Renderer Back-end supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bits indices.
1009
1010
};
1010
1011
1011
1012
// Enumeration for PushStyleColor() / PopStyleColor()
@@ -1771,25 +1772,31 @@ struct ImColor
1771
1772
// The expected behavior from your rendering function is 'if (cmd.UserCallback != NULL) { cmd.UserCallback(parent_list, cmd); } else { RenderTriangles() }'
// Special Draw Callback value to request renderer back-end to reset the graphics/render state.
1775
+
// Special Draw callback value to request renderer back-end to reset the graphics/render state.
1775
1776
// The renderer back-end needs to handle this special value, otherwise it will crash trying to call a function at this address.
1776
1777
// This is useful for example if you submitted callbacks which you know have altered the render state and you want it to be restored.
1777
1778
// It is not done by default because they are many perfectly useful way of altering render state for imgui contents (e.g. changing shader/blending settings before an Image call).
// Typically, 1 command = 1 GPU draw call (unless command is a callback)
1782
+
// Pre 1.71 back-ends will typically ignore the VtxOffset/IdxOffset fields. When (io.BackendFlags & ImGuiBackendFlags_HasVtxOffset)
1783
+
// is enabled, those fields allow us to render meshes larger than 64K vertices while keeping 16-bits indices.
1781
1784
structImDrawCmd
1782
1785
{
1783
1786
unsignedint 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[].
1784
1787
ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates
1785
1788
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.
1789
+
unsignedint VtxOffset; // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_HasVtxOffset: always 0. With ImGuiBackendFlags_HasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bits indices.
1790
+
unsignedint IdxOffset; // Start offset in index buffer. Always equal to sum of ElemCount drawn so far.
1786
1791
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
1787
1792
void* UserCallbackData; // The draw callback code can access this.
// Vertex index (override with '#define ImDrawIdx unsigned int' in imconfig.h)
1797
+
// Vertex index
1798
+
// (to allow large meshes with 16-bits indices: set 'io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end)
1799
+
// (to use 32-bits indices: override with '#define ImDrawIdx unsigned int' in imconfig.h)
1793
1800
#ifndef ImDrawIdx
1794
1801
typedefunsignedshort ImDrawIdx;
1795
1802
#endif
@@ -1835,7 +1842,8 @@ enum ImDrawListFlags_
1835
1842
{
1836
1843
ImDrawListFlags_None = 0,
1837
1844
ImDrawListFlags_AntiAliasedLines = 1 << 0, // Lines are anti-aliased (*2 the number of triangles for 1.0f wide line, otherwise *3 the number of triangles)
1838
-
ImDrawListFlags_AntiAliasedFill = 1 << 1// Filled shapes have anti-aliased edges (*2 the number of vertices)
1845
+
ImDrawListFlags_AntiAliasedFill = 1 << 1, // Filled shapes have anti-aliased edges (*2 the number of vertices)
1846
+
ImDrawListFlags_AllowVtxOffset = 1 << 2// Can emit 'VtxOffset > 0' to allow large meshes. Set when 'io.BackendFlags & ImGuiBackendFlags_HasVtxOffset' is enabled.
1839
1847
};
1840
1848
1841
1849
// Draw command list
@@ -1855,7 +1863,8 @@ struct ImDrawList
1855
1863
// [Internal, used while building lists]
1856
1864
const ImDrawListSharedData* _Data; // Pointer to shared draw data (you can use ImGui::GetDrawListSharedData() to get the one from current ImGui context)
1857
1865
constchar* _OwnerName; // Pointer to owner window's name for debugging
0 commit comments