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

#include <ShaderCpuWriteResourceBindingManager.h>

Classes

struct  Resources
 

Public Member Functions

 ShaderCpuWriteResourceBindingManager (const ShaderCpuWriteResourceBindingManager &)=delete
 
ShaderCpuWriteResourceBindingManageroperator= (const ShaderCpuWriteResourceBindingManager &)=delete
 
 ~ShaderCpuWriteResourceBindingManager ()
 
std::variant< ShaderCpuWriteResourceBindingUniquePtr, ErrorcreateShaderCpuWriteResource (const std::string &sShaderResourceName, const std::string &sResourceAdditionalInfo, size_t iResourceDataSizeInBytes, const std::unordered_set< Pipeline * > &pipelinesToUse, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource)
 
void updateResources (size_t iCurrentFrameResourceIndex)
 
void markResourceAsNeedsUpdate (ShaderCpuWriteResourceBinding *pResourceToDestroy)
 
std::pair< std::recursive_mutex, Resources > * getResources ()
 

Private Member Functions

 ShaderCpuWriteResourceBindingManager (Renderer *pRenderer)
 
std::variant< ShaderCpuWriteResourceBindingUniquePtr, ErrorhandleResourceCreation (std::variant< std::unique_ptr< ShaderCpuWriteResourceBinding >, Error > result)
 
void destroyResource (ShaderCpuWriteResourceBinding *pResourceToDestroy)
 

Private Attributes

RendererpRenderer = nullptr
 
std::pair< std::recursive_mutex, ResourcesmtxShaderCpuWriteResources
 

Friends

class Renderer
 
class ShaderCpuWriteResourceBindingUniquePtr
 

Detailed Description

Stores all shader resource bindings that have CPU write access.

Constructor & Destructor Documentation

◆ ~ShaderCpuWriteResourceBindingManager()

ne::ShaderCpuWriteResourceBindingManager::~ShaderCpuWriteResourceBindingManager ( )

Makes sure that no resource exists.

◆ ShaderCpuWriteResourceBindingManager()

ne::ShaderCpuWriteResourceBindingManager::ShaderCpuWriteResourceBindingManager ( Renderer pRenderer)
private

Initializes manager.

Parameters
pRenderer

Member Function Documentation

◆ createShaderCpuWriteResource()

std::variant< ShaderCpuWriteResourceBindingUniquePtr, Error > ne::ShaderCpuWriteResourceBindingManager::createShaderCpuWriteResource ( const std::string &  sShaderResourceName,
const std::string &  sResourceAdditionalInfo,
size_t  iResourceDataSizeInBytes,
const std::unordered_set< Pipeline * > &  pipelinesToUse,
const std::function< void *()> &  onStartedUpdatingResource,
const std::function< void()> &  onFinishedUpdatingResource 
)

Creates a new render-specific shader resource.

Parameters
sShaderResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
sResourceAdditionalInfoAdditional text that we will append to created resource name (used for logging).
iResourceDataSizeInBytesSize of the data that this resource will contain.
pipelinesToUsePipelines that use shader/parameters we are referencing.
onStartedUpdatingResourceFunction that will be called when started updating resource data. Function returns pointer to data of the specified resource data size that needs to be copied into the resource.
onFinishedUpdatingResourceFunction that will be called when finished updating (usually used for unlocking resource data mutex).
Returns
Error if something went wrong, otherwise created shader resource.

◆ destroyResource()

void ne::ShaderCpuWriteResourceBindingManager::destroyResource ( ShaderCpuWriteResourceBinding pResourceToDestroy)
private

Called by shader CPU write resource unique pointers to destroy the specified resource because it will no longer be used.

Parameters
pResourceToDestroyResource to destroy.

◆ getResources()

std::pair< std::recursive_mutex, ShaderCpuWriteResourceBindingManager::Resources > * ne::ShaderCpuWriteResourceBindingManager::getResources ( )

Returns internal resources.

Returns
Internal resources.

◆ handleResourceCreation()

std::variant< ShaderCpuWriteResourceBindingUniquePtr, Error > ne::ShaderCpuWriteResourceBindingManager::handleResourceCreation ( std::variant< std::unique_ptr< ShaderCpuWriteResourceBinding >, Error result)
private

Processes resource creation.

Parameters
resultResult of resource creation function.
Returns
Result of resource creation.

◆ markResourceAsNeedsUpdate()

void ne::ShaderCpuWriteResourceBindingManager::markResourceAsNeedsUpdate ( ShaderCpuWriteResourceBinding pResourceToDestroy)

Marks resource as "needs update", this will cause resource's update callback function to be later called multiple times.

Parameters
pResourceToDestroyResource to mark as "needs update".

◆ updateResources()

void ne::ShaderCpuWriteResourceBindingManager::updateResources ( size_t  iCurrentFrameResourceIndex)

Updates all resources marked as "needs update" and copies new (updated) data to the GPU resource of the specified frame resource.

Parameters
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

Member Data Documentation

◆ mtxShaderCpuWriteResources

std::pair<std::recursive_mutex, Resources> ne::ShaderCpuWriteResourceBindingManager::mtxShaderCpuWriteResources
private

Shader CPU write resources.

◆ pRenderer

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

Renderer that owns this manager.


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