Foundation
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Foundation::Rendering::RenderApplication Class Referenceabstract

Template base class for rendering applications. More...

#include <Application.hpp>

Inheritance diagram for Foundation::Rendering::RenderApplication:
Foundation::Native::NativeApplication Examples::ImGuiDemoApp Examples::MandelbrotComputeDemoApp Examples::ManyPassDemoApp Examples::MipGenerationApp Examples::SDFDemoApp Examples::TexturePoolApp Examples::TriangleDemoApp Examples::TriangleDemoApp Examples::Win32_ScreenCaptureApp ModelViewer::App

Classes

struct  FrameTiming
 Rolling frame timing information for performance measurements. More...
 

Public Member Functions

template<typename Backend , typename... Args>
void Initialize (ApplicationInitDesc const &desc={}, Args &&... args)
 Initialize the application with the specified RHI backend.
 
RHIExtent2D GetFramebufferSize () const
 Retrieve the framebuffer size of the current window.
 
FrameTiming GetTiming () const
 Retrieve the timing information of the last frame.
 
RendererGetRenderer () const
 Retrieve the underlying Renderer instance.
 
RHISwapchainGetSwapchain () const
 Retrieve the current RHISwapchain instance.
 
Native::NativeWindowGetNativeWindow ()
 Retrieve the current NativeWindow instance.
 
AllocatorGetAllocator ()
 Retrieve the allocator used for general application allocations.
 
AllocatorGetRendererAllocator ()
 Retrieve the allocator used for renderer allocations.
 
void RunForever ()
 Start the Render thread and run the application loop indefinitely, until the window is closed or the application is exited.
 
void WaitForFrame ()
 Wait for the render thread to start, or the next frame to be rendered.
 
void ResetRendererOnNextFrame ()
 Reset the renderer on the next frame, calling OnRendererSetup internally.
 
void Shutdown ()
 Flag the application to exit.
 
- Public Member Functions inherited from Foundation::Native::NativeApplication
template<typename T = float>
T GetApplicationTime () const
 Returns a high-resolution time in seconds since the application started.
 
size_t GetApplicationCounter () const
 Returns a high-resolution time in nanoseconds since the application started.
 
 NativeApplication ()
 
virtual ~NativeApplication ()
 

Protected Member Functions

virtual void OnDeviceSetup ()
 Actions to take after device specific resources has been set up.
 
virtual void OnBeforeFrame ()
 Action to take before each frame is executed.
 
virtual void OnAfterFrame ()
 Action to take after each frame is executed.
 
virtual void OnRendererSetup ()=0
 Set up the renderer by creating passes, resources, and other configurations.
 
virtual void OnRendererPostSetup ()
 Action to take after the renderer has been set up.
 
virtual void OnApplicationTick ()
 Action to take on every application tick.
 

Protected Attributes

ApplicationInitDesc mDesc
 
DefaultAllocator mAlloc
 
DefaultAllocator mAllocRenderer
 
Native::NativeWindow mWindow
 
UniquePtr< RHIApplicationmRHI
 
RHIApplicationScopedObjectHandle< RHIDevicemDevice
 
RHIDeviceScopedObjectHandle< RHISwapchainmSwapchain
 
UniquePtr< RenderermRenderer
 
FrameTiming mTiming {}
 
Async::Thread mRenderThread
 
Async::Condition mRenderFrame
 
Async::Mutex mRenderMutex
 
bool mRenderThreadReset {false}
 
bool mRenderThreadStarted {false}
 
bool mAppShouldClose {false}
 

Private Member Functions

void Execute ()
 
void CreateSwapchain ()
 
void InitializeInternal ()
 
void InitializeRenderer ()
 
void RenderWorker ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Foundation::Native::NativeApplication
static NativeWindow CreateNativeWindow (uint32_t width, uint32_t height, const char *title)
 Creates a window with the specified width, height, and title.
 

Detailed Description

Template base class for rendering applications.

Member Function Documentation

◆ CreateSwapchain()

void RenderApplication::CreateSwapchain ( )
private

◆ Execute()

void RenderApplication::Execute ( )
private

◆ GetAllocator()

Allocator * Foundation::Rendering::RenderApplication::GetAllocator ( )
inline

