Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Material Class Reference

#include <Material.h>

Public Member Functions

template<typename T >
void Set (const std::string &name, const T &value)
 
void SetTexture (const std::string &name, TexturePtr texture)
 
void Apply ()
 
std::shared_ptr< ShaderGetShader ()
 
MaterialID GetID ()
 

Friends

class MaterialFactory
 

Detailed Description

Definition at line 28 of file Material.h.

Member Function Documentation

◆ Apply()

void Elevate::Material::Apply ( )

Definition at line 45 of file Material.cpp.

46 {
47 if (m_shader)
48 {
49 Renderer::BindShader(m_shader);
50
51 for (const auto& uniform : m_shader->GetLayout())
52 {
53 // ignore system managed uniforms
54 if (uniform.Type == ShaderDataType::Sampler2D) continue;
55
56 if (uniform.Name == EE_SHADER_VIEWPROJ ||
57 uniform.Name == EE_SHADER_CAMPOS ||
58 uniform.Name == EE_SHADER_MODEL)
59 {
60 continue;
61 }
62
63 void* data = m_buffer.data() + uniform.Offset;
64 // Only apply the uniform if it has been defined
65 if (m_definedUniforms[uniform.Index])
66 {
67 m_shader->SetUniform(uniform.Name, uniform.Type, data);
68 }
69 }
70
71 // Reset all texture bindings
72 m_shader->SetUniform1i("has_diffuseTex", 0);
73 m_shader->SetUniform1i("has_specularTex", 0);
74 m_shader->SetUniform1i("has_ambientTex", 0);
75
76 uint32_t slot = 0;
77 for (auto& tex : m_textures)
78 {
79 if (tex.second && tex.second->IsTextureLoaded())
80 {
81 Renderer::BindTexture(tex.second, slot);
82 m_shader->SetUniform1i(tex.first, slot);
83 m_shader->SetUniform1i("has_" + tex.first, 1);
84 slot++;
85 }
86 }
87 }
88 else
89 {
90 EE_CORE_ERROR("Material::Apply() : Cannot apply uniforms to a shader that is nullptr.");
91 }
92 }
#define EE_SHADER_MODEL
Definition Shader.h:11
#define EE_SHADER_VIEWPROJ
Definition Shader.h:12
#define EE_SHADER_CAMPOS
Definition Shader.h:13
static void BindTexture(const std::shared_ptr< Texture > &texture, uint8_t slot=0)
Definition Renderer.cpp:160
static bool BindShader(const std::shared_ptr< Shader > &shader)
Definition Renderer.cpp:30

◆ GetID()

MaterialID Elevate::Material::GetID ( )
inline

Definition at line 47 of file Material.h.

47{ return m_id; }

◆ GetShader()

std::shared_ptr< Shader > Elevate::Material::GetShader ( )

Definition at line 94 of file Material.cpp.

95 {
96 return m_shader;
97 }

◆ Set()

template<typename T >
void Elevate::Material::Set ( const std::string &  name,
const T &  value 
)
inline

Definition at line 32 of file Material.h.

33 {
34 for (const auto& uniform : m_shader->GetLayout())
35 {
36 if (uniform.Name == name)
37 {
38 memcpy(m_buffer.data() + uniform.Offset, &value, sizeof(T));
39 m_definedUniforms[uniform.Index] = true;
40 }
41 }
42 }

◆ SetTexture()

void Elevate::Material::SetTexture ( const std::string &  name,
TexturePtr  texture 
)

Definition at line 40 of file Material.cpp.

41 {
42 m_textures[name] = texture;
43 }

Friends And Related Symbol Documentation

◆ MaterialFactory

friend class MaterialFactory
friend

Definition at line 63 of file Material.h.


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