diff --git a/OgreMain/include/OgreCompositor.h b/OgreMain/include/OgreCompositor.h index ebc3775404d..c3713270791 100644 --- a/OgreMain/include/OgreCompositor.h +++ b/OgreMain/include/OgreCompositor.h @@ -166,10 +166,10 @@ namespace Ogre { //TODO GSOC : These typedefs are duplicated from CompositorInstance. Solve? /// Map from name->local texture - typedef std::map GlobalTextureMap; + typedef std::unordered_map GlobalTextureMap; GlobalTextureMap mGlobalTextures; /// Store a list of MRTs we've created - typedef std::map GlobalMRTMap; + typedef std::unordered_map GlobalMRTMap; GlobalMRTMap mGlobalMRTs; }; /** @} */ diff --git a/OgreMain/include/OgreCompositorInstance.h b/OgreMain/include/OgreCompositorInstance.h index 364c3984990..9a211814772 100644 --- a/OgreMain/include/OgreCompositorInstance.h +++ b/OgreMain/include/OgreCompositorInstance.h @@ -327,10 +327,10 @@ namespace Ogre { /// Is this instance allocating resources? bool mAlive; /// Map from name->local texture. - typedef std::map LocalTextureMap; + typedef std::unordered_map LocalTextureMap; LocalTextureMap mLocalTextures; /// Store a list of MRTs we've created. - typedef std::map LocalMRTMap; + typedef std::unordered_map LocalMRTMap; LocalMRTMap mLocalMRTs; typedef std::map ReserveTextureMap; /** Textures that are not currently in use, but that we want to keep for now, diff --git a/OgreMain/include/OgreHardwarePixelBuffer.h b/OgreMain/include/OgreHardwarePixelBuffer.h index 8da5ecb0a42..0f43c5d4ff0 100644 --- a/OgreMain/include/OgreHardwarePixelBuffer.h +++ b/OgreMain/include/OgreHardwarePixelBuffer.h @@ -79,6 +79,8 @@ namespace Ogre { */ void _clearSliceRTT(size_t zoffset); friend class RenderTexture; + + String getNameForRenderTexture(const String& parentName) const; public: /// Should be called by HardwareBufferManager HardwarePixelBuffer(uint32 mWidth, uint32 mHeight, uint32 mDepth, diff --git a/OgreMain/include/OgreMaterialSerializer.h b/OgreMain/include/OgreMaterialSerializer.h index 45f9b783ccd..1deb2c6e906 100644 --- a/OgreMain/include/OgreMaterialSerializer.h +++ b/OgreMain/include/OgreMaterialSerializer.h @@ -187,11 +187,9 @@ namespace Ogre { void writeLayerBlendOperationEx(const LayerBlendOperationEx op); void writeLayerBlendSource(const LayerBlendSource lbs); - typedef std::multimap EffectMap; - void writeRotationEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); void writeTransformEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); - void writeScrollEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); + void writeScrollEffect(float scrollAnimU, float scrollAnimV); void writeEnvironmentMapEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); String convertFiltering(FilterOptions fo); diff --git a/OgreMain/src/OgreCompositor.cpp b/OgreMain/src/OgreCompositor.cpp index 534e6918b39..6fe67984900 100644 --- a/OgreMain/src/OgreCompositor.cpp +++ b/OgreMain/src/OgreCompositor.cpp @@ -157,7 +157,6 @@ CompositionTechnique* Compositor::getSupportedTechnique(const String& schemeName //----------------------------------------------------------------------- void Compositor::createGlobalTextures() { - static size_t dummyCounter = 0; if (mSupportedTechniques.empty()) return; @@ -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 @@ -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( @@ -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. diff --git a/OgreMain/src/OgreCompositorInstance.cpp b/OgreMain/src/OgreCompositorInstance.cpp index 6327b13292e..10c4c22ccb4 100644 --- a/OgreMain/src/OgreCompositorInstance.cpp +++ b/OgreMain/src/OgreCompositorInstance.cpp @@ -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) @@ -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(), ' ', '_' ); @@ -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) diff --git a/OgreMain/src/OgreHardwarePixelBuffer.cpp b/OgreMain/src/OgreHardwarePixelBuffer.cpp index 51679f5807f..54e0ad1aebb 100644 --- a/OgreMain/src/OgreHardwarePixelBuffer.cpp +++ b/OgreMain/src/OgreHardwarePixelBuffer.cpp @@ -191,4 +191,10 @@ namespace Ogre mSliceTRT[zoffset] = NULL; } + + String HardwarePixelBuffer::getNameForRenderTexture(const String& parentName) const + { + // we need to add the pointer value, as the parent texture can have multiple slices or faces + return StringUtil::format("%s:buf%p", parentName.c_str(), this); + } } diff --git a/OgreMain/src/OgreMaterialSerializer.cpp b/OgreMain/src/OgreMaterialSerializer.cpp index 6d91299c9f7..29992758d45 100644 --- a/OgreMain/src/OgreMaterialSerializer.cpp +++ b/OgreMain/src/OgreMaterialSerializer.cpp @@ -1059,45 +1059,37 @@ namespace Ogre float scrollAnimU = 0; float scrollAnimV = 0; - EffectMap effMap = pTex->getEffects(); - if (!effMap.empty()) + for (const auto& it : pTex->getEffects()) { - EffectMap::const_iterator it; - for (it = effMap.begin(); it != effMap.end(); ++it) + const TextureUnitState::TextureEffect& ef = it.second; + switch (ef.type) { - const TextureUnitState::TextureEffect& ef = it->second; - switch (ef.type) - { - case TextureUnitState::ET_ENVIRONMENT_MAP : - writeEnvironmentMapEffect(ef, pTex); - break; - case TextureUnitState::ET_ROTATE : - writeRotationEffect(ef, pTex); - break; - case TextureUnitState::ET_UVSCROLL : - scrollAnimU = scrollAnimV = ef.arg1; - break; - case TextureUnitState::ET_USCROLL : - scrollAnimU = ef.arg1; - break; - case TextureUnitState::ET_VSCROLL : - scrollAnimV = ef.arg1; - break; - case TextureUnitState::ET_TRANSFORM : - writeTransformEffect(ef, pTex); - break; - default: - break; - } + case TextureUnitState::ET_ENVIRONMENT_MAP : + writeEnvironmentMapEffect(ef, pTex); + break; + case TextureUnitState::ET_ROTATE : + writeRotationEffect(ef, pTex); + break; + case TextureUnitState::ET_UVSCROLL : + scrollAnimU = scrollAnimV = ef.arg1; + break; + case TextureUnitState::ET_USCROLL : + scrollAnimU = ef.arg1; + break; + case TextureUnitState::ET_VSCROLL : + scrollAnimV = ef.arg1; + break; + case TextureUnitState::ET_TRANSFORM : + writeTransformEffect(ef, pTex); + break; + default: + break; } } // u and v scroll animation speeds merged, if present serialize scroll_anim if(scrollAnimU || scrollAnimV) { - TextureUnitState::TextureEffect texEffect; - texEffect.arg1 = scrollAnimU; - texEffect.arg2 = scrollAnimV; - writeScrollEffect(texEffect, pTex); + writeScrollEffect(scrollAnimU, scrollAnimV); } // Content type @@ -1212,15 +1204,11 @@ namespace Ogre writeValue(StringConverter::toString(effect.amplitude)); } //----------------------------------------------------------------------- - void MaterialSerializer::writeScrollEffect( - const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex) + void MaterialSerializer::writeScrollEffect(float scrollAnimU, float scrollAnimV) { - if (effect.arg1 || effect.arg2) - { - writeAttribute(4, "scroll_anim"); - writeValue(StringConverter::toString(effect.arg1)); - writeValue(StringConverter::toString(effect.arg2)); - } + writeAttribute(4, "scroll_anim"); + writeValue(StringConverter::toString(scrollAnimU)); + writeValue(StringConverter::toString(scrollAnimV)); } //----------------------------------------------------------------------- void MaterialSerializer::writeSceneBlendFactor(const SceneBlendFactor sbf) diff --git a/OgreMain/src/OgreRenderTarget.cpp b/OgreMain/src/OgreRenderTarget.cpp index 7dd8a652ff8..6378dabfeec 100644 --- a/OgreMain/src/OgreRenderTarget.cpp +++ b/OgreMain/src/OgreRenderTarget.cpp @@ -529,7 +529,7 @@ namespace Ogre { //----------------------------------------------------------------------- void RenderTarget::update(bool swap) { - OgreGpuEventScope(mName); + GpuEventScope profileScope(mName); // call implementation updateImpl(); diff --git a/OgreMain/src/OgreScriptTranslator.cpp b/OgreMain/src/OgreScriptTranslator.cpp index 63263d6d854..5563d75868e 100644 --- a/OgreMain/src/OgreScriptTranslator.cpp +++ b/OgreMain/src/OgreScriptTranslator.cpp @@ -4790,18 +4790,24 @@ namespace Ogre{ // No errors, create - CompositionTechnique::TextureDefinition *def = mTechnique->createTextureDefinition(atom0->value); - def->width = width; - def->height = height; - def->type = type; - def->widthFactor = widthFactor; - def->heightFactor = heightFactor; - def->formatList = formats; - def->fsaa = fsaa; - def->hwGammaWrite = hwGammaWrite; - def->depthBufferId = depthBufferId; - def->pooled = pooled; - def->scope = scope; + try { + CompositionTechnique::TextureDefinition *def = mTechnique->createTextureDefinition(atom0->value); + def->width = width; + def->height = height; + def->type = type; + def->widthFactor = widthFactor; + def->heightFactor = heightFactor; + def->formatList = formats; + def->fsaa = fsaa; + def->hwGammaWrite = hwGammaWrite; + def->depthBufferId = depthBufferId; + def->pooled = pooled; + def->scope = scope; + } + catch (Exception &e) + { + compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line, e.getDescription()); + } } break; case ID_TEXTURE_REF: diff --git a/RenderSystems/Direct3D11/src/OgreD3D11HardwarePixelBuffer.cpp b/RenderSystems/Direct3D11/src/OgreD3D11HardwarePixelBuffer.cpp index d064e63501c..d08177fec7f 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11HardwarePixelBuffer.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11HardwarePixelBuffer.cpp @@ -75,9 +75,7 @@ namespace Ogre { mSliceTRT.reserve(mDepth); for(size_t zoffset=0; zoffsetgetName(); - + String name = getNameForRenderTexture(parentTexture->getName()); RenderTexture *trt = new D3D11RenderTexture(name, this, zoffset, mDevice); mSliceTRT.push_back(trt); Root::getSingleton().getRenderSystem()->attachRenderTarget(*trt); diff --git a/RenderSystems/Direct3D9/src/OgreD3D9HardwarePixelBuffer.cpp b/RenderSystems/Direct3D9/src/OgreD3D9HardwarePixelBuffer.cpp index 799329d4cfe..3f6d928e78f 100644 --- a/RenderSystems/Direct3D9/src/OgreD3D9HardwarePixelBuffer.cpp +++ b/RenderSystems/Direct3D9/src/OgreD3D9HardwarePixelBuffer.cpp @@ -985,8 +985,7 @@ void D3D9HardwarePixelBuffer::updateRenderTexture(bool writeGamma, uint fsaa, co { if (mSliceTRT.empty()) { - String name; - name = "rtt/" +Ogre::StringConverter::toString((size_t)this) + "/" + srcName; + String name = getNameForRenderTexture(srcName); mSliceTRT.push_back(OGRE_NEW D3D9RenderTexture(name, this, writeGamma, fsaa)); Root::getSingleton().getRenderSystem()->attachRenderTarget(*mSliceTRT[0]); diff --git a/RenderSystems/GL/src/OgreGLHardwarePixelBuffer.cpp b/RenderSystems/GL/src/OgreGLHardwarePixelBuffer.cpp index 32b9c665e8e..0e84e7763c6 100644 --- a/RenderSystems/GL/src/OgreGLHardwarePixelBuffer.cpp +++ b/RenderSystems/GL/src/OgreGLHardwarePixelBuffer.cpp @@ -143,8 +143,7 @@ GLTextureBuffer::GLTextureBuffer(GLRenderSystem* renderSystem, GLTexture* parent mSliceTRT.reserve(mDepth); for(uint32 zoffset=0; zoffsetgetName(); + String name = getNameForRenderTexture(parent->getName()); GLSurfaceDesc surface; surface.buffer = this; surface.zoffset = zoffset; diff --git a/RenderSystems/GL3Plus/src/OgreGL3PlusTextureBuffer.cpp b/RenderSystems/GL3Plus/src/OgreGL3PlusTextureBuffer.cpp index 773d1d09207..1c5d590f41f 100644 --- a/RenderSystems/GL3Plus/src/OgreGL3PlusTextureBuffer.cpp +++ b/RenderSystems/GL3Plus/src/OgreGL3PlusTextureBuffer.cpp @@ -85,8 +85,7 @@ namespace Ogre { mSliceTRT.reserve(mDepth); for(uint32 zoffset=0; zoffsetgetName(); + String name = getNameForRenderTexture(parent->getName()); GLSurfaceDesc surface; surface.buffer = this; surface.zoffset = zoffset; diff --git a/RenderSystems/GLES2/src/OgreGLES2HardwarePixelBuffer.cpp b/RenderSystems/GLES2/src/OgreGLES2HardwarePixelBuffer.cpp index 663dc69bfe9..2b1a1f556f6 100644 --- a/RenderSystems/GLES2/src/OgreGLES2HardwarePixelBuffer.cpp +++ b/RenderSystems/GLES2/src/OgreGLES2HardwarePixelBuffer.cpp @@ -143,8 +143,7 @@ namespace Ogre { mSliceTRT.reserve(mDepth); for(uint32 zoffset=0; zoffsetgetName(); + String name = getNameForRenderTexture(parent->getName()); GLSurfaceDesc surface; surface.buffer = this; surface.zoffset = zoffset; diff --git a/RenderSystems/Metal/src/OgreMetalHardwarePixelBuffer.mm b/RenderSystems/Metal/src/OgreMetalHardwarePixelBuffer.mm index 68719200a49..1060210ff63 100644 --- a/RenderSystems/Metal/src/OgreMetalHardwarePixelBuffer.mm +++ b/RenderSystems/Metal/src/OgreMetalHardwarePixelBuffer.mm @@ -268,8 +268,7 @@ of this software and associated documentation files (the "Software"), to deal mSliceTRT.reserve(mDepth); for(uint32 zoffset=0; zoffsetgetName(); + String name = getNameForRenderTexture(mParent->getName()); RenderTexture *trt = new VulkanRenderTexture(name, this, zoffset, mParent, mFace); mSliceTRT.push_back(trt);