OpenGL: disable vsync, atleast under Windows

This commit is contained in:
Arisotura 2019-06-20 16:00:12 +02:00
parent 77bf92a272
commit f59094e033
4 changed files with 42 additions and 0 deletions

View File

@ -620,6 +620,7 @@ _UI_EXTERN void *uiGLGetProcAddress(const char* proc);
_UI_EXTERN int uiGLGetFramebuffer(uiGLContext* ctx);
_UI_EXTERN float uiGLGetFramebufferScale(uiGLContext* ctx);
_UI_EXTERN void uiGLSwapBuffers(uiGLContext* ctx);
_UI_EXTERN void uiGLSetVSync(int sync);
_UI_ENUM(uiModifiers) {

View File

@ -193,6 +193,11 @@ void uiGLSwapBuffers(uiGLContext* ctx)
ctx->backbuffer = ctx->backbuffer ? 0 : 1;
}
void uiGLSetVSync(int sync)
{
// TODO
}
void uiGLMakeContextCurrent(uiGLContext* ctx)
{
if (!ctx)

View File

@ -3,6 +3,7 @@
#include "area.hpp"
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/wglext.h>
struct uiGLContext
@ -159,3 +160,37 @@ float uiGLGetFramebufferScale(uiGLContext* ctx)
// TODO
return 1;
}
void uiGLSetVSync(int sync)
{
static PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = NULL;
static bool symloaded = false;
if (!symloaded)
{
PFNGLGETSTRINGIPROC _glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi");
if (_glGetStringi == NULL) return;
GLint numext;
glGetIntegerv(GL_NUM_EXTENSIONS, &numext);
bool hasswapctrl = false;
for (GLint i = 0; i < numext; i++)
{
const char* ext = (const char*)_glGetStringi(GL_EXTENSIONS, i);
if (!stricmp(ext, "WGL_EXT_swap_control"))
{
hasswapctrl = true;
break;
}
}
if (hasswapctrl)
_wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
symloaded = true;
}
if (_wglSwapIntervalEXT)
_wglSwapIntervalEXT(sync);
}

View File

@ -2417,6 +2417,7 @@ void CreateMainWindow(bool opengl)
if (opengl_good)
{
uiGLMakeContextCurrent(GLContext);
uiGLSetVSync(0); // TODO: make configurable?
if (!GLScreen_Init()) opengl_good = false;
if (opengl_good)
{