Retrieve the allocator used for general application allocations.

Examples
MipGeneration.cpp, and TexturePool.cpp.

◆ GetFramebufferSize()

RHIExtent2D Foundation::Rendering::RenderApplication::GetFramebufferSize ( ) const
inline

Retrieve the framebuffer size of the current window.

◆ GetNativeWindow()

Native::NativeWindow * Foundation::Rendering::RenderApplication::GetNativeWindow ( )
inline

Retrieve the current NativeWindow instance.

Examples
ImGui.cpp, and MipGeneration.cpp.

◆ GetRenderer()

Renderer * Foundation::Rendering::RenderApplication::GetRenderer ( ) const
inline

Retrieve the underlying Renderer instance.

◆ GetRendererAllocator()

Allocator * Foundation::Rendering::RenderApplication::GetRendererAllocator ( )
inline

Retrieve the allocator used for renderer allocations.

◆ GetSwapchain()

RHISwapchain * Foundation::Rendering::RenderApplication::GetSwapchain ( ) const
inline

Retrieve the current RHISwapchain instance.

◆ GetTiming()

FrameTiming Foundation::Rendering::RenderApplication::GetTiming ( ) const
inline

Retrieve the timing information of the last frame.

◆ Initialize()

template<typename Backend , typename... Args>
void Foundation::Rendering::RenderApplication::Initialize ( ApplicationInitDesc const desc = {},
Args &&...  args 
)
inline

Initialize the application with the specified RHI backend.

Note
This must be called before RunForever().
Examples
ImGui.cpp, MandelbrotCompute.cpp, ManyPass.cpp, MeshShader.cpp, MipGeneration.cpp, SDF2D.cpp, TexturePool.cpp, and Triangle.cpp.

◆ InitializeInternal()

void RenderApplication::InitializeInternal ( )
private

◆ InitializeRenderer()

void RenderApplication::InitializeRenderer ( )
private

◆ OnAfterFrame()

virtual void Foundation::Rendering::RenderApplication::OnAfterFrame ( )
inlineprotectedvirtual

Action to take after each frame is executed.

This is run on the Render thread.

This is invoked after the renderer has submitted all passes, but before the next frame could be rendered.

Implementation may leave this empty if no action is needed.

Note
This should not be directly called.

◆ OnApplicationTick()

virtual void Foundation::Rendering::RenderApplication::OnApplicationTick ( )
inlineprotectedvirtual

Action to take on every application tick.

Note
This is run on the main thread, i.e. the calling thread of RunForever. No synchronization is performed on a per-frame basis. You may want to use WaitForFrame() to synchronize with the render thread if needed.
This runs in a tight loop in RunForever(), and is only run after the Render thread has started - i.e. after OnDeviceSetup() and OnRendererSetup() has been called, in that order.

Implementation may leave this empty if no action is needed.

Note
This should not be directly called.

Reimplemented in Examples::Win32_ScreenCaptureApp, and ModelViewer::App.

◆ OnBeforeFrame()

virtual void Foundation::Rendering::RenderApplication::OnBeforeFrame ( )
inlineprotectedvirtual

Action to take before each frame is executed.

This is run on the Render thread.

This is invoked before the renderer executes the passes, but after the current frame is acquired from the swapchain.

Implementation may leave this empty if no action is needed.

Note
This should not be directly called.

Reimplemented in Examples::ImGuiDemoApp, Examples::MipGenerationApp, and ModelViewer::App.

◆ OnDeviceSetup()

virtual void Foundation::Rendering::RenderApplication::OnDeviceSetup ( )
inlineprotectedvirtual

Actions to take after device specific resources has been set up.

This is run on the main thread, i.e. the calling thread of Initialize(), after the device and swapchain is created, but before the Renderer is created.

Implementation may leave this empty if no action is needed.

Note
This should not be directly called.

Reimplemented in Examples::ImGuiDemoApp, Examples::MipGenerationApp, Examples::TexturePoolApp, Examples::Win32_ScreenCaptureApp, and ModelViewer::App.

◆ OnRendererPostSetup()

virtual void Foundation::Rendering::RenderApplication::OnRendererPostSetup ( )
inlineprotectedvirtual

