Browse Source

engine: client: ref_common: eliminate COM_FreeLibrary in renderer names query, hardcoding them instead

pull/2/head
Alibek Omarov 2 years ago
parent
commit
ec355a83d1
  1. 112
      engine/client/ref_common.c
  2. 5
      engine/client/ref_common.h
  3. 4
      engine/common/com_strings.h

112
engine/client/ref_common.c

@ -565,66 +565,62 @@ static void SetWidthAndHeightFromCommandLine( void )
static void SetFullscreenModeFromCommandLine( void ) static void SetFullscreenModeFromCommandLine( void )
{ {
#if !XASH_MOBILE_PLATFORM #if !XASH_MOBILE_PLATFORM
if ( Sys_CheckParm("-fullscreen") ) if( Sys_CheckParm( "-fullscreen" ))
{ {
Cvar_Set( "fullscreen", "1" ); Cvar_Set( "fullscreen", "1" );
} }
else if ( Sys_CheckParm( "-windowed" ) ) else if( Sys_CheckParm( "-windowed" ))
{ {
Cvar_Set( "fullscreen", "0" ); Cvar_Set( "fullscreen", "0" );
} }
#endif #endif
} }
void R_CollectRendererNames( void ) static void R_CollectRendererNames( void )
{ {
const char *renderers[] = DEFAULT_RENDERERS; // ordering is important!
int i, cur; static const char *shortNames[] =
cur = 0;
for( i = 0; i < DEFAULT_RENDERERS_LEN; i++ )
{ {
string temp; #if XASH_REF_GL_ENABLED
void *dll, *pfn; "gl",
#endif
R_GetRendererName( temp, sizeof( temp ), renderers[i] ); #if XASH_REF_NANOGL_ENABLED
"gles1",
dll = COM_LoadLibrary( temp, false, true ); #endif
if( !dll ) #if XASH_REF_GLWES_ENABLED
{ "gles2",
Con_Reportf( "R_CollectRendererNames: can't load library %s: %s\n", temp, COM_GetLibraryError() ); #endif
continue; #if XASH_REF_GL4ES_ENABLED
} "gl4es",
#endif
pfn = COM_GetProcAddress( dll, GET_REF_API ); #if XASH_REF_SOFT_ENABLED
if( !pfn ) "soft",
{ #endif
Con_Reportf( "R_CollectRendererNames: can't find API entry point in %s\n", temp ); };
COM_FreeLibrary( dll );
continue;
}
Q_strncpy( ref.shortNames[cur], renderers[i], sizeof( ref.shortNames[cur] ));
pfn = COM_GetProcAddress( dll, GET_REF_HUMANREADABLE_NAME );
if( !pfn ) // just in case
{
Con_Reportf( "R_CollectRendererNames: can't find GetHumanReadableName export in %s\n", temp );
Q_strncpy( ref.readableNames[cur], renderers[i], sizeof( ref.readableNames[cur] ));
}
else
{
REF_HUMANREADABLE_NAME GetHumanReadableName = (REF_HUMANREADABLE_NAME)pfn;
GetHumanReadableName( ref.readableNames[cur], sizeof( ref.readableNames[cur] ));
}
Con_Printf( "Found renderer %s: %s\n", ref.shortNames[cur], ref.readableNames[cur] ); // ordering is important here too!
static const char *readableNames[ARRAYSIZE( shortNames )] =
{
#if XASH_REF_GL_ENABLED
"OpenGL",
#endif
#if XASH_REF_NANOGL_ENABLED
"GLES1 (NanoGL)",
#endif
#if XASH_REF_GLWES_ENABLED
"GLES2 (gl-wes-v2)",
#endif
#if XASH_REF_GL4ES_ENABLED
"GL4ES",
#endif
#if XASH_REF_SOFT_ENABLED
"Software",
#endif
};
cur++; ref.numRenderers = ARRAYSIZE( shortNames );
COM_FreeLibrary( dll ); ref.shortNames = shortNames;
} ref.readableNames = readableNames;
ref.numRenderers = cur;
} }
qboolean R_Init( void ) qboolean R_Init( void )
@ -678,30 +674,28 @@ qboolean R_Init( void )
// 1. Command line `-ref` argument. // 1. Command line `-ref` argument.
// 2. `ref_dll` cvar. // 2. `ref_dll` cvar.
// 3. Detected renderers in `DEFAULT_RENDERERS` order. // 3. Detected renderers in `DEFAULT_RENDERERS` order.
requested[0] = '\0'; requested[0] = 0;
if( !Sys_GetParmFromCmdLine( "-ref", requested ) && COM_CheckString( r_refdll->string ) )
// r_refdll is set to empty by default, so we can change hardcoded defaults just in case if( !success && Sys_GetParmFromCmdLine( "-ref", requested ))
Q_strncpy( requested, r_refdll->string, sizeof( requested ) ); success = R_LoadRenderer( requested );
if ( requested[0] ) if( !success && COM_CheckString( r_refdll->string ))
{
Q_strncpy( requested, r_refdll->string, sizeof( requested ));
success = R_LoadRenderer( requested ); success = R_LoadRenderer( requested );
}
if( !success ) if( !success )
{ {
int i; int i;
// cycle through renderers that we collected in CollectRendererNames for( i = 0; i < ref.numRenderers && !success; i++ )
for( i = 0; i < ref.numRenderers; i++ )
{ {
// skip renderer that was requested but failed to load // skip renderer that was requested but failed to load
if( !Q_strcmp( requested, ref.shortNames[i] ) ) if( !Q_strcmp( requested, ref.shortNames[i] ))
continue; continue;
success = R_LoadRenderer( ref.shortNames[i] ); success = R_LoadRenderer( ref.shortNames[i] );
// yay, found working one
if( success )
break;
} }
} }

5
engine/client/ref_common.h

@ -27,9 +27,10 @@ struct ref_state_s
HINSTANCE hInstance; HINSTANCE hInstance;
ref_interface_t dllFuncs; ref_interface_t dllFuncs;
// depends on build configuration
int numRenderers; int numRenderers;
string shortNames[DEFAULT_RENDERERS_LEN]; const char **shortNames;
string readableNames[DEFAULT_RENDERERS_LEN]; const char **readableNames;
}; };
extern struct ref_state_s ref; extern struct ref_state_s ref;

4
engine/common/com_strings.h

@ -68,8 +68,4 @@ GNU General Public License for more details.
#define XASH_VERSION "0.20" // engine current version #define XASH_VERSION "0.20" // engine current version
#define XASH_COMPAT_VERSION "0.99" // version we are based on #define XASH_COMPAT_VERSION "0.99" // version we are based on
// renderers order is important, software is always a last chance fallback
#define DEFAULT_RENDERERS { "gl", "gles1", "gles2", "gl4es", "soft" }
#define DEFAULT_RENDERERS_LEN 5
#endif//COM_STRINGS_H #endif//COM_STRINGS_H

Loading…
Cancel
Save