SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.08k stars 163 forks source link

High CPU usage due to glGetIntegerv #247

Closed Helyos96 closed 11 months ago

Helyos96 commented 11 months ago

SFML v2.6 - Windows 11 - Nvidia 531.26

Using a RenderWindow with vsync enabled (60hz monitor).

Problem: CPU usage spikes up and stresses a cpu core whenever imgui renders something. I narrowed it down to the calls to glGetIntegerv in void RenderDrawLists(ImDrawData* draw_data). The first of these calls will do a cpu-wait of 16ms and will cause huge CPU usage on the main thread.

I confirmed it by commenting out all these calls (and the related context-restoring code at the end of the function), and the CPU usage went back to 0%. I understand that I lose the GL context saving/restoring functionality by doing that but I prefer it over the high CPU usage.

I don't really expect it to be fixed (I guess the main app should pass those parameters to imgui-sfml rather than doing those calls to glGetIntegerv), but putting it out there for anyone wondering why their imgui-sfml usage has a high CPU impact.

eliasdaler commented 11 months ago

You can reimplement the rendering function yourself (you can access everything needed for that) and let ImGui-SFML take care of the rest.

State restore is kinda wasteful, but Dear ImGui does the same here and it leads to much easier interface for most users. More advanced users can implement the rendering as needed themselves.