Added "RemovePassTemplate" method. (#5039)

* Added "RemovePassTemplate" method.

Signed-off-by: garrieta <garrieta@amazon.com>

* RemovePassTemplate only allows to remove PassTemplates
created with the Runtime API. It now asserts if there are Passes
referencing the PassTemplate that should be removed.

Signed-off-by: garrieta <garrieta@amazon.com>
monroegm-disable-blank-issue-2
galibzon 4 years ago committed by GitHub
parent 07353ed4ad
commit 0807cb7f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -77,6 +77,16 @@ namespace AZ
const AZStd::shared_ptr<PassTemplate> GetPassTemplate(const Name& name) const;
const AZStd::vector<Pass*>& GetPassesForTemplate(const Name& templateName) const;
//! Removes a PassTemplate by name, only if the following two conditions are met:
//! 1- The template was NOT created from an Asset. This means the template will be erasable
//! only if it was created at runtime with C++.
//! 2- The are no instantiated Passes referencing such template.
//! If the template exists but both conditions are not met then the function will assert.
//! If a template with the given name doesn't exist the function does nothing.
//! This function should be used judiciously, and under rare circumstances. For example,
//! Applications that iteratively create and need to delete templates at runtime.
void RemovePassTemplate(const Name& name);
//! Removes a pass from both it's associated template (if it has one) and from the pass name mapping
void RemovePassFromLibrary(Pass* pass);

@ -94,6 +94,7 @@ namespace AZ
bool HasPassesForTemplateName(const Name& templateName) const override;
bool AddPassTemplate(const Name& name, const AZStd::shared_ptr<PassTemplate>& passTemplate) override;
const AZStd::shared_ptr<PassTemplate> GetPassTemplate(const Name& name) const override;
void RemovePassTemplate(const Name& name) override;
void RemovePassFromLibrary(Pass* pass) override;
void RegisterPass(Pass* pass) override;
void UnregisterPass(Pass* pass) override;

@ -199,6 +199,9 @@ namespace AZ
//! Retrieves a PassTemplate from the library
virtual const AZStd::shared_ptr<PassTemplate> GetPassTemplate(const Name& name) const = 0;
//! See remarks in PassLibrary.h for the function with this name.
virtual void RemovePassTemplate(const Name& name) = 0;
//! Removes all references to the given pass from the pass library
virtual void RemovePassFromLibrary(Pass* pass) = 0;

@ -236,6 +236,19 @@ namespace AZ
return true;
}
void PassLibrary::RemovePassTemplate(const Name& name)
{
auto itr = m_templateEntries.find(name);
if (itr != m_templateEntries.end())
{
AZ_Assert(itr->second.m_passes.empty(), "Can not delete PassTemplate '%s' because there are %zu Passes referencing it",
name.GetCStr(), itr->second.m_passes.size());
AZ_Assert(!itr->second.m_mappingAssetId.IsValid(), "Can not delete PassTemplate '%s' because it was created from an asset",
name.GetCStr());
m_templateEntries.erase(itr);
}
}
void PassLibrary::RemovePassFromLibrary(Pass* pass)
{
if (m_isShuttingDown)

@ -466,6 +466,11 @@ namespace AZ
return m_passLibrary.GetPassTemplate(name);
}
void PassSystem::RemovePassTemplate(const Name& name)
{
m_passLibrary.RemovePassTemplate(name);
}
void PassSystem::RemovePassFromLibrary(Pass* pass)
{
m_passLibrary.RemovePassFromLibrary(pass);

Loading…
Cancel
Save