Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RPI::ViewportContext Class Reference

#include <ViewportContext.h>

Inherits SceneNotificationBus::Handler, AzFramework::WindowNotificationBus::Handler, and AzFramework::ViewportRequestBus::Handler.

Public Types

using SizeChangedEvent = AZ::Event< AzFramework::WindowSize >
 
using ScalarChangedEvent = AZ::Event< float >
 
using SceneChangedEvent = AZ::Event< ScenePtr >
 
using PipelineChangedEvent = AZ::Event< RenderPipelinePtr >
 
using ViewChangedEvent = AZ::Event< ViewPtr >
 
using ViewportIdEvent = AZ::Event< AzFramework::ViewportId >
 

Public Member Functions

 AZ_CLASS_ALLOCATOR (ViewportContext, AZ::SystemAllocator)
 
 ViewportContext (ViewportContextManager *manager, AzFramework::ViewportId id, const AZ::Name &name, RHI::Device &device, AzFramework::NativeWindowHandle nativeWindow, ScenePtr renderScene)
 
AzFramework::ViewportId GetId () const
 Gets an opaque ID that can be used to uniquely identify this ViewportContext.
 
AzFramework::NativeWindowHandle GetWindowHandle () const
 Convenience method, gets the window handle associated with this viewport's window manager.
 
WindowContextSharedPtr GetWindowContext ()
 Gets the window context associated with this viewport.
 
ScenePtr GetRenderScene ()
 Gets the root scene (if any) associated with this viewport.
 
RenderPipelinePtr GetCurrentPipeline ()
 Gets the current render pipeline associated with our WindowContext, if there is one.
 
void SetRenderScene (ScenePtr scene)
 
void RenderTick ()
 
AZ::Name GetName () const
 
ViewGroupPtr GetViewGroup ()
 
ConstViewGroupPtr GetViewGroup () const
 
ViewPtr GetDefaultView ()
 
ConstViewPtr GetDefaultView () const
 
ViewPtr GetStereoscopicView (AZ::RPI::ViewType viewType)
 
ConstViewPtr GetStereoscopicView (AZ::RPI::ViewType viewType) const
 
AzFramework::WindowSize GetViewportSize () const
 
float GetDpiScalingFactor () const
 
void OnRenderPipelineChanged (RenderPipeline *pipeline, SceneNotification::RenderPipelineChangeType changeType) override
 Ensures our default view remains set when our scene's render pipelines are modified.
 
void OnBeginPrepareRender () override
 OnBeginPrepareRender is forwarded to our RenderTick notification to allow subscribers to do rendering.
 
void OnEndPrepareRender () override
 OnEndPrepareRender is forwarded to our WaitForRender notification to wait for any pending work.
 
void OnResolutionChanged (uint32_t width, uint32_t height) override
 
void OnDpiScaleFactorChanged (float dpiScaleFactor) override
 
void ConnectSizeChangedHandler (SizeChangedEvent::Handler &handler)
 
void ConnectDpiScalingFactorChangedHandler (ScalarChangedEvent::Handler &handler)
 
void ConnectViewMatrixChangedHandler (MatrixChangedEvent::Handler &handler, ViewType viewType=ViewType::Default)
 Notifies consumers when the view matrix has changed.
 
void ConnectProjectionMatrixChangedHandler (MatrixChangedEvent::Handler &handler, ViewType viewType=ViewType::Default)
 Notifies consumers when the projection matrix has changed.
 
void ConnectSceneChangedHandler (SceneChangedEvent::Handler &handler)
 Notifies consumers when the render scene has changed.
 
void ConnectCurrentPipelineChangedHandler (PipelineChangedEvent::Handler &handler)
 Notifies consumers when the current pipeline associated with our window has changed.
 
void ConnectDefaultViewChangedHandler (ViewChangedEvent::Handler &handler)
 Notifies consumers when the default view has changed.
 
void ConnectAboutToBeDestroyedHandler (ViewportIdEvent::Handler &handler)
 Notifies consumers when this ViewportContext is about to be destroyed.
 
const AZ::Matrix4x4 & GetCameraViewMatrix () const override
 
AZ::Matrix3x4 GetCameraViewMatrixAsMatrix3x4 () const override
 
