Thanks to visit codestin.com
Credit goes to canreader.github.io
SleakEngine
1.0.0
C++23 multi-backend game engine
Toggle main menu visibility
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
>
6
#include <
Runtime/Material.hpp
>
7
#include <
Math/Color.hpp
>
8
9
namespace
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)
16
MaterialComponent
(
GameObject
*
object
,
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)
23
MaterialComponent
(
24
GameObject
*
object
,
25
Math::Color
diffuseColor =
Math::Color::White
);
26
27
// Construct with a diffuse texture path (creates a new material)
28
MaterialComponent
(
GameObject
*
object
,
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
Color.hpp
Component.hpp
Material.hpp
OSDef.hpp
Sleak::Component::Component
Component(GameObject *object)
Definition
Component.hpp:61
Sleak::GameObject
Definition
GameObject.hpp:57
Sleak::MaterialComponent::SetShininess
void SetShininess(float shininess)
Definition
MaterialComponent.cpp:98
Sleak::MaterialComponent::Initialize
bool Initialize() override
Initializes the owned material's GPU resources.
Definition
MaterialComponent.cpp:35
Sleak::MaterialComponent::SetDiffuseTexture
void SetDiffuseTexture(const std::string &path)
Definition
MaterialComponent.cpp:86
Sleak::MaterialComponent::GetMaterialRaw
Material * GetMaterialRaw() const
Definition
MaterialComponent.cpp:77
Sleak::MaterialComponent::SetDiffuseColor
void SetDiffuseColor(Math::Color color)
Definition
MaterialComponent.cpp:81
Sleak::MaterialComponent::OnDisable
void OnDisable() override
Definition
MaterialComponent.cpp:52
Sleak::MaterialComponent::OnEnable
void OnEnable() override
Definition
MaterialComponent.cpp:50
Sleak::MaterialComponent::SetMetallic
void SetMetallic(float metallic)
Definition
MaterialComponent.cpp:103
Sleak::MaterialComponent::SetRoughness
void SetRoughness(float roughness)
Definition
MaterialComponent.cpp:108
Sleak::MaterialComponent::Update
void Update(float DeltaTime) override
Submits the material to the render command queue for this frame.
Definition
MaterialComponent.cpp:43
Sleak::MaterialComponent::MaterialComponent
MaterialComponent(GameObject *object, const RefPtr< Material > &material)
Definition
MaterialComponent.cpp:6
Sleak::MaterialComponent::GetMaterial
const RefPtr< Material > & GetMaterial() const
Definition
MaterialComponent.cpp:73
Sleak::MaterialComponent::~MaterialComponent
~MaterialComponent() override=default
Sleak::MaterialComponent::SetNormalTexture
void SetNormalTexture(const std::string &path)
Definition
MaterialComponent.cpp:92
Sleak::MaterialComponent::SetMaterial
void SetMaterial(const RefPtr< Material > &material)
Replaces the material, re-initializing it if the component is already initialized.
Definition
MaterialComponent.cpp:54
Sleak::Material
Definition
Material.hpp:87
Sleak::Math::Color
Definition
Color.hpp:16
Sleak::Math::Color::White
static const Color White
Definition
Color.hpp:21
Sleak::RefPtr
Definition
RefPtr.hpp:62
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
public
ECS
Components
MaterialComponent.hpp
Generated on
for SleakEngine by
1.18.0