Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ogre/include/gz/rendering/ogre/OgreIncludes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
#include <OgreRoot.h>
#include <OgreSceneManager.h>
#include <OgreSceneNode.h>
#ifdef OGRE_VERSION_LT_1_12_0
#include <OgreVector3.h>
#else
#include <OgreVector.h>
#endif
#include <OgreManualObject.h>
#include <OgreMaterialManager.h>
#include <OgreMatrix4.h>
Expand Down
6 changes: 6 additions & 0 deletions ogre/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ set(engine_name "ogre")

gz_add_component(${engine_name} SOURCES ${sources} GET_TARGET_NAME ogre_target)

if(OGRE_VERSION VERSION_LESS 1.10.0)
add_definitions(-DOGRE_VERSION_LT_1_10_0)
endif()
if(OGRE_VERSION VERSION_LESS 1.11.0)
add_definitions(-DOGRE_VERSION_LT_1_11_0)
endif()
if(OGRE_VERSION VERSION_LESS 1.12.0)
add_definitions(-DOGRE_VERSION_LT_1_12_0)
endif()
if(OGRE_VERSION VERSION_LESS 1.12.9)
add_definitions(-DOGRE_VERSION_LT_1_12_9)
endif()

find_package(OpenGL)

Expand Down
37 changes: 37 additions & 0 deletions ogre/src/OgreCompat.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2026 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_RENDERING_OGRE_OGRECOMPAT_HH_
#define GZ_RENDERING_OGRE_OGRECOMPAT_HH_

// Internal-only header (not installed). Provides forward-compatible aliases
// for OGRE 1.12.9+ APIs so the gz-rendering OGRE-1 backend can keep building
// against the older 1.9.x system package without scattering #if-blocks at
// every call site. The aliases shadow what 1.12.9+ already provides natively.

#include "gz/rendering/ogre/OgreIncludes.hh"

#ifdef OGRE_VERSION_LT_1_12_9
namespace Ogre
{
// Modern (1.12.9+) free-scope buffer-usage enum names map to the
// deprecated nested-scope HardwareBuffer::Usage values on older OGRE.
constexpr auto HBU_GPU_ONLY = HardwareBuffer::HBU_STATIC_WRITE_ONLY;
constexpr auto HBU_CPU_TO_GPU = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY;
}
#endif

#endif
3 changes: 1 addition & 2 deletions ogre/src/OgreDistortionPass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ namespace gz
setTexture(distortionTexture);

// @todo Explore more efficent implementations as it is run every frame
Ogre::GpuProgramParametersSharedPtr params =
_mat->getTechnique(0)->getPass(_passId)
auto params = _mat->getTechnique(0)->getPass(_passId)
->getFragmentProgramParameters();
params->setNamedConstant("scale",
Ogre::Vector3(
Expand Down
7 changes: 4 additions & 3 deletions ogre/src/OgreDynamicRenderable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <gz/common/Profiler.hh>

#include "gz/rendering/ogre/OgreDynamicRenderable.hh"
#include "OgreCompat.hh"

using namespace gz;
using namespace rendering;
Expand Down Expand Up @@ -175,13 +176,13 @@ void OgreDynamicRenderable::PrepareHardwareBuffers(size_t vertexCount,
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
this->mRenderOp.vertexData->vertexDeclaration->getVertexSize(0),
this->vertexBufferCapacity,
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
Ogre::HBU_CPU_TO_GPU);

Ogre::HardwareVertexBufferSharedPtr cbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR),
this->vertexBufferCapacity,
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
Ogre::HBU_CPU_TO_GPU);

// TODO(anyone): Custom HBU_?

Expand Down Expand Up @@ -231,7 +232,7 @@ void OgreDynamicRenderable::PrepareHardwareBuffers(size_t vertexCount,
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
this->indexBufferCapacity,
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
Ogre::HBU_CPU_TO_GPU);
// TODO(anyone): Custom HBU_?
}

