Skip to content

Commit

Permalink
Changed LightType from enum to enum class, modify SetShadowTextureSiz…
Browse files Browse the repository at this point in the history
…e to return bool

Signed-off-by: Athena Z <[email protected]>
  • Loading branch information
athenaz2 committed Aug 15, 2024
1 parent 3b1bc7a commit 94ece77
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 34 deletions.
19 changes: 14 additions & 5 deletions include/gz/rendering/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ namespace gz
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {

enum GZ_RENDERING_VISIBLE LightType
/// \enum LightType
/// \brief Enum for Light types.
enum class GZ_RENDERING_VISIBLE LightType
{
LT_EMPTY = 0,
LT_POINT = 1,
LT_DIRECTIONAL = 2,
LT_SPOT = 3
/// \brief No light type specified
EMPTY = 0,

/// \brief Point light
POINT = 1,

/// \brief Directional light
DIRECTIONAL = 2,

/// \brief Spot light
SPOT = 3
};

//
Expand Down
2 changes: 1 addition & 1 deletion include/gz/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ namespace gz
/// \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,
public: virtual bool SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize) = 0;

/// \brief Get the shadow texture size for the given light type.
Expand Down
2 changes: 1 addition & 1 deletion include/gz/rendering/base/BaseScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ namespace gz
public: virtual bool SkyEnabled() const override;

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

// Documentation inherited.
Expand Down
2 changes: 1 addition & 1 deletion ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace gz
public: virtual bool SkyEnabled() const override;

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

// Documentation inherited
Expand Down
28 changes: 15 additions & 13 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1582,15 +1582,15 @@ bool Ogre2Scene::SkyEnabled() const
}

//////////////////////////////////////////////////
void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
bool Ogre2Scene::SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize)
{
// If _lightType is not supported, block with gzerr message
if (_lightType != LightType::LT_DIRECTIONAL)
if (_lightType != LightType::DIRECTIONAL)
{
gzerr << "Light type [" << _lightType << "] is not supported."
<< std::endl;
return;
gzerr << "Light type [" << static_cast<int>(_lightType)
<< "] is not supported." << std::endl;
return false;
}

// If _textureSize exceeds max possible tex size, then use default
Expand All @@ -1599,7 +1599,7 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
gzerr << "<texture_size> of '" << _textureSize
<< "' exceeds maximum possible texture size,"
<< " using default texture size" << std::endl;
return;
return false;
}

// if _textureSize is an invalid texture size, then use default
Expand All @@ -1609,14 +1609,15 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
gzerr << "<texture_size> of '" << _textureSize
<< "' is not a valid texture size,"
<< " using default texture size" << std::endl;
return;
return false;
}

// Set shadow texture size as _textureSize if value is valid
if (_lightType == LightType::LT_DIRECTIONAL)
if (_lightType == LightType::DIRECTIONAL)
{
this->dataPtr->dirTexSize = _textureSize;
}
return true;
}

//////////////////////////////////////////////////
Expand All @@ -1625,14 +1626,15 @@ unsigned int Ogre2Scene::ShadowTextureSize(LightType _lightType) const
// todo: return based on light type, currently only dir light is supported
switch (_lightType)
{
case LightType::LT_DIRECTIONAL:
case LightType::DIRECTIONAL:
return this->dataPtr->dirTexSize;
case LightType::LT_SPOT:
case LightType::LT_POINT:
case LightType::SPOT:
case LightType::POINT:
return this->dataPtr->spotPointTexSize;
default:
case LightType::LT_EMPTY:
gzerr << "Invalid light type [" << _lightType << "]" << std::endl;
case LightType::EMPTY:
gzerr << "Invalid light type [" << static_cast<int>(_lightType) << "]"
<< std::endl;
return 0;
}
}
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,20 +1476,21 @@ bool BaseScene::SkyEnabled() const
}

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

//////////////////////////////////////////////////
unsigned int BaseScene::ShadowTextureSize(LightType _lightType) const
{
if (_lightType)
if (static_cast<int>(_lightType))
{
gzerr << "Shadow texture size not supported by: "
<< this->Engine()->Name() << std::endl;
Expand Down
20 changes: 10 additions & 10 deletions test/common_test/Scene_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,30 +753,30 @@ TEST_F(SceneTest, Sky)
}

/////////////////////////////////////////////////
TEST_F(SceneTest, ShadowTexture)
TEST_F(SceneTest, ShadowTextureSize)
{
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);
EXPECT_EQ(scene->ShadowTextureSize(LightType::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);
EXPECT_FALSE(scene->SetShadowTextureSize(LightType::POINT, 4096u));
EXPECT_EQ(scene->ShadowTextureSize(LightType::POINT), 2048u);

scene->SetShadowTextureSize(LightType::LT_SPOT, 4096u);
EXPECT_EQ(scene->ShadowTextureSize(LightType::LT_SPOT), 2048u);
EXPECT_FALSE(scene->SetShadowTextureSize(LightType::SPOT, 4096u));
EXPECT_EQ(scene->ShadowTextureSize(LightType::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);
EXPECT_TRUE(scene->SetShadowTextureSize(LightType::DIRECTIONAL, 8192u));
EXPECT_EQ(scene->ShadowTextureSize(LightType::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);
EXPECT_FALSE(scene->SetShadowTextureSize(LightType::DIRECTIONAL, 1000u));
EXPECT_EQ(scene->ShadowTextureSize(LightType::DIRECTIONAL), 8192u);
}

0 comments on commit 94ece77

Please sign in to comment.