Merge pull request #512 from aws-lumberyard-dev/AtomDebugDisplayFixes
Atom debug display fixes to work in GameMode
This commit is contained in:
+43
-12
@@ -244,9 +244,6 @@ namespace AZ::AtomBridge
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Partial implementation of the DebugDisplayRequestBus on Atom.
|
||||
// Commented out function prototypes are waiting to be implemented.
|
||||
// work tracked in [ATOM-3459]
|
||||
AtomDebugDisplayViewportInterface::AtomDebugDisplayViewportInterface(AZ::RPI::ViewportContextPtr viewportContextPtr)
|
||||
{
|
||||
ResetRenderState();
|
||||
@@ -272,9 +269,8 @@ namespace AZ::AtomBridge
|
||||
InitInternal(scene, nullptr);
|
||||
}
|
||||
|
||||
void AtomDebugDisplayViewportInterface::InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr)
|
||||
void AtomDebugDisplayViewportInterface::UpdateAuxGeom(RPI::Scene* scene, AZ::RPI::View* view)
|
||||
{
|
||||
AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId);
|
||||
if (!scene)
|
||||
{
|
||||
m_auxGeomPtr = nullptr;
|
||||
@@ -286,20 +282,46 @@ namespace AZ::AtomBridge
|
||||
m_auxGeomPtr = nullptr;
|
||||
return;
|
||||
}
|
||||
if (m_defaultInstance)
|
||||
// default instance draws to all viewports in the default scene
|
||||
if (m_defaultInstance || !view)
|
||||
{
|
||||
m_auxGeomPtr = auxGeomFP->GetDrawQueue();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_auxGeomPtr = auxGeomFP->GetOrCreateDrawQueueForView(viewportContextPtr->GetDefaultView().get());
|
||||
// cache the aux geom draw interface for the current view (aka camera)
|
||||
m_auxGeomPtr = auxGeomFP->GetOrCreateDrawQueueForView(view);
|
||||
}
|
||||
}
|
||||
|
||||
void AtomDebugDisplayViewportInterface::InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr)
|
||||
{
|
||||
AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId);
|
||||
UpdateAuxGeom(scene, viewportContextPtr ? viewportContextPtr->GetDefaultView().get() : nullptr);
|
||||
AzFramework::DebugDisplayRequestBus::Handler::BusConnect(m_viewportId);
|
||||
if (!m_defaultInstance) // only the per viewport instances need to listen for viewport changes
|
||||
{
|
||||
AZ::RPI::ViewportContextIdNotificationBus::Handler::BusConnect(viewportContextPtr->GetId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AtomDebugDisplayViewportInterface::OnViewportDefaultViewChanged(AZ::RPI::ViewPtr view)
|
||||
{
|
||||
ResetRenderState();
|
||||
if (!m_defaultInstance)
|
||||
{
|
||||
// handle viewport update (view change, scene change, etc
|
||||
auto viewportContextManager = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get();
|
||||
AZ::RPI::ViewportContextPtr viewportContextPtr = viewportContextManager->GetViewportContextById(m_viewportId);
|
||||
UpdateAuxGeom(viewportContextPtr->GetRenderScene().get(), viewportContextPtr->GetDefaultView().get());
|
||||
}
|
||||
}
|
||||
|
||||
AtomDebugDisplayViewportInterface::~AtomDebugDisplayViewportInterface()
|
||||
{
|
||||
AzFramework::DebugDisplayRequestBus::Handler::BusDisconnect(m_viewportId);
|
||||
AZ::RPI::ViewportContextIdNotificationBus::Handler::BusDisconnect();
|
||||
m_viewportId = AzFramework::InvalidViewportId;
|
||||
m_auxGeomPtr = nullptr;
|
||||
}
|
||||
@@ -1234,8 +1256,15 @@ namespace AZ::AtomBridge
|
||||
int srcOffsetX [[maybe_unused]],
|
||||
int srcOffsetY [[maybe_unused]])
|
||||
{
|
||||
// abort draw if draw is invalid or font query interface is missing.
|
||||
if (!text || size == 0.0f || !AZ::Interface<AzFramework::FontQueryInterface>::Get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AzFramework::FontDrawInterface* fontDrawInterface = AZ::Interface<AzFramework::FontQueryInterface>::Get()->GetDefaultFontDrawInterface();
|
||||
if (!fontDrawInterface || !text || size == 0.0f)
|
||||
// abort draw if font draw interface is missing
|
||||
if (!fontDrawInterface)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1263,13 +1292,15 @@ namespace AZ::AtomBridge
|
||||
const char* text,
|
||||
bool center)
|
||||
{
|
||||
auto fontQueryInterface = AZ::Interface<AzFramework::FontQueryInterface>::Get();
|
||||
if (!fontQueryInterface)
|
||||
// abort draw if draw is invalid or font query interface is missing.
|
||||
if (!text || size == 0.0f || !AZ::Interface<AzFramework::FontQueryInterface>::Get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
AzFramework::FontDrawInterface* fontDrawInterface = fontQueryInterface->GetDefaultFontDrawInterface();
|
||||
if (!fontDrawInterface || !text || size == 0.0f)
|
||||
|
||||
AzFramework::FontDrawInterface* fontDrawInterface = AZ::Interface<AzFramework::FontQueryInterface>::Get()->GetDefaultFontDrawInterface();
|
||||
// abort draw if font draw interface is missing
|
||||
if (!fontDrawInterface)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <Atom/RPI.Public/RPISystemInterface.h>
|
||||
#include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
|
||||
#include <Atom/RPI.Public/ViewportContext.h>
|
||||
#include <Atom/RPI.Public/ViewportContextBus.h>
|
||||
|
||||
namespace AZ::AtomBridge
|
||||
{
|
||||
@@ -121,6 +122,7 @@ namespace AZ::AtomBridge
|
||||
|
||||
class AtomDebugDisplayViewportInterface final
|
||||
: public AzFramework::DebugDisplayRequestBus::Handler
|
||||
, public AZ::RPI::ViewportContextIdNotificationBus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(AtomDebugDisplayViewportInterface, "{09AF6A46-0100-4FBF-8F94-E6B221322D14}", AzFramework::DebugDisplayRequestBus::Handler);
|
||||
@@ -198,6 +200,12 @@ namespace AZ::AtomBridge
|
||||
void PopMatrix() override;
|
||||
|
||||
private:
|
||||
|
||||
// ViewportContextIdNotificationBus handlers
|
||||
void OnViewportDefaultViewChanged(AZ::RPI::ViewPtr view) override;
|
||||
|
||||
|
||||
// internal helper functions
|
||||
using LineSegmentFilterFunc = AZStd::function<bool(const AZ::Vector3& lineStart, const AZ::Vector3& lineEnd, int segmentIndex)>;
|
||||
enum CircleAxis
|
||||
{
|
||||
@@ -245,6 +253,7 @@ namespace AZ::AtomBridge
|
||||
|
||||
const AZ::Matrix3x4& GetCurrentTransform() const;
|
||||
|
||||
void UpdateAuxGeom(RPI::Scene* scene, AZ::RPI::View* view);
|
||||
void InitInternal(RPI::Scene* scene, AZ::RPI::ViewportContextPtr viewportContextPtr);
|
||||
|
||||
AZ::RPI::ViewportContextPtr GetViewportContext() const;
|
||||
@@ -254,10 +263,12 @@ namespace AZ::AtomBridge
|
||||
RenderState m_rendState;
|
||||
|
||||
AZ::RPI::AuxGeomDrawPtr m_auxGeomPtr;
|
||||
bool m_defaultInstance = false; // only true for drawing to a particular viewport. What would 2D drawing mean in a scene with several windows?
|
||||
|
||||
// m_defaultInstance is true for the instance that multicasts the debug draws to all viewports
|
||||
// (with an AuxGeom render pass) in the default scene.
|
||||
bool m_defaultInstance = false;
|
||||
AzFramework::ViewportId m_viewportId = AzFramework::InvalidViewportId; // Address this instance answers on.
|
||||
AZ::RPI::ViewportContext::SceneChangedEvent::Handler
|
||||
m_sceneChangeHandler;
|
||||
AZ::RPI::ViewportContext::SceneChangedEvent::Handler m_sceneChangeHandler;
|
||||
};
|
||||
|
||||
// this is duplicated from Cry_Math.h, GetBasisVectors.
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace AZ
|
||||
|
||||
private:
|
||||
virtual ~FFont();
|
||||
bool InitFont();
|
||||
bool InitFont(AZ::RPI::Scene* renderScene);
|
||||
bool InitTexture();
|
||||
bool InitCache();
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ AZ::RPI::WindowContextSharedPtr AZ::FFont::GetDefaultWindowContext() const
|
||||
return {};
|
||||
}
|
||||
|
||||
bool AZ::FFont::InitFont()
|
||||
bool AZ::FFont::InitFont(AZ::RPI::Scene* renderScene)
|
||||
{
|
||||
auto initializationState = InitializationState::Uninitialized;
|
||||
// Do an atomic transition to Initializing if we're in the Uninitialized state.
|
||||
@@ -111,8 +111,13 @@ bool AZ::FFont::InitFont()
|
||||
return initializationState == InitializationState::Initialized;
|
||||
}
|
||||
|
||||
if (!renderScene)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create and initialize DynamicDrawContext for font draw
|
||||
AZ::RPI::Ptr<AZ::RPI::DynamicDrawContext> dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(GetDefaultViewportContext()->GetRenderScene().get());
|
||||
AZ::RPI::Ptr<AZ::RPI::DynamicDrawContext> dynamicDraw = m_atomFont->GetOrCreateDynamicDrawForScene(renderScene);
|
||||
|
||||
// Save draw srg input indices for later use
|
||||
Data::Instance<RPI::ShaderResourceGroup> drawSrg = dynamicDraw->NewDrawSrg();
|
||||
@@ -299,7 +304,7 @@ void AZ::FFont::DrawStringUInternal(
|
||||
const TextDrawContext& ctx)
|
||||
{
|
||||
// Lazily ensure we're initialized before attempting to render.
|
||||
if (!InitFont())
|
||||
if (!viewportContext || !InitFont(viewportContext->GetRenderScene().get()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1623,7 +1628,7 @@ void AZ::FFont::ScaleCoord(const RHI::Viewport& viewport, float& x, float& y) co
|
||||
|
||||
void AZ::FFont::OnBootstrapSceneReady([[maybe_unused]] AZ::RPI::Scene* bootstrapScene)
|
||||
{
|
||||
InitFont();
|
||||
InitFont(bootstrapScene);
|
||||
}
|
||||
|
||||
static void SetCommonContextFlags(AZ::TextDrawContext& ctx, const AzFramework::TextDrawParameters& params)
|
||||
|
||||
+1
@@ -336,6 +336,7 @@ namespace AZ
|
||||
bool needsFullRefresh = HandleLightTypeChange();
|
||||
|
||||
LmbrCentral::EditorShapeComponentRequestsBus::Event(GetEntityId(), &LmbrCentral::EditorShapeComponentRequests::SetShapeColor, m_controller.m_configuration.m_color);
|
||||
LmbrCentral::EditorShapeComponentRequestsBus::Event(GetEntityId(), &LmbrCentral::EditorShapeComponentRequests::SetShapeWireframeColor, m_controller.m_configuration.m_color);
|
||||
|
||||
// If photometric unit changes, convert the intensities so the actual intensity doesn't change.
|
||||
m_controller.ConvertToIntensityMode(m_controller.m_configuration.m_intensityMode);
|
||||
|
||||
Reference in New Issue
Block a user