Skip to content

Commit

Permalink
engine: implement menu extensions to allow choosing renderers from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Aug 9, 2019
1 parent a1ae770 commit 8323df2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
17 changes: 16 additions & 1 deletion engine/client/cl_gameui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,27 @@ static void pfnEnableTextInput( int enable )
Key_EnableTextInput( enable, false );
}

static int pfnGetRenderers( unsigned int num, char *shortName, size_t size1, char *readableName, size_t size2 )
{
if( num >= ref.numRenderers )
return 0;

if( shortName && size1 )
Q_strncpy( shortName, ref.shortNames[num], size1 );

if( readableName && size2 )
Q_strncpy( readableName, ref.readableNames[num], size2 );

return 1;
}

static ui_extendedfuncs_t gExtendedfuncs =
{
pfnEnableTextInput,
Con_UtfProcessChar,
Con_UtfMoveLeft,
Con_UtfMoveRight
Con_UtfMoveRight,
pfnGetRenderers
};

void UI_UnloadProgs( void )
Expand Down
11 changes: 5 additions & 6 deletions engine/client/ref_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,8 @@ void R_CollectRendererNames( void )

ref.numRenderers = 0;

for( i = 0; i < ARRAYSIZE( ref.renderers ); i++ )
for( i = 0; i < DEFAULT_RENDERERS_LEN; i++ )
{
ref_renderer_t *refdll = ref.renderers + ref.numRenderers;
string temp;
void *dll, *pfn;

Expand All @@ -592,21 +591,21 @@ void R_CollectRendererNames( void )
continue;
}

Q_strncpy( refdll->shortenedName, renderers[i], sizeof( refdll->shortenedName ));
Q_strncpy( ref.shortNames[i], renderers[i], sizeof( ref.shortNames[i] ));

pfn = COM_GetProcAddress( dll, GET_REF_HUMANREADABLE_NAME );
if( !pfn ) // just in case
{
Q_strncpy( refdll->humanReadable, renderers[i], sizeof( refdll->humanReadable ));
Q_strncpy( ref.readableNames[i], renderers[i], sizeof( ref.readableNames[i] ));
}
else
{
REF_HUMANREADABLE_NAME GetHumanReadableName = (REF_HUMANREADABLE_NAME)pfn;

GetHumanReadableName( refdll->humanReadable, sizeof( refdll->humanReadable ));
GetHumanReadableName( ref.readableNames[i], sizeof( ref.readableNames[i] ));
}

Con_Printf( "Found renderer %s: %s\n", refdll->shortenedName, refdll->humanReadable );
Con_Printf( "Found renderer %s: %s\n", ref.shortNames[i], ref.readableNames[i] );

ref.numRenderers++;
COM_FreeLibrary( dll );
Expand Down
9 changes: 2 additions & 7 deletions engine/client/ref_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ 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;
Expand All @@ -34,7 +28,8 @@ struct ref_state_s
ref_interface_t dllFuncs;

int numRenderers;
ref_renderer_t renderers[DEFAULT_RENDERERS_LEN];
string shortNames[DEFAULT_RENDERERS_LEN];
string readableNames[DEFAULT_RENDERERS_LEN];
};

extern struct ref_state_s ref;
Expand Down
2 changes: 2 additions & 0 deletions engine/menu_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ typedef struct ui_extendedfuncs_s {
int (*pfnUtfMoveRight) ( char *str, int pos, int length );

// new engine extended api start here
// returns 1 if there are more in list, otherwise 0
int (*pfnGetRenderers)( unsigned int num, char *shortName, size_t size1, char *readableName, size_t size2 );
} ui_extendedfuncs_t;

// deprecated export from old engine
Expand Down
2 changes: 1 addition & 1 deletion mainui
6 changes: 3 additions & 3 deletions ref_gl/gl_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs,
void EXPORT GetRefHumanReadableName( char *out, size_t size )
{
#if defined XASH_NANOGL
Q_strncpy( out, "OpenGLES 1(NanoGL)", size );
Q_strncpy( out, "GLES1(NanoGL)", size );
#elif defined XASH_WES
Q_strncpy( out, "OpenGLES 2(gl-wes-v2)", size );
Q_strncpy( out, "GLES2(gl-wes-v2)", size );
#else
Q_strncpy( out, "OpenGL 1.x", size );
Q_strncpy( out, "OpenGL", size );
#endif
}

0 comments on commit 8323df2

Please sign in to comment.