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.
This commit is contained in:
parent
d03f35f1bc
commit
652c98a7be
|
@ -536,12 +536,21 @@ String OS::get_joy_guid(int p_device) const {
|
||||||
|
|
||||||
void OS::set_context(int p_context) {
|
void OS::set_context(int p_context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OS::SwitchVSyncCallbackInThread OS::switch_vsync_function = NULL;
|
||||||
|
|
||||||
void OS::set_use_vsync(bool p_enable) {
|
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 {
|
bool OS::is_vsync_enabled() const {
|
||||||
|
|
||||||
return true;
|
return _use_vsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS::PowerState OS::get_power_state() {
|
OS::PowerState OS::get_power_state() {
|
||||||
|
|
13
core/os/os.h
13
core/os/os.h
|
@ -58,6 +58,7 @@ class OS {
|
||||||
int _exit_code;
|
int _exit_code;
|
||||||
int _orientation;
|
int _orientation;
|
||||||
bool _allow_hidpi;
|
bool _allow_hidpi;
|
||||||
|
bool _use_vsync;
|
||||||
|
|
||||||
char *last_error;
|
char *last_error;
|
||||||
|
|
||||||
|
@ -435,8 +436,16 @@ public:
|
||||||
|
|
||||||
virtual void set_context(int p_context);
|
virtual void set_context(int p_context);
|
||||||
|
|
||||||
virtual void set_use_vsync(bool p_enable);
|
//amazing hack because OpenGL needs this to be set on a separate thread..
|
||||||
virtual bool is_vsync_enabled() const;
|
//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 OS::PowerState get_power_state();
|
||||||
virtual int get_power_seconds_left();
|
virtual int get_power_seconds_left();
|
||||||
|
|
|
@ -215,8 +215,8 @@ public:
|
||||||
|
|
||||||
virtual bool _check_internal_feature_support(const String &p_feature);
|
virtual bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
virtual void set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
virtual bool is_vsync_enabled() const;
|
//virtual bool is_vsync_enabled() const;
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|
|
@ -2063,14 +2063,14 @@ Error OS_OSX::move_to_trash(const String &p_path) {
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_OSX::set_use_vsync(bool p_enable) {
|
void OS_OSX::_set_use_vsync(bool p_enable) {
|
||||||
CGLContextObj ctx = CGLGetCurrentContext();
|
CGLContextObj ctx = CGLGetCurrentContext();
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
GLint swapInterval = p_enable ? 1 : 0;
|
GLint swapInterval = p_enable ? 1 : 0;
|
||||||
CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
|
CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
bool OS_OSX::is_vsync_enabled() const {
|
bool OS_OSX::is_vsync_enabled() const {
|
||||||
GLint swapInterval = 0;
|
GLint swapInterval = 0;
|
||||||
CGLContextObj ctx = CGLGetCurrentContext();
|
CGLContextObj ctx = CGLGetCurrentContext();
|
||||||
|
@ -2079,7 +2079,7 @@ bool OS_OSX::is_vsync_enabled() const {
|
||||||
}
|
}
|
||||||
return swapInterval ? true : false;
|
return swapInterval ? true : false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
OS_OSX *OS_OSX::singleton = NULL;
|
OS_OSX *OS_OSX::singleton = NULL;
|
||||||
|
|
||||||
OS_OSX::OS_OSX() {
|
OS_OSX::OS_OSX() {
|
||||||
|
|
|
@ -2288,19 +2288,19 @@ String OS_Windows::get_joy_guid(int p_device) const {
|
||||||
return input->get_joy_guid_remapped(p_device);
|
return input->get_joy_guid_remapped(p_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Windows::set_use_vsync(bool p_enable) {
|
void OS_Windows::_set_use_vsync(bool p_enable) {
|
||||||
|
|
||||||
if (gl_context)
|
if (gl_context)
|
||||||
gl_context->set_use_vsync(p_enable);
|
gl_context->set_use_vsync(p_enable);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
bool OS_Windows::is_vsync_enabled() const {
|
bool OS_Windows::is_vsync_enabled() const {
|
||||||
|
|
||||||
if (gl_context)
|
if (gl_context)
|
||||||
return gl_context->is_using_vsync();
|
return gl_context->is_using_vsync();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
OS::PowerState OS_Windows::get_power_state() {
|
OS::PowerState OS_Windows::get_power_state() {
|
||||||
return power_manager->get_power_state();
|
return power_manager->get_power_state();
|
||||||
|
|
|
@ -275,8 +275,8 @@ public:
|
||||||
virtual bool is_joy_known(int p_device);
|
virtual bool is_joy_known(int p_device);
|
||||||
virtual String get_joy_guid(int p_device) const;
|
virtual String get_joy_guid(int p_device) const;
|
||||||
|
|
||||||
virtual void set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
virtual bool is_vsync_enabled() const;
|
//virtual bool is_vsync_enabled() const;
|
||||||
|
|
||||||
virtual OS::PowerState get_power_state();
|
virtual OS::PowerState get_power_state();
|
||||||
virtual int get_power_seconds_left();
|
virtual int get_power_seconds_left();
|
||||||
|
|
|
@ -2306,11 +2306,11 @@ String OS_X11::get_joy_guid(int p_device) const {
|
||||||
return input->get_joy_guid_remapped(p_device);
|
return input->get_joy_guid_remapped(p_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_X11::set_use_vsync(bool p_enable) {
|
void OS_X11::_set_use_vsync(bool p_enable) {
|
||||||
if (context_gl)
|
if (context_gl)
|
||||||
return context_gl->set_use_vsync(p_enable);
|
return context_gl->set_use_vsync(p_enable);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
bool OS_X11::is_vsync_enabled() const {
|
bool OS_X11::is_vsync_enabled() const {
|
||||||
|
|
||||||
if (context_gl)
|
if (context_gl)
|
||||||
|
@ -2318,7 +2318,7 @@ bool OS_X11::is_vsync_enabled() const {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void OS_X11::set_context(int p_context) {
|
void OS_X11::set_context(int p_context) {
|
||||||
|
|
||||||
XClassHint *classHint = XAllocClassHint();
|
XClassHint *classHint = XAllocClassHint();
|
||||||
|
|
|
@ -270,8 +270,8 @@ public:
|
||||||
|
|
||||||
virtual void set_context(int p_context);
|
virtual void set_context(int p_context);
|
||||||
|
|
||||||
virtual void set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
virtual bool is_vsync_enabled() const;
|
//virtual bool is_vsync_enabled() const;
|
||||||
|
|
||||||
virtual OS::PowerState get_power_state();
|
virtual OS::PowerState get_power_state();
|
||||||
virtual int get_power_seconds_left();
|
virtual int get_power_seconds_left();
|
||||||
|
|
|
@ -181,6 +181,10 @@ void VisualServerRaster::set_debug_generate_wireframes(bool p_generate) {
|
||||||
VSG::storage->set_debug_generate_wireframes(p_generate);
|
VSG::storage->set_debug_generate_wireframes(p_generate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualServerRaster::call_set_use_vsync(bool p_enable) {
|
||||||
|
OS::get_singleton()->_set_use_vsync(p_enable);
|
||||||
|
}
|
||||||
|
|
||||||
VisualServerRaster::VisualServerRaster() {
|
VisualServerRaster::VisualServerRaster() {
|
||||||
|
|
||||||
VSG::canvas = memnew(VisualServerCanvas);
|
VSG::canvas = memnew(VisualServerCanvas);
|
||||||
|
|
|
@ -668,6 +668,8 @@ public:
|
||||||
virtual bool has_os_feature(const String &p_feature) const;
|
virtual bool has_os_feature(const String &p_feature) const;
|
||||||
virtual void set_debug_generate_wireframes(bool p_generate);
|
virtual void set_debug_generate_wireframes(bool p_generate);
|
||||||
|
|
||||||
|
virtual void call_set_use_vsync(bool p_enable);
|
||||||
|
|
||||||
VisualServerRaster();
|
VisualServerRaster();
|
||||||
~VisualServerRaster();
|
~VisualServerRaster();
|
||||||
|
|
||||||
|
|
|
@ -158,9 +158,19 @@ void VisualServerWrapMT::finish() {
|
||||||
canvas_occluder_polygon_free_cached_ids();
|
canvas_occluder_polygon_free_cached_ids();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualServerWrapMT::set_use_vsync_callback(bool p_enable) {
|
||||||
|
|
||||||
|
singleton_mt->call_set_use_vsync(p_enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
VisualServerWrapMT *VisualServerWrapMT::singleton_mt = NULL;
|
||||||
|
|
||||||
VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread) :
|
VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread) :
|
||||||
command_queue(p_create_thread) {
|
command_queue(p_create_thread) {
|
||||||
|
|
||||||
|
singleton_mt = this;
|
||||||
|
OS::switch_vsync_function = set_use_vsync_callback; //as this goes to another thread, make sure it goes properly
|
||||||
|
|
||||||
visual_server = p_contained;
|
visual_server = p_contained;
|
||||||
create_thread = p_create_thread;
|
create_thread = p_create_thread;
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
|
|
|
@ -64,6 +64,8 @@ class VisualServerWrapMT : public VisualServer {
|
||||||
|
|
||||||
//#define DEBUG_SYNC
|
//#define DEBUG_SYNC
|
||||||
|
|
||||||
|
static VisualServerWrapMT *singleton_mt;
|
||||||
|
|
||||||
#ifdef DEBUG_SYNC
|
#ifdef DEBUG_SYNC
|
||||||
#define SYNC_DEBUG print_line("sync on: " + String(__FUNCTION__));
|
#define SYNC_DEBUG print_line("sync on: " + String(__FUNCTION__));
|
||||||
#else
|
#else
|
||||||
|
@ -584,6 +586,10 @@ public:
|
||||||
virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); }
|
virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); }
|
||||||
virtual bool has_os_feature(const String &p_feature) const { return visual_server->has_os_feature(p_feature); }
|
virtual bool has_os_feature(const String &p_feature) const { return visual_server->has_os_feature(p_feature); }
|
||||||
|
|
||||||
|
FUNC1(call_set_use_vsync, bool)
|
||||||
|
|
||||||
|
static void set_use_vsync_callback(bool p_enable);
|
||||||
|
|
||||||
VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread);
|
VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread);
|
||||||
~VisualServerWrapMT();
|
~VisualServerWrapMT();
|
||||||
|
|
||||||
|
|
|
@ -1922,6 +1922,7 @@ VisualServer::VisualServer() {
|
||||||
|
|
||||||
//ERR_FAIL_COND(singleton);
|
//ERR_FAIL_COND(singleton);
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
||||||
GLOBAL_DEF("rendering/vram_compression/import_s3tc", true);
|
GLOBAL_DEF("rendering/vram_compression/import_s3tc", true);
|
||||||
GLOBAL_DEF("rendering/vram_compression/import_etc", false);
|
GLOBAL_DEF("rendering/vram_compression/import_etc", false);
|
||||||
GLOBAL_DEF("rendering/vram_compression/import_etc2", true);
|
GLOBAL_DEF("rendering/vram_compression/import_etc2", true);
|
||||||
|
|
|
@ -980,6 +980,8 @@ public:
|
||||||
|
|
||||||
virtual void set_debug_generate_wireframes(bool p_generate) = 0;
|
virtual void set_debug_generate_wireframes(bool p_generate) = 0;
|
||||||
|
|
||||||
|
virtual void call_set_use_vsync(bool p_enable) = 0;
|
||||||
|
|
||||||
VisualServer();
|
VisualServer();
|
||||||
virtual ~VisualServer();
|
virtual ~VisualServer();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue