Ocular Engine
Ocular::Graphics::Material Class Reference
Inheritance diagram for Ocular::Graphics::Material:
Ocular::Core::Resource Ocular::Core::ObjectIO Ocular::Core::Exposable Ocular::Core::Buildable Ocular::Graphics::D3D11Material Ocular::Graphics::MaterialEmpty Ocular::Graphics::MaterialMissing

Public Member Functions

virtual void bind ()
 
virtual void unbind ()
 
virtual void unload () override
 
virtual void onLoad (Core::BuilderNode const *node) override
 
virtual void onSave (Core::BuilderNode *node) const override
 
virtual bool setTexture (uint32_t index, std::string const &name, Texture *texture)
 
TexturegetTexture (uint32_t index) const
 
virtual void removeTexture (uint32_t index)
 
uint32_t getNumTextures () const
 
std::vector< TextureSamplerInfo > const * getTextures () const
 
bool setVertexShader (std::string const &name)
 
void setVertexShader (VertexShader *shader)
 
bool setGeometryShader (std::string const &name)
 
void setGeometryShader (GeometryShader *shader)
 
bool setFragmentShader (std::string const &name)
 
void setFragmentShader (FragmentShader *shader)
 
bool setPreTessellationShader (std::string const &name)
 
void setPreTessellationShader (PreTessellationShader *shader)
 
bool setPostTessellationShader (std::string const &name)
 
void setPostTessellationShader (PostTessellationShader *shader)
 
VertexShadergetVertexShader () const
 
GeometryShadergetGeometryShader () const
 
FragmentShadergetFragmentShader () const
 
PreTessellationShadergetPreTessellationShader () const
 
PostTessellationShadergetPostTessellationShader () const
 
virtual void setUniform (std::string const &name, uint32_t registerIndex, float value)
 
virtual bool getUniform (std::string const &name, float &value)
 
virtual void setUniform (std::string const &name, uint32_t registerIndex, Math::Vector4f const &value, std::string const &type=Utils::TypeName< Math::Vector4f >::name)
 
virtual bool getUniform (std::string const &name, Math::Vector4f &value)
 
virtual void setUniform (std::string const &name, uint32_t registerIndex, Math::Matrix3x3 const &value)
 
virtual bool getUniform (std::string const &name, Math::Matrix3x3 &value)
 
virtual void setUniform (std::string const &name, uint32_t registerIndex, Math::Matrix4x4 const &value)
 
virtual bool getUniform (std::string const &name, Math::Matrix4x4 &value)
 
UniformBuffer const * getUniformBuffer () const
 
void setPrimitiveStyle (PrimitiveStyle style)
 
PrimitiveStyle getPrimitiveStyle () const
 
void setFillMode (FillMode mode)
 
FillMode getFillMode () const
 
void setRenderPriority (uint32_t priority)
 
uint32_t getRenderPriority () const
 
- Public Member Functions inherited from Ocular::Core::Resource
 Resource (File const &source)
 
virtual void forceLoad ()
 
File getSourceFile () const
 
void setSourceFile (File const &file)
 
void setIsInMemory (bool inMemory)
 
bool isInMemory () const
 
void setSize (uint64_t size)
 
uint64_t getSize () const
 
ResourceType getResourceType () const
 
void setName (std::string const &name)
 
std::string const & getName () const
 
std::string const & getMappingName () const
 
void setMappingName (std::string const &name)
 
ResourceMetadatagetMetadata () const
 
void setMetadata (ResourceMetadata *metadata)
 
- Public Member Functions inherited from Ocular::Core::Exposable
void getAllExposedNames (std::vector< std::string > &names) const
 
bool getVariable (std::string const &name, ExposedVariable &var)
 
template<typename T >
bool getVariableValue (std::string const &name, T &var)
 
template<typename T >
bool setVariableValue (std::string const &name, T const &value)
 
virtual void onVariableModified (std::string const &varName)
 

Static Public Attributes

static const std::string ShaderNodeName = "ShaderProgram"
 
static const std::string TextureNodeName = "Textures"
 
static const std::string UniformNodeName = "Uniforms"
 
static const std::string RenderStateNodeName = "RenderState"
 

Protected Member Functions

