Skip to content

Commit 49f6b0a

Browse files
Archiver GL: use StripPreprocessorDirectives function
1 parent 88ce1c8 commit 49f6b0a

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

Graphics/Archiver/src/Archiver_GL.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "DeviceObjectArchiveGL.hpp"
3737
#include "SerializedPipelineStateImpl.hpp"
3838
#include "ShaderToolsCommon.hpp"
39+
#include "ParsingTools.hpp"
3940

4041
#if !DILIGENT_NO_GLSLANG
4142
# include "GLSLUtils.hpp"
@@ -58,33 +59,6 @@ struct SerializedResourceSignatureImpl::SignatureTraits<PipelineResourceSignatur
5859
namespace
5960
{
6061

61-
#if !DILIGENT_NO_GLSLANG
62-
void StripVersionDirective(std::string& Source)
63-
{
64-
const size_t VersionPos = Source.find("#version");
65-
if (VersionPos != std::string::npos)
66-
{
67-
const size_t NewLinePos = Source.find('\n', VersionPos);
68-
if (NewLinePos != std::string::npos)
69-
Source.erase(VersionPos, NewLinePos - VersionPos + 1);
70-
}
71-
}
72-
73-
void StripExtensionDirectives(std::string& Source)
74-
{
75-
size_t pos = Source.find("#extension");
76-
while (pos != std::string::npos)
77-
{
78-
size_t end = Source.find('\n', pos);
79-
if (end == std::string::npos)
80-
end = Source.length();
81-
Source.erase(pos, end - pos + 1);
82-
83-
pos = Source.find("#extension", pos);
84-
}
85-
}
86-
#endif
87-
8862
struct CompiledShaderGL final : SerializedShaderImpl::CompiledShader
8963
{
9064
String UnrolledSource;
@@ -240,12 +214,14 @@ struct CompiledShaderGL final : SerializedShaderImpl::CompiledShader
240214
LOG_ERROR_AND_THROW("Failed to generate GLSL for shader '", ShaderCI.Desc.Name, "'");
241215

242216
// Remove #version directive
243-
// The version is added by BuildGLSLSourceString() in ShaderGLImpl.
244-
StripVersionDirective(OptimizedGLSL);
245-
217+
// The version is added by BuildGLSLSourceString() in ShaderGLImpl.
246218
// Remove #extension directives
247-
// The extensions are added by BuildGLSLSourceString() in ShaderGLImpl.
248-
StripExtensionDirectives(OptimizedGLSL);
219+
// The extensions are added by BuildGLSLSourceString() in ShaderGLImpl.
220+
// Also remove #error directives like the following:
221+
// #ifndef GL_ARB_shader_draw_parameters
222+
// #error GL_ARB_shader_draw_parameters is not supported.
223+
// #endif
224+
Parsing::StripPreprocessorDirectives(OptimizedGLSL, {{"version"}, {"extension"}, {"error"}});
249225

250226
AppendShaderSourceLanguageDefinition(OptimizedGLSL, (SourceLang != SHADER_SOURCE_LANGUAGE_DEFAULT) ? SourceLang : ShaderCI.SourceLanguage);
251227
#endif

0 commit comments

Comments
 (0)