Skip to content

Commit b3dd03f

Browse files
committed
Examples/Backends: DirectX9/10/11/12, Vulkan, OpenGL3 (Desktop GL only): Added support for large meshes (64k+ vertices) with 16-bits indices, enable 'ImGuiBackendFlags_HasVtxOffset' config flag in back-end. (#2591)
1 parent d1e8b69 commit b3dd03f

13 files changed

+69
-28
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Other Changes:
7171
- Backends: Add native Mac clipboard copy/paste default implementation in core library to match what we are
7272
dealing with Win32, and to facilitate integration in custom engines. (#2546) [@andrewwillmott]
7373
- Backends: OSX: imgui_impl_osx: Added mouse cursor support. (#2585, #1873) [@actboy168]
74+
- Examples/Backends: DirectX9/10/11/12, Vulkan, OpenGL3 (Desktop GL only): Added support for large meshes
75+
(64k+ vertices) with 16-bits indices, enable 'ImGuiBackendFlags_HasVtxOffset' config flag in back-end.
7476
- Examples/Backends: Don't filter characters under 0x10000 before calling io.AddInputCharacter(),
7577
the filtering is done in io.AddInputCharacter() itself. This is in prevision for fuller Unicode
7678
support. (#2538, #2541)

examples/imgui_impl_dx10.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
910
// https://github.com/ocornut/imgui
1011

1112
// CHANGELOG
1213
// (minor and older changes stripped away, please see git history for details)
14+
// 2019-05-29: DirectX10: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
1315
// 2019-04-30: DirectX10: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
1416
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
1517
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
@@ -208,8 +210,9 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
208210
ImGui_ImplDX10_SetupRenderState(draw_data, ctx);
209211

210212
// Render command lists
211-
int vtx_offset = 0;
212-
int idx_offset = 0;
213+
// (Because we merged all buffers into a single one, we maintain our own offset into them)
214+
int global_vtx_offset = 0;
215+
int global_idx_offset = 0;
213216
ImVec2 clip_off = draw_data->DisplayPos;
214217
for (int n = 0; n < draw_data->CmdListsCount; n++)
215218
{
@@ -235,11 +238,11 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
235238
// Bind texture, Draw
236239
ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->TextureId;
237240
ctx->PSSetShaderResources(0, 1, &texture_srv);
238-
ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
241+
ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
239242
}
240-
idx_offset += pcmd->ElemCount;
241243
}
242-
vtx_offset += cmd_list->VtxBuffer.Size;
244+
global_idx_offset += cmd_list->IdxBuffer.Size;
245+
global_vtx_offset += cmd_list->VtxBuffer.Size;
243246
}
244247

245248
// Restore modified DX state
@@ -485,6 +488,7 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
485488
{
486489
ImGuiIO& io = ImGui::GetIO();
487490
io.BackendRendererName = "imgui_impl_dx10";
491+
io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
488492

489493
// Get factory from device
490494
IDXGIDevice* pDXGIDevice = NULL;

examples/imgui_impl_dx10.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.

examples/imgui_impl_dx11.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp
910
// https://github.com/ocornut/imgui
1011

1112
// CHANGELOG
1213
// (minor and older changes stripped away, please see git history for details)
14+
// 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
1315
// 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
1416
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
1517
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
@@ -213,8 +215,9 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
213215
ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
214216

215217
// Render command lists
216-
int vtx_offset = 0;
217-
int idx_offset = 0;
218+
// (Because we merged all buffers into a single one, we maintain our own offset into them)
219+
int global_idx_offset = 0;
220+
int global_vtx_offset = 0;
218221
ImVec2 clip_off = draw_data->DisplayPos;
219222
for (int n = 0; n < draw_data->CmdListsCount; n++)
220223
{
@@ -240,11 +243,11 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
240243
// Bind texture, Draw
241244
ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->TextureId;
242245
ctx->PSSetShaderResources(0, 1, &texture_srv);
243-
ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
246+
ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
244247
}
245-
idx_offset += pcmd->ElemCount;
246248
}
247-
vtx_offset += cmd_list->VtxBuffer.Size;
249+
global_idx_offset += cmd_list->IdxBuffer.Size;
250+
global_vtx_offset += cmd_list->VtxBuffer.Size;
248251
}
249252

250253
// Restore modified DX state
@@ -492,6 +495,7 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
492495
{
493496
ImGuiIO& io = ImGui::GetIO();
494497
io.BackendRendererName = "imgui_impl_dx11";
498+
io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
495499

496500
// Get factory from device
497501
IDXGIDevice* pDXGIDevice = NULL;

examples/imgui_impl_dx11.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.

examples/imgui_impl_dx12.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67
// Issues:
78
// [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301
89

@@ -12,6 +13,7 @@
1213

1314
// CHANGELOG
1415
// (minor and older changes stripped away, please see git history for details)
16+
// 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
1517
// 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
1618
// 2019-03-29: Misc: Various minor tidying up.
1719
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
@@ -200,8 +202,9 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
200202
ImGui_ImplDX12_SetupRenderState(draw_data, ctx, fr);
201203

202204
// Render command lists
203-
int vtx_offset = 0;
204-
int idx_offset = 0;
205+
// (Because we merged all buffers into a single one, we maintain our own offset into them)
206+
int global_vtx_offset = 0;
207+
int global_idx_offset = 0;
205208
ImVec2 clip_off = draw_data->DisplayPos;
206209
for (int n = 0; n < draw_data->CmdListsCount; n++)
207210
{
@@ -224,11 +227,11 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
224227
const D3D12_RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y) };
225228
ctx->SetGraphicsRootDescriptorTable(1, *(D3D12_GPU_DESCRIPTOR_HANDLE*)&pcmd->TextureId);
226229
ctx->RSSetScissorRects(1, &r);
227-
ctx->DrawIndexedInstanced(pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
230+
ctx->DrawIndexedInstanced(pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
228231
}
229-
idx_offset += pcmd->ElemCount;
230232
}
231-
vtx_offset += cmd_list->VtxBuffer.Size;
233+
global_idx_offset += cmd_list->IdxBuffer.Size;
234+
global_vtx_offset += cmd_list->VtxBuffer.Size;
232235
}
233236
}
234237

