From e6924844daab4bd66ec4ed978ddb900a3b2d29a4 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 14 Apr 2026 11:27:13 +0500 Subject: [PATCH] engine: move FillRenderAPI and FillTriAPI to renderers to reduce amount of exports --- engine/client/cl_render.c | 45 +++++------------------- engine/client/ref_common.c | 19 +++++------ engine/ref_api.h | 47 ++++--------------------- ref/gl/gl_context.c | 70 +++++++++++++++++++++----------------- ref/null/r_context.c | 58 +++++++++++-------------------- ref/soft/r_context.c | 70 +++++++++++++++++++++----------------- 6 files changed, 122 insertions(+), 187 deletions(-) diff --git a/engine/client/cl_render.c b/engine/client/cl_render.c index 2217d0bf..f6422070 100644 --- a/engine/client/cl_render.c +++ b/engine/client/cl_render.c @@ -283,40 +283,6 @@ static render_api_t gRenderAPI = COM_SetRandomSeed, }; -static void R_FillRenderAPIFromRef( render_api_t *to, const ref_interface_t *from ) -{ - to->GetDetailScaleForTexture = from->GetDetailScaleForTexture; - to->GetExtraParmsForTexture = from->GetExtraParmsForTexture; - to->GetFrameTime = from->GetFrameTime; - to->R_SetCurrentEntity = from->R_SetCurrentEntity; - to->R_SetCurrentModel = from->R_SetCurrentModel; - to->GL_FindTexture = from->GL_FindTexture; - to->GL_TextureName = from->GL_TextureName; - to->GL_TextureData = from->GL_TextureData; - to->GL_LoadTexture = from->GL_LoadTexture; - to->GL_CreateTexture = from->GL_CreateTexture; - to->GL_LoadTextureArray = from->GL_LoadTextureArray; - to->GL_CreateTextureArray = from->GL_CreateTextureArray; - to->GL_FreeTexture = from->GL_FreeTexture; - to->DrawSingleDecal = from->DrawSingleDecal; - to->R_DecalSetupVerts = from->R_DecalSetupVerts; - to->R_EntityRemoveDecals = from->R_EntityRemoveDecals; - to->AVI_UploadRawFrame = from->AVI_UploadRawFrame; - to->GL_Bind = from->GL_Bind; - to->GL_SelectTexture = from->GL_SelectTexture; - to->GL_LoadTextureMatrix = from->GL_LoadTextureMatrix; - to->GL_TexMatrixIdentity = from->GL_TexMatrixIdentity; - to->GL_CleanUpTextureUnits = from->GL_CleanUpTextureUnits; - to->GL_TexGen = from->GL_TexGen; - to->GL_TextureTarget = from->GL_TextureTarget; - to->GL_TexCoordArrayMode = from->GL_TexCoordArrayMode; - to->GL_UpdateTexSize = from->GL_UpdateTexSize; - to->GL_DrawParticles = from->GL_DrawParticles; - to->LightVec = from->LightVec; - to->StudioGetTexture = from->StudioGetTexture; - to->GL_GetProcAddress = from->R_GetProcAddress; -} - /* =============== R_InitRenderAPI @@ -329,8 +295,15 @@ qboolean R_InitRenderAPI( void ) // make sure what render functions is cleared memset( &clgame.drawFuncs, 0, sizeof( clgame.drawFuncs )); - // fill missing functions from renderer - R_FillRenderAPIFromRef( &gRenderAPI, &ref.dllFuncs ); + gRenderAPI.GL_FindTexture = ref.dllFuncs.GL_FindTexture; + gRenderAPI.GL_TextureName = ref.dllFuncs.GL_TextureName; + gRenderAPI.GL_TextureData = ref.dllFuncs.GL_TextureData; + gRenderAPI.GL_LoadTexture = ref.dllFuncs.GL_LoadTexture; + gRenderAPI.GL_FreeTexture = ref.dllFuncs.GL_FreeTexture; + gRenderAPI.AVI_UploadRawFrame = ref.dllFuncs.AVI_UploadRawFrame; + gRenderAPI.GL_Bind = ref.dllFuncs.GL_Bind; + + ref.dllFuncs.R_FillRenderAPI( &gRenderAPI ); if( clgame.dllFuncs.pfnGetRenderInterface ) { diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index acc5b9db..decfcef9 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -480,28 +480,25 @@ static void R_UnloadProgs( void ) memset( &ref.dllFuncs, 0, sizeof( ref.dllFuncs )); } -static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src ) +static void CL_FillTriAPI( triangleapi_t *dst ) { 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; dst->SpriteTexture = TriSpriteTexture; 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; + dst->Begin = ref.dllFuncs.Begin; + dst->End = ref.dllFuncs.End; + dst->Vertex3f = ref.dllFuncs.Vertex3f; + dst->Vertex3fv = ref.dllFuncs.Vertex3fv; + + ref.dllFuncs.R_FillTriAPI( dst ); } static qboolean R_LoadProgs( const char *name ) @@ -548,7 +545,7 @@ static qboolean R_LoadProgs( const char *name ) ref.initialized = true; // initialize TriAPI callbacks - CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs ); + CL_FillTriAPI( &gTriApi ); return true; } diff --git a/engine/ref_api.h b/engine/ref_api.h index 141ec7ab..1e4ba8fd 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -596,50 +596,21 @@ typedef struct ref_interface_s qboolean (*R_BeamCull)( const vec3_t start, const vec3_t end, qboolean pvsOnly ); // Xash3D Render Interface - // Get renderer info (doesn't changes engine state at all) int (*RefGetParm)( int parm, int arg ); // generic - void (*GetDetailScaleForTexture)( int texture, float *xScale, float *yScale ); - void (*GetExtraParmsForTexture)( int texture, byte *red, byte *green, byte *blue, byte *alpha ); - float (*GetFrameTime)( void ); - // Set renderer info (tell engine about changes) - void (*R_SetCurrentEntity)( struct cl_entity_s *ent ); // tell engine about both currententity and currentmodel - void (*R_SetCurrentModel)( struct model_s *mod ); // change currentmodel but leave currententity unchanged - - // Texture tools + // Texture tools (used by engine directly) int (*GL_FindTexture)( const char *name ); const char* (*GL_TextureName)( unsigned int texnum ); const byte* (*GL_TextureData)( unsigned int texnum ); // may be NULL int (*GL_LoadTexture)( const char *name, const byte *buf, size_t size, int flags ); - int (*GL_CreateTexture)( const char *name, int width, int height, const void *buffer, texFlags_t flags ); - int (*GL_LoadTextureArray)( const char **names, int flags ); - int (*GL_CreateTextureArray)( const char *name, int width, int height, int depth, const void *buffer, texFlags_t flags ); void (*GL_FreeTexture)( unsigned int texnum ); void (*R_OverrideTextureSourceSize)( unsigned int texnum, unsigned int srcWidth, unsigned int srcHeight ); // used to override decal size for texture replacement - // Decals manipulating (draw & remove) - void (*DrawSingleDecal)( struct decal_s *pDecal, struct msurface_s *fa ); - float *(*R_DecalSetupVerts)( struct decal_s *pDecal, struct msurface_s *surf, int texture, int *outCount ); - void (*R_EntityRemoveDecals)( struct model_s *mod ); // remove all the decals from specified entity (BSP only) - // AVI void (*AVI_UploadRawFrame)( int texture, int cols, int rows, int width, int height, const byte *data ); - // glState related calls (must use this instead of normal gl-calls to prevent de-synchornize local states between engine and the client) + // glState related calls (used by engine directly) void (*GL_Bind)( int tmu, unsigned int texnum ); - void (*GL_SelectTexture)( int tmu ); - void (*GL_LoadTextureMatrix)( const float *glmatrix ); - void (*GL_TexMatrixIdentity)( void ); - void (*GL_CleanUpTextureUnits)( int last ); // pass 0 for clear all the texture units - void (*GL_TexGen)( unsigned int coord, unsigned int mode ); - void (*GL_TextureTarget)( unsigned int target ); // change texture unit mode without bind texture - void (*GL_TexCoordArrayMode)( unsigned int texmode ); - void (*GL_UpdateTexSize)( int texnum, int width, int height, int depth ); // recalc statistics - - // Misc renderer functions - void (*GL_DrawParticles)( const struct ref_viewpass_s *rvp, qboolean trans_pass, float frametime ); - colorVec (*LightVec)( const float *start, const float *end, float *lightspot, float *lightvec ); - struct mstudiotex_s *( *StudioGetTexture )( struct cl_entity_s *e ); // passed through R_RenderFrame (0 - use engine renderer, 1 - use custom client renderer) void (*GL_RenderFrame)( const struct ref_viewpass_s *rvp ); @@ -653,25 +624,21 @@ typedef struct ref_interface_s void (*R_NewMap)( void ); // clear the render entities before each frame void (*R_ClearScene)( void ); - // GL_GetProcAddress for client renderer - void* (*R_GetProcAddress)( const char *name ); - // TriAPI Interface - // NOTE: implementation isn't required to be compatible + // TriAPI Interface (functions used by engine wrappers) void (*TriRenderMode)( int mode ); void (*Begin)( int primitiveCode ); void (*End)( void ); void (*Color4f)( float r, float g, float b, float a ); // real glColor4f void (*Color4ub)( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); // real glColor4ub - void (*TexCoord2f)( float u, float v ); void (*Vertex3fv)( const float *worldPnt ); void (*Vertex3f)( float x, float y, float z ); - void (*Fog)( float flFogColor[3], float flStart, float flEnd, int bOn ); //Works just like GL_FOG, flFogColor is r/g/b. - void (*ScreenToWorld)( const float *screen, float *world ); - void (*GetMatrix)( const int pname, float *matrix ); - void (*FogParams)( float flDensity, int iFogSkybox ); void (*CullFace)( TRICULLSTYLE mode ); + // fill render_api_t and triangleapi_t with renderer-specific functions + void (*R_FillRenderAPI)( struct render_api_s *api ); + void (*R_FillTriAPI)( struct triangleapi_s *api ); + // vgui drawing implementation void (*VGUI_SetupDrawing)( qboolean rect ); void (*VGUI_UploadTextureBlock)( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight ); diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index 659ab067..1d97e78e 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -413,6 +413,42 @@ static const char *R_GetConfigName( void ) return "opengl"; } +static void R_FillRenderAPI( render_api_t *api ) +{ + api->GetDetailScaleForTexture = R_GetDetailScaleForTexture; + api->GetExtraParmsForTexture = R_GetExtraParmsForTexture; + api->GetFrameTime = R_GetFrameTime; + api->R_SetCurrentEntity = R_SetCurrentEntity; + api->R_SetCurrentModel = R_SetCurrentModel; + api->GL_CreateTexture = GL_CreateTexture; + api->GL_LoadTextureArray = GL_LoadTextureArray; + api->GL_CreateTextureArray = GL_CreateTextureArray; + api->DrawSingleDecal = DrawSingleDecal; + api->R_DecalSetupVerts = R_DecalSetupVerts; + api->R_EntityRemoveDecals = R_EntityRemoveDecals; + api->GL_SelectTexture = GL_SelectTexture; + api->GL_LoadTextureMatrix = GL_LoadTexMatrixExt; + api->GL_TexMatrixIdentity = GL_LoadIdentityTexMatrix; + api->GL_CleanUpTextureUnits = GL_CleanUpTextureUnits; + api->GL_TexGen = GL_TexGen; + api->GL_TextureTarget = GL_TextureTarget; + api->GL_TexCoordArrayMode = GL_SetTexCoordArrayMode; + api->GL_UpdateTexSize = GL_UpdateTexSize; + api->GL_DrawParticles = CL_DrawParticlesExternal; + api->LightVec = R_LightVec; + api->StudioGetTexture = R_StudioGetTexture; + api->GL_GetProcAddress = R_GetProcAddress; +} + +static void R_FillTriAPI( triangleapi_t *api ) +{ + api->TexCoord2f = TriTexCoord2f; + api->Fog = TriFog; + api->ScreenToWorld = R_ScreenToWorld; + api->GetMatrix = TriGetMatrix; + api->FogParams = TriFogParams; +} + const ref_interface_t gReffuncs = { R_Init, @@ -483,42 +519,17 @@ const ref_interface_t gReffuncs = R_BeamCull, GL_RefGetParm, - R_GetDetailScaleForTexture, - R_GetExtraParmsForTexture, - R_GetFrameTime, - - R_SetCurrentEntity, - R_SetCurrentModel, GL_FindTexture, GL_TextureName, GL_TextureData, GL_LoadTexture, - GL_CreateTexture, - GL_LoadTextureArray, - GL_CreateTextureArray, GL_FreeTexture, R_OverrideTextureSourceSize, - DrawSingleDecal, - R_DecalSetupVerts, - R_EntityRemoveDecals, - R_UploadStretchRaw, GL_Bind, - GL_SelectTexture, - GL_LoadTexMatrixExt, - GL_LoadIdentityTexMatrix, - GL_CleanUpTextureUnits, - GL_TexGen, - GL_TextureTarget, - GL_SetTexCoordArrayMode, - GL_UpdateTexSize, - - CL_DrawParticlesExternal, - R_LightVec, - R_StudioGetTexture, R_RenderFrame, Mod_SetOrthoBounds, @@ -526,22 +537,19 @@ const ref_interface_t gReffuncs = Mod_GetCurrentVis, R_NewMap, R_ClearScene, - R_GetProcAddress, TriRenderMode, TriBegin, TriEnd, _TriColor4f, _TriColor4ub, - TriTexCoord2f, TriVertex3fv, TriVertex3f, - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriFogParams, TriCullFace, + R_FillRenderAPI, + R_FillTriAPI, + VGUI_SetupDrawing, VGUI_UploadTextureBlock, }; diff --git a/ref/null/r_context.c b/ref/null/r_context.c index 82e9b8b0..3f3e6e31 100644 --- a/ref/null/r_context.c +++ b/ref/null/r_context.c @@ -59,6 +59,16 @@ static void R_StudioSetDrawInterface( struct r_studio_interface_s *pDraw ) ; } +static void R_FillRenderAPI( render_api_t *api ) +{ + ; +} + +static void R_FillTriAPI( triangleapi_t *api ) +{ + ; +} + static qboolean R_Init( void ) { gEngfuncs.R_Init_Video( REF_SOFTWARE ); @@ -493,43 +503,18 @@ static const ref_interface_t gReffuncs = .CL_DrawBeams = CL_DrawBeams, .R_BeamCull = R_BeamCull, - .RefGetParm = RefGetParm, - .GetDetailScaleForTexture = GetDetailScaleForTexture, - .GetExtraParmsForTexture = GetExtraParmsForTexture, - .GetFrameTime = GetFrameTime, + .RefGetParm = RefGetParm, - .R_SetCurrentEntity = R_SetCurrentEntity, - .R_SetCurrentModel = R_SetCurrentModel, - - .GL_FindTexture = GL_FindTexture, - .GL_TextureName = GL_TextureName, - .GL_TextureData = GL_TextureData, - .GL_LoadTexture = GL_LoadTexture, - .GL_CreateTexture = GL_CreateTexture, - .GL_LoadTextureArray = GL_LoadTextureArray, - .GL_CreateTextureArray = GL_CreateTextureArray, - .GL_FreeTexture = R_SimpleStubUInt, + .GL_FindTexture = GL_FindTexture, + .GL_TextureName = GL_TextureName, + .GL_TextureData = GL_TextureData, + .GL_LoadTexture = GL_LoadTexture, + .GL_FreeTexture = R_SimpleStubUInt, .R_OverrideTextureSourceSize = R_OverrideTextureSourceSize, - .DrawSingleDecal = DrawSingleDecal, - .R_DecalSetupVerts = R_DecalSetupVerts, - .R_EntityRemoveDecals = R_EntityRemoveDecals, - .AVI_UploadRawFrame = AVI_UploadRawFrame, - .GL_Bind = GL_Bind, - .GL_SelectTexture = R_SimpleStubInt, - .GL_LoadTextureMatrix = GL_LoadTextureMatrix, - .GL_TexMatrixIdentity = R_SimpleStub, - .GL_CleanUpTextureUnits = R_SimpleStubInt, - .GL_TexGen = GL_TexGen, - .GL_TextureTarget = R_SimpleStubUInt, - .GL_TexCoordArrayMode = R_SimpleStubUInt, - .GL_UpdateTexSize = GL_UpdateTexSize, - - .GL_DrawParticles = GL_DrawParticles, - .LightVec = LightVec, - .StudioGetTexture = StudioGetTexture, + .GL_Bind = GL_Bind, .GL_RenderFrame = GL_RenderFrame, .GL_OrthoBounds = GL_OrthoBounds, @@ -537,22 +522,19 @@ static const ref_interface_t gReffuncs = .Mod_GetCurrentVis = Mod_GetCurrentVis, .R_NewMap = R_SimpleStub, .R_ClearScene = R_SimpleStub, - .R_GetProcAddress = R_GetProcAddress, .TriRenderMode = R_SimpleStubInt, .Begin = R_SimpleStubInt, .End = R_SimpleStub, .Color4f = Color4f, .Color4ub = Color4ub, - .TexCoord2f = TexCoord2f, .Vertex3fv = Vertex3fv, .Vertex3f = Vertex3f, - .Fog = Fog, - .ScreenToWorld = ScreenToWorld, - .GetMatrix = GetMatrix, - .FogParams = FogParams, .CullFace = CullFace, + .R_FillRenderAPI = R_FillRenderAPI, + .R_FillTriAPI = R_FillTriAPI, + .VGUI_SetupDrawing = VGUI_SetupDrawing, .VGUI_UploadTextureBlock = VGUI_UploadTextureBlock, }; diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index 97bace5b..70df530b 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -398,6 +398,42 @@ static void * GAME_EXPORT R_GetProcAddress( const char *name ) return gEngfuncs.GL_GetProcAddress( name ); } +static void R_FillRenderAPI( render_api_t *api ) +{ + api->GetDetailScaleForTexture = R_GetDetailScaleForTexture; + api->GetExtraParmsForTexture = R_GetExtraParmsForTexture; + api->GetFrameTime = R_GetFrameTime; + api->R_SetCurrentEntity = R_SetCurrentEntity; + api->R_SetCurrentModel = R_SetCurrentModel; + api->GL_CreateTexture = GL_CreateTexture; + api->GL_LoadTextureArray = GL_LoadTextureArray; + api->GL_CreateTextureArray = GL_CreateTextureArray; + api->DrawSingleDecal = DrawSingleDecal; + api->R_DecalSetupVerts = R_DecalSetupVerts; + api->R_EntityRemoveDecals = R_EntityRemoveDecals; + api->GL_SelectTexture = GL_SelectTexture; + api->GL_LoadTextureMatrix = GL_LoadTexMatrixExt; + api->GL_TexMatrixIdentity = GL_LoadIdentityTexMatrix; + api->GL_CleanUpTextureUnits = GL_CleanUpTextureUnits; + api->GL_TexGen = GL_TexGen; + api->GL_TextureTarget = GL_TextureTarget; + api->GL_TexCoordArrayMode = GL_SetTexCoordArrayMode; + api->GL_UpdateTexSize = GL_UpdateTexSize; + api->GL_DrawParticles = CL_DrawParticlesExternal; + api->LightVec = R_LightVec; + api->StudioGetTexture = R_StudioGetTexture; + api->GL_GetProcAddress = R_GetProcAddress; +} + +static void R_FillTriAPI( triangleapi_t *api ) +{ + api->TexCoord2f = TriTexCoord2f; + api->Fog = TriFog; + api->ScreenToWorld = R_ScreenToWorld; + api->GetMatrix = TriGetMatrix; + api->FogParams = TriFogParams; +} + const ref_interface_t gReffuncs = { R_Init, @@ -468,42 +504,17 @@ const ref_interface_t gReffuncs = R_BeamCull, GL_RefGetParm, - R_GetDetailScaleForTexture, - R_GetExtraParmsForTexture, - R_GetFrameTime, - - R_SetCurrentEntity, - R_SetCurrentModel, GL_FindTexture, GL_TextureName, GL_TextureData, GL_LoadTexture, - GL_CreateTexture, - GL_LoadTextureArray, - GL_CreateTextureArray, GL_FreeTexture, R_OverrideTextureSourceSize, - DrawSingleDecal, - R_DecalSetupVerts, - R_EntityRemoveDecals, - R_UploadStretchRaw, GL_Bind, - GL_SelectTexture, - GL_LoadTexMatrixExt, - GL_LoadIdentityTexMatrix, - GL_CleanUpTextureUnits, - GL_TexGen, - GL_TextureTarget, - GL_SetTexCoordArrayMode, - GL_UpdateTexSize, - - CL_DrawParticlesExternal, - R_LightVec, - R_StudioGetTexture, R_RenderFrame, Mod_SetOrthoBounds, @@ -511,22 +522,19 @@ const ref_interface_t gReffuncs = Mod_GetCurrentVis, R_NewMap, R_ClearScene, - R_GetProcAddress, TriRenderMode, TriBegin, TriEnd, _TriColor4f, _TriColor4ub, - TriTexCoord2f, TriVertex3fv, TriVertex3f, - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriFogParams, TriCullFace, + R_FillRenderAPI, + R_FillTriAPI, + VGUI_SetupDrawing, VGUI_UploadTextureBlock, };