|
@@ -10,8 +10,8 @@
|
|
|
|
|
|
// Implemented features:
|
|
|
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
|
|
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
|
|
|
// Missing features:
|
|
|
-// [ ] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices (SDL_RenderGeometryRaw() is missing a vertex offset).
|
|
|
// [ ] Renderer: Multi-viewport support (multiple windows).
|
|
|
|
|
|
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
|
@@ -19,6 +19,7 @@
|
|
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
|
|
|
|
// CHANGELOG
|
|
|
+// 2021-12-03: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
|
// 2021-10-06: Backup and restore modified ClipRect/Viewport.
|
|
|
// 2021-09-21: Initial version.
|
|
|
|
|
@@ -62,6 +63,7 @@ bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer)
|
|
|
ImGui_ImplSDLRenderer_Data* bd = IM_NEW(ImGui_ImplSDLRenderer_Data)();
|
|
|
io.BackendRendererUserData = (void*)bd;
|
|
|
io.BackendRendererName = "imgui_impl_sdlrenderer";
|
|
|
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
|
|
|
|
|
bd->SDLRenderer = renderer;
|
|
|
|
|
@@ -128,7 +130,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)
|
|
|
SDL_Rect ClipRect;
|
|
|
};
|
|
|
BackupSDLRendererState old = {};
|
|
|
- old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer);
|
|
|
+ old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer) == SDL_TRUE;
|
|
|
SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport);
|
|
|
SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect);
|
|
|
|
|
@@ -171,9 +173,9 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)
|
|
|
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
|
|
|
SDL_RenderSetClipRect(bd->SDLRenderer, &r);
|
|
|
|
|
|
- const float* xy = (const float*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos));
|
|
|
- const float* uv = (const float*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv));
|
|
|
- const int* color = (const int*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col));
|
|
|
+ const float* xy = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos));
|
|
|
+ const float* uv = (const float*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv));
|
|
|
+ const int* color = (const int*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col));
|
|
|
|
|
|
// Bind texture, Draw
|
|
|
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
|
@@ -181,7 +183,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)
|
|
|
xy, (int)sizeof(ImDrawVert),
|
|
|
color, (int)sizeof(ImDrawVert),
|
|
|
uv, (int)sizeof(ImDrawVert),
|
|
|
- cmd_list->VtxBuffer.Size,
|
|
|
+ cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
|
|
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
|
|
|
}
|
|
|
}
|