diff --git a/include/gz/rendering/Light.hh b/include/gz/rendering/Light.hh index 0d50d1435..3ba82e372 100644 --- a/include/gz/rendering/Light.hh +++ b/include/gz/rendering/Light.hh @@ -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 }; // diff --git a/include/gz/rendering/Scene.hh b/include/gz/rendering/Scene.hh index ab6bddf7d..fdaa6436d 100644 --- a/include/gz/rendering/Scene.hh +++ b/include/gz/rendering/Scene.hh @@ -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. diff --git a/include/gz/rendering/base/BaseScene.hh b/include/gz/rendering/base/BaseScene.hh index cb8906333..200246a2b 100644 --- a/include/gz/rendering/base/BaseScene.hh +++ b/include/gz/rendering/base/BaseScene.hh @@ -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. diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh index 924435cb3..323c2b30b 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh @@ -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 diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index dc757bd2b..a8e383e68 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -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(_lightType) + << "] is not supported." << std::endl; + return false; } // If _textureSize exceeds max possible tex size, then use default @@ -1599,7 +1599,7 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType, gzerr << " 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 @@ -1609,14 +1609,15 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType, gzerr << " 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; } ////////////////////////////////////////////////// @@ -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(_lightType) << "]" + << std::endl; return 0; } } diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index 5754b8d57..b65112fb3 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -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(_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(_lightType)) { gzerr << "Shadow texture size not supported by: " << this->Engine()->Name() << std::endl; diff --git a/test/common_test/Scene_TEST.cc b/test/common_test/Scene_TEST.cc index 39fd68f2d..1824ea203 100644 --- a/test/common_test/Scene_TEST.cc +++ b/test/common_test/Scene_TEST.cc @@ -753,7 +753,7 @@ TEST_F(SceneTest, Sky) } ///////////////////////////////////////////////// -TEST_F(SceneTest, ShadowTexture) +TEST_F(SceneTest, ShadowTextureSize) { CHECK_SUPPORTED_ENGINE("ogre2"); @@ -761,22 +761,22 @@ TEST_F(SceneTest, ShadowTexture) 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); }