Skip to content

Commit 68cfcb9

Browse files
committed
renderer: rewrite the GLimp_LogComment() calls
- Turn GLimp_LogComment() into a macro wrapping the test for logging being enabled, - Wrap the string formatting into the macro too, - Wrap the endline character writing too, - Move the GLimp_LogComment() calls after tests doing early returns.
1 parent 18a9745 commit 68cfcb9

File tree

15 files changed

+233
-433
lines changed

15 files changed

+233
-433
lines changed

src/engine/renderer/Material.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,8 @@ void BindShaderLightMapping( Material* material ) {
908908

909909
const float interpolation = 1.0 - trilerp[0];
910910

911-
if ( r_logFile->integer ) {
912-
GLimp_LogComment( va( "Probe 0 distance = %f, probe 1 distance = %f, interpolation = %f\n",
913-
Distance( position, probes[0]->origin ), Distance( position, probes[1]->origin ), interpolation ) );
914-
}
911+
GLIMP_LOGCOMMENT( "Probe 0 distance = %f, probe 1 distance = %f, interpolation = %f",
912+
Distance( position, probes[0]->origin ), Distance( position, probes[1]->origin ), interpolation );
915913

916914
// bind u_EnvironmentMap0
917915
gl_lightMappingShaderMaterial->SetUniform_EnvironmentMap0Bindless(

src/engine/renderer/gl_shader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,13 +2351,14 @@ void GLShader::BindProgram( int deformIndex ) {
23512351

23522352
currentProgram = &shaderPrograms[index];
23532353

2354-
if ( r_logFile->integer ) {
2354+
if ( GLimp_isLogging() )
2355+
{
23552356
std::string macros;
23562357

23572358
GetCompileMacrosString( index, macros, GLCompileMacro::VERTEX | GLCompileMacro::FRAGMENT );
23582359

2359-
auto msg = Str::Format( "--- GL_BindProgram( name = '%s', macros = '%s' ) ---\n", this->GetName(), macros );
2360-
GLimp_LogComment( msg.c_str() );
2360+
GLIMP_LOGCOMMENT( "--- GL_BindProgram( name = '%s', macros = '%s' ) ---",
2361+
this->GetName(), macros );
23612362
}
23622363

23632364
GL_BindProgram( &shaderPrograms[index] );

src/engine/renderer/gl_shader.h

Lines changed: 37 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,8 @@ class GLUniform1i : protected GLUniform
685685
}
686686

687687
#if defined( LOG_GLSL_UNIFORMS )
688-
if ( r_logFile->integer )
689-
{
690-
GLimp_LogComment( va( "GLSL_SetUniform1i( %s, shader: %s, value: %d ) ---\n",
691-
this->GetName(), _shader->GetName().c_str(), value ) );
692-
}
688+
GLIMP_LOGCOMMENT( "GLSL_SetUniform1i( %s, shader: %s, value: %d )",
689+
this->GetName(), _shader->GetName().c_str(), value );
693690
#endif
694691

695692
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -738,10 +735,8 @@ class GLUniform1ui : protected GLUniform {
738735
}
739736

740737
#if defined( LOG_GLSL_UNIFORMS )
741-
if ( r_logFile->integer ) {
742-
GLimp_LogComment( va( "GLSL_SetUniform1i( %s, shader: %s, value: %d ) ---\n",
743-
this->GetName(), _shader->GetName().c_str(), value ) );
744-
}
738+
GLIMP_LOGCOMMENT( "GLSL_SetUniform1i( %s, shader: %s, value: %d )",
739+
this->GetName(), _shader->GetName().c_str(), value );
745740
#endif
746741

747742
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -789,10 +784,8 @@ class GLUniform1Bool : protected GLUniform {
789784
}
790785

791786
#if defined( LOG_GLSL_UNIFORMS )
792-
if ( r_logFile->integer ) {
793-
GLimp_LogComment( va( "GLSL_SetUniform1i( %s, shader: %s, value: %d ) ---\n",
794-
this->GetName(), _shader->GetName().c_str(), value ) );
795-
}
787+
GLIMP_LOGCOMMENT( "GLSL_SetUniform1i( %s, shader: %s, value: %d )",
788+
this->GetName(), _shader->GetName().c_str(), value );
796789
#endif
797790

798791
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -843,11 +836,8 @@ class GLUniform1f : protected GLUniform
843836
}
844837

845838
#if defined( LOG_GLSL_UNIFORMS )
846-
if ( r_logFile->integer )
847-
{
848-
GLimp_LogComment( va( "GLSL_SetUniform1f( %s, shader: %s, value: %f ) ---\n",
849-
this->GetName(), _shader->GetName().c_str(), value ) );
850-
}
839+
GLIMP_LOGCOMMENT( "GLSL_SetUniform1f( %s, shader: %s, value: %f )",
840+
this->GetName(), _shader->GetName().c_str(), value );
851841
#endif
852842

853843
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -900,11 +890,8 @@ class GLUniform1fv : protected GLUniform
900890
}
901891

902892
#if defined( LOG_GLSL_UNIFORMS )
903-
if ( r_logFile->integer )
904-
{
905-
GLimp_LogComment( va( "GLSL_SetUniform1fv( %s, shader: %s, numFloats: %d ) ---\n",
906-
this->GetName(), _shader->GetName().c_str(), numFloats ) );
907-
}
893+
GLIMP_LOGCOMMENT( "GLSL_SetUniform1fv( %s, shader: %s, numFloats: %d )",
894+
this->GetName(), _shader->GetName().c_str(), numFloats );
908895
#endif
909896

910897
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -943,11 +930,8 @@ class GLUniform2f : protected GLUniform
943930
}
944931

