diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 9d8ee9b2..255f127c 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -565,66 +565,62 @@ static void SetWidthAndHeightFromCommandLine( void ) static void SetFullscreenModeFromCommandLine( void ) { #if !XASH_MOBILE_PLATFORM - if ( Sys_CheckParm("-fullscreen") ) + if( Sys_CheckParm( "-fullscreen" )) { Cvar_Set( "fullscreen", "1" ); } - else if ( Sys_CheckParm( "-windowed" ) ) + else if( Sys_CheckParm( "-windowed" )) { Cvar_Set( "fullscreen", "0" ); } #endif } -void R_CollectRendererNames( void ) +static void R_CollectRendererNames( void ) { - const char *renderers[] = DEFAULT_RENDERERS; - int i, cur; - - cur = 0; - for( i = 0; i < DEFAULT_RENDERERS_LEN; i++ ) + // ordering is important! + static const char *shortNames[] = { - string temp; - void *dll, *pfn; - - R_GetRendererName( temp, sizeof( temp ), renderers[i] ); - - dll = COM_LoadLibrary( temp, false, true ); - if( !dll ) - { - Con_Reportf( "R_CollectRendererNames: can't load library %s: %s\n", temp, COM_GetLibraryError() ); - continue; - } - - pfn = COM_GetProcAddress( dll, GET_REF_API ); - if( !pfn ) - { - 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] )); - } +#if XASH_REF_GL_ENABLED + "gl", +#endif +#if XASH_REF_NANOGL_ENABLED + "gles1", +#endif +#if XASH_REF_GLWES_ENABLED + "gles2", +#endif +#if XASH_REF_GL4ES_ENABLED + "gl4es", +#endif +#if XASH_REF_SOFT_ENABLED + "soft", +#endif + }; - 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++; - COM_FreeLibrary( dll ); - } - ref.numRenderers = cur; + ref.numRenderers = ARRAYSIZE( shortNames ); + ref.shortNames = shortNames; + ref.readableNames = readableNames; } qboolean R_Init( void ) @@ -678,30 +674,28 @@ qboolean R_Init( void ) // 1. Command line `-ref` argument. // 2. `ref_dll` cvar. // 3. Detected renderers in `DEFAULT_RENDERERS` order. - 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 - Q_strncpy( requested, r_refdll->string, sizeof( requested ) ); + requested[0] = 0; + + if( !success && Sys_GetParmFromCmdLine( "-ref", 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 ); + } if( !success ) { int i; - // cycle through renderers that we collected in CollectRendererNames - for( i = 0; i < ref.numRenderers; i++ ) + for( i = 0; i < ref.numRenderers && !success; i++ ) { // skip renderer that was requested but failed to load - if( !Q_strcmp( requested, ref.shortNames[i] ) ) + if( !Q_strcmp( requested, ref.shortNames[i] )) continue; success = R_LoadRenderer( ref.shortNames[i] ); - - // yay, found working one - if( success ) - break; } } diff --git a/engine/client/ref_common.h b/engine/client/ref_common.h index a8ee1405..3904d58b 100644 --- a/engine/client/ref_common.h +++ b/engine/client/ref_common.h @@ -27,9 +27,10 @@ struct ref_state_s HINSTANCE hInstance; ref_interface_t dllFuncs; + // depends on build configuration int numRenderers; - string shortNames[DEFAULT_RENDERERS_LEN]; - string readableNames[DEFAULT_RENDERERS_LEN]; + const char **shortNames; + const char **readableNames; }; extern struct ref_state_s ref; diff --git a/engine/common/com_strings.h b/engine/common/com_strings.h index 50bde373..d3dc7dca 100644 --- a/engine/common/com_strings.h +++ b/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_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