#include <materialinstance.h>
|
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, int imageArrayIndex) |
|
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 Texture &texture, VkSampler sampler) |
|
bool | initConstants (BaseMaterialInstanceResource &resource, utility::ErrorState &errorState) |
|
BufferBindingInstance * | getOrCreateBufferInternal (const std::string &name) |
|
SamplerInstance * | getOrCreateSamplerInternal (const std::string &name, const Sampler *sampler) |
|
const ShaderStageConstantMap & | getShaderStageConstantMap () const |
|
ShaderConstantHash | getConstantHash () const |
|
UniformStructInstance & | createUniformRootStruct (const ShaderVariableStructDeclaration &declaration, const UniformCreatedCallback &uniformCreatedCallback) |
|
BufferBindingInstance & | addBindingInstance (std::unique_ptr< BufferBindingInstance > instance) |
|
SamplerInstance & | addSamplerInstance (std::unique_ptr< SamplerInstance > instance) |
|
ShaderConstantInstance & | addConstantInstance (std::unique_ptr< ShaderConstantInstance > instance) |
|
◆ addImageInfo()
void addImageInfo |
( |
const Texture & |
texture, |
|
|
VkSampler |
sampler |
|
) |
| |
|
protected |
◆ getConstantHash()
- Returns
- the shader constant hash for quick distinction of constant data in material instances
◆ getMaterial() [1/2]
- Returns
- base material that this instance is overriding
◆ getMaterial() [2/2]
- 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. The binding can be used to set the buffer of type T at runtime. The returned binding is only applicable to this instance. This function will assert if the name of the binding does not match the type that you are trying to create.
- Parameters
-
name | the 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]
Gets or creates a buffer binding instance for this material. The binding can be used to set any buffer of type 'BufferBindingInstance' at runtime. The returned buffer binding is only applicable to this instance.
- Parameters
-
name | the name of the buffer binding as declared in the shader. |
- Returns
- buffer binding that was found or created, nullptr if not available.
◆ getOrCreateBufferInternal()
◆ getOrCreateSampler() [1/4]
T * getOrCreateSampler |
( |
const Sampler & |
resource | ) |
|
Get or creates a nap::SamplerInstance of type T for this material, which can be set at runtime. The instance is initialized against the provided resource and only applicable to this instance.
Note that the resource type must match the instance type! The function asserts otherwise. In order to change a sampler so that its value is shared among MaterialInstances, use getMaterial().findSampler().
- Parameters
-
resource | the resource to get the instance for |
- Returns
- the sampler instance of type T, nullptr when sampler declaration doesn't exist
◆ getOrCreateSampler() [2/4]
Get or creates a nap::SamplerInstance for this material, which can be set at runtime. The instance is initialized against the provided resource and only applicable to this instance.
Note that the resource type must match the instance type! The function asserts otherwise. In order to change a sampler so that its value is shared among MaterialInstances, use getMaterial().findSampler().
- Parameters
-
resource | the resource to get the instance for |
- Returns
- the sampler instance, nullptr when sampler declaration doesn't exist or of incorrect type
◆ getOrCreateSampler() [3/4]
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().
- Parameters
-
name | the name of the sampler declared in the shader. |
- Returns
- nap::SamplerInstance of type T, nullptr when sampler declaration doesn't exist or of incorrect type
◆ getOrCreateSampler() [4/4]
Gets or creates a nap::SamplerInstance for this material, which can be set at runtime. The returned sampler is only applicable to this instance. In order to change a sampler so that its value is shared among MaterialInstances, use getMaterial().findSampler().
- Parameters
-
name | the name of the sampler declared in the shader. |
- Returns
- the sampler instance, nullptr when sampler declaration doesn't exist
◆ getOrCreateSamplerInternal()
◆ getOrCreateUniform()
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
-
name | the name of the uniform struct (ubo) as declared in the shader. |
- Returns
- uniform that was found or created, nullptr if not available.
◆ getShaderStageConstantMap()
- Returns
- a map that groups shader constant ids by shader stage. Used for creating vulkan pipelines.
◆ initBuffers()
◆ initConstants()
◆ initInternal()
◆ initSamplers()
◆ onBufferChanged()
◆ onSamplerChanged()
void onSamplerChanged |
( |
int |
imageStartIndex, |
|
|
SamplerInstance & |
samplerInstance, |
|
|
int |
imageArrayIndex |
|
) |
| |
|
protected |
◆ onUniformCreated()
void onUniformCreated |
( |
| ) |
|
|
protected |
◆ rebuildUBO()
◆ update()
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()
◆ updateSamplers()
◆ mConstantHash
◆ mDescriptorSetCache
◆ mDevice
VkDevice mDevice = nullptr |
|
protected |
◆ mMaterial
◆ mRenderService
◆ mResource
◆ mSamplerDescriptors
std::vector<VkDescriptorImageInfo> mSamplerDescriptors |
|
protected |
◆ mSamplerWriteDescriptorSets
std::vector<VkWriteDescriptorSet> mSamplerWriteDescriptorSets |
|
protected |
◆ mShaderStageConstantMap
◆ mStorageDescriptors
std::vector<VkDescriptorBufferInfo> mStorageDescriptors |
|
protected |
◆ mStorageWriteDescriptorSets
std::vector<VkWriteDescriptorSet> mStorageWriteDescriptorSets |
|
protected |
◆ mUniformBufferObjects
◆ mUniformsCreated
bool mUniformsCreated = false |
|
protected |