Skip to content

Commit

Permalink
#5565: Export polygonOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 25, 2021
1 parent 29494a5 commit 39d250b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions radiantcore/shaders/MaterialSourceGenerator.cpp
Expand Up @@ -2,6 +2,7 @@

#include "ShaderTemplate.h"
#include "string/replace.h"
#include <fmt/format.h>

namespace shaders
{
Expand All @@ -15,6 +16,11 @@ std::ostream& operator<<(std::ostream& stream, ShaderTemplate& shaderTemplate)
stream << "\tdescription \"" << string::replace_all_copy(shaderTemplate.getDescription(), "\"", "'") << "\"\n";
}

if (shaderTemplate.getMaterialFlags() & Material::FLAG_POLYGONOFFSET)
{
stream << fmt::format("\tpolygonOffset {0}\n", shaderTemplate.getPolygonOffset());
}

for (const auto& layer : shaderTemplate.getLayers())
{
stream << "\t{\n";
Expand Down
26 changes: 26 additions & 0 deletions test/MaterialExport.cpp
Expand Up @@ -16,6 +16,13 @@ inline void expectDefinitionContains(const MaterialPtr& material, const std::str
<< "Definition was: \n" << material->getDefinition();
}

inline void expectDefinitionDoesNotContain(const MaterialPtr& material, const std::string& expectedContainedString)
{
EXPECT_EQ(material->getDefinition().find(expectedContainedString), std::string::npos)
<< "Material definition contains " << expectedContainedString << " but that shouldn't be the case.\n"
<< "Definition was: \n" << material->getDefinition();
}

TEST_F(MaterialExportTest, Description)
{
auto material = GlobalMaterialManager().getMaterial("textures/exporttest/empty");
Expand All @@ -34,4 +41,23 @@ TEST_F(MaterialExportTest, Description)
expectDefinitionContains(material, fmt::format("description \"{0}\"", singleQuoted));
}

TEST_F(MaterialExportTest, PolygonOffset)
{
auto material = GlobalMaterialManager().getMaterial("textures/exporttest/empty");

EXPECT_EQ(string::trim_copy(material->getDefinition()), "");

material->setPolygonOffset(0.0);
expectDefinitionContains(material, fmt::format("polygonOffset {0}", 0.0));

material->setPolygonOffset(-1.5);
expectDefinitionContains(material, fmt::format("polygonOffset {0}", -1.5));

material->setPolygonOffset(+1.5);
expectDefinitionContains(material, fmt::format("polygonOffset {0}", 1.5));

material->clearMaterialFlag(Material::FLAG_POLYGONOFFSET);
expectDefinitionDoesNotContain(material, "polygonOffset");
}

}

0 comments on commit 39d250b

Please sign in to comment.