You.i Engine
CYIMaterial Class Reference

Detailed Description

CYIMaterial is a place holder for all the drawing parameters required by the renderer to draw a mesh/shape.

The CYIMaterial is a component of the CYISceneNode, which describes what material to use to draw itself. This object is implicitly sharable.

#include <renderer/YiMaterial.h>

Classes

struct  WrapModes
 

Public Types

enum  WrapMode : uint8_t {
  WrapMode::DefaultFromTexture,
  WrapMode::ClampToEdge,
  WrapMode::Mirror,
  WrapMode::Repeat
}
 

Public Member Functions

 CYIMaterial ()
 
 ~CYIMaterial ()
 
std::shared_ptr< CYIAssetTextureBaseGetTexture (uint32_t slot) const
 
std::shared_ptr< CYIAssetTextureBaseGetTexture (CYIStringView textureName) const
 
bool SetTexture (uint32_t slot, const std::shared_ptr< CYIAssetTextureBase > &pTexture, float *pTextureMatrix=nullptr)
 
bool SetTexture (uint32_t slot, const std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::mat3 textureMatrix)
 
bool SetTexture (CYIStringView textureName, const std::shared_ptr< CYIAssetTextureBase > &pTexture)
 
bool SetTextureMatrix (CYIStringView matrixName, const glm::mat3 &textureMatrix)
 
bool SetTextureMatrix (CYIStringView matrixName, float *pTextureMatrix=nullptr)
 
const glm::mat3 & GetTextureMatrix (uint32_t slot) const
 
const glm::mat3 & GetTextureMatrix (CYIStringView matrixName) const
 
const std::shared_ptr< CYIAssetShaderProgram > & GetShaderProgram () const
 
const std::shared_ptr< IYIUniformBufferObject > & GetShaderUniforms () const
 
void SetShaderProgram (const std::shared_ptr< CYIAssetShaderProgram > &pShaderProgram)
 
const std::map< uint32_t, std::shared_ptr< CYIAssetTextureBase > > & GetTextureBindings () const
 
const std::map< uint32_t, CYIUniformBufferId > & GetTextureIds () const
 
void ClearTextureSlot (uint32_t slot)
 
void ClearTexture (CYIStringView textureName)
 
void ClearTextureMatrix (CYIStringView matrixName)
 
void SetBlendMode (CYIRenderSystem::BlendMode mode)
 
CYIRenderSystem::BlendMode GetBlendMode () const
 
void SetColor (const CYIColor &color)
 
void SetValue (const CYIUniformBufferId &uniformBufferId, IYIUniformBufferObject::Type type, const char *pData, uint32_t count=1)
 
void RemoveValue (const CYIUniformBufferId &uniformBufferId)
 
const CYIColorGetColor () const
 
void SetCullFace (CYIRenderSystem::CullFace cullingMode)
 
CYIRenderSystem::CullFace GetCullFace () const
 
void SetWrapModes (WrapMode horizontal=WrapMode::DefaultFromTexture, WrapMode vertical=WrapMode::DefaultFromTexture)
 
WrapModes GetWrapModes () const
 
CYIAssetTextureBase::TextureConfig GetTextureWrapModes (const std::shared_ptr< CYIAssetTextureBase > &pAssetTexture) const
 
bool IsLoaded () const
 

Member Enumeration Documentation

◆ WrapMode

enum CYIMaterial::WrapMode : uint8_t
strong

Texture wrapping rules.

Note
Setting a wrap mode other than CYIMaterial::WrapMode::DefaultFromTexture overrides
Warning
Not all devices support the use of WrapMode::Mirror or WrapMode::Repeat with non-power-of-two texture sizes. A power-of-two texture size is a texture which has a height and width that are a power-of-two, for example a 256x128 texture. If a device does not support this and the texture has a non-power-of-two texture size the texture will not be rendered. It is recommended when using these modes that the texture width and height are power-of-two.
See also
CYIAssetTextureBase::SetTextureWrap
Enumerator
DefaultFromTexture 

Indicates that the wrap mode from the texture should be used. This is the default.

ClampToEdge 

Clamp texture to edge of image. This wrap mode will repeat the last pixel on the edge in the direction for the texture coordinate to which it is applied.

Mirror 

Mirror texture coordinates. This wrap mode will draw the same image but mirrored horizontally or vertically in the direction for the texture coordinate to which it is applied. */.

Repeat 

Repeats the texture – often used for tiling a background. This wrap mode will repeat the image in the direction for the texture coordinate to which it is applied.

Constructor & Destructor Documentation

