Nameless Engine
|
#include <ShaderLightArray.h>
Classes | |
struct | Resources |
Public Member Functions | |
~ShaderLightArray () | |
std::variant< std::unique_ptr< ShaderLightArraySlot >, Error > | reserveNewSlot (Node *pSpawnedOwnerLightNode, size_t iDataSizeInBytes, const std::function< void *()> &startUpdateCallback, const std::function< void()> &finishUpdateCallback) |
std::pair< std::recursive_mutex, Resources > * | getInternalResources () |
std::string | getShaderResourceName () const |
Static Public Member Functions | |
static std::unique_ptr< ShaderLightArray > | create (Renderer *pRenderer, const std::string &sShaderLightResourceName, const std::function< void(size_t)> &onSizeChanged, const std::optional< std::pair< std::function< void(size_t)>, std::string > > &optionalOnLightsInCameraFrustumCulled) |
Private Member Functions | |
ShaderLightArray (Renderer *pRenderer, const std::string &sShaderLightResourceName, const std::function< void(size_t)> &onSizeChanged, const std::optional< std::function< void(size_t)> > &optionalCallbackOnLightsInCameraFrustumCulled, const std::string &sIndicesLightsInFrustumShaderResourceName="") | |
void | onLightsInCameraFrustumCulled (size_t iCurrentFrameResourceIndex) |
std::optional< Error > | recreateArray (bool bIsInitialization=false) |
void | updateSlotsMarkedAsNeedsUpdate (size_t iCurrentFrameResourceIndex) |
std::optional< Error > | updateBindingsInAllPipelines () |
std::optional< Error > | updatePipelineBinding (Pipeline *pPipeline) |
void | freeSlot (ShaderLightArraySlot *pSlot) |
void | markSlotAsNeedsUpdate (ShaderLightArraySlot *pSlot) |
Private Attributes | |
std::pair< std::recursive_mutex, Resources > | mtxResources |
Renderer * | pRenderer = nullptr |
size_t | iElementSizeInBytes = 0 |
const std::optional< std::function< void(size_t)> > | optionalCallbackOnLightsInCameraFrustumCulled |
const std::function< void(size_t)> | onSizeChanged |
const std::string | sShaderLightResourceName |
Friends | |
class | ShaderLightArraySlot |
class | LightingShaderResourceManager |
class | Renderer |
Manages arrays (defined in shaders) related to lighting and allows modifying the array data from the CPU side.
ne::ShaderLightArray::~ShaderLightArray | ( | ) |
Makes sure there are no active slots.
|
private |
Creates a new array.
pRenderer | Used renderer. |
sShaderLightResourceName | Name of the resource (specified in shader code) that this array should bind to. |
onSizeChanged | Callback that will be called after array's size changed with the current array size passed as the only argument. |
optionalCallbackOnLightsInCameraFrustumCulled | If specified will be called after array of indices to lights in camera frustum changed (indices changed) with the current frame resource index as the only argument, otherwise (if empty) GPU resources for such array will not be created and this callback will never be called. |
sIndicesLightsInFrustumShaderResourceName | If callback for culled lights in camera frustum is specified stores name of the shader resource used for the array of indices of non-culled lights. |
|
static |
Creates a new array.
pRenderer | Used renderer. |
sShaderLightResourceName | Name of the resource (specified in shader code) that this array should bind to. |
onSizeChanged | Callback that will be called after array's size changed with the current array size passed as the only argument. |
optionalOnLightsInCameraFrustumCulled | A pair of callback and shader resource name that are used for array that stores indices of light sources in camera's frustum. If specified the callback will be called after array of indices to lights in camera frustum changed (indices changed) with the current frame resource index as the only argument, otherwise (if empty) GPU resources for such array will not be created and this callback will never be called. |
|
private |
Called by slot-objects to notify the array that a slot is no longer used.
pSlot | Slot that is being destroyed. |
std::pair< std::recursive_mutex, ShaderLightArray::Resources > * ne::ShaderLightArray::getInternalResources | ( | ) |
Returns internal resources of this array.
std::string ne::ShaderLightArray::getShaderResourceName | ( | ) | const |
Returns name of the resource (specified in shader code) that this array is binded to.
|
private |
Queues the specified slot's data to be updated later.
pSlot | Slot to update later. |
|
private |
Called after the renderer culls lights (so that indices of lights sources in camera's frustum change) to copy the new (modified) data to the GPU.
iCurrentFrameResourceIndex | Index of the frame resource that will be used to submit the next frame. |
|
private |
(Re)creates GPU resources to hold the current number of active slots and updates all previously existing slots.
bIsInitialization | true if we are creating resources for the first time and there are no active slots at the moment but since we need valid (non nullptr resources) we will create resources that will hold 1 slot, false otherwise. |
std::variant< std::unique_ptr< ShaderLightArraySlot >, Error > ne::ShaderLightArray::reserveNewSlot | ( | Node * | pSpawnedOwnerLightNode, |
size_t | iDataSizeInBytes, | ||
const std::function< void *()> & | startUpdateCallback, | ||
const std::function< void()> & | finishUpdateCallback | ||
) |
Reserves a new slot in the array to store some data.
pSpawnedOwnerLightNode | Spawned light node that requests the slot. Used for light culling. |
iDataSizeInBytes | Size of the data that you want to store in the slot in bytes. |
startUpdateCallback | Callback that will be called after you mark your slot as "needs update" when the engine is ready to copy the data to the GPU. You must return a pointer which data will be copied. |
finishUpdateCallback | Callback that will be called after the copying of your new data is finished. |
|
private |
Binds the underlying GPU resource to descriptors of pipelines that use this array in shaders.
|
private |
Goes through all slots that are marked as "needs update" and copies their new data to the GPU resource.
iCurrentFrameResourceIndex | Index of the frame resource that will be used to submit the next frame. |
|
private |
Size of one array element in bytes.
|
private |
Internal data.
|
private |
Callback that will be called after array's size changed with the current array size passed as the only argument.
|
private |
If specified will be called after array of indices to lights in camera frustum changed (indices changed) with the current frame resource index as the only argument, otherwise (if empty) GPU resources for such array will not be created and this callback will never be called.
|
private |
Used renderer.
|
private |
Name of the resource (specified in shader code) that this array should bind to.