void setDefaults ()
 
void bindShaders ()
 
void unbindShaders ()
 
void bindStateChanges ()
 
void unbindStateChanges ()
 
- Protected Member Functions inherited from Ocular::Core::Exposable
void exposeVariable (std::string const &name, std::string const &type, bool isPointer, bool isExposed, void *data)
 

Protected Attributes

VertexShaderm_VertexShader
 
GeometryShaderm_GeometryShader
 
FragmentShaderm_FragmentShader
 
PreTessellationShaderm_PreTessellationShader
 
PostTessellationShaderm_PostTessellationShader
 
RasterState m_StoredRasterState
 
std::vector< TextureSamplerInfom_Textures
 
UniformBufferm_UniformBuffer
 
uint32_t m_RenderPriority
 
- Protected Attributes inherited from Ocular::Core::Resource
ResourceType m_Type
 
ResourceMetadatam_Metadata
 
File m_SourceFile
 
bool m_IsInMemory
 
uint64_t m_SizeInMemory
 
std::string m_Name
 
std::string m_MappingName
 
- Protected Attributes inherited from Ocular::Core::Exposable
std::unordered_map< std::string, ExposedVariablem_ExposedVariables
 

Member Function Documentation

FillMode Ocular::Graphics::Material::getFillMode ( ) const
Returns
Fill mode used by this material
FragmentShader * Ocular::Graphics::Material::getFragmentShader ( ) const
Returns
The fragment shader used by this material. May be NULL if no valid shader is set.
GeometryShader * Ocular::Graphics::Material::getGeometryShader ( ) const
Returns
The geometry shader used by this material. May be NULL if no valid shader is set.
uint32_t Ocular::Graphics::Material::getNumTextures ( ) const
Returns
Number of textures attached to this material.
PostTessellationShader * Ocular::Graphics::Material::getPostTessellationShader ( ) const
Returns
The post-tessellation shader used by this material. May be NULL if no valid shader is set.
PreTessellationShader * Ocular::Graphics::Material::getPreTessellationShader ( ) const
Returns
The pre-tessellation shader used by this material. May be NULL if no valid shader is set.
PrimitiveStyle Ocular::Graphics::Material::getPrimitiveStyle ( ) const
Returns
Primitive style used by this material
uint32_t Ocular::Graphics::Material::getRenderPriority ( ) const
Returns
The render priority assigned to this Material
Texture * Ocular::Graphics::Material::getTexture ( uint32_t  index) const

Retrieves the texture stored at the specified identifier.

Parameters
[in]indexIndex of the texture to retrieve.
std::vector< TextureSamplerInfo > const * Ocular::Graphics::Material::getTextures ( ) const
Returns
Vector of all textures attached to this material.
Note
Returned vector is read-only. See Material::setTexture and Material::removeTexture to modify.
bool Ocular::Graphics::Material::getUniform ( std::string const &  name,
float &  value 
)
virtual

Returns the value of the associated uniform.

Parameters
[in]nameValid uniform name.
[out]valueValue of the specified uniform.
Returns
Returns TRUE if the value was successfully retrieved. May return FALSE if either the uniform does not exist, or it is a different type of value.
bool Ocular::Graphics::Material::getUniform ( std::string const &  name,
Math::Vector4f value 
)
virtual

Returns the value of the associated uniform.

Parameters
[in]nameValid uniform name.
[out]valueValue of the specified uniform.
Returns
Returns TRUE if the value was successfully retrieved. May return FALSE if either the uniform does not exist, or it is a different type of value.
bool Ocular::Graphics::Material::getUniform ( std::string const &  name,
Math::Matrix3x3 value 
)
virtual

Returns the value of the associated uniform.

Parameters
[in]nameValid uniform name.
[out]valueValue of the specified uniform.
Returns
Returns TRUE if the value was successfully retrieved. May return FALSE if either the uniform does not exist, or it is a different type of value.
bool Ocular::Graphics::Material::getUniform ( std::string const &  name,
Math::Matrix4x4 value 
)
virtual

Returns the value of the associated uniform.

