Skip to content

Commit

Permalink
Merge branch 'ign-rendering6' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
iche033 authored May 9, 2022
2 parents 37d51e4 + e4c9157 commit 6956c6a
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 19 deletions.
2 changes: 2 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreIncludes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#pragma GCC system_header
#else
#pragma warning(push, 0)
#pragma warning(disable:4275)
#pragma warning(disable:4005)
#endif

// This prevents some deprecation #warning messages on OSX 10.9
Expand Down
2 changes: 2 additions & 0 deletions ogre/src/OgreRenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# pragma GCC diagnostic ignored "-Wunused-parameter"
#else
# pragma warning(push, 0)
# pragma warning(disable: 4005)
# pragma warning(disable: 4275)
#endif
// leave this out of OgreIncludes as it conflicts with other files requiring
// gl.h
Expand Down
46 changes: 40 additions & 6 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ class ignition::rendering::Ogre2GpuRaysPrivate

/// \brief Min allowed angle in radians;
public: const math::Angle kMinAllowedAngle = 1e-4;

/// \brief Max number of cameras used for creating the cubemap of depth
/// textures for generating lidar data
public: const unsigned int kCubeCameraCount = 6;
};

using namespace ignition;
Expand Down Expand Up @@ -278,7 +282,7 @@ void Ogre2LaserRetroMaterialSwitcher::cameraPreRenderScene(
{
try
{
retroValue = std::get<int>(tempLaserRetro);
retroValue = static_cast<float>(std::get<int>(tempLaserRetro));
}
catch(std::bad_variant_access &e)
{
Expand Down Expand Up @@ -357,7 +361,7 @@ Ogre2GpuRays::Ogre2GpuRays()
// r = depth, g = retro, and b = n/a
this->channels = 3u;

for (unsigned int i = 0; i < 6u; ++i)
for (unsigned int i = 0; i < this->dataPtr->kCubeCameraCount; ++i)
{
this->dataPtr->cubeCam[i] = nullptr;
this->dataPtr->ogreCompositorWorkspace1st[i] = nullptr;
Expand Down Expand Up @@ -386,6 +390,9 @@ void Ogre2GpuRays::Init()
//////////////////////////////////////////////////
void Ogre2GpuRays::Destroy()
{
if (!this->dataPtr->ogreCamera)
return;

if (this->dataPtr->gpuRaysBuffer)
{
delete [] this->dataPtr->gpuRaysBuffer;
Expand Down Expand Up @@ -465,6 +472,33 @@ void Ogre2GpuRays::Destroy()
this->dataPtr->ogreCompositorNodeDef2nd);
this->dataPtr->ogreCompositorWorkspaceDef2nd.clear();
}

if (this->scene)
{
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
if (ogreSceneManager == nullptr)
{
ignerr << "Scene manager not available. "
<< "Unable to remove cameras and listeners" << std::endl;
}
else
{
for (unsigned int i = 0u; i < this->dataPtr->kCubeCameraCount; ++i)
{
if (this->dataPtr->cubeCam[i])
{
this->dataPtr->cubeCam[i]->removeListener(
this->dataPtr->particleNoiseListener[i].get());
ogreSceneManager->destroyCamera(this->dataPtr->cubeCam[i]);
this->dataPtr->cubeCam[i] = nullptr;
}
this->dataPtr->particleNoiseListener[i].reset();
this->dataPtr->laserRetroMaterialSwitcher[i].reset();
}
ogreSceneManager->destroyCamera(this->dataPtr->ogreCamera);
this->dataPtr->ogreCamera = nullptr;
}
}
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -587,19 +621,19 @@ math::Vector2d Ogre2GpuRays::SampleCubemap(const math::Vector3d &_v,
math::Vector2d uv;
if (vAbs.Z() >= vAbs.X() && vAbs.Z() >= vAbs.Y())
{
_faceIndex = _v.Z() < 0.0 ? 5.0 : 4.0;
_faceIndex = _v.Z() < 0 ? 5 : 4;
ma = 0.5 / vAbs.Z();
uv = math::Vector2d(_v.Z() < 0.0 ? -_v.X() : _v.X(), -_v.Y());
}
else if (vAbs.Y() >= vAbs.X())
{
_faceIndex = _v.Y() < 0.0 ? 3.0 : 2.0;
_faceIndex = _v.Y() < 0 ? 3 : 2;
ma = 0.5 / vAbs.Y();
uv = math::Vector2d(_v.X(), _v.Y() < 0.0 ? -_v.Z() : _v.Z());
}
else
{
_faceIndex = _v.X() < 0.0 ? 1.0 : 0.0;
_faceIndex = _v.X() < 0 ? 1 : 0;
ma = 0.5 / vAbs.X();
uv = math::Vector2d(_v.X() < 0.0 ? _v.Z() : -_v.Z(), -_v.Y());
}
Expand Down Expand Up @@ -689,7 +723,7 @@ void Ogre2GpuRays::CreateSampleTexture()
// v
pDest[index++] = uv.Y();
// face
pDest[index++] = faceIdx;
pDest[index++] = static_cast<float>(faceIdx);
// unused
pDest[index++] = 1.0;
h += hStep;
Expand Down
4 changes: 2 additions & 2 deletions ogre2/src/Ogre2RenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void Ogre2RenderEngine::Destroy()
delete this->ogreLogManager;
this->ogreLogManager = nullptr;

#if not (__APPLE__ || _WIN32)
#if !defined(__APPLE__) && !defined(_WIN32)
if (this->dummyDisplay)
{
Display *x11Display = static_cast<Display*>(this->dummyDisplay);
Expand Down Expand Up @@ -382,7 +382,7 @@ void Ogre2RenderEngine::CreateLogger()
//////////////////////////////////////////////////
void Ogre2RenderEngine::CreateContext()
{
#if not (__APPLE__ || _WIN32)
#if !defined(__APPLE__) && !defined(_WIN32)
if (this->Headless())
{
// Nothing to do
Expand Down
4 changes: 4 additions & 0 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,16 @@ void Ogre2RenderTarget::RebuildMaterial()
//////////////////////////////////////////////////
// Ogre2RenderTexture
//////////////////////////////////////////////////
#ifndef _WIN32
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Ogre2RenderTexture::Ogre2RenderTexture()
{
}
#ifndef _WIN32
#pragma GCC diagnostic pop
#endif

//////////////////////////////////////////////////
Ogre2RenderTexture::~Ogre2RenderTexture()
Expand Down
14 changes: 9 additions & 5 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void Ogre2Scene::UpdateShadowNode()
// directional lights
unsigned int atlasId = 0u;
unsigned int texSize = 2048u;
unsigned int halfTexSize = texSize * 0.5;
unsigned int halfTexSize = static_cast<unsigned int>(texSize * 0.5);
for (unsigned int i = 0; i < dirLightCount; ++i)
{
shadowParam.technique = Ogre::SHADOWMAP_PSSM;
Expand Down Expand Up @@ -866,12 +866,16 @@ void Ogre2Scene::CreateShadowNodeWithSettings(
for (size_t j = 0; j < numSplits; ++j)
{
Ogre::Vector2 uvOffset(
shadowParam.atlasStart[j].x, shadowParam.atlasStart[j].y);
static_cast<Ogre::Real>(shadowParam.atlasStart[j].x),
static_cast<Ogre::Real>(shadowParam.atlasStart[j].y));
Ogre::Vector2 uvLength(
shadowParam.resolution[j].x, shadowParam.resolution[j].y);
static_cast<Ogre::Real>(shadowParam.resolution[j].x),
static_cast<Ogre::Real>(shadowParam.resolution[j].y));

uvOffset /= Ogre::Vector2(texResolution.x, texResolution.y);
uvLength /= Ogre::Vector2(texResolution.x, texResolution.y);
uvOffset /= Ogre::Vector2(static_cast<Ogre::Real>(texResolution.x),
static_cast<Ogre::Real>(texResolution.y));
uvLength /= Ogre::Vector2(static_cast<Ogre::Real>(texResolution.x),
static_cast<Ogre::Real>(texResolution.y));

const Ogre::String texName =
"atlas" + Ogre::StringConverter::toString(shadowParam.atlasId);
Expand Down
9 changes: 6 additions & 3 deletions ogre2/src/Ogre2SegmentationMaterialSwitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ bool Ogre2SegmentationMaterialSwitcher::IsTakenColor(const math::Color &_color)
{
// Get the int value of the 24 bit color
// Multiply by 255 as color values are normalized
int64_t colorId = (_color.R() * 255) * 256 * 256 +
(_color.G() * 255) * 256 + (_color.B() * 255);
int64_t colorId = static_cast<int64_t>((_color.R() * 255) * 256 * 256 +
(_color.G() * 255) * 256 + (_color.B() * 255));

if (this->takenColors.count(colorId))
{
Expand Down Expand Up @@ -117,7 +117,10 @@ math::Color Ogre2SegmentationMaterialSwitcher::LabelToColor(int64_t _label,
int g = distribution(this->generator);
int b = distribution(this->generator);

math::Color color(r, g, b);
math::Color color(
static_cast<float>(r),
static_cast<float>(g),
static_cast<float>(b));

// if the label is colored before return the color
// don't check for taken colors in that case, all items
Expand Down
7 changes: 5 additions & 2 deletions ogre2/src/Ogre2ThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ignition::rendering::Ogre2ThermalCameraPrivate
public: Ogre::CompositorWorkspace *ogreCompositorWorkspace;

/// \brief Thermal textures.
public: Ogre::TextureGpu *ogreThermalTexture;
public: Ogre::TextureGpu *ogreThermalTexture{nullptr};

/// \brief Dummy render texture for the thermal data
public: RenderTexturePtr thermalTexture = nullptr;
Expand Down Expand Up @@ -288,7 +288,7 @@ void Ogre2ThermalCameraMaterialSwitcher::cameraPreRenderScene(
{
try
{
temp = std::get<int>(tempAny);
temp = static_cast<float>(std::get<int>(tempAny));
}
catch(std::bad_variant_access &e)
{
Expand Down Expand Up @@ -536,6 +536,7 @@ void Ogre2ThermalCamera::Destroy()
{
Ogre::MaterialManager::getSingleton().remove(
this->dataPtr->thermalMaterial->getName());
this->dataPtr->thermalMaterial.setNull();
}

if (!this->dataPtr->ogreCompositorWorkspaceDef.empty())
Expand All @@ -560,6 +561,8 @@ void Ogre2ThermalCamera::Destroy()
this->ogreCamera = nullptr;
}
}

this->dataPtr->thermalMaterialSwitcher.reset();
}

//////////////////////////////////////////////////
Expand Down
8 changes: 7 additions & 1 deletion src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,13 @@ bool BaseScene::LegacyAutoGpuFlush() const
//////////////////////////////////////////////////
void BaseScene::Clear()
{
this->nodes->DestroyAll();
this->DestroyNodes();
auto root = this->RootVisual();
if (root)
{
root->RemoveChildren();
this->DestroyNode(root);
}
this->DestroyMaterials();
this->nextObjectId = ignition::math::MAX_UI16;
}
Expand Down
9 changes: 9 additions & 0 deletions test/integration/camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,15 @@ void CameraTest::ShaderSelection(const std::string &_renderEngine)

// Clean up
engine->DestroyScene(scene);

ASSERT_EQ(1u, camera.use_count());
ASSERT_EQ(1u, gpuRays.use_count());
ASSERT_EQ(1u, thermalCamera.use_count());
if (segmentationCamera)
{
ASSERT_EQ(1u, segmentationCamera.use_count());
}

rendering::unloadEngine(engine->Name());
}

Expand Down

0 comments on commit 6956c6a

Please sign in to comment.