@@ -490,10 +490,14 @@ static void AddConst( std::string& str, const std::string& name, float v1, float
490490
491491static 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 ) {
838842std::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