From ba610a3bb0745b771ce1d0d349c3f1bb416f6cb2 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 29 Apr 2023 15:02:46 +0200 Subject: [PATCH] cg_api: implement trap_R_BatchInPVS to test if a bunch of entities are in PVS in one call --- src/engine/client/cg_api.h | 5 +++++ src/engine/client/cg_msgdef.h | 8 ++++++++ src/engine/client/cl_cgame.cpp | 15 +++++++++++++++ src/engine/renderer/tr_shade.cpp | 4 ++-- src/shared/client/cg_api.cpp | 11 +++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/engine/client/cg_api.h b/src/engine/client/cg_api.h index 032538c5ae..c271511c37 100644 --- a/src/engine/client/cg_api.h +++ b/src/engine/client/cg_api.h @@ -163,6 +163,11 @@ bool trap_GetEntityToken( char *buffer, int bufferSize ); std::vector> trap_Key_GetKeysForBinds(int team, const std::vector& binds); int trap_Key_GetCharForScancode( int scancode ); bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 ); + +std::vector trap_R_BatchInPVS( + const vec3_t origin, + const std::vector>& posEntities ); + bool trap_R_inPVVS( const vec3_t p1, const vec3_t p2 ); bool trap_R_LoadDynamicShader( const char *shadername, const char *shadertext ); int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir ); diff --git a/src/engine/client/cg_msgdef.h b/src/engine/client/cg_msgdef.h index 35bf9012e5..dd1ce1c6d5 100644 --- a/src/engine/client/cg_msgdef.h +++ b/src/engine/client/cg_msgdef.h @@ -191,6 +191,7 @@ enum cgameImport_t CG_R_LERPTAG, CG_R_REMAP_SHADER, CG_R_INPVS, + CG_R_BATCHINPVS, CG_R_LIGHTFORPOINT, CG_R_REGISTERANIMATION, CG_R_BUILDSKELETON, @@ -357,6 +358,13 @@ namespace Render { IPC::Message, std::array, std::array>, IPC::Reply >; + using BatchInPVSMsg = IPC::SyncMessage< + IPC::Message, + std::array, + std::vector>>, + IPC::Reply> + >; using LightForPointMsg = IPC::SyncMessage< IPC::Message, std::array>, IPC::Reply, std::array, std::array, int> diff --git a/src/engine/client/cl_cgame.cpp b/src/engine/client/cl_cgame.cpp index 7b75aeec06..3a8843e571 100644 --- a/src/engine/client/cl_cgame.cpp +++ b/src/engine/client/cl_cgame.cpp @@ -1287,6 +1287,21 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha }); break; + case CG_R_BATCHINPVS: + IPC::HandleMsg(channel, std::move(reader), [this] ( + const std::array& origin, + const std::vector>& posEntities, + std::vector& inPVS) + { + inPVS.reserve(posEntities.size()); + + for (const auto& posEntity : posEntities) + { + inPVS.push_back(re.inPVS(origin.data(), posEntity.data())); + } + }); + break; + case CG_R_LIGHTFORPOINT: IPC::HandleMsg(channel, std::move(reader), [this] (std::array point, std::array& ambient, std::array& directed, std::array& dir, int& res) { res = re.LightForPoint(point.data(), ambient.data(), directed.data(), dir.data()); diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index c99eb83699..bfc070e5ef 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -667,7 +667,7 @@ static void Render_generic2D( shaderStage_t *pStage ) BindAnimatedImage( &pStage->bundle[ TB_COLORMAP ] ); gl_generic2DShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] ); - glEnable( GL_DEPTH_CLAMP ); +// glEnable( GL_DEPTH_CLAMP ); if ( hasDepthFade ) { @@ -683,7 +683,7 @@ static void Render_generic2D( shaderStage_t *pStage ) Tess_DrawElements(); - glDisable( GL_DEPTH_CLAMP ); +// glDisable( GL_DEPTH_CLAMP ); GL_CheckErrors(); } diff --git a/src/shared/client/cg_api.cpp b/src/shared/client/cg_api.cpp index 1eb13c42bd..5c8b016864 100644 --- a/src/shared/client/cg_api.cpp +++ b/src/shared/client/cg_api.cpp @@ -472,6 +472,17 @@ bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 ) return res; } +std::vector trap_R_BatchInPVS( + const vec3_t origin, + const std::vector>& posEntities ) +{ + std::array myOrigin; + VectorCopy(origin, myOrigin); + std::vector inPVS; + VM::SendMsg(myOrigin, posEntities, inPVS); + return inPVS; +} + int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir ) { int result;