@@ -604,6 +607,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
604607
{
605608
ImGuiIO& io = ImGui::GetIO();
606609
io.BackendRendererName = "imgui_impl_dx12";
610+
io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
607611

608612
g_pd3dDevice = device;
609613
g_RTVFormat = rtv_format;

examples/imgui_impl_dx12.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67
// Issues:
78
// [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301
89

examples/imgui_impl_dx9.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
910
// https://github.com/ocornut/imgui
1011

1112
// CHANGELOG
1213
// (minor and older changes stripped away, please see git history for details)
14+
// 2019-05-29: DirectX9: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
1315
// 2019-04-30: DirectX9: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
1416
// 2019-03-29: Misc: Fixed erroneous assert in ImGui_ImplDX9_InvalidateDeviceObjects().
1517
// 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
@@ -172,8 +174,9 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
172174
ImGui_ImplDX9_SetupRenderState(draw_data);
173175

174176
// Render command lists
175-
int vtx_offset = 0;
176-
int idx_offset = 0;
177+
// (Because we merged all buffers into a single one, we maintain our own offset into them)
178+
int global_vtx_offset = 0;
179+
int global_idx_offset = 0;
177180
ImVec2 clip_off = draw_data->DisplayPos;
178181
for (int n = 0; n < draw_data->CmdListsCount; n++)
179182
{
@@ -196,11 +199,11 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
196199
const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->TextureId;
197200
g_pd3dDevice->SetTexture(0, texture);
198201
g_pd3dDevice->SetScissorRect(&r);
199-
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, idx_offset, pcmd->ElemCount/3);
202+
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, pcmd->VtxOffset + global_vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, pcmd->IdxOffset + global_idx_offset, pcmd->ElemCount/3);
200203
}
201-
idx_offset += pcmd->ElemCount;
202204
}
203-
vtx_offset += cmd_list->VtxBuffer.Size;
205+
global_idx_offset += cmd_list->IdxBuffer.Size;
206+
global_vtx_offset += cmd_list->VtxBuffer.Size;
204207
}
205208

