mitsuba-renderer / nanogui

Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL
Other
1.56k stars 196 forks source link

Support for VSync #151

Open TwentyPast4 opened 1 year ago

TwentyPast4 commented 1 year ago

In most situations, you want vsync to have fluid and responsive animations and to avoid screen tearing. It's a must-gave for a game and that's why it feels wrong not to have it in the common set of application function (imo). I've added vsync support to nanogui to make it as easy to use as possible while keeping the code as similar as possible and avoiding branching out two mainloop() functions.

Intended usage:

nanogui::init();
nanogui::set_vsync(true);

// the following is an example, but the vsync logic is done nanogui::mainloop
// if you have a custom main loop, see code for reference to how vsync is handled
{
ref<MyApp> app = new MyApp();
app->draw_all();
app->set_visible(true);
nanogui::mainloop();
}
nanogui::shutdown();

Also contains a small addition to nanogui Screen which updates the currently displayed cursor. This is in place to solve a bug where a widget dynamically changes its cursor , but nanogui does not update it, because it only changes the cursor on mouse move. Same thing happens when a widget position or size changes such that the widget under the cursor is not the same anymore.

Code is probably not formatted correctly as there is no clang_format or similar that I could use