From c70e2d9a7838ab6f7cd8a5d2734a7ef32017c3e7 Mon Sep 17 00:00:00 2001 From: Joilnen Date: Sat, 20 Jul 2024 17:56:25 -0300 Subject: [PATCH] Main: Compositor - range loop refactoring (#3169) --- OgreMain/src/OgreCompositor.cpp | 81 ++++++++++++++------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/OgreMain/src/OgreCompositor.cpp b/OgreMain/src/OgreCompositor.cpp index 6de573e0fe5..534e6918b39 100644 --- a/OgreMain/src/OgreCompositor.cpp +++ b/OgreMain/src/OgreCompositor.cpp @@ -48,7 +48,7 @@ Compositor::~Compositor() removeAllTechniques(); // have to call this here reather than in Resource destructor // since calling virtual methods in base destructors causes crash - unload(); + unload(); } //----------------------------------------------------------------------- CompositionTechnique *Compositor::createTechnique() @@ -163,24 +163,20 @@ void Compositor::createGlobalTextures() //To make sure that we are consistent, it is demanded that all composition //techniques define the same set of global textures. - typedef std::set StringSet; StringSet globalTextureNames; //Initialize global textures from first supported technique CompositionTechnique* firstTechnique = mSupportedTechniques[0]; - const CompositionTechnique::TextureDefinitions& tdefs = firstTechnique->getTextureDefinitions(); - CompositionTechnique::TextureDefinitions::const_iterator texDefIt = tdefs.begin(); - for (; texDefIt != tdefs.end(); ++texDefIt) + for (auto *def : firstTechnique->getTextureDefinitions()) { - CompositionTechnique::TextureDefinition* def = *texDefIt; - if (def->scope == CompositionTechnique::TS_GLOBAL) + if (def->scope == CompositionTechnique::TS_GLOBAL) { //Check that this is a legit global texture OgreAssert(def->refCompName.empty(), "Global compositor texture definition can not be a reference"); OgreAssert(def->width && def->height, "Global compositor texture definition must have absolute size"); - if (def->pooled) + if (def->pooled) { LogManager::getSingleton().logWarning("Pooling global compositor textures has no effect"); } @@ -192,27 +188,27 @@ void Compositor::createGlobalTextures() RenderTarget* rendTarget; if (def->formatList.size() > 1) { - String MRTbaseName = "mrt/c" + StringConverter::toString(dummyCounter++) + + String MRTbaseName = "mrt/c" + StringConverter::toString(dummyCounter++) + "/" + mName + "/" + def->name; - MultiRenderTarget* mrt = + MultiRenderTarget* mrt = Root::getSingleton().getRenderSystem()->createMultiRenderTarget(MRTbaseName); mGlobalMRTs[def->name] = mrt; // create and bind individual surfaces size_t atch = 0; - for (PixelFormatList::iterator p = def->formatList.begin(); + for (PixelFormatList::iterator p = def->formatList.begin(); p != def->formatList.end(); ++p, ++atch) { String texname = MRTbaseName + "/" + StringConverter::toString(atch); TexturePtr tex; - + tex = TextureManager::getSingleton().createManual( - texname, - ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, - (uint)def->width, (uint)def->height, 0, *p, TU_RENDERTARGET, 0, - def->hwGammaWrite && !PixelUtil::isFloatingPoint(*p), def->fsaa); - + texname, + ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, + (uint)def->width, (uint)def->height, 0, *p, TU_RENDERTARGET, 0, + def->hwGammaWrite && !PixelUtil::isFloatingPoint(*p), def->fsaa); + RenderTexture* rt = tex->getBuffer()->getRenderTarget(); rt->setAutoUpdated(false); mrt->bindSurface(atch, rt); @@ -220,27 +216,27 @@ void Compositor::createGlobalTextures() // Also add to local textures so we can look up String mrtLocalName = CompositorInstance::getMRTTexLocalName(def->name, atch); mGlobalTextures[mrtLocalName] = tex; - + } rendTarget = mrt; } else { - String texName = "c" + StringConverter::toString(dummyCounter++) + + String texName = "c" + StringConverter::toString(dummyCounter++) + "/" + mName + "/" + def->name; - + // space in the name mixup the cegui in the compositor demo // this is an auto generated name - so no spaces can't hart us. - std::replace( texName.begin(), texName.end(), ' ', '_' ); + std::replace( texName.begin(), texName.end(), ' ', '_' ); TexturePtr tex; tex = TextureManager::getSingleton().createManual( - texName, - ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, + texName, + ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (uint)def->width, (uint)def->height, 0, def->formatList[0], TU_RENDERTARGET, 0, - def->hwGammaWrite && !PixelUtil::isFloatingPoint(def->formatList[0]), def->fsaa); - + def->hwGammaWrite && !PixelUtil::isFloatingPoint(def->formatList[0]), def->fsaa); + rendTarget = tex->getBuffer()->getRenderTarget(); mGlobalTextures[def->name] = tex; @@ -252,19 +248,16 @@ void Compositor::createGlobalTextures() } //Validate that all other supported techniques expose the same set of global textures. - for (size_t i=1; igetTextureDefinitions(); - texDefIt = tdefs2.begin(); - for (; texDefIt != tdefs2.end(); ++texDefIt) + CompositionTechnique* technique = mSupportedTechniques[i]; + for (auto *texDef : technique->getTextureDefinitions()) { - CompositionTechnique::TextureDefinition* texDef = *texDefIt; - if (texDef->scope == CompositionTechnique::TS_GLOBAL) + if (texDef->scope == CompositionTechnique::TS_GLOBAL) { - if (globalTextureNames.find(texDef->name) == globalTextureNames.end()) + if (globalTextureNames.find(texDef->name) == globalTextureNames.end()) { isConsistent = false; break; @@ -277,25 +270,21 @@ void Compositor::createGlobalTextures() OgreAssert(isConsistent, "Different composition techniques define different global textures"); } - + } //----------------------------------------------------------------------- void Compositor::freeGlobalTextures() { - GlobalTextureMap::iterator i = mGlobalTextures.begin(); - while (i != mGlobalTextures.end()) + for (const auto& t : mGlobalTextures) { - TextureManager::getSingleton().remove(i->second); - ++i; + TextureManager::getSingleton().remove(t.second); } mGlobalTextures.clear(); - GlobalMRTMap::iterator mrti = mGlobalMRTs.begin(); - while (mrti != mGlobalMRTs.end()) + for (const auto& m : mGlobalMRTs) { // remove MRT - Root::getSingleton().getRenderSystem()->destroyRenderTarget(mrti->second->getName()); - ++mrti; + Root::getSingleton().getRenderSystem()->destroyRenderTarget(m.second->getName()); } mGlobalMRTs.clear(); @@ -305,7 +294,7 @@ const String& Compositor::getTextureInstanceName(const String& name, size_t mrtI { return getTextureInstance(name, mrtIndex)->getName(); } -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- const TexturePtr& Compositor::getTextureInstance(const String& name, size_t mrtIndex) { //Try simple texture @@ -322,9 +311,9 @@ const TexturePtr& Compositor::getTextureInstance(const String& name, size_t mrtI return i->second; } - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Non-existent global texture name", + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Non-existent global texture name", "Compositor::getTextureInstance"); - + } //--------------------------------------------------------------------- RenderTarget* Compositor::getRenderTarget(const String& name, int slice) @@ -339,7 +328,7 @@ RenderTarget* Compositor::getRenderTarget(const String& name, int slice) if (mi != mGlobalMRTs.end()) return mi->second; else - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Non-existent global texture name", + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Non-existent global texture name", "Compositor::getRenderTarget"); } //---------------------------------------------------------------------