Skip to content

Commit

Permalink
Migrate remaining renderer commands to C++ interface
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Jan 18, 2025
1 parent 24f42cc commit ac2b4dc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
4 changes: 4 additions & 0 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5016,6 +5016,10 @@ void R_BuildCubeMaps()
}
}

static Cmd::LambdaCmd buildCubeMapsCmd(
"buildcubemaps", "generate cube probes for reflection mapping",
[]( const Cmd::Args & ) { R_BuildCubeMaps(); });

/*
=================
RE_LoadWorldMap
Expand Down
62 changes: 31 additions & 31 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
GfxInfo_f
================
*/
void GfxInfo_f()
static void GfxInfo_f()
{
static const char fsstrings[][16] =
{
Expand Down Expand Up @@ -1082,31 +1082,44 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
Log::Debug("replaceMaterialMinDimensionIfPresentWithMaxDimension: %d", r_replaceMaterialMinDimensionIfPresentWithMaxDimension->integer );
}

static void GLSL_restart_f()
{
// make sure the render thread is stopped
R_SyncRenderThread();
// FIXME: uses regular logging not Print()
static Cmd::LambdaCmd gfxInfoCmd(
"gfxinfo", "dump graphics driver and configuration info",
[]( const Cmd::Args & ) { GfxInfo_f(); });

GLSL_ShutdownGPUShaders();
GLSL_InitGPUShaders();
class GlslRestartCmd : public Cmd::StaticCmd
{
public:
GlslRestartCmd() : StaticCmd(
"glsl_restart", "recompile GLSL shaders (useful when shaderpath is set)") {}

for ( int i = 0; i < tr.numShaders; i++ )
void Run( const Cmd::Args & ) const override
{
shader_t &shader = *tr.shaders[ i ];
if ( shader.stages == shader.lastStage || shader.stages[ 0 ].deformIndex == 0 )
{
continue;
}
// make sure the render thread is stopped
R_SyncRenderThread();

int deformIndex =
gl_shaderManager.getDeformShaderIndex( shader.deforms, shader.numDeforms );
GLSL_ShutdownGPUShaders();
GLSL_InitGPUShaders();

for ( shaderStage_t *stage = shader.stages; stage != shader.lastStage; stage++ )
for ( int i = 0; i < tr.numShaders; i++ )
{
stage->deformIndex = deformIndex;
shader_t &shader = *tr.shaders[ i ];
if ( shader.stages == shader.lastStage || shader.stages[ 0 ].deformIndex == 0 )
{
continue;
}

int deformIndex =
gl_shaderManager.getDeformShaderIndex( shader.deforms, shader.numDeforms );

for ( shaderStage_t *stage = shader.stages; stage != shader.lastStage; stage++ )
{
stage->deformIndex = deformIndex;
}
}
}
}
};
static GlslRestartCmd glslRestartCmdRegistration;

/*
===============
Expand Down Expand Up @@ -1354,13 +1367,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_showParallelShadowSplits = Cvar_Get( "r_showParallelShadowSplits", "0", CVAR_CHEAT | CVAR_LATCH );

Cvar::Latch( r_profilerRenderSubGroups );

// make sure all the commands added here are also removed in R_Shutdown
ri.Cmd_AddCommand( "shaderexp", R_ShaderExp_f );
ri.Cmd_AddCommand( "gfxinfo", GfxInfo_f );
ri.Cmd_AddCommand( "buildcubemaps", R_BuildCubeMaps );

ri.Cmd_AddCommand( "glsl_restart", GLSL_restart_f );
}

/*
Expand Down Expand Up @@ -1533,12 +1539,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
{
Log::Debug("RE_Shutdown( destroyWindow = %i )", destroyWindow );

ri.Cmd_RemoveCommand( "shaderexp" );
ri.Cmd_RemoveCommand( "gfxinfo" );
ri.Cmd_RemoveCommand( "buildcubemaps" );

ri.Cmd_RemoveCommand( "glsl_restart" );

if ( tr.registered )
{
R_SyncRenderThread();
Expand Down
1 change: 0 additions & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,6 @@ inline bool checkGLErrors()
shader_t *R_FindShaderByName( const char *name );
const char *RE_GetShaderNameFromHandle( qhandle_t shader );
void R_InitShaders();
void R_ShaderExp_f();
void R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset );

/*
Expand Down
30 changes: 13 additions & 17 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6855,28 +6855,24 @@ class ListShadersCmd : public Cmd::StaticCmd
};
static ListShadersCmd listShadersCmdRegistration;

void R_ShaderExp_f()
class ShaderExpCmd : public Cmd::StaticCmd
{
std::string buffer;
public:
ShaderExpCmd() : StaticCmd("shaderexp", "evaluate a q3shader expression (RB_EvalExpression)") {}

for ( int i = 1; i < ri.Cmd_Argc(); i++ )
void Run( const Cmd::Args &args ) const override
{
if ( i > 1 )
{
buffer += ' ';
}

buffer += ri.Cmd_Argv( i );
}

const char* buffer_p = buffer.c_str();
expression_t exp;
std::string expStr = args.ConcatArgs( 1 );
const char* buffer_p = expStr.c_str();
expression_t exp;

ParseExpression( &buffer_p, &exp );
ParseExpression( &buffer_p, &exp );

Log::CommandInteractionMessage( Str::Format( "%i total ops", exp.numOps ) );
Log::CommandInteractionMessage( Str::Format( "%f result", RB_EvalExpression( &exp, 0 ) ) );
}
Print( "%i total ops", exp.numOps );
Print( "%f result", RB_EvalExpression( &exp, 0 ) );
}
};
static ShaderExpCmd shaderExpCmdRegistration;

/*
====================
Expand Down

0 comments on commit ac2b4dc

Please sign in to comment.