diff --git a/src/Nazara/Shader/GlslWriter.cpp b/src/Nazara/Shader/GlslWriter.cpp index 33099e4f6..004bbc7da 100644 --- a/src/Nazara/Shader/GlslWriter.cpp +++ b/src/Nazara/Shader/GlslWriter.cpp @@ -58,7 +58,9 @@ namespace Nz } else { - assert(!entryPoint); + if (entryPoint) + throw std::runtime_error("multiple entry point functions found, this is not allowed in GLSL, please select one"); + entryPoint = &node; } } @@ -148,9 +150,16 @@ namespace Nz targetAst->Visit(previsitor); if (!previsitor.entryPoint) - throw std::runtime_error("missing entry point"); + { + if (previsitor.forwardFunctionDeclarations.empty()) + throw std::runtime_error("no function found"); + + state.entryFunc = previsitor.forwardFunctionDeclarations.front(); + previsitor.forwardFunctionDeclarations.erase(previsitor.forwardFunctionDeclarations.begin()); + } + else + state.entryFunc = previsitor.entryPoint; - state.entryFunc = previsitor.entryPoint; state.functionNames = std::move(previsitor.functionNames); AppendHeader(previsitor.forwardFunctionDeclarations); diff --git a/tests/Engine/Shader/AccessMember.cpp b/tests/Engine/Shader/AccessMember.cpp index 27914dc16..2a583526f 100644 --- a/tests/Engine/Shader/AccessMember.cpp +++ b/tests/Engine/Shader/AccessMember.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,25 +7,14 @@ #include #include -std::string_view Trim(std::string_view str) -{ - while (!str.empty() && std::isspace(str.front())) - str.remove_prefix(1); - - while (!str.empty() && std::isspace(str.back())) - str.remove_suffix(1); - - return str; -} - void ExpectingGLSL(Nz::ShaderAst::StatementPtr& shader, std::string_view expectedOutput) { Nz::GlslWriter writer; std::string output = writer.Generate(shader); std::size_t funcOffset = output.find("void main()"); - std::string_view subset = Trim(output).substr(funcOffset); - expectedOutput = Trim(expectedOutput); + std::string_view subset = Nz::Trim(output).substr(funcOffset); + expectedOutput = Nz::Trim(expectedOutput); REQUIRE(subset == expectedOutput); } @@ -42,8 +32,8 @@ void ExpectingSpirV(Nz::ShaderAst::StatementPtr& shader, std::string_view expect std::string output = printer.Print(spirv.data(), spirv.size(), settings); std::size_t funcOffset = output.find("OpFunction"); - std::string_view subset = Trim(output).substr(funcOffset); - expectedOutput = Trim(expectedOutput); + std::string_view subset = Nz::Trim(output).substr(funcOffset); + expectedOutput = Nz::Trim(expectedOutput); REQUIRE(subset == expectedOutput); }