◆ CYIMaterial()

CYIMaterial::CYIMaterial ( )

Constructor

◆ ~CYIMaterial()

CYIMaterial::~CYIMaterial ( )

Destructor

Member Function Documentation

◆ ClearTexture()

void CYIMaterial::ClearTexture ( CYIStringView  textureName)

Clear the data of the texture with the name textureName. This data will no longer be sent to the renderer or accessible in any shader programs.

◆ ClearTextureMatrix()

void CYIMaterial::ClearTextureMatrix ( CYIStringView  matrixName)

Clear the data of the texture matrix with the name matrixName. This data will no longer be sent to the renderer or accessible in any shader programs.

◆ ClearTextureSlot()

void CYIMaterial::ClearTextureSlot ( uint32_t  slot)
Deprecated:
This overload of ClearTextureSlot is deprecated. Textures should be cleared using ClearTexture which identifies the texture with a string. This overload of ClearTexture can only be used in combination with the deprecated overload of SetTexture which takes a uin32_t slot argument, and cannot be used to clear a texture with a custom name set using a currently supported overload of SetTexture.

◆ GetBlendMode()

CYIRenderSystem::BlendMode CYIMaterial::GetBlendMode ( ) const

Returns the blending mode for this material

◆ GetColor()

const CYIColor& CYIMaterial::GetColor ( ) const
Deprecated:
Get the color for this material.

◆ GetCullFace()

CYIRenderSystem::CullFace CYIMaterial::GetCullFace ( ) const

Get the culling mode used for this material.

◆ GetShaderProgram()

const std::shared_ptr<CYIAssetShaderProgram>& CYIMaterial::GetShaderProgram ( ) const

Gets the shader program. If no shader program was set, it will return null. This function should typically be used only by the renderer.

◆ GetShaderUniforms()

const std::shared_ptr<IYIUniformBufferObject>& CYIMaterial::GetShaderUniforms ( ) const

Gets the shader uniform buffer object. This construct is used to set shader uniform values that will be applied when this material is used in the renderer.

◆ GetTexture() [1/2]

std::shared_ptr<CYIAssetTextureBase> CYIMaterial::GetTexture ( uint32_t  slot) const
Deprecated:
This overload of GetTexture is deprecated. Textures should be accessed using the overload of GetTexture which identifies the texture with a string. This overload of GetTexture can only be used in combination with the deprecated overload of SetTexture which takes a uin32_t slot argument, and cannot be used to access a texture with a custom name set using the currently supported overload of SetTexture.

◆ GetTexture() [2/2]

std::shared_ptr<CYIAssetTextureBase> CYIMaterial::GetTexture ( CYIStringView  textureName) const

Gets the texture with the name textureName. If no texture with this name exists, it will return null.

◆ GetTextureBindings()

const std::map<uint32_t, std::shared_ptr<CYIAssetTextureBase> >& CYIMaterial::GetTextureBindings ( ) const

Returns the configured texture bindings for this material as an ordered map of the form (textureSlot, textureObject)

◆ GetTextureIds()

const std::map<uint32_t, CYIUniformBufferId>& CYIMaterial::GetTextureIds ( ) const

Returns the uniform buffer ids corresponding to textures for this material as an ordered map of the form (textureSlot, textureId)

◆ GetTextureMatrix() [1/2]

const glm::mat3& CYIMaterial::GetTextureMatrix ( uint32_t  slot) const
Deprecated:
This overload of GetTextureMatrix is deprecated. The texture matrix should be accessed using the overload of GetTextureMatrix which identifies the texture with a string. This overload of GetTextureMatrix can only be used in combination with the deprecated overload of SetTexture which takes a uin32_t slot argument, and cannot be used to access the texture matrix associated with a texture with a custom name set using a currently supported overload of SetTexture.

◆ GetTextureMatrix() [2/2]

const glm::mat3& CYIMaterial::GetTextureMatrix ( CYIStringView  matrixName) const

Returns the texture matrix with name matrixName. If no texture matrix has this name, it will return identity.

◆ GetTextureWrapModes()

CYIAssetTextureBase::TextureConfig CYIMaterial::GetTextureWrapModes ( const std::shared_ptr< CYIAssetTextureBase > &  pAssetTexture) const

Returns the wrap modes for a texture when used with this material.

Note
Only the wrapS and wrapT members of the returned object will be populated.

◆ GetWrapModes()

WrapModes CYIMaterial::GetWrapModes ( ) const

Returns the wrap modes for this material.

See also
SetWrapModes

◆ IsLoaded()

