SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
MaterialComponent.hpp
Go to the documentation of this file.
1#ifndef _MATERIALCOMPONENT_HPP_
2#define _MATERIALCOMPONENT_HPP_
3
4#include <ECS/Component.hpp>
5#include <Core/OSDef.hpp>
7#include <Math/Color.hpp>
8
9namespace Sleak {
10 /// Owns and binds a Material for rendering; submits it into the draw
11 /// command queue each Update while enabled.
12 /// @ingroup scene
13 class ENGINE_API MaterialComponent : public Component {
14 public:
15 // Construct with a shared material (RefPtr copy - safe for sharing)
17 const RefPtr<Material>& material);
18
19 // Construct with a raw pointer (takes ownership)
20 MaterialComponent(GameObject* object, Material* material);
21
22 // Construct with just a diffuse color (creates a new material)
24 GameObject* object,
25 Math::Color diffuseColor = Math::Color::White);
26
27 // Construct with a diffuse texture path (creates a new material)
29 const std::string& diffuseTexture);
30
31 ~MaterialComponent() override = default;
32
33 /// Initializes the owned material's GPU resources.
34 bool Initialize() override;
35 /// Submits the material to the render command queue for this frame.
36 void Update(float DeltaTime) override;
37 void OnEnable() override;
38 void OnDisable() override;
39
40 // Material access
41 /// Replaces the material, re-initializing it if the component is already initialized.
42 void SetMaterial(const RefPtr<Material>& material);
43 /// Takes ownership of a raw material pointer, re-initializing it if already initialized.
44 void SetMaterial(Material* material);
45 const RefPtr<Material>& GetMaterial() const;
46 Material* GetMaterialRaw() const;
47
48 // Convenience shortcuts that forward to the material
49 void SetDiffuseColor(Math::Color color);
50 void SetDiffuseTexture(const std::string& path);
51 void SetNormalTexture(const std::string& path);
52 void SetShininess(float shininess);
53 void SetMetallic(float metallic);
54 void SetRoughness(float roughness);
55
56 private:
57 RefPtr<Material> m_material;
58 bool m_enabled = true;
59 };
60}
61
62#endif
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
~MaterialComponent() override=default
void SetNormalTexture(const std::string &path)
void SetMaterial(const RefPtr< Material > &material)
Replaces the material, re-initializing it if the component is already initialized.
static const Color White
Definition Color.hpp:21
Root namespace for everything the engine exposes.
Definition Camera.hpp:10