A shader class, feeding data to a Program. More...
Public Member Functions | |
virtual | ~Shader () |
unsigned int | getId () const |
bool | isUsableScene () const |
bool | isUsablePostProcess () const |
bool | isUsableCompute () const |
bool | isUsableGeometry () const |
bool | isUsableRaytracing () const |
Program * | getProgram () const |
unsigned int | getMaxInstancePerBuffer () const |
bool | getIsBuiltInShader () const |
bool | getDirtyInstanceData () const |
virtual void | setProgram (Program *prog) |
void | setId (unsigned int id) |
virtual void | setMaxInstancePerBuffer (unsigned int value) |
void | setIsBuiltInShader (bool value) |
void | setDirtyInstanceData (bool value) |
virtual bool | load () override |
virtual void | unload () override |
void | reset () |
ConstantBuffer * | addConstantBuffer (unsigned int registerSlot, unsigned int space=0) |
ConstantBuffer * | getConstantBuffer (unsigned int slot, unsigned int space=0) const |
void | changeConstantBufferSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0) |
void | changeConstantBufferSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot) |
void | deleteConstantBuffer (unsigned int slot, unsigned int space=0) |
const ConstantBufferResourceDesc * | getConstantBufferPerIndex (unsigned int index) const |
void | addTexture (ShaderResource *texOrUav, unsigned int registerSlot, unsigned int space=0) |
ShaderResource * | getTexture (unsigned int slot, unsigned int space=0) const |
void | setTexture (ShaderResource *texOrUav, unsigned int slot, unsigned int space=0) |
void | changeTextureSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0) |
void | changeTextureSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot) |
void | forgetTexture (unsigned int slot, unsigned int space=0) |
const ShaderResourceDesc * | getTexturePerIndex (unsigned int index) const |
void | addSampler (Sampler *sampler, unsigned int registerSlot, unsigned int space=0) |
Sampler * | getSampler (unsigned int slot, unsigned int space=0) const |
void | setSampler (Sampler *sampler, unsigned int slot, unsigned int space=0) |
void | changeSamplerSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0) |
void | changeSamplerSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot=0) |
void | forgetSampler (unsigned int slot, unsigned int space=0) |
const SamplerResourceDesc * | getSamplerPerIndex (unsigned int index) const |
void | addUavBuffer (Buffer *buffer, unsigned int registerSlot, unsigned int space=0) |
Buffer * | getUavBuffer (unsigned int slot, unsigned int space=0) const |
void | setUavBuffer (Buffer *buffer, unsigned int slot, unsigned int space=0) |
void | changeUavBufferSlot (unsigned int fromSlot, unsigned int toSlot, unsigned int space=0) |
void | changeUavBufferSpace (unsigned int fromSpace, unsigned int toSpace, unsigned int slot=0) |
void | forgetUavBuffer (unsigned int slot, unsigned int space=0) |
const UavResourceDesc * | getUavBufferPerIndex (unsigned int index) const |
virtual ShaderInstanceMemorySlot * | addInstanceMemorySlot () |
virtual ShaderInstanceMemorySlot * | getInstanceMemorySlot (unsigned int index) |
virtual ShaderInstanceMemorySlot * | getInstanceMemorySlotReadOnly (unsigned int index) const |
virtual void | changeInstanceMemorySlotOrder (unsigned int fromIndex, unsigned int toIndex) |
virtual void | deleteInstanceMemorySlot (unsigned int index) |
bool | hasInstanceSlotSemanticName (nkMemory::StringView name) const |
virtual void | exportClassToTree (nkExport::Node *rootNode) override |
virtual void | importClassFromTree (nkExport::Node *rootNode) override |
Public Member Functions inherited from nkGraphics::Resource | |
virtual | ~Resource () |
bool | isReadyForRendering () const |
bool | isUnloaded () const |
RESOURCE_LOAD_STATE | getLoadState () const |
nkMemory::StringView | getPath () const |
RESOURCE_TYPE | getTypeName () const |
nkMemory::StringView | getName () const |
System * | getSystem () const |
bool | getHidden () const |
bool | getGpuUploadCanBeDeferred () const |
virtual void | setPath (nkMemory::StringView value) |
void | setName (nkMemory::StringView value) |
void | setHidden (bool value) |
void | setGpuUploadCanBeDeferred (bool value) |
Public Member Functions inherited from nkExport::Exportable | |
Exportable () noexcept | |
virtual | ~Exportable () |
Static Public Member Functions | |
static nkMemory::UniquePtr< Shader > | create (System *system=nullptr) |
A shader class, feeding data to a Program.
The Shader class is describing all the resources to bind to a Program during rendering.
See ShaderManager::createOrRetrieve() or Shader::create() for instantiation.
|
virtual |
Destructor.
unsigned int nkGraphics::Shader::getId | ( | ) | const |
bool nkGraphics::Shader::isUsableScene | ( | ) | const |
bool nkGraphics::Shader::isUsablePostProcess | ( | ) | const |
bool nkGraphics::Shader::isUsableCompute | ( | ) | const |
bool nkGraphics::Shader::isUsableGeometry | ( | ) | const |
bool nkGraphics::Shader::isUsableRaytracing | ( | ) | const |
Program* nkGraphics::Shader::getProgram | ( | ) | const |
unsigned int nkGraphics::Shader::getMaxInstancePerBuffer | ( | ) | const |
bool nkGraphics::Shader::getIsBuiltInShader | ( | ) | const |
bool nkGraphics::Shader::getDirtyInstanceData | ( | ) | const |
|
virtual |
prog | The program to attach to the shader. |
void nkGraphics::Shader::setId | ( | unsigned int | id | ) |
id | The id to attach to the shader. Should not be called by external code. |
|
virtual |
value | The maximum instance count allowed per instance buffer. |
void nkGraphics::Shader::setIsBuiltInShader | ( | bool | value | ) |
Sets whether the shader is considered built-in or not. Built-in shaders are shaders offered by default by the component. Such shaders trigger internal automatisms such as automatic mapping from a mesh's layout's declared position / normal / texture coordinates names to internal used names "POSITION" / "NORMAL" / "TEXCOORD". This is used internally.
value | Whether the shader is to be considered built-in (true) or not (false). |
void nkGraphics::Shader::setDirtyInstanceData | ( | bool | value | ) |
value | Whether the instance data should be flagged as dirty or not. |
|
overridevirtual |
Initializes the shader and make it ready for rendering.
Implements nkGraphics::Resource.
|
overridevirtual |
Unloads and frees all internal memory of the shader.
Implements nkGraphics::Resource.
void nkGraphics::Shader::reset | ( | ) |
Unloads and resets the shader into its default state, clearing all constant and instance data.
ConstantBuffer* nkGraphics::Shader::addConstantBuffer | ( | unsigned int | registerSlot, |
unsigned int | space = 0 |
||
) |
Adds a constant buffer to the data fed to the program.
registerSlot | The register slot the resource is attached to. |
space | The register space the resource is attached to. |
ConstantBuffer* nkGraphics::Shader::getConstantBuffer | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) | const |
slot | The register slot the requested resource covers. |
space | The register space the requested resource covers. |
void nkGraphics::Shader::changeConstantBufferSlot | ( | unsigned int | fromSlot, |
unsigned int | toSlot, | ||
unsigned int | space = 0 |
||
) |
Changes the slot a resource should be fed to.
fromSlot | The slot the resource currently feeds. |
toSlot | The slot to feed. |
space | The register space the resource currently occupies. |
void nkGraphics::Shader::changeConstantBufferSpace | ( | unsigned int | fromSpace, |
unsigned int | toSpace, | ||
unsigned int | slot | ||
) |
Changes the space a resource should be fed to.
fromSpace | The register space the resource currently feeds. |
toSpace | The space to feed. |
slot | The register slot the resource currently occupies. |
void nkGraphics::Shader::deleteConstantBuffer | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) |
Removes a constant buffer from the feeding, and frees its memory.
slot | The register slot used by the resource. |
space | The register space used by the resource. |
const ConstantBufferResourceDesc* nkGraphics::Shader::getConstantBufferPerIndex | ( | unsigned int | index | ) | const |
Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.
index | The index of the resource wanted. |
void nkGraphics::Shader::addTexture | ( | ShaderResource * | texOrUav, |
unsigned int | registerSlot, | ||
unsigned int | space = 0 |
||
) |
Adds a texture or buffer to the data fed to the program.
texOrUav | The resource to feed to the program. |
registerSlot | The register slot the resource is attached to. |
space | The register space the resource is attached to. |
ShaderResource* nkGraphics::Shader::getTexture | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) | const |
slot | The register slot the requested resource covers. |
space | The register space the requested resource covers. |
void nkGraphics::Shader::setTexture | ( | ShaderResource * | texOrUav, |
unsigned int | slot, | ||
unsigned int | space = 0 |
||
) |
Changes the resource fed to a slot and space.
texOrUav | The resource to feed. |
slot | The currently used register slot. |
space | The currently used space. |
void nkGraphics::Shader::changeTextureSlot | ( | unsigned int | fromSlot, |
unsigned int | toSlot, | ||
unsigned int | space = 0 |
||
) |
Changes the slot a resource should be fed to.
fromSlot | The slot the resource currently feeds. |
toSlot | The slot to feed. |
space | The register space the resource currently occupies. |
void nkGraphics::Shader::changeTextureSpace | ( | unsigned int | fromSpace, |
unsigned int | toSpace, | ||
unsigned int | slot | ||
) |
Changes the space a resource should be fed to.
fromSpace | The register space the resource currently feeds. |
toSpace | The space to feed. |
slot | The register slot the resource currently occupies. |
void nkGraphics::Shader::forgetTexture | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) |
Removes a resource from the feeding.
slot | The register slot used by the resource. |
space | The register space used by the resource. |
const ShaderResourceDesc* nkGraphics::Shader::getTexturePerIndex | ( | unsigned int | index | ) | const |
Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.
index | The index of the resource wanted. |
void nkGraphics::Shader::addSampler | ( | Sampler * | sampler, |
unsigned int | registerSlot, | ||
unsigned int | space = 0 |
||
) |
Adds a sampler to the data fed to the program.
sampler | The resource to feed to the program. |
registerSlot | The register slot the resource is attached to. |
space | The register space the resource is attached to. |
Sampler* nkGraphics::Shader::getSampler | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) | const |
slot | The register slot the requested resource covers. |
space | The register space the requested resource covers. |
void nkGraphics::Shader::setSampler | ( | Sampler * | sampler, |
unsigned int | slot, | ||
unsigned int | space = 0 |
||
) |
Changes the resource fed to a slot and space.
sampler | The resource to feed. |
slot | The currently used register slot. |
space | The currently used space. |
void nkGraphics::Shader::changeSamplerSlot | ( | unsigned int | fromSlot, |
unsigned int | toSlot, | ||
unsigned int | space = 0 |
||
) |
Changes the slot a resource should be fed to.
fromSlot | The slot the resource currently feeds. |
toSlot | The slot to feed. |
space | The register space the resource currently occupies. |
void nkGraphics::Shader::changeSamplerSpace | ( | unsigned int | fromSpace, |
unsigned int | toSpace, | ||
unsigned int | slot = 0 |
||
) |
Changes the space a resource should be fed to.
fromSpace | The register space the resource currently feeds. |
toSpace | The space to feed. |
slot | The register slot the resource currently occupies. |
void nkGraphics::Shader::forgetSampler | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) |
Removes a resource from the feeding.
slot | The register slot used by the resource. |
space | The register space used by the resource. |
const SamplerResourceDesc* nkGraphics::Shader::getSamplerPerIndex | ( | unsigned int | index | ) | const |
Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.
index | The index of the resource wanted. |
void nkGraphics::Shader::addUavBuffer | ( | Buffer * | buffer, |
unsigned int | registerSlot, | ||
unsigned int | space = 0 |
||
) |
Adds a uav buffer to the data fed to the program.
buffer | The resource to feed to the program. |
registerSlot | The register slot the resource is attached to. |
space | The register space the resource is attached to. |
Buffer* nkGraphics::Shader::getUavBuffer | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) | const |
slot | The register slot the requested resource covers. |
space | The register space the requested resource covers. |
void nkGraphics::Shader::setUavBuffer | ( | Buffer * | buffer, |
unsigned int | slot, | ||
unsigned int | space = 0 |
||
) |
Changes the resource fed to a slot and space.
buffer | The resource to feed. |
slot | The currently used register slot. |
space | The currently used space. |
void nkGraphics::Shader::changeUavBufferSlot | ( | unsigned int | fromSlot, |
unsigned int | toSlot, | ||
unsigned int | space = 0 |
||
) |
Changes the slot a resource should be fed to.
fromSlot | The slot the resource currently feeds. |
toSlot | The slot to feed. |
space | The register space the resource currently occupies. |
void nkGraphics::Shader::changeUavBufferSpace | ( | unsigned int | fromSpace, |
unsigned int | toSpace, | ||
unsigned int | slot = 0 |
||
) |
Changes the space a resource should be fed to.
fromSpace | The register space the resource currently feeds. |
toSpace | The space to feed. |
slot | The register slot the resource currently occupies. |
void nkGraphics::Shader::forgetUavBuffer | ( | unsigned int | slot, |
unsigned int | space = 0 |
||
) |
Removes a resource from the feeding.
slot | The register slot used by the resource. |
space | The register space used by the resource. |
const UavResourceDesc* nkGraphics::Shader::getUavBufferPerIndex | ( | unsigned int | index | ) | const |
Accesses a resource, by index. Note that an index can return different resources as the internal memory is changed. Mainly useful to loop over all the resources in one go.
index | The index of the resource wanted. |
|
virtual |
Adds an instance memory slot to the data feeding. Instance memory slots are fed sequentially, in the order they are declared. Be sure to align all structures.
|
virtual |
Retrieves an existing instance memory slot.
index | The index of the slot to retrieve. |
|
virtual |
Retrieves an existing instance memory slot, for read only operation. Use this function whenever possible as this won't dirtify the instance tracking data.
index | The index of the slot to retrieve. |
|
virtual |
Changes the ordering within the slots.
fromIndex | The slot to move. |
toIndex | The index to move the slot to. |
|
virtual |
Erases and frees an instance memory slot.
index | The index of the slot to erase. |
bool nkGraphics::Shader::hasInstanceSlotSemanticName | ( | nkMemory::StringView | name | ) | const |
Checks whether given name is part of its instance semantic names for shader input.
name | The name to check for. |
|
overridevirtual |
Exports an item into a tree describing its structure and its data.
rootNode | The node into which the object has to write its related information. |
Implements nkExport::Exportable.
|
overridevirtual |
Imports information from a tree which is supposed to describe its structure and data.
rootNode | The root node of the tree holding the information. |
Implements nkExport::Exportable.
|
static |
Creates a standalone resource, linking it to a system, but no manager. This method can be used to allocate a resource and manually manage its lifetime.
system | The system to create the resource into. If left to nullptr, then the Singleton instance will be used. |