@ -10,14 +10,15 @@
// Implemented features:
// Implemented features:
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
// [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:
// Missing features:
// [ ] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices (SDL_RenderGeometryRaw() is missing a vertex offset).
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// 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-10-06: Backup and restore modified ClipRect/Viewport.
// 2021-09-21: Initial version.
// 2021-09-21: Initial version.
@ -61,6 +62,7 @@ bool ImGui_ImplSDLRenderer_Init(SDL_Renderer* renderer)
ImGui_ImplSDLRenderer_Data * bd = IM_NEW ( ImGui_ImplSDLRenderer_Data ) ( ) ;
ImGui_ImplSDLRenderer_Data * bd = IM_NEW ( ImGui_ImplSDLRenderer_Data ) ( ) ;
io . BackendRendererUserData = ( void * ) bd ;
io . BackendRendererUserData = ( void * ) bd ;
io . BackendRendererName = " imgui_impl_sdlrenderer " ;
io . BackendRendererName = " imgui_impl_sdlrenderer " ;
io . BackendFlags | = ImGuiBackendFlags_RendererHasVtxOffset ; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
bd - > SDLRenderer = renderer ;
bd - > SDLRenderer = renderer ;
@ -127,7 +129,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)
SDL_Rect ClipRect ;
SDL_Rect ClipRect ;
} ;
} ;
BackupSDLRendererState old = { } ;
BackupSDLRendererState old = { } ;
old . ClipEnabled = SDL_RenderIsClipEnabled ( bd - > SDLRenderer ) ;
old . ClipEnabled = SDL_RenderIsClipEnabled ( bd - > SDLRenderer ) = = SDL_TRUE ;
SDL_RenderGetViewport ( bd - > SDLRenderer , & old . Viewport ) ;
SDL_RenderGetViewport ( bd - > SDLRenderer , & old . Viewport ) ;
SDL_RenderGetClipRect ( bd - > SDLRenderer , & old . ClipRect ) ;
SDL_RenderGetClipRect ( bd - > SDLRenderer , & old . ClipRect ) ;
@ -170,9 +172,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_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 ) ;
SDL_RenderSetClipRect ( bd - > SDLRenderer , & r ) ;
const float * xy = ( const float * ) ( ( const char * ) vtx_buffer + IM_OFFSETOF ( ImDrawVert , pos ) ) ;
const float * xy = ( const float * ) ( ( const char * ) ( vtx_buffer + pcmd - > VtxOffset ) + IM_OFFSETOF ( ImDrawVert , pos ) ) ;
const float * uv = ( const float * ) ( ( const char * ) vtx_buffer + IM_OFFSETOF ( ImDrawVert , uv ) ) ;
const float * uv = ( const float * ) ( ( const char * ) ( vtx_buffer + pcmd - > VtxOffset ) + IM_OFFSETOF ( ImDrawVert , uv ) ) ;
const int * color = ( const int * ) ( ( const char * ) vtx_buffer + IM_OFFSETOF ( ImDrawVert , col ) ) ;
const int * color = ( const int * ) ( ( const char * ) ( vtx_buffer + pcmd - > VtxOffset ) + IM_OFFSETOF ( ImDrawVert , col ) ) ;
// Bind texture, Draw
// Bind texture, Draw
SDL_Texture * tex = ( SDL_Texture * ) pcmd - > GetTexID ( ) ;
SDL_Texture * tex = ( SDL_Texture * ) pcmd - > GetTexID ( ) ;
@ -180,7 +182,7 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data)
xy , ( int ) sizeof ( ImDrawVert ) ,
xy , ( int ) sizeof ( ImDrawVert ) ,
color , ( int ) sizeof ( ImDrawVert ) ,
color , ( int ) sizeof ( ImDrawVert ) ,
uv , ( 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 ) ) ;
idx_buffer + pcmd - > IdxOffset , pcmd - > ElemCount , sizeof ( ImDrawIdx ) ) ;
}
}
}
}