API Documentation
Public Member Functions | Static Public Member Functions | List of all members
nkGraphics::Shader Class Reference

A shader class, feeding data to a Program. More...

Inheritance diagram for nkGraphics::Shader:
nkGraphics::Resource nkExport::Exportable

Public Member Functions

virtual ~Shader ()
 
unsigned int getId () const
 
bool isUsableScene () const
 
bool isUsablePostProcess () const
 
bool isUsableCompute () const
 
bool isUsableGeometry () const
 
bool isUsableRaytracing () const
 
ProgramgetProgram () 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 ()
 
ConstantBufferaddConstantBuffer (unsigned int registerSlot, unsigned int space=0)
 
ConstantBuffergetConstantBuffer (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 ConstantBufferResourceDescgetConstantBufferPerIndex (unsigned int index) const
 
void addTexture (ShaderResource *texOrUav, unsigned int registerSlot, unsigned int space=0)
 
ShaderResourcegetTexture (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 ShaderResourceDescgetTexturePerIndex (unsigned int index) const
 
void addSampler (Sampler *sampler, unsigned int registerSlot, unsigned int space=0)
 
SamplergetSampler (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 SamplerResourceDescgetSamplerPerIndex (unsigned int index) const
 
void addUavBuffer (Buffer *buffer, unsigned int registerSlot, unsigned int space=0)
 
BuffergetUavBuffer (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 UavResourceDescgetUavBufferPerIndex (unsigned int index) const
 
virtual ShaderInstanceMemorySlotaddInstanceMemorySlot ()
 
virtual ShaderInstanceMemorySlotgetInstanceMemorySlot (unsigned int index)
 
virtual ShaderInstanceMemorySlotgetInstanceMemorySlotReadOnly (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
 
SystemgetSystem () 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< Shadercreate (System *system=nullptr)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~Shader()

virtual nkGraphics::Shader::~Shader ( )
virtual

Destructor.

Member Function Documentation

◆ getId()

unsigned int nkGraphics::Shader::getId ( ) const
Returns
The id of the shader.

◆ isUsableScene()

bool nkGraphics::Shader::isUsableScene ( ) const
Returns
If the shader is usable for rendering a scene.

◆ isUsablePostProcess()

bool nkGraphics::Shader::isUsablePostProcess ( ) const
Returns
If the shader is usable for post processing.

◆ isUsableCompute()

bool nkGraphics::Shader::isUsableCompute ( ) const
Returns
If the shader is usable for compute.

◆ isUsableGeometry()

bool nkGraphics::Shader::isUsableGeometry ( ) const
Returns
If the shader is usable for geometry streaming.

◆ isUsableRaytracing()

bool nkGraphics::Shader::isUsableRaytracing ( ) const
Returns
If the shader is usable for raytracing.

◆ getProgram()

Program* nkGraphics::Shader::getProgram ( ) const
Returns
The attached program.

◆ getMaxInstancePerBuffer()

unsigned int nkGraphics::Shader::getMaxInstancePerBuffer ( ) const
Returns
The maximum number of instance per instance buffers.

◆ getIsBuiltInShader()

bool nkGraphics::Shader::getIsBuiltInShader ( ) const
Returns
Whether the shader is a built-in one (true) or not (false).

◆ getDirtyInstanceData()

bool nkGraphics::Shader::getDirtyInstanceData ( ) const
Returns
If the instance data has been dirtified.

◆ setProgram()

virtual void nkGraphics::Shader::setProgram ( Program prog)
virtual
Parameters
progThe program to attach to the shader.

◆ setId()

void nkGraphics::Shader::setId ( unsigned int  id)
Parameters
idThe id to attach to the shader. Should not be called by external code.

◆ setMaxInstancePerBuffer()

virtual void nkGraphics::Shader::setMaxInstancePerBuffer ( unsigned int  value)
virtual
Parameters
valueThe maximum instance count allowed per instance buffer.
Remarks
Too few instances per buffer can cause multiple buffer allocations during rendering to fill for all instances required. Too many instances per buffer will cause memory wasting as the buffer is never filled up. Try finding the balance, depending on the scene rendered.

◆ setIsBuiltInShader()

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.

Parameters
valueWhether the shader is to be considered built-in (true) or not (false).

◆ setDirtyInstanceData()

void nkGraphics::Shader::setDirtyInstanceData ( bool  value)
Parameters
valueWhether the instance data should be flagged as dirty or not.
Remarks
Dirtification will cause the instance related tracking data to be updated. In theory, should not be called by external code.

◆ load()

virtual bool nkGraphics::Shader::load ( )
overridevirtual

Initializes the shader and make it ready for rendering.

Returns
If the initialization went well (true) or not (false).

Implements nkGraphics::Resource.

◆ unload()

virtual void nkGraphics::Shader::unload ( )
overridevirtual

Unloads and frees all internal memory of the shader.

Implements nkGraphics::Resource.

◆ reset()

void nkGraphics::Shader::reset ( )

Unloads and resets the shader into its default state, clearing all constant and instance data.

◆ addConstantBuffer()

ConstantBuffer* nkGraphics::Shader::addConstantBuffer ( unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a constant buffer to the data fed to the program.

Parameters
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.
Returns
The resource freshly created. The shader is responsible for the allocated memory, external code should not delete it. See deleteConstantBuffer().

◆ getConstantBuffer()

ConstantBuffer* nkGraphics::Shader::getConstantBuffer ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ changeConstantBufferSlot()

void nkGraphics::Shader::changeConstantBufferSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeConstantBufferSpace()

void nkGraphics::Shader::changeConstantBufferSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ deleteConstantBuffer()

void nkGraphics::Shader::deleteConstantBuffer ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a constant buffer from the feeding, and frees its memory.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getConstantBufferPerIndex()

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.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addTexture()

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.

Parameters
texOrUavThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getTexture()

ShaderResource* nkGraphics::Shader::getTexture ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setTexture()

void nkGraphics::Shader::setTexture ( ShaderResource texOrUav,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
texOrUavThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeTextureSlot()

void nkGraphics::Shader::changeTextureSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeTextureSpace()

void nkGraphics::Shader::changeTextureSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetTexture()

void nkGraphics::Shader::forgetTexture ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getTexturePerIndex()

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.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addSampler()

void nkGraphics::Shader::addSampler ( Sampler sampler,
unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a sampler to the data fed to the program.

Parameters
samplerThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getSampler()

Sampler* nkGraphics::Shader::getSampler ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setSampler()

void nkGraphics::Shader::setSampler ( Sampler sampler,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
samplerThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeSamplerSlot()

void nkGraphics::Shader::changeSamplerSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeSamplerSpace()

void nkGraphics::Shader::changeSamplerSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot = 0 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetSampler()

void nkGraphics::Shader::forgetSampler ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getSamplerPerIndex()

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.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addUavBuffer()

void nkGraphics::Shader::addUavBuffer ( Buffer buffer,
unsigned int  registerSlot,
unsigned int  space = 0 
)

Adds a uav buffer to the data fed to the program.

Parameters
bufferThe resource to feed to the program.
registerSlotThe register slot the resource is attached to.
spaceThe register space the resource is attached to.

◆ getUavBuffer()

Buffer* nkGraphics::Shader::getUavBuffer ( unsigned int  slot,
unsigned int  space = 0 
) const
Parameters
slotThe register slot the requested resource covers.
spaceThe register space the requested resource covers.
Returns
Requested resource if available, nullptr else.

◆ setUavBuffer()

void nkGraphics::Shader::setUavBuffer ( Buffer buffer,
unsigned int  slot,
unsigned int  space = 0 
)

Changes the resource fed to a slot and space.

Parameters
bufferThe resource to feed.
slotThe currently used register slot.
spaceThe currently used space.

◆ changeUavBufferSlot()

void nkGraphics::Shader::changeUavBufferSlot ( unsigned int  fromSlot,
unsigned int  toSlot,
unsigned int  space = 0 
)

Changes the slot a resource should be fed to.

Parameters
fromSlotThe slot the resource currently feeds.
toSlotThe slot to feed.
spaceThe register space the resource currently occupies.

◆ changeUavBufferSpace()

void nkGraphics::Shader::changeUavBufferSpace ( unsigned int  fromSpace,
unsigned int  toSpace,
unsigned int  slot = 0 
)

Changes the space a resource should be fed to.

Parameters
fromSpaceThe register space the resource currently feeds.
toSpaceThe space to feed.
slotThe register slot the resource currently occupies.

◆ forgetUavBuffer()

void nkGraphics::Shader::forgetUavBuffer ( unsigned int  slot,
unsigned int  space = 0 
)

Removes a resource from the feeding.

Parameters
slotThe register slot used by the resource.
spaceThe register space used by the resource.

◆ getUavBufferPerIndex()

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.

Parameters
indexThe index of the resource wanted.
Returns
A description of the resource if available, nullptr else.

◆ addInstanceMemorySlot()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::addInstanceMemorySlot ( )
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.

Returns
A newly allocated slot. Shader is responsible for the memory, external code should not delete it. See deleteInstanceMemorySlot().

◆ getInstanceMemorySlot()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::getInstanceMemorySlot ( unsigned int  index)
virtual

Retrieves an existing instance memory slot.

Parameters
indexThe index of the slot to retrieve.
Returns
The slot requested if available, nullptr else.

◆ getInstanceMemorySlotReadOnly()

virtual ShaderInstanceMemorySlot* nkGraphics::Shader::getInstanceMemorySlotReadOnly ( unsigned int  index) const
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.

Parameters
indexThe index of the slot to retrieve.
Returns
The slot requested if available, nullptr else.

◆ changeInstanceMemorySlotOrder()

virtual void nkGraphics::Shader::changeInstanceMemorySlotOrder ( unsigned int  fromIndex,
unsigned int  toIndex 
)
virtual

Changes the ordering within the slots.

Parameters
fromIndexThe slot to move.
toIndexThe index to move the slot to.

◆ deleteInstanceMemorySlot()

virtual void nkGraphics::Shader::deleteInstanceMemorySlot ( unsigned int  index)
virtual

Erases and frees an instance memory slot.

Parameters
indexThe index of the slot to erase.

◆ hasInstanceSlotSemanticName()

bool nkGraphics::Shader::hasInstanceSlotSemanticName ( nkMemory::StringView  name) const

Checks whether given name is part of its instance semantic names for shader input.

Parameters
nameThe name to check for.
Returns
Whether the name provided is one of the semantics provided by the shader's instance slots.

◆ exportClassToTree()

virtual void nkGraphics::Shader::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

Exports an item into a tree describing its structure and its data.

Parameters
rootNodeThe node into which the object has to write its related information.

Implements nkExport::Exportable.

◆ importClassFromTree()

virtual void nkGraphics::Shader::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

Imports information from a tree which is supposed to describe its structure and data.

Parameters
rootNodeThe root node of the tree holding the information.

Implements nkExport::Exportable.

◆ create()

static nkMemory::UniquePtr<Shader> nkGraphics::Shader::create ( System system = nullptr)
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.

Parameters
systemThe system to create the resource into. If left to nullptr, then the Singleton instance will be used.
Returns
The created resource instance.

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