diff options
-rw-r--r-- | src/common.c | 39 | ||||
-rw-r--r-- | src/common.h | 4 | ||||
-rw-r--r-- | src/qgl_api.c | 42 | ||||
-rw-r--r-- | src/vid_sdl.c | 34 |
4 files changed, 75 insertions, 44 deletions
diff --git a/src/common.c b/src/common.c index 28b007b..29cc07b 100644 --- a/src/common.c +++ b/src/common.c @@ -1311,6 +1311,45 @@ color_index_t Com_ParseColor( const char *s, color_index_t last ) { return COLOR_NONE; } +#if USE_REF == REF_GL +/* +================ +Com_ParseExtensionString + +Helper function to parse an OpenGL-style extension string. +================ +*/ +unsigned Com_ParseExtensionString( const char *s, const char *const extnames[] ) { + unsigned mask; + const char *p; + size_t l1, l2; + int i; + + if( !s ) { + return 0; + } + + mask = 0; + while( *s ) { + p = Q_strchrnul( s, ' ' ); + l1 = p - s; + for( i = 0; extnames[i]; i++ ) { + l2 = strlen( extnames[i] ); + if( l1 == l2 && !memcmp( s, extnames[i], l1 ) ) { + mask |= 1 << i; + break; + } + } + if( !*p ) { + break; + } + s = p + 1; + } + + return mask; +} +#endif + /* ================ Com_PlayerToEntityState diff --git a/src/common.h b/src/common.h index f4d03d3..db4a06b 100644 --- a/src/common.h +++ b/src/common.h @@ -545,6 +545,10 @@ void Com_PageInMemory( void *buffer, size_t size ); color_index_t Com_ParseColor( const char *s, color_index_t last ); +#if USE_REF == REF_GL +unsigned Com_ParseExtensionString( const char *s, const char *const extnames[] ); +#endif + #ifndef _WIN32 void Com_FlushLogs( void ); #endif diff --git a/src/qgl_api.c b/src/qgl_api.c index e9503f3..0ee81a8 100644 --- a/src/qgl_api.c +++ b/src/qgl_api.c @@ -1137,40 +1137,18 @@ void QGL_InitExtensions( unsigned mask ) { #undef GPA -// must match defines in qgl_api.h! -static const char *const extnames[] = { - "GL_EXT_compiled_vertex_array", - "GL_ARB_multitexture", - "GL_EXT_texture_filter_anisotropic", - "GL_ARB_fragment_program", - "GL_ARB_vertex_buffer_object" -}; - -static const int numextnames = sizeof( extnames ) / sizeof( extnames[0] ); - unsigned QGL_ParseExtensionString( const char *s ) { - unsigned mask = 0; - const char *p; - size_t l1, l2; - int i; - - while( *s ) { - p = Q_strchrnul( s, ' ' ); - l1 = p - s; - for( i = 0; i < numextnames; i++ ) { - l2 = strlen( extnames[i] ); - if( l1 == l2 && !memcmp( s, extnames[i], l1 ) ) { - mask |= 1 << i; - break; - } - } - if( !*p ) { - break; - } - s = p + 1; - } + // must match defines in qgl_api.h! + static const char *const extnames[] = { + "GL_EXT_compiled_vertex_array", + "GL_ARB_multitexture", + "GL_EXT_texture_filter_anisotropic", + "GL_ARB_fragment_program", + "GL_ARB_vertex_buffer_object", + NULL + }; - return mask; + return Com_ParseExtensionString( s, extnames ); } void QGL_EnableLogging( qboolean enable ) diff --git a/src/vid_sdl.c b/src/vid_sdl.c index ece3b11..d446b99 100644 --- a/src/vid_sdl.c +++ b/src/vid_sdl.c @@ -572,9 +572,19 @@ void VID_EndFrame( void ) { #define SHOW_SYNC() \ Com_DDDPrintf( "%s: %u\n", __func__, sdl.sync_count ) +static unsigned glx_parse_extension_string( const char *s ) { + static const char *const extnames[] = { + "GLX_SGI_video_sync", + NULL + }; + + return Com_ParseExtensionString( s, extnames ); +} + static void init_glx( void ) { const char *extensions; cvar_t *gl_video_sync; + unsigned mask; if( !sdl.dpy ) { return; @@ -588,20 +598,20 @@ static void init_glx( void ) { gl_video_sync = Cvar_Get( "gl_video_sync", "1", 0 ); extensions = sdl.glXQueryExtensionsString( sdl.dpy, DefaultScreen( sdl.dpy ) ); - if( extensions && *extensions ) { - if( Q_stristr( extensions, "GLX_SGI_video_sync" ) ) { - if( gl_video_sync->integer ) { - Com_Printf( "...enabling GLX_SGI_video_sync\n" ); - sdl.glXGetVideoSyncSGI = SDL_GL_GetProcAddress( "glXGetVideoSyncSGI" ); - sdl.glXWaitVideoSyncSGI = SDL_GL_GetProcAddress( "glXWaitVideoSyncSGI" ); - sdl.glXGetVideoSyncSGI( &sdl.sync_count ); - sdl.flags |= QVF_VIDEOSYNC; - } else { - Com_Printf( "...ignoring GLX_SGI_video_sync\n" ); - } + mask = glx_parse_extension_string( extensions ); + if( mask & 1 ) { + if( gl_video_sync->integer ) { + Com_Printf( "...enabling GLX_SGI_video_sync\n" ); + sdl.glXGetVideoSyncSGI = SDL_GL_GetProcAddress( "glXGetVideoSyncSGI" ); + sdl.glXWaitVideoSyncSGI = SDL_GL_GetProcAddress( "glXWaitVideoSyncSGI" ); + sdl.glXGetVideoSyncSGI( &sdl.sync_count ); + sdl.flags |= QVF_VIDEOSYNC; } else { - Com_Printf( "GLX_SGI_video_sync not found\n" ); + Com_Printf( "...ignoring GLX_SGI_video_sync\n" ); } + } else if( gl_video_sync->integer ) { + Com_Printf( "GLX_SGI_video_sync not found\n" ); + Cvar_Set( "gl_video_sync", "0" ); } } #endif |