void SetCameraViewMatrix (const AZ::Matrix4x4 &matrix) override
 
const AZ::Matrix4x4 & GetCameraProjectionMatrix () const override
 
void SetCameraProjectionMatrix (const AZ::Matrix4x4 &matrix) override
 
AZ::Transform GetCameraTransform () const override
 
void SetCameraTransform (const AZ::Transform &transform) override
 

Friends

class ViewportContextManager
 

Detailed Description

ViewportContext wraps a native window and represents a minimal viewport in which a scene is rendered on-screen. ViewportContexts are registered on creation to allow consumers to listen to notifications and manage the view stack for a given viewport.

Constructor & Destructor Documentation

◆ ViewportContext()

AZ::RPI::ViewportContext::ViewportContext ( ViewportContextManager manager,
AzFramework::ViewportId  id,
const AZ::Name &  name,
RHI::Device device,
AzFramework::NativeWindowHandle  nativeWindow,
ScenePtr  renderScene 
)

Used by ViewportContextManager, use AZ::Interface<ViewportContextRequestsInterface>::Get()->CreateViewportContext to create a viewport context from outside of the ViewportContextManager.

Member Function Documentation

◆ ConnectDpiScalingFactorChangedHandler()

void AZ::RPI::ViewportContext::ConnectDpiScalingFactorChangedHandler ( ScalarChangedEvent::Handler &  handler)

Notifies consumers when the viewport DPI scaling ratio has changed. Alternatively, connect to ViewportContextNotificationsBus and listen to ViewportContextNotifications::OnViewportDpiScalingChanged.

◆ ConnectSizeChangedHandler()

void AZ::RPI::ViewportContext::ConnectSizeChangedHandler ( SizeChangedEvent::Handler &  handler)

Notifies consumers when the viewport size has changed. Alternatively, connect to ViewportContextNotificationsBus and listen to ViewportContextNotifications::OnViewportSizeChanged.

◆ GetDefaultView()

ViewPtr AZ::RPI::ViewportContext::GetDefaultView ( )

Gets the default view associated with this ViewportContext. Alternatively, use AZ::RPI::ViewportContextRequests::Get()->GetCurrentViewGroup()->GetView().

◆ GetDpiScalingFactor()

float AZ::RPI::ViewportContext::GetDpiScalingFactor ( ) const

Gets the screen DPI scaling factor. This value is cached and updated on-demand, so may be efficiently queried.

See also
AzFramework::WindowRequests::GetDpiScaleFactor

◆ GetName()

AZ::Name AZ::RPI::ViewportContext::GetName ( ) const

Gets the current name of this ViewportContext. This name is used to tie this ViewportContext to its View stack, and ViewportContexts may be renamed via AZ::RPI::ViewportContextRequests::Get()->RenameViewportContext(...).

◆ GetStereoscopicView()

ViewPtr AZ::RPI::ViewportContext::GetStereoscopicView ( AZ::RPI::ViewType  viewType)

Gets the stereoscopic view associated with this ViewportContext. Alternatively, use AZ::RPI::ViewportContextRequests::Get()->GetCurrentViewGroup()->GetView(AZ::RPI::ViewType).

◆ GetViewGroup()

ViewGroupPtr AZ::RPI::ViewportContext::GetViewGroup ( )

Gets the view group associated with this ViewportContext. Alternatively, use AZ::RPI::ViewportContextRequests::Get()->GetCurrentViewGroup().

◆ GetViewportSize()

AzFramework::WindowSize AZ::RPI::ViewportContext::GetViewportSize ( ) const

Gets the current size of the viewport. This value is cached and updated on-demand, so may be efficiently queried.

◆ RenderTick()

void AZ::RPI::ViewportContext::RenderTick ( )

Runs one simulation and render tick and renders a frame to this viewport's window.

Note
This is likely to be replaced by a tick management system in the RPI.

◆ SetRenderScene()

void AZ::RPI::ViewportContext::SetRenderScene ( ScenePtr  scene)

Sets the root scene associated with this viewport. This does not provide a default render pipeline, one must be provided to enable rendering.


The documentation for this class was generated from the following file: