Skip to content

Commit 8fe0baa

Browse files
committed
gl_shader: 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 11ec5c1 commit 8fe0baa

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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 );
@@ -840,7 +844,10 @@ std::string GLShaderManager::GetDeformShaderName( const int index ) {
840844
std::string GLShaderManager::BuildDeformShaderText( const std::string& steps ) {
841845
std::string shaderText;
842846

843-
shaderText = steps + "\n";
847+
shaderText = "\n" + steps + "\n";
848+
849+
shaderText += "#line 2000000000\n";
850+
844851
shaderText += GetShaderText( "deformVertexes_vp.glsl" );
845852

846853
return shaderText;
@@ -1196,6 +1203,13 @@ std::string GLShaderManager::ProcessInserts( const std::string& shaderText ) con
11961203

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

1329-
shaderType.mainText = GetShaderText( filename );
1343+
/* The deform vertex header is prepended to the mainText,
1344+
so we should reset line numbering after it. */
1345+
shaderType.mainText = "#line 0\n" + GetShaderText( filename );
13301346
}
13311347
}
13321348

@@ -3068,4 +3084,4 @@ GlobalUBOProxy::GlobalUBOProxy() :
30683084
u_Tonemap( this ),
30693085
u_TonemapParms( this ),
30703086
u_Exposure( this ) {
3071-
}
3087+
}

0 commit comments

Comments
 (0)