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

#include <GlslShaderTextureResourceBinding.h>

Inheritance diagram for ne::GlslShaderTextureResourceBinding:
ne::ShaderTextureResourceBinding ne::ShaderResourceBindingBase

Classes

struct  PushConstantIndices
 

Public Member Functions

std::string getPathToTextureResource ()
 
void copyResourceIndexToPushConstants (PipelineShaderConstantsManager *pPushConstantsManager, VulkanPipeline *pUsedPipeline)
 
virtual std::optional< ErroruseNewTexture (std::unique_ptr< TextureHandle > pTextureToUse) override
 
virtual std::optional< ErrorchangeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse) override
 
virtual std::optional< ErroruseNewTexture (std::unique_ptr< TextureHandle > pTextureToUse)=0
 
- Public Member Functions inherited from ne::ShaderResourceBindingBase
virtual std::optional< ErrorchangeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse)=0
 
std::string getShaderResourceName () const
 

Protected Member Functions

 GlslShaderTextureResourceBinding (const std::string &sResourceName, std::unique_ptr< TextureHandle > pTextureToUse, std::unordered_map< VulkanPipeline *, PushConstantIndices > pushConstantIndices)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources () override
 
- Protected Member Functions inherited from ne::ShaderTextureResourceBinding
 ShaderTextureResourceBinding (const std::string &sShaderResourceName)
 
- Protected Member Functions inherited from ne::ShaderResourceBindingBase
 ShaderResourceBindingBase (const std::string &sShaderResourceName)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources ()=0
 

Static Private Member Functions

static std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Errorcreate (const std::string &sShaderResourceName, const std::unordered_set< Pipeline * > &pipelinesToUse, std::unique_ptr< TextureHandle > pTextureToUse)
 
static std::variant< std::unique_ptr< ShaderArrayIndex >, ErrorgetTextureIndexInShaderArray (const std::string &sShaderResourceName, VulkanPipeline *pPipelineToLookIn)
 
static std::optional< ErrorbindTextureToShaderDescriptorArray (const std::string &sShaderResourceName, VulkanPipeline *pPipelineWithDescriptors, VkImageView pTextureView, unsigned int iIndexIntoShaderArray)
 

Private Attributes

std::pair< std::mutex, std::unique_ptr< TextureHandle > > mtxUsedTexture
 
std::pair< std::recursive_mutex, std::unordered_map< VulkanPipeline *, PushConstantIndices > > mtxPushConstantIndices
 

Friends

class ShaderTextureResourceBindingManager
 

Detailed Description

References some texture from shader code.

Constructor & Destructor Documentation

◆ GlslShaderTextureResourceBinding()

ne::GlslShaderTextureResourceBinding::GlslShaderTextureResourceBinding ( const std::string &  sResourceName,
std::unique_ptr< TextureHandle pTextureToUse,
std::unordered_map< VulkanPipeline *, PushConstantIndices pushConstantIndices 
)
protected

Initializes the resource.

Remarks
Used internally, for outside usage prefer to use create.
Parameters
sResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
pTextureToUseTexture that should be binded to a descriptor in shader array.
pushConstantIndicesIndices of push constants (per-pipeline) to copy texture index to.

Member Function Documentation

◆ bindTextureToShaderDescriptorArray()

std::optional< Error > ne::GlslShaderTextureResourceBinding::bindTextureToShaderDescriptorArray ( const std::string &  sShaderResourceName,
VulkanPipeline pPipelineWithDescriptors,
VkImageView  pTextureView,
unsigned int  iIndexIntoShaderArray 
)
staticprivate

Binds the specified image view to the sampler descriptor of the specified pipeline for binding that corresponds to the specified shader resource name.

Parameters
sShaderResourceNameName of the shader resource to get binding index in descriptor set.
pPipelineWithDescriptorsPipeline which descriptors to use.
pTextureViewTexture view to bind.
iIndexIntoShaderArrayIndex to a descriptor (in the shader texture array) to bind.
Returns
Error if something went wrong.

◆ changeUsedPipelines()

std::optional< Error > ne::GlslShaderTextureResourceBinding::changeUsedPipelines ( const std::unordered_set< Pipeline * > &  pipelinesToUse)
overridevirtual

Called to make the resource to discard currently used pipelines and bind/reference other pipelines.

Warning
Expects that the caller is using some mutex to protect this shader resource from being used in the draw function while this function is not finished (i.e. make sure the CPU will not queue a new frame while this function is not finished).
Remarks
For example, for this function can be called from a mesh node that changed its geometry and thus added/removed some material slots, or if some material that mesh node is using changed its pipeline.
Parameters
pipelinesToUsePipelines to use instead of the current ones.
Returns
Error if something went wrong.

Implements ne::ShaderResourceBindingBase.

◆ copyResourceIndexToPushConstants()

void ne::GlslShaderTextureResourceBinding::copyResourceIndexToPushConstants ( PipelineShaderConstantsManager pPushConstantsManager,
VulkanPipeline pUsedPipeline 
)
inline

Copies resource index (into shader arrays) to a push constant.

Parameters
pPushConstantsManagerPush constants manager.
pUsedPipelineCurrent pipeline.

◆ create()

std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Error > ne::GlslShaderTextureResourceBinding::create ( const std::string &  sShaderResourceName,
const std::unordered_set< Pipeline * > &  pipelinesToUse,
std::unique_ptr< TextureHandle pTextureToUse 
)
staticprivate

Creates a GLSL shader resource for referencing texture in shader array.

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).
pipelinesToUsePipelines that use shader/parameters we are referencing.
pTextureToUseTexture that should be binded to a descriptor in shader array.
Returns
Error if something went wrong, otherwise created shader resource.

◆ getPathToTextureResource()

std::string ne::GlslShaderTextureResourceBinding::getPathToTextureResource ( )

Returns path to a file/directory that stores used texture resource.

Returns
Path relative to the res directory.

◆ getTextureIndexInShaderArray()

std::variant< std::unique_ptr< ShaderArrayIndex >, Error > ne::GlslShaderTextureResourceBinding::getTextureIndexInShaderArray ( const std::string &  sShaderResourceName,
VulkanPipeline pPipelineToLookIn 
)
staticprivate

Asks the index manager for an index into the requested shader array resource.

Parameters
sShaderResourceNameName of the shader array resource defined in GLSL.
pPipelineToLookInPipeline to look for an index manager that will provide the index into shader array.
Returns
Error if something went wrong, otherwise received index into shader array.

◆ onAfterAllPipelinesRefreshedResources()

std::optional< Error > ne::GlslShaderTextureResourceBinding::onAfterAllPipelinesRefreshedResources ( )
overrideprotectedvirtual

Called from pipeline manager to notify that all pipelines released their internal resources and now restored them so their internal resources (for example push constants) might be different now and shader resource now needs to check that everything that it needs is still there and possibly re-bind to pipeline's descriptors since these might have been also re-created.

Returns
Error if something went wrong.

Implements ne::ShaderResourceBindingBase.

◆ useNewTexture()

std::optional< Error > ne::GlslShaderTextureResourceBinding::useNewTexture ( std::unique_ptr< TextureHandle pTextureToUse)
overridevirtual

Makes the shader resource to reference the new (specified) texture.

Warning
Expects that the caller is using some mutex to protect this shader resource from being used in the draw function while this function is not finished (i.e. make sure the CPU will not queue a new frame while this function is not finished).
Parameters
pTextureToUseTexture to reference.
Returns
Error if something went wrong.

Implements ne::ShaderTextureResourceBinding.

Member Data Documentation

◆ mtxPushConstantIndices

std::pair<std::recursive_mutex, std::unordered_map<VulkanPipeline*, PushConstantIndices> > ne::GlslShaderTextureResourceBinding::mtxPushConstantIndices
private

Index of push constant (per-pipeline) to copy index into shader array.

◆ mtxUsedTexture

std::pair<std::mutex, std::unique_ptr<TextureHandle> > ne::GlslShaderTextureResourceBinding::mtxUsedTexture
private

Texture that we bind to descriptor.


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