Skip to content

Commit

Permalink
Modify get/set ShadowTextureSize funcs, use ifdef for file paths
Browse files Browse the repository at this point in the history
Signed-off-by: Athena Z <[email protected]>
  • Loading branch information
athenaz2 committed Aug 14, 2024
1 parent 18b734c commit 3b1bc7a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
10 changes: 5 additions & 5 deletions include/gz/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1271,14 +1271,14 @@ namespace gz
/// \return true to sky is enabled, false otherwise
public: virtual bool SkyEnabled() const = 0;

/// @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
/// \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;

/// @brief \brief Get the shadow texture size for the given light type.
/// @param _lightType Light type that creates the shadow
/// \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)
const = 0;

Expand Down
53 changes: 33 additions & 20 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
*
*/

#include <GL/gl.h>
#ifdef __APPLE__
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
#ifndef _WIN32
#include <GL/gl.h>
#endif
#endif

#include <gz/common/Console.hh>

Expand Down Expand Up @@ -98,6 +106,9 @@ class gz::rendering::Ogre2ScenePrivate
/// \brief Shadow texture size for directional light
public: unsigned int dirTexSize = 2048u;

/// \brief Shadow texture size for spot and point lights
public: unsigned int spotPointTexSize = 2048u;

/// \brief Flag to alert the user its usage of PreRender/PostRender
/// is incorrect
public: bool frameUpdateStarted = false;
Expand Down Expand Up @@ -693,7 +704,7 @@ void Ogre2Scene::UpdateShadowNode()
}

// others
unsigned int spotPointTexSize = 2048u;
unsigned int spotPointTexSize = this->dataPtr->spotPointTexSize;
unsigned int rowIdx = 0;
unsigned int colIdx = 0;
unsigned int rowSize = this->dataPtr->maxTexSize / spotPointTexSize;
Expand Down Expand Up @@ -1574,6 +1585,14 @@ bool Ogre2Scene::SkyEnabled() const
void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
unsigned int _textureSize)
{
// If _lightType is not supported, block with gzerr message
if (_lightType != LightType::LT_DIRECTIONAL)
{
gzerr << "Light type [" << _lightType << "] is not supported."
<< std::endl;
return;
}

// If _textureSize exceeds max possible tex size, then use default
if (_textureSize > this->dataPtr->maxTexSize / 2)
{
Expand All @@ -1583,21 +1602,9 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
return;
}

// 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)
{
texSizeOptions.push_back(texSizeOption);
texSizeOption *= 2;
}

// 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 (_textureSize < 1024u || _textureSize > (this->dataPtr->maxTexSize / 2)
|| !math::isPowerOfTwo(_textureSize))
{
gzerr << "<texture_size> of '" << _textureSize
<< "' is not a valid texture size,"
Expand All @@ -1616,12 +1623,18 @@ void Ogre2Scene::SetShadowTextureSize(LightType _lightType,
unsigned int Ogre2Scene::ShadowTextureSize(LightType _lightType) const
{
// todo: return based on light type, currently only dir light is supported
if (_lightType)
switch (_lightType)
{
return this->dataPtr->dirTexSize;
case LightType::LT_DIRECTIONAL:
return this->dataPtr->dirTexSize;
case LightType::LT_SPOT:
case LightType::LT_POINT:
return this->dataPtr->spotPointTexSize;
default:
case LightType::LT_EMPTY:
gzerr << "Invalid light type [" << _lightType << "]" << std::endl;
return 0;
}

return this->dataPtr->dirTexSize;
}

//////////////////////////////////////////////////
Expand Down
9 changes: 7 additions & 2 deletions src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1482,14 +1482,19 @@ void BaseScene::SetShadowTextureSize(LightType _lightType,
if (_lightType || _textureSize)
{
gzerr << "Setting shadow texture size not supported by: "
<< this->Engine()->Name() << std::endl;
<< this->Engine()->Name() << std::endl;
}
}

//////////////////////////////////////////////////
unsigned int BaseScene::ShadowTextureSize(LightType _lightType) const
{
return this->ShadowTextureSize(_lightType);
if (_lightType)
{
gzerr << "Shadow texture size not supported by: "
<< this->Engine()->Name() << std::endl;
}
return 0;
}

//////////////////////////////////////////////////
Expand Down

0 comments on commit 3b1bc7a

Please sign in to comment.