Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3200

Merged
merged 5 commits into from
Aug 23, 2024
Merged

Devel #3200

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: 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
2 changes: 2 additions & 0 deletions OgreMain/include/OgreHardwarePixelBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions OgreMain/include/OgreMaterialSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ namespace Ogre {
void writeLayerBlendOperationEx(const LayerBlendOperationEx op);
void writeLayerBlendSource(const LayerBlendSource lbs);

typedef std::multimap<TextureUnitState::TextureEffectType, TextureUnitState::TextureEffect> 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);
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
6 changes: 6 additions & 0 deletions OgreMain/src/OgreHardwarePixelBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
68 changes: 28 additions & 40 deletions OgreMain/src/OgreMaterialSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ namespace Ogre {
//-----------------------------------------------------------------------
void RenderTarget::update(bool swap)
{
OgreGpuEventScope(mName);
GpuEventScope profileScope(mName);
// call implementation
updateImpl();

Expand Down
30 changes: 18 additions & 12 deletions OgreMain/src/OgreScriptTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ namespace Ogre {
mSliceTRT.reserve(mDepth);
for(size_t zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/"+StringConverter::toString((size_t)this) + "/" + parentTexture->getName();

String name = getNameForRenderTexture(parentTexture->getName());
RenderTexture *trt = new D3D11RenderTexture(name, this, zoffset, mDevice);
mSliceTRT.push_back(trt);
Root::getSingleton().getRenderSystem()->attachRenderTarget(*trt);
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Direct3D9/src/OgreD3D9HardwarePixelBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/GL/src/OgreGLHardwarePixelBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ GLTextureBuffer::GLTextureBuffer(GLRenderSystem* renderSystem, GLTexture* parent
mSliceTRT.reserve(mDepth);
for(uint32 zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/" + StringConverter::toString((size_t)this) + "/" + parent->getName();
String name = getNameForRenderTexture(parent->getName());
GLSurfaceDesc surface;
surface.buffer = this;
surface.zoffset = zoffset;
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/GL3Plus/src/OgreGL3PlusTextureBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace Ogre {
mSliceTRT.reserve(mDepth);
for(uint32 zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/" + StringConverter::toString((size_t)this) + "/" + parent->getName();
String name = getNameForRenderTexture(parent->getName());
GLSurfaceDesc surface;
surface.buffer = this;
surface.zoffset = zoffset;
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/GLES2/src/OgreGLES2HardwarePixelBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ namespace Ogre {
mSliceTRT.reserve(mDepth);
for(uint32 zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/" + StringConverter::toString((size_t)this) + "/" + parent->getName();
String name = getNameForRenderTexture(parent->getName());
GLSurfaceDesc surface;
surface.buffer = this;
surface.zoffset = zoffset;
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Metal/src/OgreMetalHardwarePixelBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ of this software and associated documentation files (the "Software"), to deal
mSliceTRT.reserve(mDepth);
for(uint32 zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/" + StringConverter::toString((size_t)this) + "/" + baseName;
String name = getNameForRenderTexture(baseName);
RenderTexture *trt = OGRE_NEW MetalRenderTexture( device, name, this,
renderTexture, resolveTexture,
mFormat, zoffset, mFace, fsaa, level,
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ namespace Ogre
mSliceTRT.reserve(mDepth);
for(size_t zoffset=0; zoffset<mDepth; ++zoffset)
{
String name;
name = "rtt/"+StringConverter::toString((size_t)this) + "/" + mParent->getName();
String name = getNameForRenderTexture(mParent->getName());

RenderTexture *trt = new VulkanRenderTexture(name, this, zoffset, mParent, mFace);
mSliceTRT.push_back(trt);
Expand Down