Shader/GlslWriter: Accepts mono-functions shader without specifying entry points
This commit is contained in:
parent
7140e322c1
commit
ac57b3fbf4
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Shader/GlslWriter.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
#include <Nazara/Shader/SpirvPrinter.hpp>
|
||||
|
|
@ -6,25 +7,14 @@
|
|||
#include <Catch/catch.hpp>
|
||||
#include <cctype>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue