-
Notifications
You must be signed in to change notification settings - Fork 37
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
Problems when rendering window one frame at a time #167
Comments
EDIT: Also, if it is possible, seeing more of your code would help us help you. :P |
This is my understanding from writing a non-polling event loop, that might help you out A typical conrod event loop looks like this:
the
Input events can be received at any time, but update and render are called at a fixed rate, 60fps by default. That's the rate set by If the VST host is calling your code once per frame, does it also supply all the input events that happened in that frame? If not, I think there's no way around handling the input events as they happen. In which case you might need a separate thread to collect input events, then when the VST calls each frame, use that as the Update and Render events. |
The VST host calls my render callback. The window runs in the same thread as the host, and creating another thread for event handling is not possible/allowed in this situation. |
@Boscop conrod's
As of PistonDevelopers/conrod#855 conrod no longer needs to know about either of these events, so if you do want to stick to your current setup (rather than switch to the glium feature), you might not need to do much else. Just call |
I'm using conrod & piston_window for the GUI in a VST plugin, but I'm having some problems with event handling:
The way the GUI is run in a VST is, one frame at a time.
So I can't use while let Some(event) = gui.window.next() { because that stalls, but when I try to do one frame by doing if let Some(event) = gui.window.next() { it doesn't register input events. So I tried while let Some(event) = gui.window.poll_event() { which seemed like a logical way to do it (only process events that are in the queue right now, don't block to wait for new events at the end of the queue), then I get input events, but no render events so the GUI doesn't render!
So what should I do to handle the GUI one frame at a time / without internal event loop?
Also, I have another question: What exactly does the event loop do behind the scenes (with the value given by window.set_ups())? Is there a way to turn the event loop off?
(This question is also relevant for writing game UIs, where the game should be in control of the loop and the GUI should be drawn over the scene.)
The host creates the window for each plugin and passes the handle to the plugin, then the plugin creates a child window with the given parent, and creates an opengl context on it.
I forked and modified conrod, piston_window, piston/window, glutin and glutin_window so I could pass the parent HWND down to where glutin creates the window. (I also modified glutin so that the child windows are created in the same thread and so that I could register timers on the window etc.).
Then I register a timer on that child window that calls my UI rendering callback repeatedly.
I already tested this before using only glutin and shaders to render my plugin GUI: https://i.imgur.com/Oi6JUzd.png
I created a standalone version of the plugin to test it, that passes NULL as the parent HWND so that glutin creates a normal window, and when I use
while let Some(event) = gui.window.next() {
it works correctly:But it stalls (because of while) so I can't use this in the plugin version), but if I use
if let Some(event) = gui.window.next() {
on every frame, I only get Input events:But I don't get render events, so nothing gets rendered.
My gui consists of a slider widget. I have it set up so that it prints 'value changed' when I change the slider with the mouse.
I wanted to see if the input is still being processed, even though nothing is rendered in this case.
But if I click on where the slider widget would be rendered, it doesn't print 'value changed' so the input apparently doesn't get processed correctly either.
What's weird is that I get mouse move events even if i dont move the mouse.
So I thought, maybe with 'while' I never get render events because for some reason it 1. puts input events before render events and 2. creates input events on every frame even when there is no input.
So I changed the code to this:
Now it seems to work better: it renders and processes input, but it's very laggy and I'm not sure if this is the best way to do it.. And if there are no new events, it still waits until it got 10, which shouldn't happen. So my questions are:
Especially because the UI rendering is done in a callback triggered by a timer that fires every few ms.
Edit: It seems the method of breaking out of the while loop after 10 events doesn't work in the plugin version (only in standalone, but laggy as hell). In the plugin version it renders but I get no input events. Why could that be?
The text was updated successfully, but these errors were encountered: