Skip to content

Commit

Permalink
Cleaned up style with code check, added unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Athena Z <[email protected]>
  • Loading branch information
athenaz2 committed Aug 12, 2024
1 parent dd1bdb1 commit 41e94c8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
8 changes: 5 additions & 3 deletions include/gz/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1273,12 +1273,14 @@ namespace gz

/// @brief \brief Set the shadow texture size for the given light type.
/// @param _lightType Light type that creates the shadow
/// @param _textureSize Shadow texture size
public: virtual void SetShadowTextureSize(LightType _lightType, unsigned int _textureSize) = 0;
/// @param _textureSize Shadow texture size
public: virtual void SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize) = 0;

/// @brief \brief Get the shadow texture size for the given light type.
/// @param _lightType Light type that creates the shadow
public: virtual unsigned int ShadowTextureSize(LightType _lightType) = 0;
public: virtual unsigned int ShadowTextureSize(LightType _lightType)
const = 0;

/// \brief Sets the given GI as the current new active GI solution
/// \param[in] _gi GI solution that should be active. Nullptr to disable
Expand Down
6 changes: 4 additions & 2 deletions include/gz/rendering/base/BaseScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,12 @@ namespace gz
public: virtual bool SkyEnabled() const override;

// Documentation inherited.
public: virtual void SetShadowTextureSize(LightType _lightType, unsigned int _textureSize) override;
public: virtual void SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize) override;

// Documentation inherited.
public: virtual unsigned int ShadowTextureSize(LightType _lightType) override;
public: virtual unsigned int ShadowTextureSize(LightType _lightType) const
override;

// Documentation inherited.
public: virtual void SetActiveGlobalIllumination(
Expand Down
6 changes: 4 additions & 2 deletions ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ namespace gz
public: virtual bool SkyEnabled() const override;

// Documentation inherited
public: void SetShadowTextureSize(LightType _lightType, unsigned int _textureSize);
public: void SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize);

// Documentation inherited
public: unsigned int ShadowTextureSize(LightType _lightType);
public: unsigned int ShadowTextureSize(LightType _lightType) const
override;

// Documentation inherited
public: virtual void SetActiveGlobalIllumination(
Expand Down
14 changes: 8 additions & 6 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,8 @@ bool Ogre2Scene::SkyEnabled() const
}

//////////////////////////////////////////////////
void Ogre2Scene::SetShadowTextureSize(LightType _lightType, unsigned int _textureSize)
void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize)
{
// If _textureSize exceeds max possible tex size, then use default
if (_textureSize > this->dataPtr->maxTexSize / 2)
Expand All @@ -1580,9 +1581,10 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType, unsigned int _textur
<< "' exceeds maximum possible texture size,"
<< " using default texture size" << std::endl;
return;
}
}

// Generate list of possible tex size options, each a power of 2, starting at 1024
// Generate list of possible tex size options, each a power of 2,
// starting at 1024
std::vector<unsigned int> texSizeOptions;
unsigned int texSizeOption = 1024u;
while (texSizeOption <= this->dataPtr->maxTexSize / 2)
Expand All @@ -1591,11 +1593,11 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType, unsigned int _textur
texSizeOption *= 2;
}

// if _textureSize is not a valid texture size, then use default
// if _textureSize is an invalid texture size, then use default
bool validTexSize = std::find(texSizeOptions.begin(),
texSizeOptions.end(), _textureSize)
!= texSizeOptions.end() ? true : false;
if (!validTexSize)
if (!validTexSize)
{
gzerr << "<texture_size> of '" << _textureSize
<< "' is not a valid texture size,"
Expand All @@ -1611,7 +1613,7 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType, unsigned int _textur
}

//////////////////////////////////////////////////
unsigned int Ogre2Scene::ShadowTextureSize(LightType _lightType)
unsigned int Ogre2Scene::ShadowTextureSize(LightType _lightType) const
{
// todo: return based on light type, currently only dir light is supported
if (_lightType)
Expand Down
7 changes: 4 additions & 3 deletions src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1476,17 +1476,18 @@ bool BaseScene::SkyEnabled() const
}

//////////////////////////////////////////////////
void BaseScene::SetShadowTextureSize(LightType _lightType, unsigned int _textureSize)
void BaseScene::SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize)
{
if (_lightType || _textureSize)
if (_lightType || _textureSize)
{
gzerr << "Setting shadow texture size not supported by: "
<< this->Engine()->Name() << std::endl;
}
}

//////////////////////////////////////////////////
unsigned int BaseScene::ShadowTextureSize(LightType _lightType)
unsigned int BaseScene::ShadowTextureSize(LightType _lightType) const
{
return this->ShadowTextureSize(_lightType);
}
Expand Down
29 changes: 29 additions & 0 deletions test/common_test/Scene_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,32 @@ TEST_F(SceneTest, Sky)
// Clean up
engine->DestroyScene(scene);
}

/////////////////////////////////////////////////
TEST_F(SceneTest, ShadowTexture)
{
CHECK_SUPPORTED_ENGINE("ogre2");

auto scene = engine->CreateScene("scene");
ASSERT_NE(nullptr, scene);

// Default shadow texture size for directional light is 2048u
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_DIRECTIONAL), 2048u);

// Currently only support setting shadow texture size for
// directional light
// If set shadow texture size for other light types, it is ignored
scene->SetShadowTextureSize(LightType::LT_POINT, 4096u);
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_POINT), 2048u);

scene->SetShadowTextureSize(LightType::LT_SPOT, 4096u);
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_SPOT), 2048u);

// If set shadow texture size to a valid value, change it
scene->SetShadowTextureSize(LightType::LT_DIRECTIONAL, 8192u);
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_DIRECTIONAL), 8192u);

// If set shadow texture size to an invalid value, use default
scene->SetShadowTextureSize(LightType::LT_DIRECTIONAL, 1000u);
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_DIRECTIONAL), 8192u);
}

0 comments on commit 41e94c8

Please sign in to comment.