Skip to content

Commit 41ab201

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 ef2ae9e commit 41ab201

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 21 additions & 4 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 );
@@ -838,7 +842,10 @@ std::string GLShaderManager::GetDeformShaderName( const int index ) {
838842
std::string GLShaderManager::BuildDeformShaderText( const std::string& steps ) {
839843
std::string shaderText;
840844

841-
shaderText = steps + "\n";
845+
shaderText = "\n" + steps + "\n";
846+
847+
shaderText += "#line 2000000000\n";
848+
842849
shaderText += GetShaderText( "deformVertexes_vp.glsl" );
843850

844851
return shaderText;
@@ -1193,7 +1200,15 @@ std::string GLShaderManager::ProcessInserts( const std::string& shaderText ) con
11931200
int lineCount = 0;
11941201

11951202
while ( std::getline( shaderTextStream, line, '\n' ) ) {
1203+
/* The deform vertex header is prepended to the mainText and is part
1204+
of the shaderText, so we should reset line numbering after it. */
1205+
if ( line == "#line 0" ) {
1206+
lineCount = 0;
1207+
continue;
1208+
}
1209+
11961210
++lineCount;
1211+
11971212
const std::string::size_type position = line.find( "#insert" );
11981213
if ( position == std::string::npos || line.find_first_not_of( " \t" ) != position ) {
11991214
out += line + "\n";
@@ -1324,7 +1339,9 @@ void GLShaderManager::InitShader( GLShader* shader ) {
13241339
if ( shaderType.enabled ) {
13251340
Com_sprintf( filename, sizeof( filename ), "%s%s.glsl", shaderType.path.c_str(), shaderType.postfix );
13261341

1327-
shaderType.mainText = GetShaderText( filename );
1342+
/* The deform vertex header is prepended to the mainText,
1343+
so we should reset line numbering after it. */
1344+
shaderType.mainText = "#line 0\n" + GetShaderText( filename );
13281345
}
13291346
}
13301347

@@ -3066,4 +3083,4 @@ GlobalUBOProxy::GlobalUBOProxy() :
30663083
u_Tonemap( this ),
30673084
u_TonemapParms( this ),
30683085
u_Exposure( this ) {
3069-
}
3086+
}

0 commit comments

Comments
 (0)