SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
MaterialComponent.cpp
Go to the documentation of this file.
3
4namespace Sleak {
5
7 GameObject* object, const RefPtr<Material>& material)
8 : Component(object), m_material(material) {}
9
11 Material* material)
12 : Component(object) {
13 if (material)
14 m_material = RefPtr<Material>(material);
15 else
16 m_material = RefPtr<Material>(new Material());
17 }
18
20 Math::Color diffuseColor)
21 : Component(object) {
22 Material* mat = new Material();
23 mat->SetDiffuseColor(diffuseColor);
24 m_material = RefPtr<Material>(mat);
25 }
26
28 GameObject* object, const std::string& diffuseTexture)
29 : Component(object) {
30 Material* mat = new Material();
31 mat->SetDiffuseTexture(diffuseTexture);
32 m_material = RefPtr<Material>(mat);
33 }
34
36 if (m_material) {
37 m_material->Initialize();
38 }
39 bIsInitialized = true;
40 return true;
41 }
42
43 void MaterialComponent::Update(float DeltaTime) {
44 if (!m_enabled || !m_material)
45 return;
46
48 }
49
50 void MaterialComponent::OnEnable() { m_enabled = true; }
51
52 void MaterialComponent::OnDisable() { m_enabled = false; }
53
55 const RefPtr<Material>& material) {
56 m_material = material;
57 if (bIsInitialized && m_material) {
58 m_material->Initialize();
59 }
60 }
61
63 if (material)
64 m_material = RefPtr<Material>(material);
65 else
66 m_material = RefPtr<Material>(new Material());
67
68 if (bIsInitialized && m_material) {
69 m_material->Initialize();
70 }
71 }
72
74 return m_material;
75 }
76
78 return m_material.IsValid() ? m_material.get() : nullptr;
79 }
80
82 if (m_material)
83 m_material->SetDiffuseColor(color);
84 }
85
87 const std::string& path) {
88 if (m_material)
89 m_material->SetDiffuseTexture(path);
90 }
91
93 const std::string& path) {
94 if (m_material)
95 m_material->SetNormalTexture(path);
96 }
97
98 void MaterialComponent::SetShininess(float shininess) {
99 if (m_material)
100 m_material->SetShininess(shininess);
101 }
102
103 void MaterialComponent::SetMetallic(float metallic) {
104 if (m_material)
105 m_material->SetMetallic(metallic);
106 }
107
108 void MaterialComponent::SetRoughness(float roughness) {
109 if (m_material)
110 m_material->SetRoughness(roughness);
111 }
112}
Component(GameObject *object)
Definition Component.hpp:61
void SetShininess(float shininess)
bool Initialize() override
Initializes the owned material's GPU resources.
void SetDiffuseTexture(const std::string &path)
Material * GetMaterialRaw() const
void SetDiffuseColor(Math::Color color)
void SetMetallic(float metallic)
void SetRoughness(float roughness)
void Update(float DeltaTime) override
Submits the material to the render command queue for this frame.
MaterialComponent(GameObject *object, const RefPtr< Material > &material)
const RefPtr< Material > & GetMaterial() const
void SetNormalTexture(const std::string &path)
void SetMaterial(const RefPtr< Material > &material)
Replaces the material, re-initializing it if the component is already initialized.
void SetDiffuseTexture(Texture *texture)
Definition Material.cpp:140
void SetDiffuseColor(Math::Color color)
Definition Material.cpp:268
static RenderCommandQueue * GetInstance()
Lazily creates and returns the process-wide singleton instance.
void SubmitBindMaterial(::Sleak::Material *material)
Queues a material bind, switching shader/texture state for subsequent draws.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10