You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Set vsync on window creation when using GLES3.
Add vsync to Windows platform
This commit is contained in:
@@ -4414,7 +4414,7 @@ void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mo
|
|||||||
|
|
||||||
#if defined(GLES3_ENABLED)
|
#if defined(GLES3_ENABLED)
|
||||||
if (gl_manager) {
|
if (gl_manager) {
|
||||||
gl_manager->set_use_vsync(p_vsync_mode == DisplayServer::VSYNC_ENABLED);
|
gl_manager->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -4675,6 +4675,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
|
|||||||
if (gl_manager) {
|
if (gl_manager) {
|
||||||
Error err = gl_manager->window_create(id, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height);
|
Error err = gl_manager->window_create(id, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height);
|
||||||
ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL window");
|
ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL window");
|
||||||
|
window_set_vsync_mode(p_vsync_mode, id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod
|
|||||||
Error err = gl_manager->window_create(window_id_counter, wd.window_view, p_rect.size.width, p_rect.size.height);
|
Error err = gl_manager->window_create(window_id_counter, wd.window_view, p_rect.size.width, p_rect.size.height);
|
||||||
ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL context");
|
ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL context");
|
||||||
}
|
}
|
||||||
|
window_set_vsync_mode(p_vsync_mode, window_id_counter);
|
||||||
#endif
|
#endif
|
||||||
[wd.window_view updateLayerDelegate];
|
[wd.window_view updateLayerDelegate];
|
||||||
id = window_id_counter++;
|
id = window_id_counter++;
|
||||||
@@ -2999,7 +3000,7 @@ void DisplayServerMacOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_
|
|||||||
_THREAD_SAFE_METHOD_
|
_THREAD_SAFE_METHOD_
|
||||||
#if defined(GLES3_ENABLED)
|
#if defined(GLES3_ENABLED)
|
||||||
if (gl_manager) {
|
if (gl_manager) {
|
||||||
gl_manager->set_use_vsync(p_vsync_mode);
|
gl_manager->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(VULKAN_ENABLED)
|
#if defined(VULKAN_ENABLED)
|
||||||
|
|||||||
@@ -2023,6 +2023,12 @@ void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn
|
|||||||
context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
|
context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(GLES3_ENABLED)
|
||||||
|
if (gl_manager) {
|
||||||
|
gl_manager->set_use_vsync(p_window, p_vsync_mode != DisplayServer::VSYNC_DISABLED);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_window) const {
|
DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_window) const {
|
||||||
@@ -2032,6 +2038,13 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_
|
|||||||
return context_vulkan->get_vsync_mode(p_window);
|
return context_vulkan->get_vsync_mode(p_window);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(GLES3_ENABLED)
|
||||||
|
if (gl_manager) {
|
||||||
|
return gl_manager->is_using_vsync(p_window) ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return DisplayServer::VSYNC_ENABLED;
|
return DisplayServer::VSYNC_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3601,6 +3614,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
|
|||||||
windows.erase(id);
|
windows.erase(id);
|
||||||
ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create an OpenGL window.");
|
ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create an OpenGL window.");
|
||||||
}
|
}
|
||||||
|
window_set_vsync_mode(p_vsync_mode, id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ Error GLManager_Windows::_create_context(GLWindow &win, GLDisplay &gl_display) {
|
|||||||
return ERR_CANT_CREATE;
|
return ERR_CANT_CREATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wglSwapIntervalEXT) {
|
||||||
|
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,50 +297,30 @@ void GLManager_Windows::swap_buffers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error GLManager_Windows::initialize() {
|
Error GLManager_Windows::initialize() {
|
||||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
|
||||||
wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT");
|
|
||||||
//glWrapperInit(wrapper_get_proc_address);
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLManager_Windows::set_use_vsync(bool p_use) {
|
void GLManager_Windows::set_use_vsync(DisplayServer::WindowID p_window_id, bool p_use) {
|
||||||
/*
|
GLWindow &win = get_window(p_window_id);
|
||||||
static bool setup = false;
|
GLWindow *current = _current_window;
|
||||||
static PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
|
|
||||||
static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalMESA = nullptr;
|
|
||||||
static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
|
|
||||||
|
|
||||||
if (!setup) {
|
if (&win != _current_window) {
|
||||||
setup = true;
|
window_make_current(p_window_id);
|
||||||
String extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display));
|
|
||||||
if (extensions.find("GLX_EXT_swap_control") != -1) {
|
|
||||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalEXT");
|
|
||||||
}
|
|
||||||
if (extensions.find("GLX_MESA_swap_control") != -1) {
|
|
||||||
glXSwapIntervalMESA = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA");
|
|
||||||
}
|
|
||||||
if (extensions.find("GLX_SGI_swap_control") != -1) {
|
|
||||||
glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int val = p_use ? 1 : 0;
|
|
||||||
if (glXSwapIntervalMESA) {
|
if (wglSwapIntervalEXT) {
|
||||||
glXSwapIntervalMESA(val);
|
win.use_vsync = p_use;
|
||||||
} else if (glXSwapIntervalSGI) {
|
wglSwapIntervalEXT(p_use ? 1 : 0);
|
||||||
glXSwapIntervalSGI(val);
|
}
|
||||||
} else if (glXSwapIntervalEXT) {
|
|
||||||
GLXDrawable drawable = glXGetCurrentDrawable();
|
if (current != _current_window) {
|
||||||
glXSwapIntervalEXT(x11_display, drawable, val);
|
_current_window = current;
|
||||||
} else {
|
make_current();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
use_vsync = p_use;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLManager_Windows::is_using_vsync() const {
|
bool GLManager_Windows::is_using_vsync(DisplayServer::WindowID p_window_id) const {
|
||||||
return use_vsync;
|
return get_window(p_window_id).use_vsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC GLManager_Windows::get_hdc(DisplayServer::WindowID p_window_id) {
|
HDC GLManager_Windows::get_hdc(DisplayServer::WindowID p_window_id) {
|
||||||
@@ -354,7 +338,6 @@ GLManager_Windows::GLManager_Windows(ContextType p_context_type) {
|
|||||||
|
|
||||||
direct_render = false;
|
direct_render = false;
|
||||||
glx_minor = glx_major = 0;
|
glx_minor = glx_major = 0;
|
||||||
use_vsync = false;
|
|
||||||
_current_window = nullptr;
|
_current_window = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ private:
|
|||||||
struct GLWindow {
|
struct GLWindow {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
bool use_vsync = false;
|
||||||
|
|
||||||
// windows specific
|
// windows specific
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
@@ -72,8 +73,8 @@ private:
|
|||||||
|
|
||||||
GLWindow *_current_window = nullptr;
|
GLWindow *_current_window = nullptr;
|
||||||
|
|
||||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
|
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = nullptr;
|
||||||
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
|
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = nullptr;
|
||||||
|
|
||||||
// funcs
|
// funcs
|
||||||
void _internal_set_current_window(GLWindow *p_win);
|
void _internal_set_current_window(GLWindow *p_win);
|
||||||
@@ -86,7 +87,6 @@ private:
|
|||||||
|
|
||||||
bool direct_render;
|
bool direct_render;
|
||||||
int glx_minor, glx_major;
|
int glx_minor, glx_major;
|
||||||
bool use_vsync;
|
|
||||||
ContextType context_type;
|
ContextType context_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -110,8 +110,8 @@ public:
|
|||||||
|
|
||||||
Error initialize();
|
Error initialize();
|
||||||
|
|
||||||
void set_use_vsync(bool p_use);
|
void set_use_vsync(DisplayServer::WindowID p_window_id, bool p_use);
|
||||||
bool is_using_vsync() const;
|
bool is_using_vsync(DisplayServer::WindowID p_window_id) const;
|
||||||
|
|
||||||
HDC get_hdc(DisplayServer::WindowID p_window_id);
|
HDC get_hdc(DisplayServer::WindowID p_window_id);
|
||||||
HGLRC get_hglrc(DisplayServer::WindowID p_window_id);
|
HGLRC get_hglrc(DisplayServer::WindowID p_window_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user