Parameters
[in]nameValid uniform name.
[out]valueValue of the specified uniform.
Returns
Returns TRUE if the value was successfully retrieved. May return FALSE if either the uniform does not exist, or it is a different type of value.
UniformBuffer const * Ocular::Graphics::Material::getUniformBuffer ( ) const
Returns
Constant pointer to the UniformBuffer
VertexShader * Ocular::Graphics::Material::getVertexShader ( ) const
Returns
The vertex shader used by this material. May be NULL if no valid shader is set.
void Ocular::Graphics::Material::onLoad ( Core::BuilderNode const *  node)
overridevirtual

Alternate creation method (opposed to the constructor) in which one is provided with a BuilderNode chain. This chain may be explored to retrieve any relevant variables, and their values, that may have been stored in it.

This method will typically mirror the onSave, in which relevant values are stored within the chain.

Parameters
[in]nodeNode to extract variable information from

Reimplemented from Ocular::Core::ObjectIO.

Reimplemented in Ocular::Graphics::MaterialEmpty, and Ocular::Graphics::MaterialMissing.

void Ocular::Graphics::Material::onSave ( Core::BuilderNode node) const
overridevirtual

Method used to add an object's data to an existing node chain in preparation for being save to a file.

Parameters
[in]nodeNode to place variable information in

Reimplemented from Ocular::Core::ObjectIO.

Reimplemented in Ocular::Graphics::MaterialEmpty, and Ocular::Graphics::MaterialMissing.

void Ocular::Graphics::Material::removeTexture ( uint32_t  index)
virtual

Removes the texture at the specified index from this material.

Parameters
[in]index

Reimplemented in Ocular::Graphics::D3D11Material.

void Ocular::Graphics::Material::setFillMode ( FillMode  mode)

Sets the fill mode that the material should render as.

Parameters
[in]fill
bool Ocular::Graphics::Material::setFragmentShader ( std::string const &  name)

Sets the fragment shader used by this Material.

Parameters
[in]nameName of the shader to use.
Returns
Returns TRUE if the shader was successfully set. May fail if no ShaderProgram with a matching name was discovered, or if that ShaderProgram did not contain a fragment shader.
void Ocular::Graphics::Material::setFragmentShader ( FragmentShader shader)

Sets the fragment shader used by this Material.

Parameters
[in]shaderPointer to the shared fragment shader to use.
bool Ocular::Graphics::Material::setGeometryShader ( std::string const &  name)

Sets the geometry shader used by this Material.

Parameters
[in]nameName of the shader to use.
Returns
Returns TRUE if the shader was successfully set. May fail if no ShaderProgram with a matching name was discovered, or if that ShaderProgram did not contain a geometry shader.
void Ocular::Graphics::Material::setGeometryShader ( GeometryShader shader)

Sets the geometry shader used by this Material.

Parameters
[in]shaderPointer to the shared geometry shader to use.
bool Ocular::Graphics::Material::setPostTessellationShader ( std::string const &  name)

Sets the post-tessellation shader used by this Material.

Parameters
[in]nameName of the shader to use.
Returns
Returns TRUE if the shader was successfully set. May fail if no ShaderProgram with a matching name was discovered, or if that ShaderProgram did not contain a post-tessellation shader.
void Ocular::Graphics::Material::setPostTessellationShader ( PostTessellationShader shader)

Sets the post-tessellation shader used by this Material.

Parameters
[in]shaderPointer to the shared post-tessellation shader to use.
bool Ocular::Graphics::Material::setPreTessellationShader ( std::string const &  name)

Sets the pre-tessellation shader used by this Material.

Parameters
[in]nameName of the shader to use.
Returns
Returns TRUE if the shader was successfully set. May fail if no ShaderProgram with a matching name was discovered, or if that ShaderProgram did not contain a pre-tessellation shader.
void Ocular::Graphics::Material::setPreTessellationShader ( PreTessellationShader shader)

Sets the pre-tessellation shader used by this Material.

Parameters
[in]shaderPointer to the shared pre-tessellation shader to use.
void Ocular::Graphics::Material::setPrimitiveStyle ( PrimitiveStyle  style)

Sets the primitive style that the material should render as.

Parameters
[in]style
void Ocular::Graphics::Material::setRenderPriority ( uint32_t  priority)

Sets the priority of the material in the render queue.