bool CYIMaterial::IsLoaded ( ) const

Returns true if all the available textures and shader programs are uploaded to the GPU, false otherwise.

◆ RemoveValue()

void CYIMaterial::RemoveValue ( const CYIUniformBufferId uniformBufferId)

◆ SetBlendMode()

void CYIMaterial::SetBlendMode ( CYIRenderSystem::BlendMode  mode)

Set the blending mode for this material

◆ SetColor()

void CYIMaterial::SetColor ( const CYIColor color)
Deprecated:
This function is deprecated. Instead SetValue should be called with CYIUniformBufferId::s_YiColorID as the uniformBufferId argument, IYIUniformBufferObject::Type::FVec4 as the type argument, 1 as the count argument, (char *)glm::value_ptr(color.GetColorVector()), where color is the CYIColor value that would have been passed into color, as the pData argument.

Set the color for this material. The color will be clamped so that its components lie between 0.0f and 1.0f.

The default shader treats the CYIColor as a channel-wise multiplier. For example, if the CYIColor is cyan, with values (0.0, 1.0, 1.0), and is applied to a texture with an underlying color of yellow (1.0, 1.0, 0.0), the resulting color is (0.0, 1.0, 0.0), which is green.

The behaviour of the color can be changed by changing the shader program used by this Material.

See also
SetShaderProgram
SetValue

◆ SetCullFace()

void CYIMaterial::SetCullFace ( CYIRenderSystem::CullFace  cullingMode)

Set the cullingMode to be used for this material.

◆ SetShaderProgram()

void CYIMaterial::SetShaderProgram ( const std::shared_ptr< CYIAssetShaderProgram > &  pShaderProgram)

Sets the shader program. Null shader program is allowed, but won't deallocate the previously set shader program.

◆ SetTexture() [1/3]

bool CYIMaterial::SetTexture ( uint32_t  slot,
const std::shared_ptr< CYIAssetTextureBase > &  pTexture,
float *  pTextureMatrix = nullptr 
)
Deprecated:
This overload of SetTexture is deprecated. Textures should be set using an overload of SetTexture which identifies the texture with a string.

◆ SetTexture() [2/3]

bool CYIMaterial::SetTexture ( uint32_t  slot,
const std::shared_ptr< CYIAssetTextureBase > &  pTexture,
const glm::mat3  textureMatrix 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ SetTexture() [3/3]

bool CYIMaterial::SetTexture ( CYIStringView  textureName,
const std::shared_ptr< CYIAssetTextureBase > &  pTexture 
)

Assigns a texture to the material with string identifier textureName. If the texture was successfully set, the function will return true, otherwise it will return false.

The string which the rendering system uses to refer to the texture will be textureName.

See also
SetTextureMatrix

◆ SetTextureMatrix() [1/2]

bool CYIMaterial::SetTextureMatrix ( CYIStringView  matrixName,
const glm::mat3 &  textureMatrix 
)

Assigns a texture matrix to the material with string identifier textureName. If the texture matrix was successfully set, the function will return true, otherwise it will return false.

Each texture has an associated 3x3 matrix, which can be used to re-map texture coordinates to a different space inside the texture. This is useful for things like animated textures or texture atlases. Passing nullptr for this matrix equates to using the identity matrix. For platforms that don't support non-power-of-two textures, the matrix will be scaled to re-map the coordinate space to the subregion of the power-of-two texture that contains the image.

The string which the rendering system uses to refer to the texture matrix will be matrixName.

◆ SetTextureMatrix() [2/2]

bool CYIMaterial::SetTextureMatrix ( CYIStringView  matrixName,
float *  pTextureMatrix = nullptr 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Passing nullptr into the pTextureMatrix argument will set the matrix to identity.

◆ SetValue()

void CYIMaterial::SetValue ( const CYIUniformBufferId uniformBufferId,
IYIUniformBufferObject::Type  type,
const char *  pData,
uint32_t  count = 1 
)

◆ SetWrapModes()

void CYIMaterial::SetWrapModes ( WrapMode  horizontal = WrapMode::DefaultFromTexture,
WrapMode  vertical = WrapMode::DefaultFromTexture 
)

Sets the rules for how the texture coordinates should be wrapped if they extend past the bounds (< 0 or > 1). horizontal determines how to wrap on the horizontal axis (also known as S axis), vertical determines how to wrap on the vertical axis (also known as T axis). Both parameters default to WrapMode::DefaultFromTexture, which indicates that the wrap mode from the associated texture(s) should be used.

See also
CYIMaterial::WrapMode

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