ref: gl: more simple search of GL func with alternative name (EXT, OES suffixes or no suffix)

This commit is contained in:
Alibek Omarov 2023-10-22 19:16:16 +03:00
parent 3ac8ad9484
commit 3251b68df5

View file

@ -551,46 +551,52 @@ qboolean GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char
// functions are cleared before all the extensions are evaluated // functions are cleared before all the extensions are evaluated
if(( *func->func = (void *)gEngfuncs.GL_GetProcAddress( func->name )) == NULL ) if(( *func->func = (void *)gEngfuncs.GL_GetProcAddress( func->name )) == NULL )
{ {
string name; string name;
char *end;
size_t i = 0;
#ifdef XASH_GLES
const char *suffixes[] = { "", "EXT", "OES" };
#else
const char *suffixes[] = { "", "EXT" };
#endif
// HACK: fix ARB names // HACK: fix ARB names
const char *str = Q_strstr( func->name, "ARB" ); Q_strncpy( name, func->name, sizeof( name ));
Q_strncpy( name, func->name, MAX_STRING ); if(( end = Q_strstr( name, "ARB" )))
if( str )
{ {
name[str - func->name] = '\0'; // cut func suffix *end = '\0';
// if this was glFuncARB, try glFunc }
*func->func = gEngfuncs.GL_GetProcAddress( name ); else // I need Q_strstrnul
{
end = name + Q_strlen( name );
i++; // skip empty suffix
}
for( ; i < sizeof( suffixes ) / sizeof( suffixes[0] ); i++ )
{
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
gEngfuncs.Con_Printf( S_NOTE "found %s\n", name );
*func->func = f;
break;
} }
else else
{ {
// set pointer to func name end to cut it correctly *end = '\0'; // cut suffix, try next
str = func->name + Q_strlen( func->name ); }
name[str - func->name] = '\0';
} }
// try glFuncEXT // not found...
if( !*func->func ) if( i == sizeof( suffixes ) / sizeof( suffixes[0] ))
{ {
Q_strncat( name, "EXT", MAX_STRING );
*func->func = gEngfuncs.GL_GetProcAddress( name );
}
#ifdef XASH_GLES
// try glFuncOES
if( !*func->func )
{
name[str - func->name] = '\0'; // cut EXT from previous try
Q_strncat( name, "OES", MAX_STRING );
*func->func = gEngfuncs.GL_GetProcAddress( name );
}
#endif
if( !*func->func )
GL_SetExtension( r_ext, false ); GL_SetExtension( r_ext, false );
else // GL_GetProcAddress prints errors about missing functions, so tell user that we found it with different name }
gEngfuncs.Con_Printf( S_NOTE "found %s\n", name );
} }
} }
#endif #endif