diff --git a/include/gz/rendering/Scene.hh b/include/gz/rendering/Scene.hh index 633373502..338dfea91 100644 --- a/include/gz/rendering/Scene.hh +++ b/include/gz/rendering/Scene.hh @@ -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 diff --git a/include/gz/rendering/base/BaseScene.hh b/include/gz/rendering/base/BaseScene.hh index aec08a600..cb8906333 100644 --- a/include/gz/rendering/base/BaseScene.hh +++ b/include/gz/rendering/base/BaseScene.hh @@ -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( diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh index 0e78ca4f8..924435cb3 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh @@ -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( diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index 1ddcf7c4a..af98843be 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -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) @@ -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 texSizeOptions; unsigned int texSizeOption = 1024u; while (texSizeOption <= this->dataPtr->maxTexSize / 2) @@ -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 << " of '" << _textureSize << "' is not a valid texture size," @@ -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) diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index 2d3a0370d..134032f4e 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -1476,9 +1476,10 @@ 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; @@ -1486,7 +1487,7 @@ void BaseScene::SetShadowTextureSize(LightType _lightType, unsigned int _texture } ////////////////////////////////////////////////// -unsigned int BaseScene::ShadowTextureSize(LightType _lightType) +unsigned int BaseScene::ShadowTextureSize(LightType _lightType) const { return this->ShadowTextureSize(_lightType); } diff --git a/test/common_test/Scene_TEST.cc b/test/common_test/Scene_TEST.cc index 7803547f5..39fd68f2d 100644 --- a/test/common_test/Scene_TEST.cc +++ b/test/common_test/Scene_TEST.cc @@ -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); +}