945932
#if defined( LOG_GLSL_UNIFORMS )
946-
if ( r_logFile->integer )
947-
{
948-
GLimp_LogComment( va( "GLSL_SetUniform2f( %s, shader: %s, value: [ %f, %f ] ) ---\n",
949-
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ] ) );
950-
}
933+
GLIMP_LOGCOMMENT( "GLSL_SetUniform2f( %s, shader: %s, value: [ %f, %f ] )",
934+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ] );
951935
#endif
952936

953937
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1003,11 +987,8 @@ class GLUniform3f : protected GLUniform
1003987
}
1004988

1005989
#if defined( LOG_GLSL_UNIFORMS )
1006-
if ( r_logFile->integer )
1007-
{
1008-
GLimp_LogComment( va( "GLSL_SetUniform3f( %s, shader: %s, value: [ %f, %f, %f ] ) ---\n",
1009-
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ] ) );
1010-
}
990+
GLIMP_LOGCOMMENT( "GLSL_SetUniform3f( %s, shader: %s, value: [ %f, %f, %f ] )",
991+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ] );
1011992
#endif
1012993

1013994
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1063,11 +1044,8 @@ class GLUniform4f : protected GLUniform
10631044
}
10641045

10651046
#if defined( LOG_GLSL_UNIFORMS )
1066-
if ( r_logFile->integer )
1067-
{
1068-
GLimp_LogComment( va( "GLSL_SetUniform4f( %s, shader: %s, value: [ %f, %f, %f, %f ] ) ---\n",
1069-
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] ) );
1070-
}
1047+
GLIMP_LOGCOMMENT( "GLSL_SetUniform4f( %s, shader: %s, value: [ %f, %f, %f, %f ] )",
1048+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] );
10711049
#endif
10721050

10731051
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1120,11 +1098,8 @@ class GLUniform4fv : protected GLUniform
11201098
}
11211099

11221100
#if defined( LOG_GLSL_UNIFORMS )
1123-
if ( r_logFile->integer )
1124-
{
1125-
GLimp_LogComment( va( "GLSL_SetUniform4fv( %s, shader: %s, numV: %d ) ---\n",
1126-
this->GetName(), _shader->GetName().c_str(), numV ) );
1127-
}
1101+
GLIMP_LOGCOMMENT( "GLSL_SetUniform4fv( %s, shader: %s, numV: %d )",
1102+
this->GetName(), _shader->GetName().c_str(), numV );
11281103
#endif
11291104

11301105
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1163,13 +1138,11 @@ class GLUniformMatrix4f : protected GLUniform
11631138
}
11641139

11651140
#if defined( LOG_GLSL_UNIFORMS )
1166-
if ( r_logFile->integer )
1167-
{
1168-
GLimp_LogComment( va( "GLSL_SetUniformMatrix4f( %s, shader: %s, transpose: %d, [ %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f ] ) ---\n",
1169-
this->GetName(), _shader->GetName().c_str(), transpose,
1170-
m[ 0 ], m[ 1 ], m[ 2 ], m[ 3 ], m[ 4 ], m[ 5 ], m[ 6 ], m[ 7 ], m[ 8 ], m[ 9 ], m[ 10 ], m[ 11 ], m[ 12 ],
1171-
m[ 13 ], m[ 14 ], m[ 15 ] ) );
1172-
}
1141+
GLIMP_LOGCOMMENT( "GLSL_SetUniformMatrix4f( %s, shader: %s, transpose: %d, "
1142+
"[ %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f ] )",
1143+
this->GetName(), _shader->GetName().c_str(), transpose,
1144+
m[ 0 ], m[ 1 ], m[ 2 ], m[ 3 ], m[ 4 ], m[ 5 ], m[ 6 ], m[ 7 ], m[ 8 ],
1145+
m[ 9 ], m[ 10 ], m[ 11 ], m[ 12 ], m[ 13 ], m[ 14 ], m[ 15 ] );
11731146
#endif
11741147

