diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-12-16 17:09:25 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-12-16 17:11:02 -0300 |
commit | 652c98a7beb8fc8a8aad5075a673caf21994a2ba (patch) | |
tree | caa203abb2bcdb839f6bc7568d7119aa948120db /core/os | |
parent | d03f35f1bc0ecf09d436ebb44356f8add5b95a3e (diff) |
Add epic hack so vsync can be toggled in run-time from script. Fixes #14458.
Call needs to be routed via visual server to reach the proper thread.
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/os.cpp | 11 | ||||
-rw-r--r-- | core/os/os.h | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp index d81e70e612..7010d44930 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -536,12 +536,21 @@ String OS::get_joy_guid(int p_device) const { void OS::set_context(int p_context) { } + +OS::SwitchVSyncCallbackInThread OS::switch_vsync_function = NULL; + void OS::set_use_vsync(bool p_enable) { + _use_vsync = p_enable; + if (switch_vsync_function) { //if a function was set, use function + switch_vsync_function(p_enable); + } else { //otherwise just call here + _set_use_vsync(p_enable); + } } bool OS::is_vsync_enabled() const { - return true; + return _use_vsync; } OS::PowerState OS::get_power_state() { diff --git a/core/os/os.h b/core/os/os.h index d9f7b91daa..2faaa6ab8f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -58,6 +58,7 @@ class OS { int _exit_code; int _orientation; bool _allow_hidpi; + bool _use_vsync; char *last_error; @@ -435,8 +436,16 @@ public: virtual void set_context(int p_context); - virtual void set_use_vsync(bool p_enable); - virtual bool is_vsync_enabled() const; + //amazing hack because OpenGL needs this to be set on a separate thread.. + //also core can't access servers, so a callback must be used + typedef void (*SwitchVSyncCallbackInThread)(bool); + + static SwitchVSyncCallbackInThread switch_vsync_function; + void set_use_vsync(bool p_enable); + bool is_vsync_enabled() const; + + //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed + virtual void _set_use_vsync(bool p_enable) {} virtual OS::PowerState get_power_state(); virtual int get_power_seconds_left(); |