Skip to content

Commit

Permalink
Add unit tests and redid some logic
Browse files Browse the repository at this point in the history
Signed-off-by: Athena Z <athenaz@google.com>
  • Loading branch information
athenaz2 committed Aug 15, 2024
1 parent ebf0f41 commit b0f29b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1484,29 +1484,29 @@ void MinimalScene::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
auto textureSizeElem = elem->FirstChildElement("texture_size");
if (nullptr != elem && nullptr != textureSizeElem->GetText())
{
std::string lightType = textureSizeElem->Attribute("light_type");
if (lightType == "directional")
unsigned int texSize;
std::stringstream texSizeStr;
texSizeStr << std::string(textureSizeElem->GetText());
texSizeStr >> texSize;
if (texSizeStr.fail())
{
unsigned int texSize;
std::stringstream texSizeStr;
texSizeStr << std::string(textureSizeElem->GetText());
texSizeStr >> texSize;
if (texSizeStr.fail())
{
gzerr << "Unable to set <texture_size> to '" << texSizeStr.str()
<< "' using default directional light texture size"
<< std::endl;
}
else
gzerr << "Unable to set <texture_size> to '" << texSizeStr.str()
<< "' using default directional light texture size"
<< std::endl;
}
else
{
std::string lightType = textureSizeElem->Attribute("light_type");
if (lightType == "directional")
{
renderWindow->SetShadowTextureSize(
rendering::LightType::LT_DIRECTIONAL, texSize);
}
}
else
{
gzerr << "Light type [" << lightType << "] is not supported."
else
{
gzerr << "Light type [" << lightType << "] is not supported."
<< std::endl;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/integration/minimal_scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
" <near>0.1</near>"
" <far>5000</far>"
"</camera_clip>"
"<shadows>"
" <texture_size light_type=\"directional\">8192</texture_size>"
"</shadows>"
"<horizontal_fov>60</horizontal_fov>"
"<view_controller>ortho</view_controller>"
"</plugin>";
Expand Down Expand Up @@ -131,6 +134,11 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
EXPECT_DOUBLE_EQ(0.1, camera->NearClipPlane());
EXPECT_DOUBLE_EQ(5000.0, camera->FarClipPlane());

EXPECT_EQ(8192u, scene->ShadowTextureSize(
rendering::LightType::LT_DIRECTIONAL));
EXPECT_EQ(2048u, scene->ShadowTextureSize(rendering::LightType::LT_SPOT));
EXPECT_EQ(2048u, scene->ShadowTextureSize(rendering::LightType::LT_POINT));

EXPECT_NEAR(60, camera->HFOV().Degree(), 1e-4);

EXPECT_EQ(rendering::CameraProjectionType::CPT_ORTHOGRAPHIC,
Expand Down

0 comments on commit b0f29b0

Please sign in to comment.