GL/GLES: vsync.

This commit is contained in:
bkaradzic 2013-04-27 15:16:05 -07:00
parent 3ed331220f
commit 2ef508139f
11 changed files with 42 additions and 15 deletions

View file

@ -70,6 +70,11 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug,
bgfx::setDebug(_debug); bgfx::setDebug(_debug);
return false; return false;
} }
else if (key->m_key == Key::F7)
{
_reset ^= BGFX_RESET_VSYNC;
reset = true;
}
else if (key->m_key == Key::F8) else if (key->m_key == Key::F8)
{ {
_reset ^= BGFX_RESET_MSAA_X16; _reset ^= BGFX_RESET_MSAA_X16;

View file

@ -77,6 +77,8 @@ namespace bgfx
success = eglMakeCurrent(m_display, m_surface, m_surface, m_context); success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context."); BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
eglSwapInterval(m_display, 0);
# if BX_PLATFORM_EMSCRIPTEN # if BX_PLATFORM_EMSCRIPTEN
emscripten_set_canvas_size(_width, _height); emscripten_set_canvas_size(_width, _height);
# endif // BX_PLATFORM_EMSCRIPTEN # endif // BX_PLATFORM_EMSCRIPTEN
@ -93,8 +95,9 @@ namespace bgfx
m_context = NULL; m_context = NULL;
} }
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/) void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
{ {
eglSwapInterval(m_display, _vsync ? 1 : 0);
} }
void GlContext::swap() void GlContext::swap()

View file

@ -23,7 +23,7 @@ namespace bgfx
void create(uint32_t _width, uint32_t _height); void create(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
void resize(uint32_t _width, uint32_t _height); void resize(uint32_t _width, uint32_t _height, bool _vsync);
void swap(); void swap();
void import(); void import();

View file

@ -12,6 +12,10 @@
namespace bgfx namespace bgfx
{ {
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
# define GL_IMPORT(_optional, _proto, _func) _proto _func # define GL_IMPORT(_optional, _proto, _func) _proto _func
# include "glimports.h" # include "glimports.h"
# undef GL_IMPORT # undef GL_IMPORT
@ -119,7 +123,7 @@ namespace bgfx
XFree(visualInfo); XFree(visualInfo);
#if BGFX_CONFIG_RENDERER_OPENGL >= 31 #if BGFX_CONFIG_RENDERER_OPENGL >= 31
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB"); glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
if (NULL != glXCreateContextAttribsARB) if (NULL != glXCreateContextAttribsARB)
{ {
BX_TRACE("Create GL 3.1 context."); BX_TRACE("Create GL 3.1 context.");
@ -147,7 +151,7 @@ namespace bgfx
import(); import();
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT"); glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT");
if (NULL != glXSwapIntervalEXT) if (NULL != glXSwapIntervalEXT)
{ {
BX_TRACE("Using glXSwapIntervalEXT."); BX_TRACE("Using glXSwapIntervalEXT.");
@ -155,7 +159,7 @@ namespace bgfx
} }
else else
{ {
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI"); glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI");
if (NULL != glXSwapIntervalSGI) if (NULL != glXSwapIntervalSGI)
{ {
BX_TRACE("Using glXSwapIntervalSGI."); BX_TRACE("Using glXSwapIntervalSGI.");
@ -176,8 +180,18 @@ namespace bgfx
glXDestroyContext(s_display, m_context); glXDestroyContext(s_display, m_context);
} }
void GlContext::resize(uint32_t _width, uint32_t _height) void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
{ {
int32_t interval = _vsync ? 1 : 0;
if (NULL != glXSwapIntervalEXT)
{
glXSwapIntervalEXT(s_display, 0, interval);
}
else if (NULL != glXSwapIntervalSGI)
{
glXSwapIntervalSGI(interval);
}
} }
void GlContext::swap() void GlContext::swap()

View file

@ -22,7 +22,7 @@ namespace bgfx
void create(uint32_t _width, uint32_t _height); void create(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
void resize(uint32_t _width, uint32_t _height); void resize(uint32_t _width, uint32_t _height, bool _vsync);
void swap(); void swap();
void import(); void import();

View file

@ -19,7 +19,7 @@ namespace bgfx
void create(uint32_t _width, uint32_t _height); void create(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
void resize(uint32_t _width, uint32_t _height); void resize(uint32_t _width, uint32_t _height, bool _vsync);
void swap(); void swap();
void import(); void import();

View file

@ -47,7 +47,7 @@ namespace bgfx
{ {
} }
void GlContext::resize(uint32_t _width, uint32_t _height) void GlContext::resize(uint32_t _width, uint32_t _height, bool /*_vsync*/)
{ {
m_graphicsInterface->ResizeBuffers(m_context, _width, _height); m_graphicsInterface->ResizeBuffers(m_context, _width, _height);
} }

View file

@ -28,7 +28,7 @@ namespace bgfx
void create(uint32_t _width, uint32_t _height); void create(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
void resize(uint32_t _width, uint32_t _height); void resize(uint32_t _width, uint32_t _height, bool _vsync);
void swap(); void swap();
void import(); void import();

View file

@ -238,8 +238,12 @@ namespace bgfx
m_opengl32dll = NULL; m_opengl32dll = NULL;
} }
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/) void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
{ {
if (NULL != wglSwapIntervalEXT)
{
wglSwapIntervalEXT(_vsync ? 1 : 0);
}
} }
void GlContext::swap() void GlContext::swap()

View file

@ -66,7 +66,7 @@ namespace bgfx
void create(uint32_t _width, uint32_t _height); void create(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
void resize(uint32_t _width, uint32_t _height); void resize(uint32_t _width, uint32_t _height, bool _vsync);
void swap(); void swap();
void import(); void import();

View file

@ -291,7 +291,8 @@ namespace bgfx
uint32_t msaa = 1<<( (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT); uint32_t msaa = 1<<( (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT);
msaa = uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa); msaa = uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
setRenderContextSize(_resolution.m_width, _resolution.m_height, msaa); bool vsync = !!(m_resolution.m_flags&BGFX_RESET_VSYNC);
setRenderContextSize(_resolution.m_width, _resolution.m_height, msaa, vsync);
updateCapture(); updateCapture();
} }
} }
@ -393,7 +394,7 @@ namespace bgfx
#endif // BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3 #endif // BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
} }
void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _msaa = 0) void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _msaa = 0, bool _vsync = false)
{ {
if (_width != 0 if (_width != 0
|| _height != 0) || _height != 0)
@ -406,7 +407,7 @@ namespace bgfx
{ {
destroyMsaaFbo(); destroyMsaaFbo();
m_glctx.resize(_width, _height); m_glctx.resize(_width, _height, _vsync);
createMsaaFbo(_width, _height, _msaa); createMsaaFbo(_width, _height, _msaa);
} }