CSEngine
Loading...
Searching...
No Matches
CSE::RenderComponent Class Reference
Inheritance diagram for CSE::RenderComponent:
CSE::SComponent CSE::SIRender CSE::SObject CSE::SISComponent CSE::VariableBinder

Public Member Functions

 COMPONENT_DEFINE_CONSTRUCTOR (RenderComponent)
 
void Exterminate () override
 
void Init () override
 
void Tick (float elapsedTime) override
 
SComponentClone (SGameObject *object) override
 
void SetMatrix (const CameraMatrixStruct &cameraMatrixStruct, const GLProgramHandle *handle) override
 
void Render (const GLProgramHandle *handle) const override
 
void SetIsEnable (bool is_enable) override
 
SMaterialGetMaterial () const override
 
void SetMaterial (SMaterial *material)
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
- Public Member Functions inherited from CSE::SComponent
 SComponent (std::string classType, SGameObject *gameObject)
 
 SComponent (const SComponent &src)
 
void Start () override
 
virtual void CopyReference (SComponent *src, std::map< SGameObject *, SGameObject * > lists_obj, std::map< SComponent *, SComponent * > lists_comp)
 
virtual auto GetComponent () -> SObject *
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
void SetGameObject (SGameObject *object)
 
virtual SGameObjectGetGameObject () const
 
virtual bool GetIsEnable () const
 
std::string GetClassType () const
 
void SetClassType (std::string type)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 
- Public Member Functions inherited from CSE::SISComponent
 SISComponent (const SISComponent &src)=default
 
- Public Member Functions inherited from CSE::SIRender
SMaterialGetMaterialReference () const
 

Additional Inherited Members

- Public Attributes inherited from CSE::SIRender
bool isRenderActive = false
 
- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SComponent
SGameObjectgameObject = nullptr
 
bool isEnable = true
 
std::string m_classType
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 
- Protected Attributes inherited from CSE::SIRender
SMaterialmaterial = nullptr
 

Detailed Description

Definition at line 15 of file RenderComponent.h.

Member Function Documentation

◆ Clone()

SComponent * RenderComponent::Clone ( SGameObject object)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 82 of file RenderComponent.cpp.

82 {
83 INIT_COMPONENT_CLONE(RenderComponent, clone);
84
85 clone->isRenderActive = isRenderActive;
86 clone->SetMaterial(material);
87
88 return clone;
89}

◆ Exterminate()

void RenderComponent::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 20 of file RenderComponent.cpp.

20 {
21 if (material != nullptr) {
22 const auto& mode = material->GetMode();
23 if (m_renderMgr != nullptr) {
24 m_renderMgr->Remove(this, (RenderContainer::RenderGroupMode) mode);
25 m_renderMgr->Remove(this, RenderContainer::DEPTH_ONLY);
26 }
27 }
28 SAFE_DELETE(m_material_clone);
29 material = nullptr;
30}

◆ GetMaterial()

SMaterial * RenderComponent::GetMaterial ( ) const
overridevirtual

Implements CSE::SIRender.

Definition at line 97 of file RenderComponent.cpp.

97 {
98 return m_material_clone;
99}

◆ Init()

void RenderComponent::Init ( )
overridevirtual

Implements CSE::SISComponent.

Definition at line 32 of file RenderComponent.cpp.

32 {
33
34 if (!m_disableShadow) {
35 m_lightMgr = CORE->GetCore(LightMgr);
36 m_renderMgr->Register(this, RenderContainer::DEPTH_ONLY);
37 }
38
39 m_mesh = gameObject->GetComponent<DrawableStaticMeshComponent>();
40 if (m_mesh != nullptr) {
41 m_skinningMesh = dynamic_cast<DrawableSkinnedMeshComponent*>(m_mesh);
42 }
43
44 if (material == nullptr) {
45 isEnable = isRenderActive = false;
46 }
47
48 isRenderActive = isEnable;
49}

◆ PrintValue()

std::string RenderComponent::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 124 of file RenderComponent.cpp.

124 {
125 PRINT_START("component");
126
127 PRINT_VALUE(material, ConvertSpaceStr(material->GetHash()));
128
129 PRINT_END("component");
130}

◆ Render()

void RenderComponent::Render ( const GLProgramHandle handle) const
overridevirtual

Implements CSE::SIRender.

Definition at line 68 of file RenderComponent.cpp.

68 {
69
70 if (m_mesh == nullptr || m_material_clone == nullptr || gameObject->isPrefab()) return;
71
72 SetJointMatrix(handle);
73 ShaderUtil::BindAttributeToShader(*handle, m_mesh->GetMeshID());
74}
static void BindAttributeToShader(const GLProgramHandle &handle, const GLMeshID &meshId)
Binds the attributes to the shader.

◆ SetIsEnable()

void RenderComponent::SetIsEnable ( bool  is_enable)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 76 of file RenderComponent.cpp.

76 {
77 SComponent::SetIsEnable(is_enable);
78
79 isRenderActive = isEnable;
80}

◆ SetMaterial()

void RenderComponent::SetMaterial ( SMaterial material)

Definition at line 101 of file RenderComponent.cpp.

101 {
102 auto renderMgr = CORE->GetCore(RenderMgr);
103 if (this->material == nullptr)
104 this->material = SResource::Create<SMaterial>(Settings::GetDefaultDeferredMaterialId());
105 else {
106 const auto& mode = this->material->GetMode();
107 renderMgr->Remove(this, (RenderContainer::RenderGroupMode) mode);
108 this->material = material;
109 }
110
111 const auto& mode = this->material->GetMode();
112 renderMgr->Register(this, (RenderContainer::RenderGroupMode) mode);
113
114 SAFE_DELETE(m_material_clone)
115 m_material_clone = new SMaterial(this->material);
116}
Class for managing rendering operations.
Definition RenderMgr.h:21

◆ SetMatrix()

void RenderComponent::SetMatrix ( const CameraMatrixStruct cameraMatrixStruct,
const GLProgramHandle handle 
)
overridevirtual

Implements CSE::SIRender.

Definition at line 62 of file RenderComponent.cpp.

62 {
63 ShaderUtil::BindCameraToShader(*handle, cameraMatrixStruct.camera, cameraMatrixStruct.cameraPosition,
64 cameraMatrixStruct.projection,
65 static_cast<const TransformComponent*>(gameObject->GetTransform())->GetMatrix());
66}
static void BindCameraToShader(const GLProgramHandle &handle, const mat4 &camera, const vec3 &cameraPosition, const mat4 &projection, const mat4 &transform)
Binds the camera data to the shader.

◆ SetValue()

void RenderComponent::SetValue ( std::string  name_str,
VariableBinder::Arguments  value 
)
overridevirtual

Implements CSE::VariableBinder.

Definition at line 118 of file RenderComponent.cpp.

118 {
119 if (name_str == "material") {
120 SetMaterial(SResource::Create<SMaterial>(value[0]));
121 }
122}

◆ Tick()

void RenderComponent::Tick ( float  elapsedTime)
overridevirtual

Implements CSE::SISComponent.

Definition at line 51 of file RenderComponent.cpp.

51 {
52
53 if (m_mesh == nullptr) {
54 m_mesh = gameObject->GetComponent<DrawableStaticMeshComponent>();
55 if (m_mesh != nullptr) {
56 m_skinningMesh = dynamic_cast<DrawableSkinnedMeshComponent*>(m_mesh);
57 }
58 }
59}

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