Skip to content

Commit

Permalink
Main: Compositor - range loop refactoring (OGRECave#3169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joilnen authored Jul 20, 2024
1 parent 252e2ae commit c70e2d9
Showing 1 changed file with 35 additions and 46 deletions.
81 changes: 35 additions & 46 deletions OgreMain/src/OgreCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<String> 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");
}
Expand All @@ -192,55 +188,55 @@ 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);

// 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;
Expand All @@ -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; i<mSupportedTechniques.size(); i++)
for (size_t i = 1; i < mSupportedTechniques.size(); i++)
{
CompositionTechnique* technique = mSupportedTechniques[i];
bool isConsistent = true;
size_t numGlobals = 0;
const CompositionTechnique::TextureDefinitions& tdefs2 = technique->getTextureDefinitions();
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;
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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");
}
//---------------------------------------------------------------------
Expand Down

0 comments on commit c70e2d9

Please sign in to comment.