Skip to content

Commit

Permalink
cg_api: implement trap_R_BatchInPVS to test if a bunch of entities ar…
Browse files Browse the repository at this point in the history
…e in PVS in one call
  • Loading branch information
illwieckz committed May 31, 2024
1 parent 203729d commit ba610a3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/engine/client/cg_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ bool trap_GetEntityToken( char *buffer, int bufferSize );
std::vector<std::vector<Keyboard::Key>> trap_Key_GetKeysForBinds(int team, const std::vector<std::string>& binds);
int trap_Key_GetCharForScancode( int scancode );
bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 );

std::vector<bool> trap_R_BatchInPVS(
const vec3_t origin,
const std::vector<std::array<float, 3>>& 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 );
Expand Down
8 changes: 8 additions & 0 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -357,6 +358,13 @@ namespace Render {
IPC::Message<IPC::Id<VM::QVM, CG_R_INPVS>, std::array<float, 3>, std::array<float, 3>>,
IPC::Reply<bool>
>;
using BatchInPVSMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<
VM::QVM, CG_R_BATCHINPVS>,
std::array<float, 3>,
std::vector<std::array<float, 3>>>,
IPC::Reply<std::vector<bool>>
>;
using LightForPointMsg = IPC::SyncMessage<
IPC::Message<IPC::Id<VM::QVM, CG_R_LIGHTFORPOINT>, std::array<float, 3>>,
IPC::Reply<std::array<float, 3>, std::array<float, 3>, std::array<float, 3>, int>
Expand Down
15 changes: 15 additions & 0 deletions src/engine/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,21 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
});
break;

case CG_R_BATCHINPVS:
IPC::HandleMsg<Render::BatchInPVSMsg>(channel, std::move(reader), [this] (
const std::array<float, 3>& origin,
const std::vector<std::array<float, 3>>& posEntities,
std::vector<bool>& 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<Render::LightForPointMsg>(channel, std::move(reader), [this] (std::array<float, 3> point, std::array<float, 3>& ambient, std::array<float, 3>& directed, std::array<float, 3>& dir, int& res) {
res = re.LightForPoint(point.data(), ambient.data(), directed.data(), dir.data());
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -683,7 +683,7 @@ static void Render_generic2D( shaderStage_t *pStage )

Tess_DrawElements();

glDisable( GL_DEPTH_CLAMP );
// glDisable( GL_DEPTH_CLAMP );

GL_CheckErrors();
}
Expand Down
11 changes: 11 additions & 0 deletions src/shared/client/cg_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ bool trap_R_inPVS( const vec3_t p1, const vec3_t p2 )
return res;
}

std::vector<bool> trap_R_BatchInPVS(
const vec3_t origin,
const std::vector<std::array<float, 3>>& posEntities )
{
std::array<float, 3> myOrigin;
VectorCopy(origin, myOrigin);
std::vector<bool> inPVS;
VM::SendMsg<Render::BatchInPVSMsg>(myOrigin, posEntities, inPVS);
return inPVS;
}

int trap_R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir )
{
int result;
Expand Down

0 comments on commit ba610a3

Please sign in to comment.