Set vsync on window creation when using GLES3.
Add vsync to Windows platform
This commit is contained in:
parent
4935493f72
commit
58a9cfee80
|
@ -4414,7 +4414,7 @@ void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mo
|
|||
|
||||
#if defined(GLES3_ENABLED)
|
||||
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
|
||||
}
|
||||
|
@ -4675,6 +4675,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
|
|||
if (gl_manager) {
|
||||
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");
|
||||
window_set_vsync_mode(p_vsync_mode, id);
|
||||
}
|
||||
#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);
|
||||
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
|
||||
[wd.window_view updateLayerDelegate];
|
||||
id = window_id_counter++;
|
||||
|
@ -2999,7 +3000,7 @@ void DisplayServerMacOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_
|
|||
_THREAD_SAFE_METHOD_
|
||||
#if defined(GLES3_ENABLED)
|
||||
if (gl_manager) {
|
||||
gl_manager->set_use_vsync(p_vsync_mode);
|
||||
gl_manager->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
|
||||
}
|
||||
#endif
|
||||
#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);
|
||||
}
|
||||
#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
|
||||
|
||||
|
|
|
@ -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;
|
||||
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 (!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");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue