NAP
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseMaterialInstance Class Reference

#include <materialinstance.h>

Public Member Functions

virtual UniformStructInstancegetOrCreateUniform (const std::string &name)
 
template<class T >
T * getOrCreateBuffer (const std::string &name)
 
BufferBindingInstancegetOrCreateBuffer (const std::string &name)
 
template<class T >
T * getOrCreateSampler (const std::string &name)
 
SamplerInstancegetOrCreateSampler (const std::string &name)
 
BaseMaterialgetMaterial ()
 
const BaseMaterialgetMaterial () const
 
virtual const DescriptorSetupdate ()
 
- Public Member Functions inherited from UniformContainer
 UniformContainer ()=default
 
virtual ~UniformContainer ()=default
 
 UniformContainer (const UniformContainer &)=delete
 
UniformContaineroperator= (const UniformContainer &)=delete
 
UniformStructInstancefindUniform (const std::string &name)
 
BufferBindingInstancefindBinding (const std::string &name)
 
UniformStructInstancegetUniform (const std::string &name)
 
BufferBindingInstancegetBinding (const std::string &name)
 
const SamplerInstanceListgetSamplers () const
 
const BufferBindingInstanceListgetBufferBindings () const
 
const UniformStructInstanceListgetUniformStructs () const
 
SamplerInstancefindSampler (const std::string &name) const
 

Protected Member Functions

bool initInternal (RenderService &renderService, BaseMaterial &material, BaseMaterialInstanceResource &instanceResource, utility::ErrorState &errorState)
 
void rebuildUBO (UniformBufferObject &ubo, UniformStructInstance *overrideStruct)
 
void onUniformCreated ()
 
void onSamplerChanged (int imageStartIndex, SamplerInstance &samplerInstance)
 
void onBufferChanged (int storageBufferIndex, BufferBindingInstance &bindingInstance)
 
void updateBuffers (const DescriptorSet &descriptorSet)
 
bool initBuffers (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
void updateSamplers (const DescriptorSet &descriptorSet)
 
bool initSamplers (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState)
 
void addImageInfo (const Texture2D &texture2D, VkSampler sampler)
 
BufferBindingInstancegetOrCreateBufferInternal (const std::string &name)
 
SamplerInstancegetOrCreateSamplerInternal (const std::string &name)
 
- Protected Member Functions inherited from UniformContainer
UniformStructInstancecreateUniformRootStruct (const ShaderVariableStructDeclaration &declaration, const UniformCreatedCallback &uniformCreatedCallback)
 
BufferBindingInstanceaddBindingInstance (std::unique_ptr< BufferBindingInstance > instance)
 
SamplerInstanceaddSamplerInstance (std::unique_ptr< SamplerInstance > instance)
 

Protected Attributes

VkDevice mDevice = nullptr
 
RenderServicemRenderService = nullptr
 
BaseMaterialmMaterial = nullptr
 
BaseMaterialInstanceResourcemResource = nullptr
 
DescriptorSetCachemDescriptorSetCache
 
std::vector< UniformBufferObjectmUniformBufferObjects
 
std::vector< VkWriteDescriptorSet > mStorageWriteDescriptorSets
 
std::vector< VkDescriptorBufferInfo > mStorageDescriptors
 
std::vector< VkWriteDescriptorSet > mSamplerWriteDescriptorSets
 
std::vector< VkDescriptorImageInfo > mSamplerDescriptors
 
bool mUniformsCreated = false
 

Additional Inherited Members

- Public Types inherited from UniformContainer
using UniformStructInstanceList = std::vector< std::unique_ptr< UniformStructInstance > >
 
using BufferBindingInstanceList = std::vector< std::unique_ptr< BufferBindingInstance > >
 
using SamplerInstanceList = std::vector< std::unique_ptr< SamplerInstance > >
 

Description

Base class of MaterialInstance and ComputeMaterialInstance

Inheritance diagram for BaseMaterialInstance:
[legend]
Collaboration diagram for BaseMaterialInstance:
[legend]

Member Function Documentation

◆ addImageInfo()

void addImageInfo ( const Texture2D texture2D,
VkSampler  sampler 
)
protected

◆ getMaterial() [1/2]

BaseMaterial* getMaterial ( )
Returns
base material that this instance is overriding

◆ getMaterial() [2/2]

const BaseMaterial* getMaterial ( ) const
Returns
base material that this instance is overriding

◆ getOrCreateBuffer() [1/2]

T * getOrCreateBuffer ( const std::string &  name)

Gets or creates a nap::BufferBindingInstance of type T for this material instance. This means that the buffer binding returned is only applicable to this instance. In order to change a buffer binding so that its value is shared among MaterialInstances, use getMaterial().getBinding(). This function will assert if the name of the binding does not match the type that you are trying to create.

material_instance->getOrCreateBinding<nap::BufferBindingVec4Instance>("inBinding");
Parameters
namethe name of the buffer binding as declared in the shader.
Returns
buffer binding that was found or created, nullptr if not available.

◆ getOrCreateBuffer() [2/2]

BufferBindingInstance* getOrCreateBuffer ( const std::string &  name)

Gets or creates a buffer binding isntance for this material instance. This means that the buffer binding returned is only applicable to this instance. In order to change a buffer binding so that its value is shared among MaterialInstances, use getMaterial().getBinding().

Parameters
namethe name of the buffer binding as declared in the shader.
Returns
buffer binding that was found or created, nullptr if not available.

◆ getOrCreateBufferInternal()

BufferBindingInstance* getOrCreateBufferInternal ( const std::string &  name)
protected

◆ getOrCreateSampler() [1/2]

T * getOrCreateSampler ( const std::string &  name)

Gets or creates a nap::SamplerInstance of type T for this material instance. This means that the sampler returned is only applicable to this instance. In order to change a sampler so that its value is shared among MaterialInstances, use getMaterial().findSampler(). This function will assert if the name of the sampler does not match the type that you are trying to create.

material_instance->getOrCreateSampler<nap::Sampler2DInstance>("inTexture");
Parameters
namethe name of the sampler declared in the shader.
Returns
nap::SamplerInstance of type T, nullptr if not available.

◆ getOrCreateSampler() [2/2]

SamplerInstance* getOrCreateSampler ( const std::string &  name)

Gets or creates a nap::SamplerInstance for this material instance. This means that the sampler returned is only applicable to this instance. In order to change a sampler so that its value is shared among MaterialInstances, use getMaterial().findSampler(). This function will assert if the name of the uniform does not match the type that you are trying to create.

Parameters
namethe name of the sampler declared in the shader.
Returns
nap::SamplerInstance of type T, nullptr if not available.

◆ getOrCreateSamplerInternal()

SamplerInstance* getOrCreateSamplerInternal ( const std::string &  name)
protected

◆ getOrCreateUniform()

virtual UniformStructInstance* getOrCreateUniform ( const std::string &  name)
virtual

Gets or creates a uniform struct (ubo) for this material instance. This means that the uniform returned is only applicable to this instance. In order to change a uniform so that its value is shared among MaterialInstances, use getMaterial().getUniform().

Parameters
namethe name of the uniform struct (ubo) as declared in the shader.
Returns
uniform that was found or created, nullptr if not available.

◆ initBuffers()

bool initBuffers ( BaseMaterialInstanceResource resource,
utility::ErrorState errorState 
)
protected

◆ initInternal()

bool initInternal ( RenderService renderService,
BaseMaterial material,
BaseMaterialInstanceResource instanceResource,
utility::ErrorState errorState 
)
protected

◆ initSamplers()

bool initSamplers ( BaseMaterialInstanceResource resource,
utility::ErrorState errorState 
)
protected

◆ onBufferChanged()

void onBufferChanged ( int  storageBufferIndex,
BufferBindingInstance bindingInstance 
)
protected

◆ onSamplerChanged()

void onSamplerChanged ( int  imageStartIndex,
SamplerInstance samplerInstance 
)
protected

◆ onUniformCreated()

void onUniformCreated ( )
protected

◆ rebuildUBO()

void rebuildUBO ( UniformBufferObject ubo,
UniformStructInstance overrideStruct 
)
protected

◆ update()

virtual const DescriptorSet& update ( )
virtual

This must be called before each draw. It will push the current uniform and sampler data into memory that is accessible for the GPU. A descriptor set will be returned that must be used in VkCmdBindDescriptorSets before the Vulkan draw call is issued.

VkDescriptorSet descriptor_set = mat_instance.update();
vkCmdBindDescriptorSets(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.mLayout, 0, 1, &descriptor_set, 0, nullptr);
Returns
Descriptor to be used in vkCmdBindDescriptorSets.

◆ updateBuffers()

void updateBuffers ( const DescriptorSet descriptorSet)
protected

◆ updateSamplers()

void updateSamplers ( const DescriptorSet descriptorSet)
protected

Member Data Documentation

◆ mDescriptorSetCache

DescriptorSetCache* mDescriptorSetCache
protected

◆ mDevice

VkDevice mDevice = nullptr
protected

◆ mMaterial

BaseMaterial* mMaterial = nullptr
protected

◆ mRenderService

RenderService* mRenderService = nullptr
protected

◆ mResource

BaseMaterialInstanceResource* mResource = nullptr
protected

◆ mSamplerDescriptors

std::vector<VkDescriptorImageInfo> mSamplerDescriptors
protected

◆ mSamplerWriteDescriptorSets

std::vector<VkWriteDescriptorSet> mSamplerWriteDescriptorSets
protected

◆ mStorageDescriptors

std::vector<VkDescriptorBufferInfo> mStorageDescriptors
protected

◆ mStorageWriteDescriptorSets

std::vector<VkWriteDescriptorSet> mStorageWriteDescriptorSets
protected

◆ mUniformBufferObjects

std::vector<UniformBufferObject> mUniformBufferObjects
protected

◆ mUniformsCreated

bool mUniformsCreated = false
protected
nap::Sampler2DInstance
Definition: samplerinstance.h:73
nap::TypedBufferBindingNumericInstance
Definition: bufferbindinginstance.h:271