Skip to content

Commit 983d178

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 983d178

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/engine/renderer/gl_shader.cpp

Lines changed: 20 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;
@@ -1194,6 +1201,13 @@ std::string GLShaderManager::ProcessInserts( const std::string& shaderText ) con
11941201

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

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

@@ -3066,4 +3082,4 @@ GlobalUBOProxy::GlobalUBOProxy() :
30663082
u_Tonemap( this ),
30673083
u_TonemapParms( this ),
30683084
u_Exposure( this ) {
3069-
}
3085+
}

0 commit comments

Comments
 (0)