11751148
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1218,11 +1191,10 @@ class GLUniformMatrix32f : protected GLUniform {
12181191
}
12191192

12201193
#if defined( LOG_GLSL_UNIFORMS )
1221-
if ( r_logFile->integer ) {
1222-
GLimp_LogComment( va( "GLSL_SetUniformMatrix32f( %s, shader: %s, transpose: %d, [ %f, %f, %f, %f, %f, %f ] ) ---\n",
1223-
this->GetName(), _shader->GetName().c_str(), transpose,
1224-
m[0], m[1], m[2], m[3], m[4], m[5] ) );
1225-
}
1194+
GLIMP_LOGCOMMENT( "GLSL_SetUniformMatrix32f( %s, shader: %s, transpose: %d, "
1195+
"[ %f, %f, %f, %f, %f, %f ] )",
1196+
this->GetName(), _shader->GetName().c_str(), transpose,
1197+
m[0], m[1], m[2], m[3], m[4], m[5] );
12261198
#endif
12271199

12281200
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1264,11 +1236,8 @@ class GLUniformMatrix4fv : protected GLUniform
12641236
}
12651237

12661238
#if defined( LOG_GLSL_UNIFORMS )
1267-
if ( r_logFile->integer )
1268-
{
1269-
GLimp_LogComment( va( "GLSL_SetUniformMatrix4fv( %s, shader: %s, numMatrices: %d, transpose: %d ) ---\n",
1270-
this->GetName(), _shader->GetName().c_str(), numMatrices, transpose ) );
1271-
}
1239+
GLIMP_LOGCOMMENT( "GLSL_SetUniformMatrix4fv( %s, shader: %s, numMatrices: %d, transpose: %d )",
1240+
this->GetName(), _shader->GetName().c_str(), numMatrices, transpose );
12721241
#endif
12731242

12741243
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1306,11 +1275,8 @@ class GLUniformMatrix34fv : protected GLUniform
13061275
}
13071276

13081277
#if defined( LOG_GLSL_UNIFORMS )
1309-
if ( r_logFile->integer )
1310-
{
1311-
GLimp_LogComment( va( "GLSL_SetUniformMatrix34fv( %s, shader: %s, numMatrices: %d, transpose: %d ) ---\n",
1312-
this->GetName(), _shader->GetName().c_str(), numMatrices, transpose ) );
1313-
}
1278+
GLIMP_LOGCOMMENT( "GLSL_SetUniformMatrix34fv( %s, shader: %s, numMatrices: %d, transpose: %d )",
1279+
this->GetName(), _shader->GetName().c_str(), numMatrices, transpose );
13141280
#endif
13151281

13161282
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -3786,13 +3752,9 @@ class u_ColorModulateColorGen_Float :
37863752
const bool vertexOverbright = false,
37873753
const bool useMapLightFactor = false )
37883754
{
3789-
if ( r_logFile->integer ) {
3790-
GLimp_LogComment(
3791-
va( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Float( "
3792-
"program = %s, colorGen = %s, alphaGen = %s ) ---\n",
3793-
_shader->GetName().c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) )
3794-
);
3795-
}
3755+
GLIMP_LOGCOMMENT( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Float( "
3756+
"program = %s, colorGen = %s, alphaGen = %s ) ---",
3757+
_shader->GetName().c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) );
37963758

37973759
colorModulation_t colorModulation = ColorModulateColorGen(
37983760
colorGen, alphaGen, vertexOverbright, useMapLightFactor );
@@ -3821,13 +3783,9 @@ class u_ColorModulateColorGen_Uint :
38213783
const bool vertexOverbright = false,
38223784
const bool useMapLightFactor = false )
38233785
{
3824-
if ( r_logFile->integer ) {
3825-
GLimp_LogComment(
3826-
va( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Uint( "
3827-
"program = %s, colorGen = %s, alphaGen = %s ) ---\n",
3828-
_shader->GetName().c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) )
3829-
);
3830-
}
3786+
GLIMP_LOGCOMMENT( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Uint( "
3787+
"program = %s, colorGen = %s, alphaGen = %s ) ---",
3788+
_shader->GetName().c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) );
38313789

38323790
colorModulation_t colorModulation = ColorModulateColorGen(
38333791
colorGen, alphaGen, vertexOverbright, useMapLightFactor );

0 commit comments

Comments
 (0)