Skip to content

Commit

Permalink
Main: improve naming scheme of compositor textures
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Aug 23, 2024
1 parent 47ffa50 commit 5d8105d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions OgreMain/include/OgreCompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ namespace Ogre {

//TODO GSOC : These typedefs are duplicated from CompositorInstance. Solve?
/// Map from name->local texture
typedef std::map<String,TexturePtr> GlobalTextureMap;
typedef std::unordered_map<String,TexturePtr> GlobalTextureMap;
GlobalTextureMap mGlobalTextures;
/// Store a list of MRTs we've created
typedef std::map<String,MultiRenderTarget*> GlobalMRTMap;
typedef std::unordered_map<String,MultiRenderTarget*> GlobalMRTMap;
GlobalMRTMap mGlobalMRTs;
};
/** @} */
Expand Down
4 changes: 2 additions & 2 deletions OgreMain/include/OgreCompositorInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ namespace Ogre {
/// Is this instance allocating resources?
bool mAlive;
/// Map from name->local texture.
typedef std::map<String,TexturePtr> LocalTextureMap;
typedef std::unordered_map<String,TexturePtr> LocalTextureMap;
LocalTextureMap mLocalTextures;
/// Store a list of MRTs we've created.
typedef std::map<String,MultiRenderTarget*> LocalMRTMap;
typedef std::unordered_map<String,MultiRenderTarget*> LocalMRTMap;
LocalMRTMap mLocalMRTs;
typedef std::map<CompositionTechnique::TextureDefinition*, TexturePtr> ReserveTextureMap;
/** Textures that are not currently in use, but that we want to keep for now,
Expand Down
14 changes: 6 additions & 8 deletions OgreMain/src/OgreCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ CompositionTechnique* Compositor::getSupportedTechnique(const String& schemeName
//-----------------------------------------------------------------------
void Compositor::createGlobalTextures()
{
static size_t dummyCounter = 0;
if (mSupportedTechniques.empty())
return;

Expand All @@ -184,14 +183,14 @@ void Compositor::createGlobalTextures()

//TODO GSOC : Heavy copy-pasting from CompositorInstance. How to we solve it?

// unique, even without dummyCounter, as these are global
String baseName = StringUtil::format("%s.%s", def->name.c_str(), mName.c_str());

/// Make the tetxure
RenderTarget* rendTarget;
if (def->formatList.size() > 1)
{
String MRTbaseName = "mrt/c" + StringConverter::toString(dummyCounter++) +
"/" + mName + "/" + def->name;
MultiRenderTarget* mrt =
Root::getSingleton().getRenderSystem()->createMultiRenderTarget(MRTbaseName);
MultiRenderTarget* mrt = Root::getSingleton().getRenderSystem()->createMultiRenderTarget(baseName);
mGlobalMRTs[def->name] = mrt;

// create and bind individual surfaces
Expand All @@ -200,7 +199,7 @@ void Compositor::createGlobalTextures()
p != def->formatList.end(); ++p, ++atch)
{

String texname = MRTbaseName + "/" + StringConverter::toString(atch);
String texname = StringUtil::format("mrt%zu.%s", atch, baseName.c_str());
TexturePtr tex;

tex = TextureManager::getSingleton().createManual(
Expand All @@ -223,8 +222,7 @@ void Compositor::createGlobalTextures()
}
else
{
String texName = "c" + StringConverter::toString(dummyCounter++) +
"/" + mName + "/" + def->name;
String texName = baseName;

// space in the name mixup the cegui in the compositor demo
// this is an auto generated name - so no spaces can't hart us.
Expand Down
22 changes: 11 additions & 11 deletions OgreMain/src/OgreCompositorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,23 +684,24 @@ void CompositorInstance::createResources(bool forResizeOnly)
fsaaHint = BLANKSTRING;
}
hwGamma = hwGamma || def->hwGammaWrite;


// need dummy counter as there may be multiple definitions with the same name in the chain
String baseName = StringUtil::format("%s.chain%zu.%s", def->name.c_str(), dummyCounter++,
mChain->getViewport()->getTarget()->getName().c_str());

/// Make the tetxure
if (def->formatList.size() > 1)
{
String MRTbaseName = "mrt/c" + StringConverter::toString(dummyCounter++) +
"/" + def->name + "/" + mChain->getViewport()->getTarget()->getName();
MultiRenderTarget* mrt =
Root::getSingleton().getRenderSystem()->createMultiRenderTarget(MRTbaseName);
MultiRenderTarget* mrt = Root::getSingleton().getRenderSystem()->createMultiRenderTarget(baseName);
mLocalMRTs[def->name] = mrt;

// create and bind individual surfaces
size_t atch = 0;
for (PixelFormatList::iterator p = def->formatList.begin();
p != def->formatList.end(); ++p, ++atch)
{

String texname = MRTbaseName + "/" + StringConverter::toString(atch);
String texname = StringUtil::format("mrt%zu.%s", atch, baseName.c_str());
String mrtLocalName = getMRTTexLocalName(def->name, atch);
TexturePtr tex;
if (def->pooled)
Expand Down Expand Up @@ -733,9 +734,8 @@ void CompositorInstance::createResources(bool forResizeOnly)
}
else
{
String texName = "c" + StringConverter::toString(dummyCounter++) +
"/" + def->name + "/" + mChain->getViewport()->getTarget()->getName();

String texName = baseName;

// 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(), ' ', '_' );
Expand Down Expand Up @@ -882,7 +882,7 @@ void CompositorInstance::deriveTextureRenderTargetOptions(
//---------------------------------------------------------------------
String CompositorInstance::getMRTTexLocalName(const String& baseName, size_t attachment)
{
return StringUtil::format("%s/%zu", baseName.c_str(), attachment);
return StringUtil::format("mrt%zu.%s", attachment, baseName.c_str());
}
//-----------------------------------------------------------------------
void CompositorInstance::freeResources(bool forResizeOnly, bool clearReserveTextures)
Expand Down

0 comments on commit 5d8105d

Please sign in to comment.