NAP
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Material Class Reference

#include <material.h>

Classes

struct  VertexAttributeBinding
 

Public Member Functions

 Material (Core &core)
 
virtual bool init (utility::ErrorState &errorState) override
 
const ShadergetShader () const
 
EBlendMode getBlendMode () const
 
void setBlendMode (EBlendMode blendMode)
 
EDepthMode getDepthMode () const
 
void setDepthMode (EDepthMode depthMode)
 
const VertexAttributeBindingfindVertexAttributeBinding (const std::string &shaderAttributeID) const
 
- Public Member Functions inherited from BaseMaterial
 BaseMaterial (Core &core)
 
virtual ~BaseMaterial ()=default
 
const BaseShadergetShader () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 
- Public Member Functions inherited from UniformContainer
 UniformContainer ()=default
 
virtual ~UniformContainer ()=default
 
 UniformContainer (const UniformContainer &)=delete
 
UniformContaineroperator= (const UniformContainer &)=delete
 
UniformStructInstancefindUniform (const std::string &name) const
 
SamplerInstancefindSampler (const std::string &name) const
 
BufferBindingInstancefindBinding (const std::string &name) const
 
ShaderConstantInstancefindConstant (const std::string &name) const
 
const SamplerInstanceListgetSamplers () const
 
const BufferBindingInstanceListgetBufferBindings () const
 
const ShaderConstantInstanceListgetConstants () const
 
const UniformStructInstanceListgetUniformStructs () const
 

Static Public Member Functions

static const std::vector< VertexAttributeBinding > & sGetDefaultVertexAttributeBindings ()
 
- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Public Attributes

std::vector< VertexAttributeBindingmVertexAttributeBindings
 Property: 'VertexAttributeBindings' Optional, mapping from mesh vertex attr to shader vertex attr. More...
 
ResourcePtr< ShadermShader = nullptr
 Property: 'Shader' The shader that this material is using. More...
 
EBlendMode mBlendMode = EBlendMode::Opaque
 Property: 'BlendMode' Optional, blend mode for this material. More...
 
EDepthMode mDepthMode = EDepthMode::InheritFromBlendMode
 Property: 'DepthMode' Optional, determines how the Z buffer is used. More...
 
- Public Attributes inherited from BaseMaterial
std::vector< ResourcePtr< UniformStruct > > mUniforms
 Property: 'Uniforms' Static uniforms (as read from file, or as set in code before calling init()) More...
 
std::vector< ResourcePtr< BufferBinding > > mBuffers
 Property: 'Buffers' Static buffer bindings (as read from file, or as set in code before calling init()) More...
 
std::vector< ResourcePtr< Sampler > > mSamplers
 Property: 'Samplers' Static samplers (as read from file, or as set in code before calling init()) More...
 
std::vector< ResourcePtr< ShaderConstant > > mConstants
 Property: 'Constants' Static constants (as read from file, or as set in code before calling init()) More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Public Types inherited from UniformContainer
using UniformStructInstanceList = std::vector< std::unique_ptr< UniformStructInstance > >
 
using BufferBindingInstanceList = std::vector< std::unique_ptr< BufferBindingInstance > >
 
using SamplerInstanceList = std::vector< std::unique_ptr< SamplerInstance > >
 
using ShaderConstantInstanceList = std::vector< std::unique_ptr< ShaderConstantInstance > >
 
- Protected Member Functions inherited from BaseMaterial
bool rebuild (const BaseShader &shader, utility::ErrorState &errorState)
 
- Protected Member Functions inherited from UniformContainer
UniformStructInstancecreateUniformRootStruct (const ShaderVariableStructDeclaration &declaration, const UniformCreatedCallback &uniformCreatedCallback)
 
BufferBindingInstanceaddBindingInstance (std::unique_ptr< BufferBindingInstance > instance)
 
SamplerInstanceaddSamplerInstance (std::unique_ptr< SamplerInstance > instance)
 
ShaderConstantInstanceaddConstantInstance (std::unique_ptr< ShaderConstantInstance > instance)
 

Description

Resource that acts as the main interface to a vertex or fragment shader. Controls how vertex buffers are bound to shader inputs.

Note that there is no implicit synchronization of access to shader resources bound to buffer bindings and regular uniforms between render passes. Therefore, it is currently not recommended to write to storage buffers inside vertex and/or fragment shaders over consecutive render passes within a single frame.

Inheritance diagram for Material:
[legend]
Collaboration diagram for Material:
[legend]

Constructor & Destructor Documentation

◆ Material()

Material ( Core core)
Parameters
corethe core instance

Member Function Documentation

◆ findVertexAttributeBinding()

const VertexAttributeBinding* findVertexAttributeBinding ( const std::string &  shaderAttributeID) const

Finds the mesh / shader attribute binding based on the given shader attribute ID.

Parameters
shaderAttributeIDID of the shader vertex attribute.

◆ getBlendMode()

EBlendMode getBlendMode ( ) const

Returns the current blend mode. Shared by all objects rendered with this material, unless overridden in a nap::MaterialInstance.

Returns
Active blend mode

◆ getDepthMode()

EDepthMode getDepthMode ( ) const

Returns the current depth mode. Shared by all objects rendered with this material, unless overridden in a nap::MaterialInstance.

Returns
Depth mode

◆ getShader()

const Shader& getShader ( ) const
Returns
The graphics shader

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initializes the material. Validates and converts all the declared shader variables into instances and sets up the vertex buffer bindings.

Parameters
errorStatecontains the error if initialization fails.
Returns
if initialization succeeded.

Reimplemented from Object.

◆ setBlendMode()

void setBlendMode ( EBlendMode  blendMode)

Sets the blend mode to use. Shared by all objects rendered with this material, unless overridden in a nap::MaterialInstance.

Parameters
blendModenew blend mode to use

◆ setDepthMode()

void setDepthMode ( EDepthMode  depthMode)

Sets the depth mode to use. Shared by all objects rendered with this material, unless overridden in a nap::MaterialInstance.

Parameters
depthModenew depth mode to use.

◆ sGetDefaultVertexAttributeBindings()

static const std::vector<VertexAttributeBinding>& sGetDefaultVertexAttributeBindings ( )
static
Returns
Returns a mapping with default values for mesh to shader vertex attribute IDs.

Member Data Documentation

◆ mBlendMode

Property: 'BlendMode' Optional, blend mode for this material.

◆ mDepthMode

Property: 'DepthMode' Optional, determines how the Z buffer is used.

◆ mShader

ResourcePtr<Shader> mShader = nullptr

Property: 'Shader' The shader that this material is using.

◆ mVertexAttributeBindings

std::vector<VertexAttributeBinding> mVertexAttributeBindings

Property: 'VertexAttributeBindings' Optional, mapping from mesh vertex attr to shader vertex attr.