Skip to content

Commit c253c8b

Browse files
author
Nick Klingensmith
committed
Vsync for wgl
Signed-off-by: Nick Klingensmith <quic_nklingen@quicinc.com>
1 parent df127ec commit c253c8b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

sk_gpu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,8 +3321,10 @@ DXGI_FORMAT skg_ind_to_dxgi(skg_ind_fmt_ format) {
33213321

33223322
typedef BOOL (*wglChoosePixelFormatARB_proc) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
33233323
typedef HGLRC (*wglCreateContextAttribsARB_proc) (HDC hDC, HGLRC hShareContext, const int *attribList);
3324+
typedef BOOL (*wglSwapIntervalEXT_proc) (int interval);
33243325
wglChoosePixelFormatARB_proc wglChoosePixelFormatARB;
33253326
wglCreateContextAttribsARB_proc wglCreateContextAttribsARB;
3327+
wglSwapIntervalEXT_proc wglSwapIntervalEXT;
33263328
#endif
33273329

33283330
#ifdef _SKG_GL_LOAD_GLX
@@ -3830,6 +3832,7 @@ int32_t gl_init_wgl() {
38303832
// Function pointers we need to actually initialize OpenGL
38313833
wglChoosePixelFormatARB = (wglChoosePixelFormatARB_proc )wglGetProcAddress("wglChoosePixelFormatARB");
38323834
wglCreateContextAttribsARB = (wglCreateContextAttribsARB_proc)wglGetProcAddress("wglCreateContextAttribsARB");
3835+
wglSwapIntervalEXT = (wglSwapIntervalEXT_proc )wglGetProcAddress("wglSwapIntervalEXT");
38333836

38343837
// Shut down the dummy so we can set up OpenGL for real
38353838
wglMakeCurrent (dummy_dc, 0);
@@ -3902,6 +3905,9 @@ int32_t gl_init_wgl() {
39023905
skg_log(skg_log_critical, "Couldn't activate GL context!");
39033906
return false;
39043907
}
3908+
3909+
// Turn on vsync
3910+
if (wglSwapIntervalEXT) wglSwapIntervalEXT(1);
39053911
#endif // _SKG_GL_LOAD_WGL
39063912
return 1;
39073913
}
@@ -5222,6 +5228,7 @@ void skg_swapchain_bind(skg_swapchain_t *swapchain) {
52225228
skg_tex_target_bind(&swapchain->_surface, -1, 0);
52235229
#elif defined(_SKG_GL_LOAD_WGL)
52245230
wglMakeCurrent((HDC)swapchain->_hdc, gl_hrc);
5231+
if (wglSwapIntervalEXT) wglSwapIntervalEXT(1); // Enable VSync
52255232
skg_tex_target_bind(nullptr, -1, 0);
52265233
#elif defined(_SKG_GL_LOAD_EGL)
52275234
eglMakeCurrent(egl_display, swapchain->_egl_surface, swapchain->_egl_surface, egl_context);

src/sk_gpu_gl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@
6565

6666
typedef BOOL (*wglChoosePixelFormatARB_proc) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
6767
typedef HGLRC (*wglCreateContextAttribsARB_proc) (HDC hDC, HGLRC hShareContext, const int *attribList);
68+
typedef BOOL (*wglSwapIntervalEXT_proc) (int interval);
6869
wglChoosePixelFormatARB_proc wglChoosePixelFormatARB;
6970
wglCreateContextAttribsARB_proc wglCreateContextAttribsARB;
71+
wglSwapIntervalEXT_proc wglSwapIntervalEXT;
7072
#endif
7173

7274
#ifdef _SKG_GL_LOAD_GLX
@@ -574,6 +576,7 @@ int32_t gl_init_wgl() {
574576
// Function pointers we need to actually initialize OpenGL
575577
wglChoosePixelFormatARB = (wglChoosePixelFormatARB_proc )wglGetProcAddress("wglChoosePixelFormatARB");
576578
wglCreateContextAttribsARB = (wglCreateContextAttribsARB_proc)wglGetProcAddress("wglCreateContextAttribsARB");
579+
wglSwapIntervalEXT = (wglSwapIntervalEXT_proc )wglGetProcAddress("wglSwapIntervalEXT");
577580

578581
// Shut down the dummy so we can set up OpenGL for real
579582
wglMakeCurrent (dummy_dc, 0);
@@ -646,6 +649,9 @@ int32_t gl_init_wgl() {
646649
skg_log(skg_log_critical, "Couldn't activate GL context!");
647650
return false;
648651
}
652+
653+
// Turn on vsync
654+
if (wglSwapIntervalEXT) wglSwapIntervalEXT(1);
649655
#endif // _SKG_GL_LOAD_WGL
650656
return 1;
651657
}
@@ -1966,6 +1972,7 @@ void skg_swapchain_bind(skg_swapchain_t *swapchain) {
19661972
skg_tex_target_bind(&swapchain->_surface, -1, 0);
19671973
#elif defined(_SKG_GL_LOAD_WGL)
19681974
wglMakeCurrent((HDC)swapchain->_hdc, gl_hrc);
1975+
if (wglSwapIntervalEXT) wglSwapIntervalEXT(1); // Enable VSync
19691976
skg_tex_target_bind(nullptr, -1, 0);
19701977
#elif defined(_SKG_GL_LOAD_EGL)
19711978
eglMakeCurrent(egl_display, swapchain->_egl_surface, swapchain->_egl_surface, egl_context);

0 commit comments

Comments
 (0)