Action to take after the renderer has been set up.

This is run on the Render thread, immediately after OnRendererSetup has been called, and before the first frame is rendered.

Implementation may leave this empty if no action is needed.

Note
This should not be directly called.

Reimplemented in Examples::MipGenerationApp, and ModelViewer::App.

◆ OnRendererSetup()

virtual void Foundation::Rendering::RenderApplication::OnRendererSetup ( )
protectedpure virtual

Set up the renderer by creating passes, resources, and other configurations.

Note
This is where you should set up your rendering pipeline.
This is invoked by InitializeRenderer on the Render thread, within a Renderer::BeginSetup and Renderer::EndSetup clause, thus invoking Renderer::BeginSetup, Renderer::EndSetup here again is incorrect. and will be called again if the swapchain is recreated.
This MUST be implemented by the subclass.
This should not be directly called.

Implemented in Examples::ImGuiDemoApp, Examples::MandelbrotComputeDemoApp, Examples::ManyPassDemoApp, Examples::TriangleDemoApp, Examples::MipGenerationApp, Examples::SDFDemoApp, Examples::TexturePoolApp, Examples::TriangleDemoApp, Examples::Win32_ScreenCaptureApp, and ModelViewer::App.

◆ RenderWorker()

void RenderApplication::RenderWorker ( )
private

◆ ResetRendererOnNextFrame()

void RenderApplication::ResetRendererOnNextFrame ( )

Reset the renderer on the next frame, calling OnRendererSetup internally.

Note
This can be called from any thread, and will be executed on the Render thread on the next frame of its work.

◆ RunForever()

void RenderApplication::RunForever ( )

Start the Render thread and run the application loop indefinitely, until the window is closed or the application is exited.

A Window will be created if Initialize was called with desc.present == true.

Examples
ImGui.cpp, MandelbrotCompute.cpp, ManyPass.cpp, MeshShader.cpp, MipGeneration.cpp, SDF2D.cpp, TexturePool.cpp, and Triangle.cpp.

◆ Shutdown()

void RenderApplication::Shutdown ( )

Flag the application to exit.

Note
This can be called from any thread.
This does not immediately terminate the application. At the end of the current tick of the main loop in RunForever(), the application will exit gracefully if this is called, or the main window is closed.

◆ WaitForFrame()

void RenderApplication::WaitForFrame ( )

Wait for the render thread to start, or the next frame to be rendered.

Member Data Documentation

◆ mAlloc

DefaultAllocator Foundation::Rendering::RenderApplication::mAlloc
protected

◆ mAllocRenderer

DefaultAllocator Foundation::Rendering::RenderApplication::mAllocRenderer
protected

◆ mAppShouldClose

bool Foundation::Rendering::RenderApplication::mAppShouldClose {false}
protected

◆ mDesc

ApplicationInitDesc Foundation::Rendering::RenderApplication::mDesc
protected

◆ mDevice

RHIApplicationScopedObjectHandle<RHIDevice> Foundation::Rendering::RenderApplication::mDevice
protected

◆ mRenderer

UniquePtr<Renderer> Foundation::Rendering::RenderApplication::mRenderer
protected

◆ mRenderFrame

Async::Condition Foundation::Rendering::RenderApplication::mRenderFrame
protected

◆ mRenderMutex

Async::Mutex Foundation::Rendering::RenderApplication::mRenderMutex
protected

◆ mRenderThread

Async::Thread Foundation::Rendering::RenderApplication::mRenderThread
protected

◆ mRenderThreadReset

bool Foundation::Rendering::RenderApplication::mRenderThreadReset {false}
protected

◆ mRenderThreadStarted

bool Foundation::Rendering::RenderApplication::mRenderThreadStarted {false}
protected

◆ mRHI

UniquePtr<RHIApplication> Foundation::Rendering::RenderApplication::mRHI
protected

◆ mSwapchain

RHIDeviceScopedObjectHandle<RHISwapchain> Foundation::Rendering::RenderApplication::mSwapchain
protected

◆ mTiming

FrameTiming Foundation::Rendering::RenderApplication::mTiming {}
protected

◆ mWindow

Native::NativeWindow Foundation::Rendering::RenderApplication::mWindow
protected

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