* ATOM-16747 RPISystemInterface::GetDefaultScene returns the scene created by PreviewRenderer but not the Main Scene
Deprecate GetDefaultScene() function.
Update all the places which use GetDefaultScene to use Scene::GetFeatureProcessorFromEntityId or GetMainScene.
Tested with Editor, UI Editor, Material Editor, game launcher.
Signed-off-by: Qing Tao <55564570+VickyAtAZ@users.noreply.github.com>
(cherry picked from commit 8da6bea073)
This commit is contained in:
@@ -70,7 +70,8 @@ namespace AZ
|
||||
void InitializeSystemAssets() override;
|
||||
void RegisterScene(ScenePtr scene) override;
|
||||
void UnregisterScene(ScenePtr scene) override;
|
||||
ScenePtr GetScene(const SceneId& sceneId) const override;
|
||||
Scene* GetScene(const SceneId& sceneId) const override;
|
||||
Scene* GetSceneByName(const AZ::Name& name) const override;
|
||||
ScenePtr GetDefaultScene() const override;
|
||||
RenderPipelinePtr GetRenderPipelineForWindow(AzFramework::NativeWindowHandle windowHandle) override;
|
||||
Data::Asset<ShaderAsset> GetCommonShaderAssetForSrgs() const override;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <Atom/RPI.Public/Base.h>
|
||||
|
||||
#include <AzCore/Name/Name.h>
|
||||
#include <AzFramework/Windowing/WindowBus.h>
|
||||
|
||||
namespace AZ
|
||||
@@ -46,11 +47,14 @@ namespace AZ
|
||||
//! Unregister a scene from RPISystem. The scene won't be simulated or rendered.
|
||||
virtual void UnregisterScene(ScenePtr scene) = 0;
|
||||
|
||||
// [GFX TODO] to be removed when we have scene setup in AZ Core
|
||||
virtual ScenePtr GetDefaultScene() const = 0;
|
||||
|
||||
//! Deprecated. Use GetSceneByName(name), GetSceneForEntityContextId(entityContextId) or Scene::GetSceneForEntityId(AZ::EntityId entityId) instead
|
||||
AZ_DEPRECATED(virtual ScenePtr GetDefaultScene() const = 0;, "This method has been deprecated. Please use GetSceneByName(name), GetSceneForEntityContextId(entityContextId) or Scene::GetSceneForEntityId(AZ::EntityId entityId) instead.");
|
||||
|
||||
//! Get scene by using scene id.
|
||||
virtual ScenePtr GetScene(const SceneId& sceneId) const = 0;
|
||||
virtual Scene* GetScene(const SceneId& sceneId) const = 0;
|
||||
|
||||
//! Get scene by using scene name.
|
||||
virtual Scene* GetSceneByName(const AZ::Name& name) const = 0;
|
||||
|
||||
//! Get the render pipeline created for a window
|
||||
virtual RenderPipelinePtr GetRenderPipelineForWindow(AzFramework::NativeWindowHandle windowHandle) = 0;
|
||||
|
||||
@@ -80,6 +80,9 @@ namespace AZ
|
||||
//! Gets the RPI::Scene for a given entityContextId.
|
||||
//! May return nullptr if there is no RPI::Scene created for that entityContext.
|
||||
static Scene* GetSceneForEntityContextId(AzFramework::EntityContextId entityContextId);
|
||||
|
||||
//! Gets the RPI::Scene for a given entityId.
|
||||
static Scene* GetSceneForEntityId(AZ::EntityId entityId);
|
||||
|
||||
~Scene();
|
||||
|
||||
@@ -135,6 +138,8 @@ namespace AZ
|
||||
|
||||
const SceneId& GetId() const;
|
||||
|
||||
AZ::Name GetName() const;
|
||||
|
||||
//! Set default pipeline by render pipeline ID.
|
||||
//! It returns true if the default render pipeline was set from the input ID.
|
||||
//! If the specified render pipeline doesn't exist in this scene then it won't do anything and returns false.
|
||||
@@ -245,6 +250,9 @@ namespace AZ
|
||||
// The uuid to identify this scene.
|
||||
SceneId m_id;
|
||||
|
||||
// Scene's name which is set at initialization. Can be empty
|
||||
AZ::Name m_name;
|
||||
|
||||
bool m_activated = false;
|
||||
bool m_taskGraphActive = false; // update during tick, to ensure it only changes on frame boundaries
|
||||
|
||||
@@ -286,13 +294,10 @@ namespace AZ
|
||||
template<typename FeatureProcessorType>
|
||||
FeatureProcessorType* Scene::GetFeatureProcessorForEntity(AZ::EntityId entityId)
|
||||
{
|
||||
// Find the entity context for the entity ID.
|
||||
AzFramework::EntityContextId entityContextId = AzFramework::EntityContextId::CreateNull();
|
||||
AzFramework::EntityIdContextQueryBus::EventResult(entityContextId, entityId, &AzFramework::EntityIdContextQueryBus::Events::GetOwningContextId);
|
||||
|
||||
if (!entityContextId.IsNull())
|
||||
RPI::Scene* renderScene = GetSceneForEntityId(entityId);
|
||||
if (renderScene)
|
||||
{
|
||||
return GetFeatureProcessorForEntityContextId<FeatureProcessorType>(entityContextId);
|
||||
return renderScene->GetFeatureProcessor<FeatureProcessorType>();
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Name/Name.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
@@ -25,6 +26,9 @@ namespace AZ
|
||||
|
||||
//! List of feature processors which the scene will initially enable.
|
||||
AZStd::vector<AZStd::string> m_featureProcessorNames;
|
||||
|
||||
//! A name used as scene id. It can be used to search a registered scene via RPISystemInterface::GetScene()
|
||||
AZ::Name m_nameId;
|
||||
};
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
|
||||
@@ -699,9 +699,7 @@ namespace AZ
|
||||
m_parentScene = parentScene;
|
||||
|
||||
AZ_Assert(m_visScene == nullptr, "IVisibilityScene already created for this RPI::Scene");
|
||||
char sceneIdBuf[40] = "";
|
||||
m_parentScene->GetId().ToString(sceneIdBuf);
|
||||
AZ::Name visSceneName(AZStd::string::format("RenderCullScene[%s]", sceneIdBuf));
|
||||
AZ::Name visSceneName(AZStd::string::format("RenderCullScene[%s]", m_parentScene->GetName().GetCStr()));
|
||||
m_visScene = AZ::Interface<AzFramework::IVisibilitySystem>::Get()->CreateVisibilityScene(visSceneName);
|
||||
|
||||
#ifdef AZ_CULL_DEBUG_ENABLED
|
||||
|
||||
@@ -159,6 +159,11 @@ namespace AZ
|
||||
AZ_Assert(false, "Scene was already registered");
|
||||
return;
|
||||
}
|
||||
else if (!scene->GetName().IsEmpty() && scene->GetName() == sceneItem->GetName())
|
||||
{
|
||||
// only report a warning if there is a scene with duplicated name
|
||||
AZ_Warning("RPISystem", false, "There is a registered scene with same name [%s]", scene->GetName().GetCStr());
|
||||
}
|
||||
}
|
||||
|
||||
m_scenes.push_back(scene);
|
||||
@@ -177,11 +182,35 @@ namespace AZ
|
||||
AZ_Assert(false, "Can't unregister scene which wasn't registered");
|
||||
}
|
||||
|
||||
ScenePtr RPISystem::GetScene(const SceneId& sceneId) const
|
||||
Scene* RPISystem::GetScene(const SceneId& sceneId) const
|
||||
{
|
||||
for (const auto& scene : m_scenes)
|
||||
{
|
||||
if (scene->GetId() == sceneId)
|
||||
{
|
||||
return scene.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Scene* RPISystem::GetSceneByName(const AZ::Name& name) const
|
||||
{
|
||||
for (const auto& scene : m_scenes)
|
||||
{
|
||||
if (scene->GetName() == name)
|
||||
{
|
||||
return scene.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScenePtr RPISystem::GetDefaultScene() const
|
||||
{
|
||||
for (const auto& scene : m_scenes)
|
||||
{
|
||||
if (scene->GetName() == AZ::Name("Main"))
|
||||
{
|
||||
return scene;
|
||||
}
|
||||
@@ -189,16 +218,6 @@ namespace AZ
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScenePtr RPISystem::GetDefaultScene() const
|
||||
{
|
||||
if (m_scenes.size() > 0)
|
||||
{
|
||||
return m_scenes[0];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
RenderPipelinePtr RPISystem::GetRenderPipelineForWindow(AzFramework::NativeWindowHandle windowHandle)
|
||||
{
|
||||
RenderPipelinePtr renderPipeline;
|
||||
|
||||
@@ -45,7 +45,9 @@ namespace AZ
|
||||
auto shaderAsset = RPISystemInterface::Get()->GetCommonShaderAssetForSrgs();
|
||||
scene->m_srg = ShaderResourceGroup::Create(shaderAsset, sceneSrgLayout->GetName());
|
||||
}
|
||||
|
||||
|
||||
scene->m_name = sceneDescriptor.m_nameId;
|
||||
|
||||
return ScenePtr(scene);
|
||||
}
|
||||
|
||||
@@ -83,10 +85,23 @@ namespace AZ
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Scene* Scene::GetSceneForEntityId(AZ::EntityId entityId)
|
||||
{
|
||||
// Find the entity context for the entity ID.
|
||||
AzFramework::EntityContextId entityContextId = AzFramework::EntityContextId::CreateNull();
|
||||
AzFramework::EntityIdContextQueryBus::EventResult(entityContextId, entityId, &AzFramework::EntityIdContextQueryBus::Events::GetOwningContextId);
|
||||
|
||||
if (!entityContextId.IsNull())
|
||||
{
|
||||
return GetSceneForEntityContextId(entityContextId);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Scene::Scene()
|
||||
{
|
||||
m_id = Uuid::CreateRandom();
|
||||
m_id = AZ::Uuid::CreateRandom();
|
||||
m_cullingScene = aznew CullingScene();
|
||||
SceneRequestBus::Handler::BusConnect(m_id);
|
||||
m_drawFilterTagRegistry = RHI::DrawFilterTagRegistry::Create();
|
||||
@@ -299,7 +314,6 @@ namespace AZ
|
||||
// Force to update the lookup table since adding render pipeline would effect any pipeline states created before pass system tick
|
||||
RebuildPipelineStatesLookup();
|
||||
|
||||
AZ_Assert(!m_id.IsNull(), "RPI::Scene needs to have a valid uuid.");
|
||||
SceneNotificationBus::Event(m_id, &SceneNotification::OnRenderPipelineAdded, pipeline);
|
||||
}
|
||||
|
||||
@@ -785,6 +799,11 @@ namespace AZ
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
AZ::Name Scene::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool Scene::SetDefaultRenderPipeline(const RenderPipelineId& pipelineId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user