Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An empty event callback (fired by glfwPostEmptyEvent), even during window resize #952

Open
AngryCarrot789 opened this issue Dec 8, 2023 · 2 comments

Comments

@AngryCarrot789
Copy link

Description

I've hit a slight roadblock in making a desktop UI, because I need to be able to run code even if a window is in the resize phase (the user's LMB is pressed but they aren't moving their mouse).

During the resize phase, I can only 'do' stuff on the main thread during the events that get fired when the window is actually resized (window/framebuffer size changed callbacks, and the refresh callback), but there's no way to run code while the user just keeps their mouse still but still holding the LMB.

According to the GLFW source code, glfwPostEmptyEvent posts WM_NULL which I assume is ignored but does cause glfwWaitEvents to return (but only when not resizing though). So it would be nice if it could instead post a custom window message, which gets handled by GLFW, and causes an event to be fired on the main thread, even during the resize phase

@AngryCarrot789 AngryCarrot789 changed the title A callback fired by glfwPostEmptyEvent, even during window resize An empty event callback (fired by glfwPostEmptyEvent), even during window resize Dec 8, 2023
@Spasi
Copy link
Member

Spasi commented Dec 16, 2023

Hey @AngryCarrot789,

The recommended approach to handle this issue is to decouple event processing from rendering with multiple threads. The main thread handles the event loop with blocking glfwWaitEvents, while a secondary thread continuously renders at the target frame rate, or vsync limit.

For example code, see the Vorbis sample. In this case there's even a third thread handling audio, but it demonstrates nicely how you can pace everything at different rates and avoid any blocking.

@AngryCarrot789
Copy link
Author

I was trying to implement an executor service for the main thread, because I'm trying to implement a retained mode GUI, and while I did manage to get it to work while not resizing the window, it obviously won't work during resize since there's no event that gets fired while the user is not moving their mouse but the LMB is pressed.

The only way I can get it to work is by making my entire application have it's own thread and when it wants to change the size of a window I would use the executor service I mentioned, except it would only be able to execute code when not resizing.

I made a pull request on the GLFW git repo, but I don't know if it will go anywhere honestly, mainly because it only works on windows: glfw/glfw#2443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants