Skip to content

Commit

Permalink
#5532: The value of the polygonOffset keyword is optional, adjust the…
Browse files Browse the repository at this point in the history
… parser
  • Loading branch information
codereader committed Feb 19, 2021
1 parent 110bc03 commit a7352a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/ishaders.h
Expand Up @@ -58,6 +58,7 @@ class Material
FLAG_NOPORTALFOG = 1 << 8, // noPortalFog
FLAG_UNSMOOTHEDTANGENTS = 1 << 9, // unsmoothedTangents
FLAG_MIRROR = 1 << 10, // mirror
FLAG_POLYGONOFFSET = 1 << 11, // has polygonOffset
};

// Surface Flags
Expand Down
21 changes: 20 additions & 1 deletion radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -94,7 +94,26 @@ bool ShaderTemplate::parseShaderFlags(parser::DefTokeniser& tokeniser,
}
else if (token == "polygonoffset")
{
_polygonOffset = string::convert<float>(tokeniser.nextToken(), 0);
_materialFlags |= Material::FLAG_POLYGONOFFSET;

// The value argument is optional, try to parse the next token
if (tokeniser.hasMoreTokens())
{
try
{
_polygonOffset = std::stof(tokeniser.peek());
// success, exhaust the token
tokeniser.skipTokens(1);
}
catch (const std::logic_error&) // logic_error is base of invalid_argument out_of_range exceptions
{
_polygonOffset = 1.0f;
}
}
else
{
_polygonOffset = 1.0f;
}
}
else if (token == "clamp")
{
Expand Down

0 comments on commit a7352a9

Please sign in to comment.