Merge pull request #1882 from rextimmy/gl_vsync

OpenGL vsync fixes.
This commit is contained in:
Areloch 2016-12-28 21:45:12 -06:00 committed by GitHub
commit 4a84c68137
7 changed files with 47 additions and 4 deletions

View file

@ -172,12 +172,21 @@ void GFXGLDevice::initGLState()
PlatformGL::setVSync(smDisableVSync ? 0 : 1);
//install vsync callback
Con::NotifyDelegate clbk(this, &GFXGLDevice::vsyncCallback);
Con::addVariableNotify("$pref::Video::disableVerticalSync", clbk);
//OpenGL 3 need a binded VAO for render
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
void GFXGLDevice::vsyncCallback()
{
PlatformGL::setVSync(smDisableVSync ? 0 : 1);
}
GFXGLDevice::GFXGLDevice(U32 adapterIndex) :
mAdapterIndex(adapterIndex),
mNeedUpdateVertexAttrib(false),

View file

@ -256,6 +256,8 @@ private:
GFXVertexBuffer* findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize); ///< Returns an existing volatile VB which has >= numVerts and the same vert flags/size, or creates a new VB if necessary
GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary
void vsyncCallback(); ///< Vsync callback
void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc.

View file

@ -41,7 +41,12 @@ namespace GL
void gglPerformExtensionBinds(void *context)
{
#ifdef TORQUE_OS_WIN
if (!gladLoadWGL(wglGetCurrentDC()))
{
AssertFatal(false, "Unable to load GLAD WGL extensions. Make sure your OpenGL drivers are up to date!");
}
#endif
}
}

View file

@ -30,7 +30,7 @@
#include "tGL.h"
#include <glad/glad_wgl.h>
#define gglHasWExtension(window, EXTENSION) GLAD_WGL_##EXTENSION
#define gglHasWExtension(EXTENSION) GLAD_WGL_##EXTENSION
#endif //TORQUE_OPENGL

View file

@ -269,7 +269,7 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
if (!wglMakeCurrent(hdcGL, tempGLRC))
AssertFatal(false, "Couldn't make temp GL context.");
if( gglHasWExtension(hdcGL, ARB_create_context) )
if( gglHasWExtension( ARB_create_context) )
{
int const create_attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, OGL_MAJOR,

View file

@ -6,6 +6,8 @@
#include "gfx/gl/tGL/tWGL.h"
#endif
#include "gfx/gl/gfxGLUtils.h"
namespace PlatformGL
{
@ -69,6 +71,9 @@ namespace PlatformGL
void setVSync(const int i)
{
PRESERVE_FRAMEBUFFER();
// Nvidia needs to have the default framebuffer bound or the vsync calls fail
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if( i == 1 || i == -1 )
{
int ret = SDL_GL_SetSwapInterval(-1);
@ -78,6 +83,7 @@ namespace PlatformGL
}
else
SDL_GL_SetSwapInterval(0);
}
}

View file

@ -2,11 +2,32 @@
#include "platform/platformGL.h"
#include "gfx/gl/tGL/tWGL.h"
#include "gfx/gl/gfxGLUtils.h"
void PlatformGL::setVSync(const int i)
{
if (gglHasWExtension(wglGetCurrentDC(), EXT_swap_control))
if (gglHasWExtension(EXT_swap_control))
{
PRESERVE_FRAMEBUFFER();
// NVidia needs to have the default framebuffer bound or the vsync calls fail
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (gglHasWExtension(EXT_swap_control_tear))
{
if (i == 1 || i == -1)
{
BOOL ret = wglSwapIntervalEXT(-1);
if (!ret)
wglSwapIntervalEXT(1);
}
else
{
wglSwapIntervalEXT(i);
}
return;
}
//fallback with no EXT_swap_control_tear
wglSwapIntervalEXT(i);
}
}