diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-11-26 12:37:59 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-11-26 12:37:59 +0100 |
| commit | 6817e821af9d69363466025f17ee367cfaa4550e (patch) | |
| tree | 0ccee8a354141b7e5eefac83da657c030e1a9f9e /src | |
| parent | 102437f1eedce8589d947bf8791d6d5f413d445b (diff) | |
STR 1373: adds vsync control to OpenGL contexts on macOS
Windows and X11 to follow, no idea about Wayland.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Gl_Window.cxx | 15 | ||||
| -rw-r--r-- | src/Fl_Gl_Window_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm | 15 |
4 files changed, 34 insertions, 0 deletions
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index a3c2641bd..b59d7d5de 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -161,6 +161,21 @@ void Fl_Gl_Window::swap_buffers() { pGlWindowDriver->swap_buffers(); } +/** + Sets the rate at which the GL windows swaps buffers. + */ +void Fl_Gl_Window::swap_interval(int frames) { + pGlWindowDriver->swap_interval(frames); +} + +/** + Gets the rate at which the GL windows swaps buffers. + */ +int Fl_Gl_Window::swap_interval() const { + return pGlWindowDriver->swap_interval(); +} + + void Fl_Gl_Window::flush() { if (!shown()) return; uchar save_valid = valid_f_ & 1; diff --git a/src/Fl_Gl_Window_Driver.H b/src/Fl_Gl_Window_Driver.H index 839c5bc93..79f696905 100644 --- a/src/Fl_Gl_Window_Driver.H +++ b/src/Fl_Gl_Window_Driver.H @@ -69,6 +69,8 @@ public: virtual void swap_buffers() {} virtual void resize(int /*is_a_resize*/, int /*w*/, int /*h*/) {} virtual char swap_type(); + virtual void swap_interval(int) { } + virtual int swap_interval() { return -1; } virtual int flush_begin(char&) {return 0;} virtual void gl_hide_before(void *&) {} // the default implementation may be enough static Fl_Gl_Choice *find_begin(int m, const int *alistp); diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H index 79b93e6df..21a3a4589 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H @@ -38,6 +38,8 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver { void swap_buffers() FL_OVERRIDE; void resize(int is_a_resize, int w, int h) FL_OVERRIDE; char swap_type() FL_OVERRIDE; + void swap_interval(int) FL_OVERRIDE; + int swap_interval() FL_OVERRIDE; Fl_Gl_Choice *find(int m, const int *alistp) FL_OVERRIDE; GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g) FL_OVERRIDE; void set_gl_context(Fl_Window* w, GLContext context) FL_OVERRIDE; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm index a2c8e7578..43bc2d480 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm @@ -355,6 +355,21 @@ void Fl_Cocoa_Gl_Window_Driver::swap_buffers() { char Fl_Cocoa_Gl_Window_Driver::swap_type() {return copy;} +void Fl_Cocoa_Gl_Window_Driver::swap_interval(int n) { + GLint interval = (GLint)n; + NSOpenGLContext* ctx = (NSOpenGLContext*)pWindow->context(); + if (ctx) + [ctx setValues:&interval forParameter:NSOpenGLContextParameterSwapInterval]; +} + +int Fl_Cocoa_Gl_Window_Driver::swap_interval() { + GLint interval = (GLint)-1; + NSOpenGLContext* ctx = (NSOpenGLContext*)pWindow->context(); + if (ctx) + [ctx getValues:&interval forParameter:NSOpenGLContextParameterSwapInterval]; + return interval; +} + void Fl_Cocoa_Gl_Window_Driver::resize(int is_a_resize, int w, int h) { if (pWindow->shown()) apply_scissor(); [(NSOpenGLContext*)pWindow->context() update]; |