Expand Down
3 changes: 1 addition & 2 deletions ogre/src/OgreGaussianNoisePass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ namespace gz
GZ_ASSERT(technique, "Null OGRE material technique");
Ogre::Pass *pass = technique->getPass(_passId);
GZ_ASSERT(pass, "Null OGRE material pass");
Ogre::GpuProgramParametersSharedPtr params =
pass->getFragmentProgramParameters();
auto params = pass->getFragmentProgramParameters();
#if OGRE_VERSION_LT_1_11_0
GZ_ASSERT(!params.isNull(), "Null OGRE material GPU parameters");
#else
Expand Down
18 changes: 13 additions & 5 deletions ogre/src/OgreHeightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,12 @@ void OgreHeightmap::SetupShadows(bool _enableShadows)
matProfile = static_cast<GzTerrainMatGen::SM2Profile *>(
matGen->getActiveProfile());
#else
matProfile = static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile *>(
// Since OGRE 1.11 the custom GzTerrainMatGen path is disabled and
// CreateMaterial() installs our TerrainMaterial generator whose Profile is
// not an SM2Profile. Use dynamic_cast so the nullptr guard below skips the
// SM2Profile-only setters and avoids writing past the real Profile object
// (the static_cast path led to heap corruption during loadAllTerrains).
matProfile = dynamic_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile *>(
matGen->getActiveProfile());
#endif

Expand Down Expand Up @@ -1508,7 +1513,7 @@ GzTerrainMatGen::SM2Profile::ShaderHelperGLSL::generateFragmentProgram(

this->defaultFpParams(_prof, _terrain, _tt, ret);

Ogre::GpuProgramParametersSharedPtr params = ret->getDefaultParameters();
auto params = ret->getDefaultParameters();
params->setIgnoreMissingParams(false);

Ogre::uint maxLayers = _prof->getMaxLayers(_terrain);
Expand Down Expand Up @@ -1892,7 +1897,7 @@ void GzTerrainMatGen::SM2Profile::ShaderHelperGLSL::defaultVpParams(
const SM2Profile *_prof, const Ogre::Terrain *_terrain,
TechniqueType _tt, const Ogre::HighLevelGpuProgramPtr &_prog)
{
Ogre::GpuProgramParametersSharedPtr params = _prog->getDefaultParameters();
auto params = _prog->getDefaultParameters();
params->setIgnoreMissingParams(true);

params->setNamedAutoConstant("worldMatrix",
Expand Down Expand Up @@ -2768,9 +2773,12 @@ Ogre::MaterialPtr TerrainMaterial::Profile::generate(
if (!pass->hasFragmentProgram())
continue;

Ogre::GpuProgramParametersSharedPtr params =
pass->getFragmentProgramParameters();
auto params = pass->getFragmentProgramParameters();
#if OGRE_VERSION_LT_1_11_0
if (params.isNull())
#else
if (!params)
#endif
continue;

// set up shadow split points in a way that is consistent with the
Expand Down
9 changes: 6 additions & 3 deletions ogre/src/OgreLensFlarePass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <OgreGpuProgram.h>
#include <OgrePass.h>
#include <OgreTechnique.h>
#ifdef OGRE_VERSION_LT_1_12_0
#include <OgreVector3.h>
#else
#include <OgreVector.h>
#endif
#ifdef _MSC_VER
# pragma warning(pop)
#endif
Expand Down Expand Up @@ -375,8 +379,7 @@ void OgreLensFlareCompositorListenerPrivate::notifyMaterialRender(
GZ_ASSERT(technique, "Null OGRE material technique");
Ogre::Pass *pass = technique->getPass(static_cast<uint16_t>(_passId));
GZ_ASSERT(pass, "Null OGRE material pass");
Ogre::GpuProgramParametersSharedPtr params =
pass->getFragmentProgramParameters();
auto params = pass->getFragmentProgramParameters();

const Ogre::Camera *camera;

Expand Down Expand Up @@ -424,7 +427,7 @@ void OgreLensFlareCompositorListenerPrivate::notifyMaterialRender(

++this->owner.dataPtr->currentFaceIdx;

GpuProgramParametersSharedPtr psParams = pass->getFragmentProgramParameters();
auto psParams = pass->getFragmentProgramParameters();

psParams->setNamedConstant("vpAspectRatio", camera->getAspectRatio());
psParams->setNamedConstant("lightPos", lightPos);
Expand Down
6 changes: 2 additions & 4 deletions ogre/src/OgreMaterial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,13 @@ void OgreMaterial::UpdateShaderParams()
GZ_PROFILE("OgreMaterial::UpdateShaderParams");
if (this->vertexShaderParams && this->vertexShaderParams->IsDirty())
{
Ogre::GpuProgramParametersSharedPtr ogreParams;
ogreParams = this->ogrePass->getVertexProgramParameters();
auto ogreParams = this->ogrePass->getVertexProgramParameters();
this->UpdateShaderParams(this->vertexShaderParams, ogreParams);
this->vertexShaderParams->ClearDirty();
}
if (this->fragmentShaderParams && this->fragmentShaderParams->IsDirty())
{
Ogre::GpuProgramParametersSharedPtr ogreParams;
ogreParams = this->ogrePass->getFragmentProgramParameters();
auto ogreParams = this->ogrePass->getFragmentProgramParameters();
this->UpdateShaderParams(this->fragmentShaderParams, ogreParams);
this->fragmentShaderParams->ClearDirty();
}
Expand Down
15 changes: 15 additions & 0 deletions ogre/src/OgreMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,19 @@ void OgreMesh::SetSkeletonAnimationEnabled(const std::string &_name,
if (_enabled)
{
Ogre::SkeletonInstance *skel = this->ogreEntity->getSkeleton();
#ifdef OGRE_VERSION_LT_1_11_0
Ogre::Skeleton::BoneIterator iter = skel->getBoneIterator();
while (iter.hasMoreElements())
{
Ogre::Bone* bone = iter.getNext();
bone->setManuallyControlled(false);
}
#else
for (Ogre::Bone* bone : skel->getBones())
{
bone->setManuallyControlled(false);
}
#endif
}

// update animation state
Expand Down Expand Up @@ -192,13 +199,21 @@ std::unordered_map<std::string, float> OgreMesh::SkeletonWeights() const
if (!anim->hasBlendMask())
anim->createBlendMask(skel->getNumBones());

#ifdef OGRE_VERSION_LT_1_11_0
Ogre::Skeleton::BoneIterator iter = skel->getBoneIterator();
while (iter.hasMoreElements())
{
Ogre::Bone* bone = iter.getNext();
mapWeights[bone->getName()] =
anim->getBlendMaskEntry(bone->getHandle());
}
#else
for (Ogre::Bone* bone : skel->getBones())
{
mapWeights[bone->getName()] =
anim->getBlendMaskEntry(bone->getHandle());
}
#endif
}

return mapWeights;
Expand Down
7 changes: 4 additions & 3 deletions ogre/src/OgreMeshFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "gz/rendering/ogre/OgreConversions.hh"
#include "gz/rendering/ogre/OgreIncludes.hh"
#include "OgreCompat.hh"
#include "gz/rendering/ogre/OgreMesh.hh"
#include "gz/rendering/ogre/OgreMeshFactory.hh"
#include "gz/rendering/ogre/OgreRenderEngine.hh"
Expand Down Expand Up @@ -335,15 +336,15 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc)
vBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
vertexDecl->getVertexSize(0),
vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
Ogre::HBU_GPU_ONLY,
false);

if (subMesh.TexCoordCountBySet(0) > 0)
{
texBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
vertexDecl->getVertexSize(1),
vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
Ogre::HBU_GPU_ONLY,
false);
}

Expand Down Expand Up @@ -396,7 +397,7 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc)
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
ogreSubMesh->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
Ogre::HBU_GPU_ONLY,
false);

iBuf = ogreSubMesh->indexData->indexBuffer;
Expand Down
11 changes: 8 additions & 3 deletions ogre/src/OgreRTShaderSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,12 @@ void OgreRTShaderSystem::RemoveShaders(OgreSubMesh *_subMesh)
}
}

