Nameless Engine
|
#include <ShaderCpuWriteResourceManager.h>
Classes | |
struct | Resources |
Public Member Functions | |
ShaderCpuWriteResourceManager (const ShaderCpuWriteResourceManager &)=delete | |
ShaderCpuWriteResourceManager & | operator= (const ShaderCpuWriteResourceManager &)=delete |
~ShaderCpuWriteResourceManager () | |
std::variant< ShaderCpuWriteResourceUniquePtr, Error > | createShaderCpuWriteResource (const std::string &sShaderResourceName, const std::string &sResourceAdditionalInfo, size_t iResourceSizeInBytes, const std::unordered_set< Pipeline * > &pipelinesToUse, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource) |
void | updateResources (size_t iCurrentFrameResourceIndex) |
void | markResourceAsNeedsUpdate (ShaderCpuWriteResource *pResourceToDestroy) |
std::pair< std::recursive_mutex, Resources > * | getResources () |
Private Member Functions | |
ShaderCpuWriteResourceManager (Renderer *pRenderer) | |
std::variant< ShaderCpuWriteResourceUniquePtr, Error > | handleResourceCreation (std::variant< std::unique_ptr< ShaderCpuWriteResource >, Error > result) |
void | destroyResource (ShaderCpuWriteResource *pResourceToDestroy) |
Private Attributes | |
Renderer * | pRenderer = nullptr |
std::pair< std::recursive_mutex, Resources > | mtxShaderCpuWriteResources |
Friends | |
class | Renderer |
class | ShaderCpuWriteResourceUniquePtr |
Stores all shader resources with CPU write access.
ne::ShaderCpuWriteResourceManager::~ShaderCpuWriteResourceManager | ( | ) |
Makes sure that no resource exists.
|
private |
Initializes manager.
pRenderer |
std::variant< ShaderCpuWriteResourceUniquePtr, Error > ne::ShaderCpuWriteResourceManager::createShaderCpuWriteResource | ( | const std::string & | sShaderResourceName, |
const std::string & | sResourceAdditionalInfo, | ||
size_t | iResourceSizeInBytes, | ||
const std::unordered_set< Pipeline * > & | pipelinesToUse, | ||
const std::function< void *()> & | onStartedUpdatingResource, | ||
const std::function< void()> & | onFinishedUpdatingResource | ||
) |
Creates a new render-specific shader resource.
sShaderResourceName | Name of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing). |
sResourceAdditionalInfo | Additional text that we will append to created resource name (used for logging). |
iResourceSizeInBytes | Size of the data that this resource will contain. Note that this size will most likely be padded to be a multiple of 256 because of the hardware requirement for shader constant buffers. |
pipelinesToUse | Pipelines that use shader/parameters we are referencing. |
onStartedUpdatingResource | Function 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. |
onFinishedUpdatingResource | Function that will be called when finished updating (usually used for unlocking resource data mutex). |
|
private |
Called by shader CPU write resource unique pointers to destroy the specified resource because it will no longer be used.
pResourceToDestroy | Resource to destroy. |
std::pair< std::recursive_mutex, ShaderCpuWriteResourceManager::Resources > * ne::ShaderCpuWriteResourceManager::getResources | ( | ) |
Returns internal resources.
|
private |
Processes resource creation.
result | Result of resource creation function. |
void ne::ShaderCpuWriteResourceManager::markResourceAsNeedsUpdate | ( | ShaderCpuWriteResource * | pResourceToDestroy | ) |
Marks resource as "needs update", this will cause resource's update callback function to be later called multiple times.
pResourceToDestroy | Resource to mark as "needs update". |
void ne::ShaderCpuWriteResourceManager::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.
iCurrentFrameResourceIndex | Index of the frame resource that will be used to submit the next frame. |
|
private |
Shader CPU write resources.
|
private |
Renderer that owns this manager.