Files
o3de/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkinnedMesh/SkinnedMeshDebugDisplay.cpp
T
AMZN-koppersr 5e4094b258 Revamped AzFramework::Scene (#332)
Updated AzFramework::Scene to allow it to serve as the one-stop location for localized singletons. Localized singletons in this case are instance that can only occur once in an environment but multiple times within an application. As an example, this allows settings up a single camera per viewport for instance.

Highlights of changes:

Replaced the original ebuses with interfaces and events for easy of use and performance.
Removed the Entity Context specific code and moved that to new locations within the Entity Context itself.
Allowed basic inheritance. If a subsystem isn't found in a scene the parent can optionally be searched.
Scenes can enter a zombie state and avoid immediately being deleted. This is needed for situations where subsystems can't be destroyed until async calls have been completed.
2021-04-29 08:50:48 -07:00

111 lines
5.2 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <CryCommon/IConsole.h>
#include <SkinnedMesh/SkinnedMeshDebugDisplay.h>
#include <Atom/Feature/SkinnedMesh/SkinnedMeshStatsBus.h>
#include <Atom/RPI.Public/Scene.h>
#include <AzFramework/Scene/SceneSystemInterface.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <ISystem.h>
namespace AZ
{
namespace Render
{
SkinnedMeshDebugDisplay::SkinnedMeshDebugDisplay()
{
CrySystemEventBus::Handler::BusConnect();
AZ::Render::Bootstrap::NotificationBus::Handler::BusConnect();
}
SkinnedMeshDebugDisplay::~SkinnedMeshDebugDisplay()
{
AZ::Render::Bootstrap::NotificationBus::Handler::BusDisconnect();
CrySystemEventBus::Handler::BusDisconnect();
AzFramework::ViewportDebugDisplayEventBus::Handler::BusDisconnect();
}
void SkinnedMeshDebugDisplay::OnCrySystemInitialized(ISystem& system, [[maybe_unused]] const SSystemInitParams& systemInitParams)
{
// Once CrySystem is initialized, we can register cvars
if (system.GetGlobalEnvironment() && system.GetGlobalEnvironment()->pConsole)
{
system.GetGlobalEnvironment()->pConsole->Register("r_skinnedMeshDisplaySceneStats", &r_skinnedMeshDisplaySceneStats, 0, VF_NULL,
CVARHELP("Enable debug display of skinned mesh stats\n"
" 1 = 'Skinned Mesh Scene Stats': This represents all lods of all the skinned meshes in the scene, not just what's in view."
" Effectively, this is everything that is created and uploaded to the GPU, though only the visible subset of meshes/lods will be skinned.\n"));
}
else
{
AZ_Assert(false, "Attempting to register r_skinnedMeshDisplaySceneStats before the cvar system has been initialized");
}
}
void SkinnedMeshDebugDisplay::OnCrySystemShutdown(ISystem& system)
{
if (system.GetGlobalEnvironment() && system.GetGlobalEnvironment()->pConsole)
{
system.GetGlobalEnvironment()->pConsole->UnregisterVariable("r_skinnedMeshDisplaySceneStats");
}
else
{
AZ_Assert(false, "Attempting to unregister r_skinnedMeshDisplaySceneStats after the cvar system has been shut down");
}
}
void SkinnedMeshDebugDisplay::OnCryEditorInitialized()
{
// Once the editor is initialized, listen to ViewportDebugDisplayEventBus
AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull();
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
AzFramework::ViewportDebugDisplayEventBus::Handler::BusConnect(editorEntityContextId);
}
void SkinnedMeshDebugDisplay::DisplayViewport2d([[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)
{
if (r_skinnedMeshDisplaySceneStats == 1)
{
// Get scene id when DisplayViewport2d is called. The RPI Scene may not be ready when OnCryEditorInitialized was called
SkinnedMeshSceneStats stats{};
SkinnedMeshStatsRequestBus::EventResult(stats, m_sceneId, &SkinnedMeshStatsRequestBus::Events::GetSceneStats);
float x = 0;
float y = 16.0f; // By default, the editor's debug display text shows the number of entities in the top left corner. Offset so the skinned mesh stats don't overlap
float size = 1.25f;
bool center = false;
AZStd::string debugString = AZStd::string::format(
"Skinned Mesh Scene Stats:\n"
" SkinnedMeshRenderProxy count: %zu\n"
" DispatchItem count: %zu\n"
" Read only buffer view count: %zu\n"
" Writable buffer view count: %zu\n"
" Bone count: %zu\n"
" Vertex count: %zu\n",
stats.skinnedMeshRenderProxyCount, stats.dispatchItemCount, stats.readOnlyBufferViewCount, stats.writableBufferViewCount, stats.boneCount, stats.vertexCount
);
debugDisplay.Draw2dTextLabel(x, y, size, debugString.c_str(), center);
}
}
void SkinnedMeshDebugDisplay::OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene)
{
m_sceneId = bootstrapScene->GetId();
}
}// namespace Render
}// namespace AZ