this->dataPtr->shaderGenerator->removeShaderBasedTechnique(srcTechnique,
s->Name() + Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
if (srcTechnique)
{
this->dataPtr->shaderGenerator->removeShaderBasedTechnique(
srcTechnique,
s->Name() + Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
}
#endif
}
catch(const Ogre::Exception &e)
Expand Down Expand Up @@ -612,7 +616,8 @@ void OgreRTShaderSystem::ApplyShadows(OgreScenePtr _scene)
sceneMgr->setShadowTextureCasterMaterial("PSSM/shadow_caster");
#else
Ogre::MaterialPtr mat =
Ogre::MaterialManager::getSingleton().getByName("PSSM/shadow_caster");
Ogre::MaterialManager::getSingleton().getByName(
"PSSM/shadow_caster", Ogre::RGN_DEFAULT);
sceneMgr->setShadowTextureCasterMaterial(mat);
#endif

Expand Down
21 changes: 2 additions & 19 deletions ogre/src/OgreRenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
*
*/

#ifndef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
#else
# pragma warning(push)
# pragma warning(disable: 4005)
# pragma warning(disable: 4275)
#endif
// leave this out of OgreIncludes as it conflicts with other files requiring
// gl.h
#include <OgreGLFBORenderTexture.h>
#ifndef _WIN32
# pragma GCC diagnostic pop
#else
# pragma warning(pop)
#endif


#include <gz/common/Console.hh>
#include <gz/common/Profiler.hh>
Expand Down Expand Up @@ -440,10 +423,10 @@ unsigned int OgreRenderTexture::GLId() const
if (!this->ogreTexture)
return 0u;

GLuint texId;
unsigned int texId = 0u;
this->ogreTexture->getCustomAttribute("GLID", &texId);

return static_cast<unsigned int>(texId);
return texId;
}

//////////////////////////////////////////////////
Expand Down
5 changes: 3 additions & 2 deletions ogre/src/OgreScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "gz/rendering/ogre/OgreGrid.hh"
#include "gz/rendering/ogre/OgreHeightmap.hh"
#include "gz/rendering/ogre/OgreIncludes.hh"
#include "OgreCompat.hh"
#include "gz/rendering/ogre/OgreInertiaVisual.hh"
#include "gz/rendering/ogre/OgreJointVisual.hh"
#include "gz/rendering/ogre/OgreLidarVisual.hh"
Expand Down Expand Up @@ -85,7 +86,7 @@ namespace gz
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize(this->kColorBinding),
mRenderOp.vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
Ogre::HBU_GPU_ONLY);

// Bind buffer
bind->setBinding(this->kColorBinding, vbuf);
Expand Down Expand Up @@ -718,7 +719,7 @@ bool OgreScene::InitObject(OgreObjectPtr _object, unsigned int _id,
void OgreScene::CreateContext()
{
Ogre::Root *root = OgreRenderEngine::Instance()->OgreRoot();
this->ogreSceneManager = root->createSceneManager(Ogre::ST_GENERIC);
this->ogreSceneManager = root->createSceneManager("DefaultSceneManager");

#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
this->ogreSceneManager->addRenderQueueListener(
Expand Down
Loading
Loading