Skip to content

Commit f2b6520

Browse files
committed
renderer: fix shader dump line numbering
- reset line number at GLSL shader start - use custom line number for the GLSL header to avoid line number duplicates - use custom line number for the deform vertex header - reset line count on `#line 0`
1 parent e80ec08 commit f2b6520

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/engine/renderer/gl_shader.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,14 @@ static void AddConst( std::string& str, const std::string& name, float v1, float
490490

491491
static std::string GenVersionDeclaration( const std::vector<addedExtension_t> &addedExtensions ) {
492492
// Declare version.
493-
std::string str = Str::Format( "#version %d %s\n\n",
493+
std::string str = Str::Format( "#version %d %s\n",
494494
glConfig.shadingLanguageVersion,
495495
glConfig.shadingLanguageVersion >= 150 ? ( glConfig.glCoreProfile ? "core" : "compatibility" ) : "" );
496496

497+
str += "#line 1000000000\n";
498+
499+
str += "\n";
500+
497501
// Add supported GLSL extensions.
498502
for ( const auto& addedExtension : addedExtensions ) {
499503
addExtension( str, addedExtension.available, addedExtension.minGlslVersion, addedExtension.name );
@@ -859,7 +863,10 @@ std::string GLShaderManager::GetDeformShaderName( const int index ) {
859863
std::string GLShaderManager::BuildDeformShaderText( const std::string& steps ) {
860864
std::string shaderText;
861865

862-
shaderText = steps + "\n";
866+
shaderText = "\n" + steps + "\n";
867+
868+
shaderText += "#line 2000000000\n";
869+
863870
shaderText += GetShaderText( "deformVertexes_vp.glsl" );
864871

865872
return shaderText;
@@ -1223,6 +1230,13 @@ std::string GLShaderManager::ProcessInserts( const std::string& shaderText ) con
12231230

12241231
while ( std::getline( shaderTextStream, line, '\n' ) ) {
12251232
++lineCount;
1233+
1234+
/* The deform vertex header is prepended to the mainText and is part
1235+
of the shaderText, so we should reset line numbering after it. */
1236+
if ( line == "#line 0" ) {
1237+
lineCount = 0;
1238+
}
1239+
12261240
const std::string::size_type position = line.find( "#insert" );
12271241
if ( position == std::string::npos || line.find_first_not_of( " \t" ) != position ) {
12281242
out += line + "\n";
@@ -1353,7 +1367,9 @@ void GLShaderManager::InitShader( GLShader* shader ) {
13531367
if ( shaderType.enabled ) {
13541368
Com_sprintf( filename, sizeof( filename ), "%s%s.glsl", shaderType.path.c_str(), shaderType.postfix );
13551369

1356-
shaderType.mainText = GetShaderText( filename );
1370+
/* The deform vertex header is prepended to the mainText,
1371+
so we should reset line numbering after it. */
1372+
shaderType.mainText = "#line 0\n" + GetShaderText( filename );
13571373
}
13581374
}
13591375

0 commit comments

Comments
 (0)