|
3 | 3 |
|
4 | 4 | // Implemented features:
|
5 | 5 | // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
|
| 6 | +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. |
6 | 7 |
|
7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
8 | 9 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
|
9 | 10 | // https://github.com/ocornut/imgui
|
10 | 11 |
|
11 | 12 | // CHANGELOG
|
12 | 13 | // (minor and older changes stripped away, please see git history for details)
|
| 14 | +// 2019-05-29: Metal: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag. |
13 | 15 | // 2019-04-30: Metal: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
14 | 16 | // 2019-02-11: Metal: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
15 | 17 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
@@ -76,6 +78,7 @@ bool ImGui_ImplMetal_Init(id<MTLDevice> device)
|
76 | 78 | {
|
77 | 79 | ImGuiIO& io = ImGui::GetIO();
|
78 | 80 | io.BackendRendererName = "imgui_impl_metal";
|
| 81 | + io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; |
79 | 82 |
|
80 | 83 | static dispatch_once_t onceToken;
|
81 | 84 | dispatch_once(&onceToken, ^{
|
@@ -478,13 +481,10 @@ - (void)renderDrawData:(ImDrawData *)drawData
|
478 | 481 | for (int n = 0; n < drawData->CmdListsCount; n++)
|
479 | 482 | {
|
480 | 483 | const ImDrawList* cmd_list = drawData->CmdLists[n];
|
481 |
| - ImDrawIdx idx_buffer_offset = 0; |
482 | 484 |
|
483 | 485 | memcpy((char *)vertexBuffer.buffer.contents + vertexBufferOffset, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
|
484 | 486 | memcpy((char *)indexBuffer.buffer.contents + indexBufferOffset, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
|
485 | 487 |
|
486 |
| - [commandEncoder setVertexBufferOffset:vertexBufferOffset atIndex:0]; |
487 |
| - |
488 | 488 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
489 | 489 | {
|
490 | 490 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
@@ -522,14 +522,15 @@ - (void)renderDrawData:(ImDrawData *)drawData
|
522 | 522 | // Bind texture, Draw
|
523 | 523 | if (pcmd->TextureId != NULL)
|
524 | 524 | [commandEncoder setFragmentTexture:(__bridge id<MTLTexture>)(pcmd->TextureId) atIndex:0];
|
| 525 | + |
| 526 | + [commandEncoder setVertexBufferOffset:(vertexBufferOffset + pcmd->VtxOffset * sizeof(ImDrawVert)) atIndex:0]; |
525 | 527 | [commandEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
|
526 | 528 | indexCount:pcmd->ElemCount
|
527 | 529 | indexType:sizeof(ImDrawIdx) == 2 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32
|
528 | 530 | indexBuffer:indexBuffer.buffer
|
529 |
| - indexBufferOffset:indexBufferOffset + idx_buffer_offset]; |
| 531 | + indexBufferOffset:indexBufferOffset + pcmd->IdxOffset * sizeof(ImDrawIdx)]; |
530 | 532 | }
|
531 | 533 | }
|
532 |
| - idx_buffer_offset += pcmd->ElemCount * sizeof(ImDrawIdx); |
533 | 534 | }
|
534 | 535 |
|
535 | 536 | vertexBufferOffset += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
|
0 commit comments