Browse Source

engine: ref: add optional export to determine actual human readable renderer name

pull/2/head
Alibek Omarov 5 years ago
parent
commit
a1ae770f70
  1. 69
      engine/client/ref_common.c
  2. 9
      engine/client/ref_common.h
  3. 3
      engine/common/com_strings.h
  4. 4
      engine/ref_api.h
  5. 18
      ref_gl/gl_context.c

69
engine/client/ref_common.c

@ -430,23 +430,16 @@ static qboolean R_LoadProgs( const char *name ) @@ -430,23 +430,16 @@ static qboolean R_LoadProgs( const char *name )
if( ref.hInstance ) R_UnloadProgs();
#ifdef XASH_INTERNAL_GAMELIBS
if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) ))
{
return false;
}
#else
FS_AllowDirectPaths( true );
if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) ))
{
FS_AllowDirectPaths( false );
return false;
}
#endif
FS_AllowDirectPaths( false );
if( ( GetRefAPI = (REFAPI)COM_GetProcAddress( ref.hInstance, "GetRefAPI" )) == NULL )
if( !( GetRefAPI = (REFAPI)COM_GetProcAddress( ref.hInstance, GET_REF_API )) )
{
COM_FreeLibrary( ref.hInstance );
Con_Reportf( "R_LoadProgs: can't init renderer API\n" );
@ -509,13 +502,12 @@ static void R_GetRendererName( char *dest, size_t size, const char *opt ) @@ -509,13 +502,12 @@ static void R_GetRendererName( char *dest, size_t size, const char *opt )
if( !Q_strstr( opt, va( ".%s", OS_LIB_EXT )))
{
// shortened renderer name
Q_snprintf( dest, size, "%sref_%s.%s",
#ifdef OS_LIB_PREFIX
OS_LIB_PREFIX,
#ifdef XASH_INTERNAL_GAMELIBS
Q_snprintf( dest, size, "ref_%s", opt );
#else
"",
Q_snprintf( dest, size, "%sref_%s.%s",
OS_LIB_PREFIX, opt, OS_LIB_EXT );
#endif
opt, OS_LIB_EXT );
Con_Printf( "Loading renderer by short name: %s\n", opt );
}
else
@ -574,10 +566,57 @@ static void SetFullscreenModeFromCommandLine( ) @@ -574,10 +566,57 @@ static void SetFullscreenModeFromCommandLine( )
#endif
}
void R_CollectRendererNames( void )
{
const char *renderers[] = DEFAULT_RENDERERS;
int i;
ref.numRenderers = 0;
for( i = 0; i < ARRAYSIZE( ref.renderers ); i++ )
{
ref_renderer_t *refdll = ref.renderers + ref.numRenderers;
string temp;
void *dll, *pfn;
R_GetRendererName( temp, sizeof( temp ), renderers[i] );
dll = COM_LoadLibrary( temp, false, true );
if( !dll )
continue;
pfn = COM_GetProcAddress( dll, GET_REF_API );
if( !pfn )
{
COM_FreeLibrary( dll );
continue;
}
Q_strncpy( refdll->shortenedName, renderers[i], sizeof( refdll->shortenedName ));
pfn = COM_GetProcAddress( dll, GET_REF_HUMANREADABLE_NAME );
if( !pfn ) // just in case
{
Q_strncpy( refdll->humanReadable, renderers[i], sizeof( refdll->humanReadable ));
}
else
{
REF_HUMANREADABLE_NAME GetHumanReadableName = (REF_HUMANREADABLE_NAME)pfn;
GetHumanReadableName( refdll->humanReadable, sizeof( refdll->humanReadable ));
}
Con_Printf( "Found renderer %s: %s\n", refdll->shortenedName, refdll->humanReadable );
ref.numRenderers++;
COM_FreeLibrary( dll );
continue;
}
}
qboolean R_Init( void )
{
qboolean success = false;
int i;
string refopt;
gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" );
@ -598,6 +637,8 @@ qboolean R_Init( void ) @@ -598,6 +637,8 @@ qboolean R_Init( void )
SetWidthAndHeightFromCommandLine();
SetFullscreenModeFromCommandLine();
R_CollectRendererNames();
// command line have priority
if( !Sys_GetParmFromCmdLine( "-ref", refopt ) )
{

9
engine/client/ref_common.h

@ -20,12 +20,21 @@ GNU General Public License for more details. @@ -20,12 +20,21 @@ GNU General Public License for more details.
#define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( cl.playernum + 1 ) && e->player )
typedef struct ref_renderer_s
{
string shortenedName;
string humanReadable;
} ref_renderer_t;
struct ref_state_s
{
qboolean initialized;
HINSTANCE hInstance;
ref_interface_t dllFuncs;
int numRenderers;
ref_renderer_t renderers[DEFAULT_RENDERERS_LEN];
};
extern struct ref_state_s ref;

3
engine/common/com_strings.h

@ -65,4 +65,7 @@ GNU General Public License for more details. @@ -65,4 +65,7 @@ GNU General Public License for more details.
#define XASH_ENGINE_NAME "Xash3D FWGS"
#define DEFAULT_RENDERERS { "gl", "gles1", "gles2", "soft" }
#define DEFAULT_RENDERERS_LEN 4
#endif//COM_STRINGS_H

4
engine/ref_api.h

@ -609,5 +609,9 @@ typedef struct ref_interface_s @@ -609,5 +609,9 @@ typedef struct ref_interface_s
} ref_interface_t;
typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals );
#define GET_REF_API "GetRefAPI"
typedef void (*REF_HUMANREADABLE_NAME)( char *out, size_t len );
#define GET_REF_HUMANREADABLE_NAME "GetRefHumanReadableName"
#endif // REF_API

18
ref_gl/gl_context.c

@ -120,7 +120,9 @@ void Mod_UnloadTextures( model_t *mod ) @@ -120,7 +120,9 @@ void Mod_UnloadTextures( model_t *mod )
case mod_sprite:
Mod_SpriteUnloadTextures( mod->cache.data );
break;
default: gEngfuncs.Host_Error( "Mod_UnloadModel: unsupported type %d\n", mod->type );
default:
ASSERT( 0 );
break;
}
}
@ -130,8 +132,6 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf ) @@ -130,8 +132,6 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf )
if( create )
{
switch( mod->type )
{
case mod_studio:
@ -146,7 +146,6 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf ) @@ -146,7 +146,6 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf )
case mod_brush:
// Mod_LoadBrushModel( mod, buf, loaded );
break;
default: gEngfuncs.Host_Error( "Mod_LoadModel: unsupported type %d\n", mod->type );
}
}
@ -472,3 +471,14 @@ int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, @@ -472,3 +471,14 @@ int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs,
return REF_API_VERSION;
}
void EXPORT GetRefHumanReadableName( char *out, size_t size )
{
#if defined XASH_NANOGL
Q_strncpy( out, "OpenGLES 1(NanoGL)", size );
#elif defined XASH_WES
Q_strncpy( out, "OpenGLES 2(gl-wes-v2)", size );
#else
Q_strncpy( out, "OpenGL 1.x", size );
#endif
}

Loading…
Cancel
Save