diff options
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/display_server_windows.cpp | 14 | ||||
-rw-r--r-- | platform/windows/gl_manager_windows.cpp | 59 | ||||
-rw-r--r-- | platform/windows/gl_manager_windows.h | 10 |
3 files changed, 40 insertions, 43 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index af80a07da9..0b878feb7f 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -2023,6 +2023,12 @@ void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn context_vulkan->set_vsync_mode(p_window, p_vsync_mode); } #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 { @@ -2032,6 +2038,13 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_ return context_vulkan->get_vsync_mode(p_window); } #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; } @@ -3601,6 +3614,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, windows.erase(id); ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create an OpenGL window."); } + window_set_vsync_mode(p_vsync_mode, id); } #endif diff --git a/platform/windows/gl_manager_windows.cpp b/platform/windows/gl_manager_windows.cpp index 900bca8258..5b39c56ea3 100644 --- a/platform/windows/gl_manager_windows.cpp +++ b/platform/windows/gl_manager_windows.cpp @@ -185,6 +185,10 @@ Error GLManager_Windows::_create_context(GLWindow &win, GLDisplay &gl_display) { return ERR_CANT_CREATE; } + if (!wglSwapIntervalEXT) { + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + } + return OK; } @@ -293,50 +297,30 @@ void GLManager_Windows::swap_buffers() { } Error GLManager_Windows::initialize() { - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT"); - //glWrapperInit(wrapper_get_proc_address); - return OK; } -void GLManager_Windows::set_use_vsync(bool p_use) { - /* - static bool setup = false; - static PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr; - static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalMESA = nullptr; - static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; - - if (!setup) { - setup = true; - 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"); - } +void GLManager_Windows::set_use_vsync(DisplayServer::WindowID p_window_id, bool p_use) { + GLWindow &win = get_window(p_window_id); + GLWindow *current = _current_window; + + if (&win != _current_window) { + window_make_current(p_window_id); } - int val = p_use ? 1 : 0; - if (glXSwapIntervalMESA) { - glXSwapIntervalMESA(val); - } else if (glXSwapIntervalSGI) { - glXSwapIntervalSGI(val); - } else if (glXSwapIntervalEXT) { - GLXDrawable drawable = glXGetCurrentDrawable(); - glXSwapIntervalEXT(x11_display, drawable, val); - } else { - return; + + if (wglSwapIntervalEXT) { + win.use_vsync = p_use; + wglSwapIntervalEXT(p_use ? 1 : 0); + } + + if (current != _current_window) { + _current_window = current; + make_current(); } - use_vsync = p_use; - */ } -bool GLManager_Windows::is_using_vsync() const { - return use_vsync; +bool GLManager_Windows::is_using_vsync(DisplayServer::WindowID p_window_id) const { + return get_window(p_window_id).use_vsync; } 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; glx_minor = glx_major = 0; - use_vsync = false; _current_window = nullptr; } diff --git a/platform/windows/gl_manager_windows.h b/platform/windows/gl_manager_windows.h index c6d5f9f855..94f3ce9860 100644 --- a/platform/windows/gl_manager_windows.h +++ b/platform/windows/gl_manager_windows.h @@ -54,6 +54,7 @@ private: struct GLWindow { int width = 0; int height = 0; + bool use_vsync = false; // windows specific HDC hDC; @@ -72,8 +73,8 @@ private: GLWindow *_current_window = nullptr; - PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; - PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT; + PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = nullptr; + PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = nullptr; // funcs void _internal_set_current_window(GLWindow *p_win); @@ -86,7 +87,6 @@ private: bool direct_render; int glx_minor, glx_major; - bool use_vsync; ContextType context_type; private: @@ -110,8 +110,8 @@ public: Error initialize(); - void set_use_vsync(bool p_use); - bool is_using_vsync() const; + void set_use_vsync(DisplayServer::WindowID p_window_id, bool p_use); + bool is_using_vsync(DisplayServer::WindowID p_window_id) const; HDC get_hdc(DisplayServer::WindowID p_window_id); HGLRC get_hglrc(DisplayServer::WindowID p_window_id); |