Nameless Engine
Loading...
Searching...
No Matches
ne::FrameResourceManager Class Reference

#include <FrameResourceManager.h>

Classes

struct  CurrentFrameResource
 

Public Member Functions

 FrameResourceManager (const FrameResourceManager &)=delete
 
FrameResourceManageroperator= (const FrameResourceManager &)=delete
 
std::pair< std::recursive_mutex, CurrentFrameResource > * getCurrentFrameResource ()
 
std::pair< std::recursive_mutex *, std::vector< FrameResource * > > getAllFrameResources ()
 

Static Public Member Functions

static constexpr unsigned int getFrameResourceCount ()
 
static std::variant< std::unique_ptr< FrameResourceManager >, Errorcreate (Renderer *pRenderer)
 

Private Member Functions

 FrameResourceManager (Renderer *pRenderer)
 
void switchToNextFrameResource ()
 

Static Private Member Functions

static std::array< std::unique_ptr< FrameResource >, iFrameResourceCountcreateRenderDependentFrameResources (Renderer *pRenderer)
 

Private Attributes

RendererpRenderer = nullptr
 
std::pair< std::recursive_mutex, CurrentFrameResourcemtxCurrentFrameResource
 
std::array< std::unique_ptr< FrameResource >, iFrameResourceCountvFrameResources
 

Static Private Attributes

static constexpr unsigned int iFrameResourceCount = 2
 

Friends

class Renderer
 
class VulkanRenderer
 

Detailed Description

Controls GPU resources (mostly constant buffers) that contain frame-specific data.

Used to not wait for the GPU to finish drawing a frame on the CPU side and instead continue drawing another frame (on the CPU side) without touching resources that can be in use by the GPU because it's drawing the previous frame.

Constructor & Destructor Documentation

◆ FrameResourceManager()

ne::FrameResourceManager::FrameResourceManager ( Renderer pRenderer)
private

Creates uninitialized manager.

Parameters
pRendererRenderer that owns this manager.

Member Function Documentation

◆ create()

std::variant< std::unique_ptr< FrameResourceManager >, Error > ne::FrameResourceManager::create ( Renderer pRenderer)
static

Creates a new frame resources manager.

Parameters
pRendererRenderer that owns this manager.
Returns
Error if something went wrong, otherwise created manager.

◆ createRenderDependentFrameResources()

std::array< std::unique_ptr< FrameResource >, FrameResourceManager::getFrameResourceCount()> ne::FrameResourceManager::createRenderDependentFrameResources ( Renderer pRenderer)
staticprivate

Creates a render-specific frame resources depending on the renderer used.

Parameters
pRendererUsed renderer.
Returns
Render-specific frame resources

◆ getAllFrameResources()

std::pair< std::recursive_mutex *, std::vector< FrameResource * > > ne::FrameResourceManager::getAllFrameResources ( )

Returns all frame resources.

Remarks
Generally used to reference internal resources of all frame resources.
Do not delete (free) returned pointers.
Returns
All frame resources (use with mutex).

◆ getCurrentFrameResource()

std::pair< std::recursive_mutex, FrameResourceManager::CurrentFrameResource > * ne::FrameResourceManager::getCurrentFrameResource ( )

Returns currently used frame resource. Must be used with mutex.

Returns
Current frame resource.

◆ getFrameResourceCount()

static constexpr unsigned int ne::FrameResourceManager::getFrameResourceCount ( )
inlinestaticconstexpr

Returns the number of used frame resources.

Returns
Number of frame resources being used.

◆ switchToNextFrameResource()

void ne::FrameResourceManager::switchToNextFrameResource ( )
private

Uses mutex from getCurrentFrameResource to switch to the next available frame resource.

Remarks
After this function is finished calls to getCurrentFrameResource will return next frame resource.
Next frame resource (that we switched to) can still be used by the GPU, it's up to the caller to check whether the frame resource is used by the GPU or not.

Member Data Documentation

◆ iFrameResourceCount

constexpr unsigned int ne::FrameResourceManager::iFrameResourceCount = 2
staticconstexprprivate

Number of frames "in-flight" that the CPU can submit to the GPU without waiting.

◆ mtxCurrentFrameResource

std::pair<std::recursive_mutex, CurrentFrameResource> ne::FrameResourceManager::mtxCurrentFrameResource
private

Points to the currently used item from vFrameResources.

◆ pRenderer

Renderer* ne::FrameResourceManager::pRenderer = nullptr
private

Renderer that owns this manager.

◆ vFrameResources

std::array<std::unique_ptr<FrameResource>, iFrameResourceCount> ne::FrameResourceManager::vFrameResources
private

Array of frame-specific resources, all contain the same data.


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