Important: 'out_list' is generally going to be draw_data->CmdLists, but may be another temporary list as long at it is expected that the result will be later merged into draw_data->CmdLists[].
| 2288 | // Important: 'out_list' is generally going to be draw_data->CmdLists, but may be another temporary list |
| 2289 | // as long at it is expected that the result will be later merged into draw_data->CmdLists[]. |
| 2290 | void ImGui::AddDrawListToDrawDataEx(ImDrawData* draw_data, ImVector<ImDrawList*>* out_list, ImDrawList* draw_list) |
| 2291 | { |
| 2292 | if (draw_list->CmdBuffer.Size == 0) |
| 2293 | return; |
| 2294 | if (draw_list->CmdBuffer.Size == 1 && draw_list->CmdBuffer[0].ElemCount == 0 && draw_list->CmdBuffer[0].UserCallback == NULL) |
| 2295 | return; |
| 2296 | |
| 2297 | // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. |
| 2298 | // May trigger for you if you are using PrimXXX functions incorrectly. |
| 2299 | IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size); |
| 2300 | IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size); |
| 2301 | if (!(draw_list->Flags & ImDrawListFlags_AllowVtxOffset)) |
| 2302 | IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); |
| 2303 | |
| 2304 | // Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window) |
| 2305 | // If this assert triggers because you are drawing lots of stuff manually: |
| 2306 | // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds. |
| 2307 | // Be mindful that the lower-level ImDrawList API doesn't filter vertices. Use the Metrics/Debugger window to inspect draw list contents. |
| 2308 | // - If you want large meshes with more than 64K vertices, you can either: |
| 2309 | // (A) Handle the ImDrawCmd::VtxOffset value in your renderer backend, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'. |
| 2310 | // Most example backends already support this from 1.71. Pre-1.71 backends won't. |
| 2311 | // 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. |
| 2312 | // (B) Or handle 32-bit indices in your renderer backend, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h. |
| 2313 | // Most example backends already support this. For example, the OpenGL example code detect index size at compile-time: |
| 2314 | // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); |
| 2315 | // Your own engine or render API may use different parameters or function calls to specify index sizes. |
| 2316 | // 2 and 4 bytes indices are generally supported by most graphics API. |
| 2317 | // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching |
| 2318 | // the 64K limit to split your draw commands in multiple draw lists. |
| 2319 | if (sizeof(ImDrawIdx) == 2) |
| 2320 | IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above"); |
| 2321 | |
| 2322 | // Resolve callback data pointers |
| 2323 | if (draw_list->_CallbacksDataBuf.Size > 0) |
| 2324 | for (ImDrawCmd& cmd : draw_list->CmdBuffer) |
| 2325 | if (cmd.UserCallback != NULL && cmd.UserCallbackDataOffset != -1 && cmd.UserCallbackDataSize > 0) |
| 2326 | cmd.UserCallbackData = draw_list->_CallbacksDataBuf.Data + cmd.UserCallbackDataOffset; |
| 2327 | |
| 2328 | // Add to output list + records state in ImDrawData |
| 2329 | out_list->push_back(draw_list); |
| 2330 | draw_data->CmdListsCount++; |
| 2331 | draw_data->TotalVtxCount += draw_list->VtxBuffer.Size; |
| 2332 | draw_data->TotalIdxCount += draw_list->IdxBuffer.Size; |
| 2333 | } |
| 2334 | |
| 2335 | void ImDrawData::AddDrawList(ImDrawList* draw_list) |
| 2336 | { |