Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Engine::Graphics::Material Class Reference

an semi-abstract class that represents a material to a shader More...

#include <Material.hpp>

Public Member Functions

 Material (Shader *referenceShader)
 The default constructor.
 
void CreateParameter (const char *name, MaterialParameterType type)
 Creates a parameter for the material.
 
void * SetParameter (const char *name, void *value)
 Sets the value of a parameter.
 
Engine::Success ApplyMaterialParams ()
 Applies both the material values to the shader.
 
ShaderGetShader ()
 Gets the shader used by the material.
 

Detailed Description

an semi-abstract class that represents a material to a shader

This class is used to create a material that can be used with a shader. Materials are used to pass data to the shader, and to tell the shader how to handle that data. To create a material, you must first assign a shader to the material. From there, you tell the material what the parameters of the shader are, and what values the shader should use for those parameters. This is done with the CreateParameter and SetParameter methods.

Examples

There are two ways to create a materials:

Constructor & Destructor Documentation

◆ Material()

Engine::Graphics::Material::Material ( Shader referenceShader)

The default constructor.

Takes in a shader to use as a reference for the material.

Member Function Documentation

◆ ApplyMaterialParams()

Engine::Success Engine::Graphics::Material::ApplyMaterialParams ( )

Applies both the material values to the shader.

This method gets called by the renderer when the material is applied.

Returns
Engine::Success::SUCCESS if the material was applied successfully. If one parameter failed to apply correctly, then the method returns an Engine::Success::FAILURE

◆ CreateParameter()

void Engine::Graphics::Material::CreateParameter ( const char *  name,
MaterialParameterType  type 
)

Creates a parameter for the material.

This method takes in a parameter name and a parameter type and keeps track of the parameters in the material. This method will throw an error if the parameter already exists.

Parameters
nameThe name of the parameter
typeThe type of the parameter

◆ GetShader()

Engine::Graphics::Shader * Engine::Graphics::Material::GetShader ( )

Gets the shader used by the material.

@reutnrs The shader used by the material

◆ SetParameter()

void * Engine::Graphics::Material::SetParameter ( const char *  name,
void *  value 
)

Sets the value of a parameter.

This method takes a reference to a value and assigns it to the parameter with the specified name. This method will throw an error if the parameter does not exist.

You can either pass a dynamic variable, or a pointer to an existing value. There is however no pointer safety, but the method returns a void pointer to the value that was set.

Parameters
nameThe name of the parameter
valueThe value to assign to the parameter
Returns
A void pointer to the value that was set. Should be cast to the correct type.
Warning
This method does not check if the input value is the correct type. If there is a mismatch, the program will potentially segfault, or lead to undefined behavior.

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