206209
// Restore the DX9 transform
@@ -217,6 +220,7 @@ bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
217220
{
218221
ImGuiIO& io = ImGui::GetIO();
219222
io.BackendRendererName = "imgui_impl_dx9";
223+
io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
220224

221225
g_pd3dDevice = device;
222226
g_pd3dDevice->AddRef();

examples/imgui_impl_dx9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
6+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
67

78
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
89
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.

examples/imgui_impl_opengl3.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
// Implemented features:
77
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
8+
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices.
89

910
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
1011
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
1112
// https://github.com/ocornut/imgui
1213

1314
// CHANGELOG
1415
// (minor and older changes stripped away, please see git history for details)
16+
// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
1517
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
1618
// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
1719
// 2019-03-15: OpenGL: Added a dummy GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
@@ -102,6 +104,13 @@
102104
#endif
103105
#endif
104106

107+
// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
108+
#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
109+
#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 1
110+
#else
111+
#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 0
112+
#endif
113+
105114
// OpenGL Data
106115
static char g_GlslVersionString[32] = "";
107116
static GLuint g_FontTexture = 0;
@@ -263,7 +272,6 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
263272
for (int n = 0; n < draw_data->CmdListsCount; n++)
264273
{
265274
const ImDrawList* cmd_list = draw_data->CmdLists[n];
266-
size_t idx_buffer_offset = 0;
267275

268276
// Upload vertex/index buffers
269277
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
@@ -300,10 +308,13 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
300308

301309
// Bind texture, Draw
302310
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
303-
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)idx_buffer_offset);
311+
#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
312+
glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)pcmd->IdxOffset, (GLint)pcmd->VtxOffset);
313+
#else
314+
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)pcmd->IdxOffset);
315+
#endif
304316
}
305317
}
306-
idx_buffer_offset += pcmd->ElemCount * sizeof(ImDrawIdx);
307318
}
308319
}
309320

examples/imgui_impl_opengl3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// Implemented features:
77
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
8+
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices.
89

910
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
1011
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.

examples/imgui_impl_vulkan.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// dear imgui: Renderer for Vulkan
22
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
33

4+
// Implemented features:
5+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
46
// Missing features:
57
// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
68

@@ -20,6 +22,7 @@
2022

2123
// CHANGELOG
2224
// (minor and older changes stripped away, please see git history for details)
25+
// 2019-05-29: Vulkan: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_HasVtxOffset flag.
2326
// 2019-04-30: Vulkan: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
2427
// 2019-04-04: *BREAKING CHANGE*: Vulkan: Added ImageCount/MinImageCount fields in ImGui_ImplVulkan_InitInfo, required for initialization (was previously a hard #define IMGUI_VK_QUEUED_FRAMES 2). Added ImGui_ImplVulkan_SetMinImageCount().
2528
// 2019-04-04: Vulkan: Added VkInstance argument to ImGui_ImplVulkanH_CreateWindow() optional helper.
@@ -375,8 +378,9 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
375378
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
376379

377380
// Render command lists
378-
int vtx_offset = 0;
379-
int idx_offset = 0;
381+
// (Because we merged all buffers into a single one, we maintain our own offset into them)
382+
int global_vtx_offset = 0;
383+
int global_idx_offset = 0;
380384
for (int n = 0; n < draw_data->CmdListsCount; n++)
381385
{
382386
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -418,12 +422,12 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
418422
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
419423

420424
// Draw
421-
vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
425+
vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
422426
}
423427
}
424-
idx_offset += pcmd->ElemCount;
425428
}
426-
vtx_offset += cmd_list->VtxBuffer.Size;
429+
global_idx_offset += cmd_list->IdxBuffer.Size;
430+
global_vtx_offset += cmd_list->VtxBuffer.Size;
427431
}
428432
}
429433

@@ -801,6 +805,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
801805
{
802806
ImGuiIO& io = ImGui::GetIO();
803807
io.BackendRendererName = "imgui_impl_vulkan";
808+
io.BackendFlags |= ImGuiBackendFlags_HasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
804809

805810
IM_ASSERT(info->Instance != VK_NULL_HANDLE);
806811
IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);

examples/imgui_impl_vulkan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// dear imgui: Renderer for Vulkan
22
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
33

4+
// Implemented features:
5+
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
46
// Missing features:
57
// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
68

0 commit comments

Comments
 (0)