Skip to content

Commit

Permalink
ref/gl: refactor gl extension checking again
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn authored and a1batross committed Feb 27, 2024
1 parent 328d41a commit 5bbe02d
Showing 1 changed file with 50 additions and 41 deletions.
91 changes: 50 additions & 41 deletions ref/gl/gl_opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,62 +556,71 @@ qboolean GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char
for( func = funcs; func && func->name; func++ )
{
// functions are cleared before all the extensions are evaluated
#ifndef XASH_GLES // arb on gles is last (TODO: separate search tables for GLES/CORE)
if(( *func->func = (void *)gEngfuncs.GL_GetProcAddress( func->name )) == NULL )
#endif
{
string name;
char *end;
size_t i = 0;
string name;
char *end;
size_t i = 0;
qboolean first_try = true;
// NULL means just func->name, but empty suffix cuts ARB suffix if present
#ifdef XASH_GLES
const char *suffixes[] = { "", "EXT", "OES", "ARB" };
const char *suffixes[] = { "", "EXT", "OES", NULL, "ARB" };
#else
const char *suffixes[] = { "", "EXT" };
const char *suffixes[] = { NULL, "", "EXT", "ARB" };
#endif

// HACK: fix ARB names
Q_strncpy( name, func->name, sizeof( name ));
if(( end = Q_strstr( name, "ARB" )))
// Remove ARB suffix
Q_strncpy( name, func->name, sizeof( name ));
if(( end = Q_strstr( name, "ARB" )))
{
*end = '\0';
}
else // I need Q_strstrnul
{
end = name + Q_strlen( name );
}

for( ; i < sizeof( suffixes ) / sizeof( suffixes[0] ); i++ )
{
void *f;
const char *pname = name;
size_t name_len = end - pname;
const char *orig_suffix = func->name + name_len;

if( suffixes[i] )
{
*end = '\0';
// if suffix is original suffix, it's handled with NULL
if( orig_suffix[0] && !Q_strcmp( orig_suffix, suffixes[i] ))
continue;
Q_strncat( name, suffixes[i], sizeof( name ));
}
else // I need Q_strstrnul
else
{
end = name + Q_strlen( name );
#ifndef XASH_GLES
i++; // skip empty suffix
#endif
// if original name does not have a suffix, it will be handled with empty suffix
if( !orig_suffix[0] )
continue;
pname = func->name;
}

for( ; i < sizeof( suffixes ) / sizeof( suffixes[0] ); i++ )
if(( f = gEngfuncs.GL_GetProcAddress( pname )))
{
void *f;

Q_strncat( name, suffixes[i], sizeof( name ));

if(( f = gEngfuncs.GL_GetProcAddress( name )))
{
// GL_GetProcAddress prints errors about missing functions, so tell user that we found it with different name
#ifdef XASH_GLES
if(i != 0)
#endif
gEngfuncs.Con_Printf( S_NOTE "found %s\n", name );
// if we already tried this function, notify about success after previous error from GL_GetProcAddress
if(!first_try)
gEngfuncs.Con_Printf( S_NOTE "found %s\n", pname );
first_try = false;

*func->func = f;
break;
}
else
{
*end = '\0'; // cut suffix, try next
}
*func->func = f;
break;
}

// not found...
if( i == sizeof( suffixes ) / sizeof( suffixes[0] ))
else
{
GL_SetExtension( r_ext, false );
*end = '\0'; // cut suffix, try next
}
}

// not found...
if( i == sizeof( suffixes ) / sizeof( suffixes[0] ))
{
GL_SetExtension( r_ext, false );
}
}
#endif

Expand Down

0 comments on commit 5bbe02d

Please sign in to comment.