You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FramebufferWidget.hpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <widget/Widget.hpp>
  3. namespace rack {
  4. namespace widget {
  5. /** Caches its children's draw() result to a framebuffer image.
  6. When dirty, its children will be re-rendered on the next call to step().
  7. */
  8. struct FramebufferWidget : Widget {
  9. struct Internal;
  10. Internal* internal;
  11. bool dirty = true;
  12. bool bypassed = false;
  13. float oversample = 1.0;
  14. /** Redraw when the world offset of the FramebufferWidget changes its fractional value. */
  15. bool dirtyOnSubpixelChange = true;
  16. /** If finite, the maximum size of the framebuffer is the viewport expanded by this margin.
  17. The framebuffer is re-rendered when the viewport moves outside the margin.
  18. */
  19. math::Vec viewportMargin = math::Vec(INFINITY, INFINITY);
  20. FramebufferWidget();
  21. ~FramebufferWidget();
  22. /** Requests to re-render children to the framebuffer on the next draw(). */
  23. void setDirty(bool dirty = true);
  24. int getImageHandle();
  25. NVGLUframebuffer* getFramebuffer();
  26. math::Vec getFramebufferSize();
  27. void deleteFramebuffer();
  28. void step() override;
  29. /** Draws the framebuffer to the NanoVG scene, re-rendering it if necessary.
  30. */
  31. void draw(const DrawArgs& args) override;
  32. /** Re-renders the framebuffer, re-creating it if necessary.
  33. Handles oversampling (if >1) by rendering to a temporary (larger) framebuffer and then downscaling it to the main persistent framebuffer.
  34. */
  35. void render(math::Vec scale = math::Vec(1, 1), math::Vec offsetF = math::Vec(0, 0), math::Rect clipBox = math::Rect::inf());
  36. /** Initializes the current GL context and draws children to it.
  37. */
  38. virtual void drawFramebuffer();
  39. void onDirty(const DirtyEvent& e) override;
  40. void onContextCreate(const ContextCreateEvent& e) override;
  41. void onContextDestroy(const ContextDestroyEvent& e) override;
  42. };
  43. } // namespace widget
  44. } // namespace rack