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
 
void SetTexture (uint32_t slot, const std::shared_ptr< CYIAssetTextureBase > &pTexture, float *pTextureMatrix=nullptr)
 
void SetTexture (uint32_t slot, const std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::mat3 textureMatrix)
 
const glm::mat3 & GetTextureMatrix (uint32_t slot) 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
 
void ClearTextureSlot (uint32_t slot)
 
void SetBlendMode (CYIRenderSystem::BlendMode mode)
 
CYIRenderSystem::BlendMode GetBlendMode () const
 
void SetColor (const CYIColor &color)
 
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

◆ ClearTextureSlot()

void CYIMaterial::ClearTextureSlot ( uint32_t  slot)

Clear the data in the indicated texture slot, this data will no longer be sent to the renderer or accessible in any shader programs

◆ GetBlendMode()

CYIRenderSystem::BlendMode CYIMaterial::GetBlendMode ( ) const

Returns the blending mode for this material

◆ GetColor()

const CYIColor& CYIMaterial::GetColor ( ) const

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()

std::shared_ptr<CYIAssetTextureBase> CYIMaterial::GetTexture ( uint32_t  slot) const

Gets the texture assigned to texture slot. If no texture were assigned to the given slot, it will return null. Slot should be between 0 and the maximum amount of texture units available on your target platform

◆ 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)

◆ GetTextureMatrix()

const glm::mat3& CYIMaterial::GetTextureMatrix ( uint32_t  slot) const

Returns the texture matrix for the texture in slot slot.

◆ 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.

◆ SetBlendMode()

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

Set the blending mode for this material

◆ SetColor()

void CYIMaterial::SetColor ( const CYIColor color)

Set the color for this material

◆ 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/2]

void CYIMaterial::SetTexture ( uint32_t  slot,
const std::shared_ptr< CYIAssetTextureBase > &  pTexture,
float *  pTextureMatrix = nullptr 
)

Assigns a texture to a texture slot. Null textures are allowed, but won't deallocate the previously set texture. Slot should be between 0 and the maximum amount of texture units available on your target platform.

Each texture has an associated 3x3 pTextureMatrix, 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 provided pTexture will be bound to the slot sampler location.

◆ SetTexture() [2/2]

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

◆ 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: