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 )
if( ref.hInstance ) R_UnloadProgs(); if( ref.hInstance ) R_UnloadProgs();
#ifdef XASH_INTERNAL_GAMELIBS
if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) ))
{
return false;
}
#else
FS_AllowDirectPaths( true ); FS_AllowDirectPaths( true );
if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) )) if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) ))
{ {
FS_AllowDirectPaths( false ); FS_AllowDirectPaths( false );
return false; return false;
} }
#endif
FS_AllowDirectPaths( false ); 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 ); COM_FreeLibrary( ref.hInstance );
Con_Reportf( "R_LoadProgs: can't init renderer API\n" ); 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 )
if( !Q_strstr( opt, va( ".%s", OS_LIB_EXT ))) if( !Q_strstr( opt, va( ".%s", OS_LIB_EXT )))
{ {
// shortened renderer name // shortened renderer name
Q_snprintf( dest, size, "%sref_%s.%s", #ifdef XASH_INTERNAL_GAMELIBS
#ifdef OS_LIB_PREFIX Q_snprintf( dest, size, "ref_%s", opt );
OS_LIB_PREFIX,
#else #else
"", Q_snprintf( dest, size, "%sref_%s.%s",
OS_LIB_PREFIX, opt, OS_LIB_EXT );
#endif #endif
opt, OS_LIB_EXT );
Con_Printf( "Loading renderer by short name: %s\n", opt ); Con_Printf( "Loading renderer by short name: %s\n", opt );
} }
else else
@ -574,10 +566,57 @@ static void SetFullscreenModeFromCommandLine( )
#endif #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 R_Init( void )
{ {
qboolean success = false; qboolean success = false;
int i;
string refopt; string refopt;
gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" ); gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" );
@ -598,6 +637,8 @@ qboolean R_Init( void )
SetWidthAndHeightFromCommandLine(); SetWidthAndHeightFromCommandLine();
SetFullscreenModeFromCommandLine(); SetFullscreenModeFromCommandLine();
R_CollectRendererNames();
// command line have priority // command line have priority
if( !Sys_GetParmFromCmdLine( "-ref", refopt ) ) if( !Sys_GetParmFromCmdLine( "-ref", refopt ) )
{ {

9
engine/client/ref_common.h

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

3
engine/common/com_strings.h

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

4
engine/ref_api.h

@ -609,5 +609,9 @@ typedef struct ref_interface_s
} ref_interface_t; } ref_interface_t;
typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals ); 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 #endif // REF_API

18
ref_gl/gl_context.c

@ -120,7 +120,9 @@ void Mod_UnloadTextures( model_t *mod )
case mod_sprite: case mod_sprite:
Mod_SpriteUnloadTextures( mod->cache.data ); Mod_SpriteUnloadTextures( mod->cache.data );
break; 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 )
if( create ) if( create )
{ {
switch( mod->type ) switch( mod->type )
{ {
case mod_studio: case mod_studio:
@ -146,7 +146,6 @@ qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf )
case mod_brush: case mod_brush:
// Mod_LoadBrushModel( mod, buf, loaded ); // Mod_LoadBrushModel( mod, buf, loaded );
break; break;
default: gEngfuncs.Host_Error( "Mod_LoadModel: unsupported type %d\n", mod->type ); 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,
return REF_API_VERSION; 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