2019-02-18 19:25:26 +01:00
|
|
|
#include "common.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "library.h"
|
|
|
|
#include "cl_tent.h"
|
2019-03-16 03:15:32 +01:00
|
|
|
#include "platform/platform.h"
|
2019-03-16 05:58:44 +01:00
|
|
|
#include "vid_common.h"
|
2019-02-18 19:25:26 +01:00
|
|
|
|
|
|
|
struct ref_state_s ref;
|
|
|
|
ref_globals_t refState;
|
|
|
|
|
|
|
|
convar_t *gl_vsync;
|
|
|
|
convar_t *gl_showtextures;
|
|
|
|
convar_t *r_decals;
|
|
|
|
convar_t *r_adjust_fov;
|
2019-07-27 12:27:40 +02:00
|
|
|
convar_t *r_showtree;
|
2021-11-22 10:42:16 +01:00
|
|
|
convar_t *gl_msaa_samples;
|
2019-06-17 07:37:34 +02:00
|
|
|
convar_t *gl_clear;
|
2019-07-27 23:23:22 +02:00
|
|
|
convar_t *r_refdll;
|
2019-02-18 19:25:26 +01:00
|
|
|
|
|
|
|
void R_GetTextureParms( int *w, int *h, int texnum )
|
|
|
|
{
|
2019-03-22 14:36:46 +01:00
|
|
|
if( w ) *w = REF_GET_PARM( PARM_TEX_WIDTH, texnum );
|
|
|
|
if( h ) *h = REF_GET_PARM( PARM_TEX_HEIGHT, texnum );
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_FreeImage
|
|
|
|
|
|
|
|
Frees image by name
|
|
|
|
================
|
|
|
|
*/
|
2020-01-19 02:15:54 +01:00
|
|
|
void GAME_EXPORT GL_FreeImage( const char *name )
|
2019-02-18 19:25:26 +01:00
|
|
|
{
|
|
|
|
int texnum;
|
|
|
|
|
2019-11-17 16:05:05 +01:00
|
|
|
if( !ref.initialized )
|
|
|
|
return;
|
|
|
|
|
2019-03-15 19:23:59 +01:00
|
|
|
if(( texnum = ref.dllFuncs.GL_FindTexture( name )) != 0 )
|
|
|
|
ref.dllFuncs.GL_FreeTexture( texnum );
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|
|
|
|
|
2020-09-14 13:32:46 +02:00
|
|
|
void R_UpdateRefState( void )
|
2019-03-28 16:17:26 +01:00
|
|
|
{
|
|
|
|
refState.time = cl.time;
|
|
|
|
refState.oldtime = cl.oldtime;
|
|
|
|
refState.realtime = host.realtime;
|
|
|
|
refState.frametime = host.frametime;
|
2020-09-14 13:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GL_RenderFrame( const ref_viewpass_t *rvp )
|
|
|
|
{
|
|
|
|
R_UpdateRefState();
|
2019-03-28 16:17:26 +01:00
|
|
|
|
|
|
|
VectorCopy( rvp->vieworigin, refState.vieworg );
|
|
|
|
VectorCopy( rvp->viewangles, refState.viewangles );
|
|
|
|
|
|
|
|
ref.dllFuncs.GL_RenderFrame( rvp );
|
|
|
|
}
|
|
|
|
|
2022-09-20 17:06:19 +02:00
|
|
|
static intptr_t pfnEngineGetParm( int parm, int arg )
|
2019-03-15 19:23:59 +01:00
|
|
|
{
|
|
|
|
return CL_RenderGetParm( parm, arg, false ); // prevent recursion
|
|
|
|
}
|
|
|
|
|
2019-03-16 02:17:56 +01:00
|
|
|
static world_static_t *pfnGetWorld( void )
|
|
|
|
{
|
|
|
|
return &world;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnStudioEvent( const mstudioevent_t *event, const cl_entity_t *e )
|
|
|
|
{
|
|
|
|
clgame.dllFuncs.pfnStudioEvent( event, e );
|
|
|
|
}
|
|
|
|
|
|
|
|
static efrag_t* pfnGetEfragsFreeList( void )
|
|
|
|
{
|
|
|
|
return clgame.free_efrags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnSetEfragsFreeList( efrag_t *list )
|
|
|
|
{
|
|
|
|
clgame.free_efrags = list;
|
|
|
|
}
|
|
|
|
|
2019-03-16 02:24:27 +01:00
|
|
|
static model_t *pfnGetDefaultSprite( enum ref_defaultsprite_e spr )
|
2019-03-16 02:17:56 +01:00
|
|
|
{
|
|
|
|
switch( spr )
|
|
|
|
{
|
|
|
|
case REF_DOT_SPRITE: return cl_sprite_dot;
|
|
|
|
case REF_CHROME_SPRITE: return cl_sprite_shell;
|
|
|
|
default: Host_Error( "GetDefaultSprite: unknown sprite %d\n", spr );
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *pfnMod_Extradata( int type, model_t *m )
|
|
|
|
{
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case mod_alias: return Mod_AliasExtradata( m );
|
|
|
|
case mod_studio: return Mod_StudioExtradata( m );
|
|
|
|
case mod_sprite: // fallthrough
|
|
|
|
case mod_brush: return NULL;
|
|
|
|
default: Host_Error( "Mod_Extradata: unknown type %d\n", type );
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static model_t *pfnMod_GetCurrentLoadingModel( void )
|
|
|
|
{
|
|
|
|
return loadmodel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnMod_SetCurrentLoadingModel( model_t *m )
|
|
|
|
{
|
|
|
|
loadmodel = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnGetPredictedOrigin( vec3_t v )
|
|
|
|
{
|
|
|
|
VectorCopy( cl.simorg, v );
|
|
|
|
}
|
|
|
|
|
2019-05-02 18:05:09 +02:00
|
|
|
static color24 *pfnCL_GetPaletteColor( int color ) // clgame.palette[color]
|
2019-03-16 02:17:56 +01:00
|
|
|
{
|
2019-03-16 02:24:27 +01:00
|
|
|
return &clgame.palette[color];
|
2019-03-16 02:17:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnCL_GetScreenInfo( int *width, int *height ) // clgame.scrInfo, ptrs may be NULL
|
|
|
|
{
|
|
|
|
if( width ) *width = clgame.scrInfo.iWidth;
|
|
|
|
if( height ) *height = clgame.scrInfo.iHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnSetLocalLightLevel( int level )
|
|
|
|
{
|
|
|
|
cl.local.light_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
pfnPlayerInfo
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static player_info_t *pfnPlayerInfo( int index )
|
|
|
|
{
|
|
|
|
if( index == -1 ) // special index for menu
|
|
|
|
return &gameui.playerinfo;
|
|
|
|
|
2022-08-13 00:29:45 +02:00
|
|
|
if( index < 0 || index >= cl.maxclients )
|
2019-03-16 02:17:56 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &cl.players[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
pfnGetPlayerState
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static entity_state_t *R_StudioGetPlayerState( int index )
|
|
|
|
{
|
|
|
|
if( index < 0 || index >= cl.maxclients )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &cl.frames[cl.parsecountmod].playerstate[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pfnGetStudioModelInterface( int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio )
|
|
|
|
{
|
2019-04-16 22:39:37 +02:00
|
|
|
return clgame.dllFuncs.pfnGetStudioModelInterface ?
|
|
|
|
clgame.dllFuncs.pfnGetStudioModelInterface( version, ppinterface, pstudio ) :
|
|
|
|
0;
|
2019-03-16 02:17:56 +01:00
|
|
|
}
|
|
|
|
|
2021-06-01 18:28:52 +02:00
|
|
|
static poolhandle_t pfnImage_GetPool( void )
|
2019-03-16 02:17:56 +01:00
|
|
|
{
|
|
|
|
return host.imagepool;
|
|
|
|
}
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
static const bpc_desc_t *pfnImage_GetPFDesc( int idx )
|
2019-03-16 02:17:56 +01:00
|
|
|
{
|
|
|
|
return &PFDesc[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnDrawNormalTriangles( void )
|
|
|
|
{
|
|
|
|
clgame.dllFuncs.pfnDrawNormalTriangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pfnDrawTransparentTriangles( void )
|
|
|
|
{
|
|
|
|
clgame.dllFuncs.pfnDrawTransparentTriangles();
|
|
|
|
}
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
static screenfade_t *pfnRefGetScreenFade( void )
|
|
|
|
{
|
|
|
|
return &clgame.fade;
|
|
|
|
}
|
|
|
|
|
2019-06-17 06:36:46 +02:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_DoResetGamma
|
|
|
|
gamma will be reset for
|
|
|
|
some type of screenshots
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static qboolean R_DoResetGamma( void )
|
|
|
|
{
|
|
|
|
switch( cls.scrshot_action )
|
|
|
|
{
|
|
|
|
case scrshot_envshot:
|
|
|
|
case scrshot_skyshot:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
static qboolean R_Init_Video_( const int type )
|
|
|
|
{
|
|
|
|
host.apply_opengl_config = true;
|
2023-03-13 03:31:27 +01:00
|
|
|
Cbuf_AddTextf( "exec %s.cfg", ref.dllFuncs.R_GetConfigName());
|
2019-07-27 23:23:22 +02:00
|
|
|
Cbuf_Execute();
|
|
|
|
host.apply_opengl_config = false;
|
|
|
|
|
|
|
|
return R_Init_Video( type );
|
|
|
|
}
|
|
|
|
|
2019-02-18 19:25:26 +01:00
|
|
|
static ref_api_t gEngfuncs =
|
|
|
|
{
|
2019-03-22 14:36:46 +01:00
|
|
|
pfnEngineGetParm,
|
2019-03-16 02:17:56 +01:00
|
|
|
|
2019-05-02 18:05:09 +02:00
|
|
|
(void*)Cvar_Get,
|
|
|
|
(void*)Cvar_FindVarExt,
|
2019-03-16 02:17:56 +01:00
|
|
|
Cvar_VariableValue,
|
|
|
|
Cvar_VariableString,
|
|
|
|
Cvar_SetValue,
|
|
|
|
Cvar_Set,
|
2019-05-02 18:05:09 +02:00
|
|
|
(void*)Cvar_RegisterVariable,
|
2019-03-16 02:17:56 +01:00
|
|
|
Cvar_FullSet,
|
|
|
|
|
|
|
|
Cmd_AddRefCommand,
|
|
|
|
Cmd_RemoveCommand,
|
|
|
|
Cmd_Argc,
|
|
|
|
Cmd_Argv,
|
|
|
|
Cmd_Args,
|
|
|
|
|
|
|
|
Cbuf_AddText,
|
|
|
|
Cbuf_InsertText,
|
|
|
|
Cbuf_Execute,
|
|
|
|
|
|
|
|
Con_Printf,
|
|
|
|
Con_DPrintf,
|
|
|
|
Con_Reportf,
|
|
|
|
|
|
|
|
Con_NPrintf,
|
|
|
|
Con_NXPrintf,
|
|
|
|
CL_CenterPrint,
|
|
|
|
Con_DrawStringLen,
|
|
|
|
Con_DrawString,
|
|
|
|
CL_DrawCenterPrint,
|
|
|
|
|
|
|
|
CL_GetLocalPlayer,
|
|
|
|
CL_GetViewModel,
|
|
|
|
CL_GetEntityByIndex,
|
|
|
|
R_BeamGetEntity,
|
|
|
|
CL_GetWaterEntity,
|
|
|
|
CL_AddVisibleEntity,
|
|
|
|
|
|
|
|
Mod_SampleSizeForFace,
|
|
|
|
Mod_BoxVisible,
|
|
|
|
pfnGetWorld,
|
|
|
|
Mod_PointInLeaf,
|
|
|
|
Mod_CreatePolygonsForHull,
|
|
|
|
|
|
|
|
R_StudioGetAnim,
|
|
|
|
pfnStudioEvent,
|
|
|
|
|
|
|
|
CL_DrawEFX,
|
|
|
|
CL_ThinkParticle,
|
|
|
|
R_FreeDeadParticles,
|
|
|
|
CL_AllocParticleFast,
|
|
|
|
CL_AllocElight,
|
|
|
|
pfnGetDefaultSprite,
|
2019-03-17 17:14:53 +01:00
|
|
|
R_StoreEfrags,
|
2019-03-16 02:17:56 +01:00
|
|
|
|
|
|
|
Mod_ForName,
|
|
|
|
pfnMod_Extradata,
|
|
|
|
CL_ModelHandle,
|
|
|
|
pfnMod_GetCurrentLoadingModel,
|
|
|
|
pfnMod_SetCurrentLoadingModel,
|
|
|
|
|
|
|
|
CL_GetRemapInfoForEntity,
|
|
|
|
CL_AllocRemapInfo,
|
|
|
|
CL_FreeRemapInfo,
|
|
|
|
CL_UpdateRemapInfo,
|
|
|
|
|
|
|
|
CL_ExtraUpdate,
|
|
|
|
Host_Error,
|
|
|
|
COM_SetRandomSeed,
|
|
|
|
COM_RandomFloat,
|
|
|
|
COM_RandomLong,
|
2019-03-22 14:36:46 +01:00
|
|
|
pfnRefGetScreenFade,
|
2019-03-16 02:17:56 +01:00
|
|
|
CL_TextMessageGet,
|
|
|
|
pfnGetPredictedOrigin,
|
|
|
|
pfnCL_GetPaletteColor,
|
|
|
|
pfnCL_GetScreenInfo,
|
|
|
|
pfnSetLocalLightLevel,
|
2019-03-16 03:15:32 +01:00
|
|
|
Sys_CheckParm,
|
2019-03-16 02:17:56 +01:00
|
|
|
|
|
|
|
pfnPlayerInfo,
|
|
|
|
R_StudioGetPlayerState,
|
|
|
|
Mod_CacheCheck,
|
|
|
|
Mod_LoadCacheFile,
|
|
|
|
Mod_Calloc,
|
|
|
|
pfnGetStudioModelInterface,
|
|
|
|
|
|
|
|
_Mem_AllocPool,
|
|
|
|
_Mem_FreePool,
|
|
|
|
_Mem_Alloc,
|
|
|
|
_Mem_Realloc,
|
|
|
|
_Mem_Free,
|
|
|
|
|
|
|
|
COM_LoadLibrary,
|
|
|
|
COM_FreeLibrary,
|
|
|
|
COM_GetProcAddress,
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
R_Init_Video_,
|
2019-03-16 03:15:32 +01:00
|
|
|
R_Free_Video,
|
|
|
|
|
|
|
|
GL_SetAttribute,
|
|
|
|
GL_GetAttribute,
|
|
|
|
GL_GetProcAddress,
|
2019-03-16 05:58:44 +01:00
|
|
|
GL_SwapBuffers,
|
2019-03-16 02:17:56 +01:00
|
|
|
|
2019-03-24 21:24:31 +01:00
|
|
|
SW_CreateBuffer,
|
|
|
|
SW_LockBuffer,
|
|
|
|
SW_UnlockBuffer,
|
|
|
|
|
2019-03-16 02:17:56 +01:00
|
|
|
BuildGammaTable,
|
|
|
|
LightToTexGamma,
|
2019-06-17 06:36:46 +02:00
|
|
|
R_DoResetGamma,
|
2019-03-16 02:17:56 +01:00
|
|
|
|
|
|
|
CL_GetLightStyle,
|
|
|
|
CL_GetDynamicLight,
|
|
|
|
CL_GetEntityLight,
|
|
|
|
R_FatPVS,
|
|
|
|
GL_GetOverviewParms,
|
|
|
|
Sys_DoubleTime,
|
|
|
|
|
|
|
|
pfnGetPhysent,
|
|
|
|
pfnTraceSurface,
|
2023-01-05 21:50:42 +01:00
|
|
|
PM_CL_TraceLine,
|
2019-03-16 02:17:56 +01:00
|
|
|
CL_VisTraceLine,
|
|
|
|
CL_TraceLine,
|
|
|
|
pfnGetMoveVars,
|
|
|
|
|
|
|
|
Image_AddCmdFlags,
|
|
|
|
Image_SetForceFlags,
|
|
|
|
Image_ClearForceFlags,
|
|
|
|
Image_CustomPalette,
|
|
|
|
Image_Process,
|
|
|
|
FS_LoadImage,
|
|
|
|
FS_SaveImage,
|
|
|
|
FS_CopyImage,
|
|
|
|
FS_FreeImage,
|
|
|
|
Image_SetMDLPointer,
|
|
|
|
pfnImage_GetPool,
|
|
|
|
pfnImage_GetPFDesc,
|
|
|
|
|
|
|
|
pfnDrawNormalTriangles,
|
|
|
|
pfnDrawTransparentTriangles,
|
2022-07-01 18:37:21 +02:00
|
|
|
&clgame.drawFuncs,
|
|
|
|
|
|
|
|
&g_fsapi,
|
2019-02-18 19:25:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void R_UnloadProgs( void )
|
|
|
|
{
|
|
|
|
if( !ref.hInstance ) return;
|
|
|
|
|
|
|
|
// deinitialize renderer
|
|
|
|
ref.dllFuncs.R_Shutdown();
|
|
|
|
|
|
|
|
Cvar_FullSet( "host_refloaded", "0", FCVAR_READ_ONLY );
|
|
|
|
|
|
|
|
COM_FreeLibrary( ref.hInstance );
|
|
|
|
ref.hInstance = NULL;
|
|
|
|
|
|
|
|
memset( &refState, 0, sizeof( refState ));
|
2019-03-17 12:26:57 +01:00
|
|
|
memset( &ref.dllFuncs, 0, sizeof( ref.dllFuncs ));
|
2019-02-18 19:25:26 +01:00
|
|
|
|
|
|
|
Cvar_Unlink( FCVAR_RENDERINFO | FCVAR_GLCONFIG );
|
|
|
|
Cmd_Unlink( CMD_REFDLL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src )
|
|
|
|
{
|
|
|
|
dst->version = TRI_API_VERSION;
|
|
|
|
dst->Begin = src->Begin;
|
|
|
|
dst->RenderMode = TriRenderMode;
|
|
|
|
dst->End = src->End;
|
|
|
|
dst->Color4f = TriColor4f;
|
|
|
|
dst->Color4ub = TriColor4ub;
|
|
|
|
dst->TexCoord2f = src->TexCoord2f;
|
|
|
|
dst->Vertex3f = src->Vertex3f;
|
|
|
|
dst->Vertex3fv = src->Vertex3fv;
|
|
|
|
dst->Brightness = TriBrightness;
|
|
|
|
dst->CullFace = TriCullFace;
|
2019-03-17 17:41:11 +01:00
|
|
|
dst->SpriteTexture = TriSpriteTexture;
|
2019-02-18 19:25:26 +01:00
|
|
|
dst->WorldToScreen = TriWorldToScreen;
|
|
|
|
dst->Fog = src->Fog;
|
|
|
|
dst->ScreenToWorld = src->ScreenToWorld;
|
|
|
|
dst->GetMatrix = src->GetMatrix;
|
|
|
|
dst->BoxInPVS = TriBoxInPVS;
|
|
|
|
dst->LightAtPoint = TriLightAtPoint;
|
|
|
|
dst->Color4fRendermode = TriColor4fRendermode;
|
|
|
|
dst->FogParams = src->FogParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
static qboolean R_LoadProgs( const char *name )
|
|
|
|
{
|
|
|
|
extern triangleapi_t gTriApi;
|
|
|
|
static ref_api_t gpEngfuncs;
|
|
|
|
REFAPI GetRefAPI; // single export
|
|
|
|
|
|
|
|
if( ref.hInstance ) R_UnloadProgs();
|
|
|
|
|
2019-07-01 04:50:31 +02:00
|
|
|
FS_AllowDirectPaths( true );
|
2019-02-18 19:25:26 +01:00
|
|
|
if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) ))
|
|
|
|
{
|
2019-07-01 04:50:31 +02:00
|
|
|
FS_AllowDirectPaths( false );
|
2019-10-11 10:46:59 +02:00
|
|
|
Con_Reportf( "R_LoadProgs: can't load renderer library %s: %s\n", name, COM_GetLibraryError() );
|
2019-07-01 04:50:31 +02:00
|
|
|
return false;
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FS_AllowDirectPaths( false );
|
|
|
|
|
2019-08-09 02:39:24 +02:00
|
|
|
if( !( GetRefAPI = (REFAPI)COM_GetProcAddress( ref.hInstance, GET_REF_API )) )
|
2019-02-18 19:25:26 +01:00
|
|
|
{
|
|
|
|
COM_FreeLibrary( ref.hInstance );
|
2019-10-19 15:47:16 +02:00
|
|
|
Con_Reportf( "R_LoadProgs: can't find GetRefAPI entry point in %s\n", name );
|
2019-02-18 19:25:26 +01:00
|
|
|
ref.hInstance = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make local copy of engfuncs to prevent overwrite it with user dll
|
|
|
|
memcpy( &gpEngfuncs, &gEngfuncs, sizeof( gpEngfuncs ));
|
|
|
|
|
|
|
|
if( !GetRefAPI( REF_API_VERSION, &ref.dllFuncs, &gpEngfuncs, &refState ))
|
|
|
|
{
|
|
|
|
COM_FreeLibrary( ref.hInstance );
|
|
|
|
Con_Reportf( "R_LoadProgs: can't init renderer API: wrong version\n" );
|
|
|
|
ref.hInstance = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-24 16:45:27 +01:00
|
|
|
refState.developer = host_developer.value;
|
2019-02-18 19:25:26 +01:00
|
|
|
|
2019-03-15 19:23:59 +01:00
|
|
|
if( !ref.dllFuncs.R_Init( ) )
|
2019-02-18 19:25:26 +01:00
|
|
|
{
|
|
|
|
COM_FreeLibrary( ref.hInstance );
|
2019-03-15 19:23:59 +01:00
|
|
|
Con_Reportf( "R_LoadProgs: can't init renderer!\n" ); //, ref.dllFuncs.R_GetInitError() );
|
2019-02-18 19:25:26 +01:00
|
|
|
ref.hInstance = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY );
|
|
|
|
ref.initialized = true;
|
|
|
|
|
|
|
|
// initialize TriAPI callbacks
|
|
|
|
CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_Shutdown( void )
|
|
|
|
{
|
2019-03-06 14:23:33 +01:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
|
|
|
|
|
|
|
// release SpriteTextures
|
|
|
|
for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ )
|
|
|
|
{
|
|
|
|
if( !mod->name[0] ) continue;
|
2019-03-17 12:26:57 +01:00
|
|
|
Mod_FreeModel( mod );
|
2019-03-06 14:23:33 +01:00
|
|
|
}
|
|
|
|
memset( clgame.sprites, 0, sizeof( clgame.sprites ));
|
|
|
|
|
2019-03-17 12:26:57 +01:00
|
|
|
// correctly free all models before render unload
|
|
|
|
// change this if need add online render changing
|
|
|
|
Mod_FreeAll();
|
2019-02-18 19:25:26 +01:00
|
|
|
R_UnloadProgs();
|
|
|
|
ref.initialized = false;
|
|
|
|
}
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
static void R_GetRendererName( char *dest, size_t size, const char *opt )
|
2019-02-18 19:25:26 +01:00
|
|
|
{
|
2020-11-29 00:05:42 +01:00
|
|
|
if( !Q_strstr( opt, "." OS_LIB_EXT ))
|
2019-07-27 23:23:22 +02:00
|
|
|
{
|
2019-10-11 04:36:17 +02:00
|
|
|
const char *format;
|
|
|
|
|
2019-08-09 02:39:24 +02:00
|
|
|
#ifdef XASH_INTERNAL_GAMELIBS
|
2019-10-11 04:36:17 +02:00
|
|
|
if( !Q_strcmp( opt, "ref_" ))
|
|
|
|
format = "%s";
|
|
|
|
else
|
|
|
|
format = "ref_%s";
|
2019-03-15 19:23:59 +01:00
|
|
|
#else
|
2019-10-11 04:36:17 +02:00
|
|
|
if( !Q_strcmp( opt, "ref_" ))
|
|
|
|
format = OS_LIB_PREFIX "%s." OS_LIB_EXT;
|
|
|
|
else
|
|
|
|
format = OS_LIB_PREFIX "ref_%s." OS_LIB_EXT;
|
2019-03-15 19:23:59 +01:00
|
|
|
#endif
|
2019-10-11 04:36:17 +02:00
|
|
|
Q_snprintf( dest, size, format, opt );
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// full path
|
|
|
|
Q_strcpy( dest, opt );
|
|
|
|
}
|
2019-04-14 21:04:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
static qboolean R_LoadRenderer( const char *refopt )
|
2019-04-14 21:04:32 +02:00
|
|
|
{
|
2019-07-27 23:23:22 +02:00
|
|
|
string refdll;
|
2019-04-14 21:04:32 +02:00
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
R_GetRendererName( refdll, sizeof( refdll ), refopt );
|
|
|
|
|
2019-10-11 04:11:45 +02:00
|
|
|
Con_Printf( "Loading renderer: %s -> %s\n", refopt, refdll );
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
if( !R_LoadProgs( refdll ))
|
|
|
|
{
|
|
|
|
R_Shutdown();
|
|
|
|
Sys_Warn( S_ERROR "Can't initialize %s renderer!\n", refdll );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Reportf( "Renderer %s initialized\n", refdll );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-05 01:07:49 +02:00
|
|
|
static void SetWidthAndHeightFromCommandLine( void )
|
2019-07-27 23:23:22 +02:00
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
Sys_GetIntFromCmdLine( "-width", &width );
|
|
|
|
Sys_GetIntFromCmdLine( "-height", &height );
|
|
|
|
|
|
|
|
if( width < 1 || height < 1 )
|
2019-04-14 21:04:32 +02:00
|
|
|
{
|
2019-07-27 23:23:22 +02:00
|
|
|
// Not specified or invalid, so don't bother.
|
|
|
|
return;
|
2019-04-14 21:04:32 +02:00
|
|
|
}
|
2019-07-27 23:23:22 +02:00
|
|
|
|
2019-10-30 19:36:07 +01:00
|
|
|
R_SaveVideoMode( width, height, width, height );
|
2019-07-27 23:23:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-05 01:07:49 +02:00
|
|
|
static void SetFullscreenModeFromCommandLine( void )
|
2019-07-27 23:23:22 +02:00
|
|
|
{
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_MOBILE_PLATFORM
|
2019-07-27 23:23:22 +02:00
|
|
|
if ( Sys_CheckParm("-fullscreen") )
|
2019-04-14 21:04:32 +02:00
|
|
|
{
|
2019-07-27 23:23:22 +02:00
|
|
|
Cvar_Set( "fullscreen", "1" );
|
2019-04-14 21:04:32 +02:00
|
|
|
}
|
2019-07-27 23:23:22 +02:00
|
|
|
else if ( Sys_CheckParm( "-windowed" ) )
|
2019-04-14 21:04:32 +02:00
|
|
|
{
|
2019-07-27 23:23:22 +02:00
|
|
|
Cvar_Set( "fullscreen", "0" );
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|
2019-07-27 23:23:22 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-08-09 02:39:24 +02:00
|
|
|
void R_CollectRendererNames( void )
|
|
|
|
{
|
|
|
|
const char *renderers[] = DEFAULT_RENDERERS;
|
2021-01-07 11:07:09 +01:00
|
|
|
int i, cur;
|
2019-08-09 02:39:24 +02:00
|
|
|
|
2021-01-07 11:07:09 +01:00
|
|
|
cur = 0;
|
2019-08-09 03:44:50 +02:00
|
|
|
for( i = 0; i < DEFAULT_RENDERERS_LEN; i++ )
|
2019-08-09 02:39:24 +02:00
|
|
|
{
|
|
|
|
string temp;
|
|
|
|
void *dll, *pfn;
|
|
|
|
|
|
|
|
R_GetRendererName( temp, sizeof( temp ), renderers[i] );
|
|
|
|
|
|
|
|
dll = COM_LoadLibrary( temp, false, true );
|
|
|
|
if( !dll )
|
2019-10-11 10:46:59 +02:00
|
|
|
{
|
|
|
|
Con_Reportf( "R_CollectRendererNames: can't load library %s: %s\n", temp, COM_GetLibraryError() );
|
2019-08-09 02:39:24 +02:00
|
|
|
continue;
|
2019-10-11 10:46:59 +02:00
|
|
|
}
|
2019-08-09 02:39:24 +02:00
|
|
|
|
|
|
|
pfn = COM_GetProcAddress( dll, GET_REF_API );
|
|
|
|
if( !pfn )
|
|
|
|
{
|
2019-10-19 15:47:16 +02:00
|
|
|
Con_Reportf( "R_CollectRendererNames: can't find API entry point in %s\n", temp );
|
2019-08-09 02:39:24 +02:00
|
|
|
COM_FreeLibrary( dll );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-07 11:07:09 +01:00
|
|
|
Q_strncpy( ref.shortNames[cur], renderers[i], sizeof( ref.shortNames[cur] ));
|
2019-08-09 02:39:24 +02:00
|
|
|
|
|
|
|
pfn = COM_GetProcAddress( dll, GET_REF_HUMANREADABLE_NAME );
|
|
|
|
if( !pfn ) // just in case
|
|
|
|
{
|
2019-11-28 17:18:50 +01:00
|
|
|
Con_Reportf( "R_CollectRendererNames: can't find GetHumanReadableName export in %s\n", temp );
|
2021-01-07 11:07:09 +01:00
|
|
|
Q_strncpy( ref.readableNames[cur], renderers[i], sizeof( ref.readableNames[cur] ));
|
2019-08-09 02:39:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
REF_HUMANREADABLE_NAME GetHumanReadableName = (REF_HUMANREADABLE_NAME)pfn;
|
|
|
|
|
2021-01-07 11:07:09 +01:00
|
|
|
GetHumanReadableName( ref.readableNames[cur], sizeof( ref.readableNames[cur] ));
|
2019-08-09 02:39:24 +02:00
|
|
|
}
|
|
|
|
|
2021-01-07 11:07:09 +01:00
|
|
|
Con_Printf( "Found renderer %s: %s\n", ref.shortNames[cur], ref.readableNames[cur] );
|
2019-08-09 02:39:24 +02:00
|
|
|
|
2021-01-07 11:07:09 +01:00
|
|
|
cur++;
|
2019-08-09 02:39:24 +02:00
|
|
|
COM_FreeLibrary( dll );
|
|
|
|
}
|
2021-01-07 11:07:09 +01:00
|
|
|
ref.numRenderers = cur;
|
2019-08-09 02:39:24 +02:00
|
|
|
}
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
qboolean R_Init( void )
|
|
|
|
{
|
|
|
|
qboolean success = false;
|
2021-01-03 00:16:48 +01:00
|
|
|
string requested;
|
2019-02-18 19:25:26 +01:00
|
|
|
|
|
|
|
gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" );
|
2019-12-02 00:13:41 +01:00
|
|
|
gl_showtextures = Cvar_Get( "r_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" );
|
2019-02-18 19:25:26 +01:00
|
|
|
r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" );
|
|
|
|
r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" );
|
2021-11-22 10:42:16 +01:00
|
|
|
gl_msaa_samples = Cvar_Get( "gl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" );
|
2019-06-17 07:37:34 +02:00
|
|
|
gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" );
|
2019-07-27 12:27:40 +02:00
|
|
|
r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" );
|
2019-07-27 23:23:22 +02:00
|
|
|
r_refdll = Cvar_Get( "r_refdll", "", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "choose renderer implementation, if supported" );
|
2019-02-18 19:25:26 +01:00
|
|
|
|
2021-12-06 02:57:32 +01:00
|
|
|
// cvars that are expected to exist
|
2021-12-06 03:02:30 +01:00
|
|
|
Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" );
|
|
|
|
Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" );
|
|
|
|
Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" );
|
|
|
|
Cvar_Get( "r_dynamic", "1", FCVAR_ARCHIVE, "allow dynamic lighting (dlights, lightstyles)" );
|
|
|
|
Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" );
|
|
|
|
Cvar_Get( "tracerred", "0.8", 0, "tracer red component weight ( 0 - 1.0 )" );
|
|
|
|
Cvar_Get( "tracergreen", "0.8", 0, "tracer green component weight ( 0 - 1.0 )" );
|
|
|
|
Cvar_Get( "tracerblue", "0.4", 0, "tracer blue component weight ( 0 - 1.0 )" );
|
|
|
|
Cvar_Get( "traceralpha", "0.5", 0, "tracer alpha amount ( 0 - 1.0 )" );
|
2021-12-06 02:57:32 +01:00
|
|
|
|
2021-12-06 03:17:25 +01:00
|
|
|
Cvar_Get( "r_sprite_lerping", "1", FCVAR_ARCHIVE, "enables sprite animation lerping" );
|
|
|
|
Cvar_Get( "r_sprite_lighting", "1", FCVAR_ARCHIVE, "enables sprite lighting (blood etc)" );
|
|
|
|
|
|
|
|
Cvar_Get( "r_drawviewmodel", "1", 0, "draw firstperson weapon model" );
|
|
|
|
Cvar_Get( "r_glowshellfreq", "2.2", 0, "glowing shell frequency update" );
|
|
|
|
|
2021-03-01 18:03:32 +01:00
|
|
|
// cvars that are expected to exist by client.dll
|
|
|
|
// refdll should just get pointer to them
|
|
|
|
Cvar_Get( "r_drawentities", "1", FCVAR_CHEAT, "render entities" );
|
|
|
|
Cvar_Get( "cl_himodels", "1", FCVAR_ARCHIVE, "draw high-resolution player models in multiplayer" );
|
|
|
|
|
2019-07-27 23:23:22 +02:00
|
|
|
// cvars are created, execute video config
|
|
|
|
Cbuf_AddText( "exec video.cfg" );
|
|
|
|
Cbuf_Execute();
|
|
|
|
|
|
|
|
// Set screen resolution and fullscreen mode if passed in on command line.
|
|
|
|
// this is done after executing video.cfg, as the command line values should take priority.
|
|
|
|
SetWidthAndHeightFromCommandLine();
|
|
|
|
SetFullscreenModeFromCommandLine();
|
|
|
|
|
2019-08-09 02:39:24 +02:00
|
|
|
R_CollectRendererNames();
|
|
|
|
|
2021-01-03 00:16:48 +01:00
|
|
|
// Priority:
|
|
|
|
// 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 ) )
|
2019-07-27 23:23:22 +02:00
|
|
|
// r_refdll is set to empty by default, so we can change hardcoded defaults just in case
|
2021-01-03 00:16:48 +01:00
|
|
|
Q_strncpy( requested, r_refdll->string, sizeof( requested ) );
|
2019-03-06 14:23:33 +01:00
|
|
|
|
2021-01-03 00:16:48 +01:00
|
|
|
if ( requested[0] )
|
|
|
|
success = R_LoadRenderer( requested );
|
|
|
|
|
|
|
|
if( !success )
|
2019-07-27 23:23:22 +02:00
|
|
|
{
|
2021-01-02 02:47:35 +01:00
|
|
|
int i;
|
2019-07-27 23:23:22 +02:00
|
|
|
|
2021-01-02 02:47:35 +01:00
|
|
|
// cycle through renderers that we collected in CollectRendererNames
|
|
|
|
for( i = 0; i < ref.numRenderers; i++ )
|
2019-07-27 23:23:22 +02:00
|
|
|
{
|
2021-01-02 02:47:35 +01:00
|
|
|
// skip renderer that was requested but failed to load
|
2021-01-03 00:16:48 +01:00
|
|
|
if( !Q_strcmp( requested, ref.shortNames[i] ) )
|
2021-01-02 02:47:35 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
success = R_LoadRenderer( ref.shortNames[i] );
|
|
|
|
|
|
|
|
// yay, found working one
|
|
|
|
if( success )
|
|
|
|
break;
|
2019-07-27 23:23:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
Host_Error( "Can't initialize any renderer. Check your video drivers!" );
|
2019-10-11 06:42:44 +02:00
|
|
|
return false;
|
2019-07-27 23:23:22 +02:00
|
|
|
}
|
2019-05-12 02:09:40 +02:00
|
|
|
|
2019-03-06 14:23:33 +01:00
|
|
|
SCR_Init();
|
|
|
|
|
|
|
|
return true;
|
2019-02-18 19:25:26 +01:00
|
|
|
}
|