From ac2b4dc3b528ab3bf3768633c7f6208a0f3b2be8 Mon Sep 17 00:00:00 2001 From: slipher Date: Tue, 7 Jan 2025 17:38:49 -0300 Subject: [PATCH] Migrate remaining renderer commands to C++ interface --- src/engine/renderer/tr_bsp.cpp | 4 ++ src/engine/renderer/tr_init.cpp | 62 +++++++++++++++---------------- src/engine/renderer/tr_local.h | 1 - src/engine/renderer/tr_shader.cpp | 30 +++++++-------- 4 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index e8a56f282f..f366f28379 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -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 diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index e53b947f84..543adc87c0 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -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] = { @@ -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; /* =============== @@ -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 ); } /* @@ -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(); diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index b1f1f6e3fc..42988156a4 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -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 ); /* diff --git a/src/engine/renderer/tr_shader.cpp b/src/engine/renderer/tr_shader.cpp index 57b6767e09..f5c2b10184 100644 --- a/src/engine/renderer/tr_shader.cpp +++ b/src/engine/renderer/tr_shader.cpp @@ -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; /* ====================