diff options
author | David Robillard <d@drobilla.net> | 2020-10-24 13:28:22 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-24 13:28:22 +0200 |
commit | 612aae5147abec2be9523c1d2858550e5d8a150d (patch) | |
tree | 2f88ed8d310af34e8c401dc14ed75f589b847a73 /examples | |
parent | 9c2f1888f033dc577464d41cb18839b988de7987 (diff) | |
download | pugl-612aae5147abec2be9523c1d2858550e5d8a150d.tar.gz pugl-612aae5147abec2be9523c1d2858550e5d8a150d.tar.bz2 pugl-612aae5147abec2be9523c1d2858550e5d8a150d.zip |
Replace live resize with loop events
This allows the application to control how recursive loops are handled rather
than have Pugl impose behavior which can get in the way. For example, an
application may not want to continuously animate while being resized, or set up
its rendering differently in this situation. For example, with Vulkan, setting
up a different swapchain can be necessary for smooth performance while live
resizing on Windows, and Pugl has no ability to do this.
I think it was a mistake to add this timer to Pugl itself, because it was
always a bit of a leaky abstraction, and not very appropriate for a library
that is supposed to be a thin abstraction layer. Though it almost seemed like
things ran as usual while resizing on Windows and MacOS, the main event loop
being stalled can be confusing, and there was no way to detect this. This way,
applications must explicitly handle this situation and can implement the
behavior they want without Pugl getting in the way.
This also simplifies the Pugl implementation a bit, which is always nice.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pugl_shader_demo.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c index 1122410..4b8064d 100644 --- a/examples/pugl_shader_demo.c +++ b/examples/pugl_shader_demo.c @@ -47,12 +47,14 @@ #include <math.h> #include <stddef.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -static const int defaultWidth = 512; -static const int defaultHeight = 512; +static const int defaultWidth = 512; +static const int defaultHeight = 512; +static const uintptr_t resizeTimerId = 1u; typedef struct { @@ -166,11 +168,24 @@ onEvent(PuglView* view, const PuglEvent* event) break; case PUGL_EXPOSE: onExpose(view); break; case PUGL_CLOSE: app->quit = 1; break; + case PUGL_LOOP_ENTER: + puglStartTimer(view, + resizeTimerId, + 1.0 / (double)puglGetViewHint(view, PUGL_REFRESH_RATE)); + break; + case PUGL_LOOP_LEAVE: + puglStopTimer(view, resizeTimerId); + break; case PUGL_KEY_PRESS: if (event->key.key == 'q' || event->key.key == PUGL_KEY_ESCAPE) { app->quit = 1; } break; + case PUGL_TIMER: + if (event->timer.id == resizeTimerId) { + puglPostRedisplay(view); + } + break; default: break; } |