Wasabi
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
WMaterial Class Reference

#include <WMaterial.hpp>

Inheritance diagram for WMaterial:
WFileAsset WBase

Public Member Functions

virtual std::string GetTypeName () const override
 
virtual void SetID (uint32_t newID) override
 
virtual void SetName (std::string newName) override
 
virtual WError Bind (class WRenderTarget *rt, bool bindDescSet=true, bool bindPushConsts=true)
 
VkDescriptorSet GetDescriptorSet () const
 
class WEffectGetEffect () const
 
template<typename T >
WError SetVariable (const char *varName, T value)
 
template<typename T >
WError SetVariableArray (const char *varName, T *arr, int numElements)
 
WError SetVariableData (const char *varName, void *data, size_t len)
 
WError SetTexture (uint32_t bindingIndex, class WImage *img, uint32_t arrayIndex=0)
 
WError SetTexture (std::string name, class WImage *img, uint32_t arrayIndex=0)
 
virtual bool Valid () const override
 
virtual WError SaveToStream (WFile *file, std::ostream &outputStream) override
 
virtual WError LoadFromStream (WFile *file, std::istream &inputStream, std::vector< void * > &args, std::string nameSuffix) override
 
- Public Member Functions inherited from WFileAsset
 WFileAsset (class Wasabi *const app, uint32_t ID=0)
 
virtual WError LoadFromStream (class WFile *file, std::istream &inputStream, vector< void * > &args, std::string nameSuffix)=0
 
- Public Member Functions inherited from WBase
 WBase (class Wasabi *const app, uint32_t ID=0)
 
uint32_t GetID () const
 
std::string GetName () const
 
class WasabiGetAppPtr () const
 
void AddReference ()
 
void RemoveReference ()
 

Static Public Member Functions

static std::string _GetTypeName ()
 
static std::vector< void * > LoadArgs ()
 

Protected Member Functions

 WMaterial (class Wasabi *const app, uint32_t ID=0)
 
WError CreateForEffect (class WEffect *const effect, uint32_t bindingSet=0)
 

Friends

class WEffect
 
class WFile
 

Additional Inherited Members

- Protected Attributes inherited from WBase
class Wasabim_app
 
uint32_t m_ID
 
std::string m_name
 

Detailed Description

A WMaterial contains the information needed to pass shader parameters to WEffects and their shaders. Parameters include all types of variables and textures. WMaterials provide a convenient interface for setting values without having to deal with memory mapping between the host and the client (The RAM and the GPU memory). In Vulkan terms, a WMaterial is a descriptor set that is a subset of all descriptors of a WEffect. Each material may have a descriptor set containing all bound resources of a WEffect, or only a subset of them.

Member Function Documentation

◆ _GetTypeName()

static std::string WMaterial::_GetTypeName ( )
static

Returns "Material" string.

Returns
Returns "Material" string

◆ Bind()

virtual WError WMaterial::Bind ( class WRenderTarget rt,
bool  bindDescSet = true,
bool  bindPushConsts = true 
)
virtual

Binds the resources to the pipeline. In Vulkan terms, this binds the descriptor set associated with this material as well as the push constants.

Parameters
rtRender target to bind to its command buffer
bindDescSetWhether or not to bind the descriptor set
bindPushConstsWhether or not to bind push constants
Returns
Error code, see WError.h

◆ CreateForEffect()

WError WMaterial::CreateForEffect ( class WEffect *const  effect,
uint32_t  bindingSet = 0 
)
protected

Builds the material's resources to be used for a certain effect. The material may be created for only a subset of the bound resources of the WEffect using the boundResources parameter.

Parameters
effectEffect to use
bindingSetSet index to use from effect
Returns
Error code, see WError.h

◆ GetDescriptorSet()

VkDescriptorSet WMaterial::GetDescriptorSet ( ) const

Retrieves the Vulkan descriptor set created by this material.

Returns
Material's descriptor set

◆ GetEffect()

class WEffect* WMaterial::GetEffect ( ) const
Returns
The effect of this material.

◆ GetTypeName()

virtual std::string WMaterial::GetTypeName ( ) const
overridevirtual

This function must be implemented by a child class. This is used for debugging, in which a class should return its name.

Returns
The name of the class

Implements WBase.

◆ SetID()

virtual void WMaterial::SetID ( uint32_t  newID)
overridevirtual

Sets the ID of this object and notifies its manager.

Parameters
newIDNew ID

Implements WBase.

◆ SetName()

virtual void WMaterial::SetName ( std::string  newName)
overridevirtual

Sets the name of this object.

Parameters
nameNew name for the object

Implements WBase.

◆ SetTexture() [1/2]

WError WMaterial::SetTexture ( std::string  name,
class WImage img,
uint32_t  arrayIndex = 0 
)

Sets a texture in the bound effect.

Parameters
nameName of the texture to bind to
imgThe image to set the texture to, can be nullptr
arrayIndexIndex into the texture array (if its an array)
Returns
Error code, see WError.h

◆ SetTexture() [2/2]

WError WMaterial::SetTexture ( uint32_t  bindingIndex,
class WImage img,
uint32_t  arrayIndex = 0 
)

Sets a texture in the bound effect.

Parameters
bindingIndexThe binding index of the texture
imgThe image to set the texture to, can be nullptr
arrayIndexIndex into the texture array (if its an array)
Returns
Error code, see WError.h

◆ SetVariable()

template<typename T >
WError WMaterial::SetVariable ( const char *  varName,
value 
)
inline

Sets a variable in one of the bound effect's shaders whose name is varName and whose type is T. If multiple variables have the same name, they will all be set.

Parameters
varNameName of the variable to set
valueValue to set
Returns
Error code, see WError.h

◆ SetVariableArray()

template<typename T >
WError WMaterial::SetVariableArray ( const char *  varName,
T *  arr,
int  numElements 
)
inline

Sets a variable in one of the bound effect's shaders whose name is varName and whose type is an array of T. If multiple variables have the same name, they will all be set.

Parameters
varNameName of the variable to set
arrAddress of the array to set
numElementsNumber of elements in arr
Returns
Error code, see WError.h

◆ SetVariableData()

WError WMaterial::SetVariableData ( const char *  varName,
void *  data,
size_t  len 
)

Sets a variable in one of the bound effect's shaders whose name is varName and whose type can be anything. The set variable's size must match the len parameter for successful setting. If multiple variables have the same name, they will all be set. If the target variable is a structure, make sure to properly pad the members as specified by the Vulkan specs. If the target variable is an array of structures, you should also make sure that the structure is padded at the end of it. Refer to: https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/html/vkspec.html#interfaces-resources-layout Wasabi will automatically do the padding for all the data, except when the user is explicitly setting structures data using this function.

Parameters
varNameName of the variable to set
dataAddress of the memory to set the variable's data to
lenLength of data, in bytes
Returns
Error code, see WError.h

◆ Valid()

virtual bool WMaterial::Valid ( ) const
overridevirtual

Checks the validity of the material. A material is valid if it has a valid effect assigned to it.

Returns
true of the material is valid, false otherwise

Implements WBase.


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