See Graphics::RenderPriority for pre-set priority values.

Parameters
[in]priority
bool Ocular::Graphics::Material::setTexture ( uint32_t  index,
std::string const &  name,
Texture texture 
)
virtual

Assigns a texture to a specific input register for use by the shaders that are part of this material. All textures are automatically bound to all relevant (non-NULL) shader stages.

Depending on the underlying graphics API, and shader implementation language, some may make use of the index or the name or both.

Note that some texture assignment indices and names are reserved by the engine. See ----— for a list of all reserved locations.

Parameters
[in]indexThe index to bind the texture to. This can be on the range of 0 to (GraphicsDriver::getMaxBoundTextures - 1). Note that indices do not have to be sequential. For example, you may have use 0, 1, 3, 79.
[in]nameThe name to bind the texture to.
[in]textureThe texture to bind.
Returns
TRUE if texture was successfully set. May fail due to invalid index value.

Reimplemented in Ocular::Graphics::D3D11Material.

void Ocular::Graphics::Material::setUniform ( std::string const &  name,
uint32_t  registerIndex,
float  value 
)
virtual

Sets the value of the specified uniform.

Note
This uniform value is set for all valid shaders associated with this material.
Parameters
[in]nameValid uniform name.
[in]registerIndexFirst register that the uniform occupies. Each register is 16 bytes, and a single uniform may occupy multiple registers at once.
[in]valueSingle floating-point value for the uniform.
Returns
TRUE if the Uniform value was set successfully. May fail due to invalid index, etc.
void Ocular::Graphics::Material::setUniform ( std::string const &  name,
uint32_t  registerIndex,
Math::Vector4f const &  value,
std::string const &  type = Utils::TypeName<Math::Vector4f>::name 
)
virtual

Sets the value of the specified uniform.

Note
This uniform value is set for all valid shaders associated with this material.
Parameters
[in]nameValid uniform name.
[in]registerIndexFirst register that the uniform occupies. Each register is 16 bytes, and a single uniform may occupy multiple registers at once.
[in]valueA 4-component Vector value for the uniform.
[in]typeUniform type. Used to differentiate between Vector4f and Color uniforms.
Returns
TRUE if the Uniform value was set successfully. May fail due to invalid index, etc.
void Ocular::Graphics::Material::setUniform ( std::string const &  name,
uint32_t  registerIndex,
Math::Matrix3x3 const &  value 
)
virtual

Sets the value of the specified uniform.

Note
This uniform value is set for all valid shaders associated with this material.
Parameters
[in]nameValid uniform name.
[in]registerIndexFirst register that the uniform occupies. Each register is 16 bytes, and a single uniform may occupy multiple registers at once.
[in]valueA 3x3 matrix value for the uniform.
Returns
TRUE if the Uniform value was set successfully. May fail due to invalid index, etc.
void Ocular::Graphics::Material::setUniform ( std::string const &  name,
uint32_t  registerIndex,
Math::Matrix4x4 const &  value 
)
virtual

Sets the value of the specified uniform.

Note
This uniform value is set for all valid shaders associated with this material.
Parameters
[in]nameValid uniform name.
[in]registerIndexFirst register that the uniform occupies. Each register is 16 bytes, and a single uniform may occupy multiple registers at once.
[in]valueA 4x4 matrix value for the uniform.
Returns
TRUE if the Uniform value was set successfully. May fail due to invalid index, etc.
bool Ocular::Graphics::Material::setVertexShader ( std::string const &  name)

Sets the vertex shader used by this Material.

Parameters
[in]nameName of the shader to use.
Returns
Returns TRUE if the shader was successfully set. May fail if no ShaderProgram with a matching name was discovered, or if that ShaderProgram did not contain a vertex shader.
void Ocular::Graphics::Material::setVertexShader ( VertexShader shader)

Sets the vertex shader used by this Material.

Parameters
[in]shaderPointer to the shared vertex shader to use.
void Ocular::Graphics::Material::unload ( )
overridevirtual

Frees all memory used by this Resource.

Reimplemented from Ocular::Core::Resource.

Reimplemented in Ocular::Graphics::MaterialEmpty, and Ocular::Graphics::MaterialMissing.


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