1#include "RenderComponent.h"
2#include "../Manager/Render/RenderMgr.h"
3#include "../Manager/LightMgr.h"
4#include "../Manager/EngineCore.h"
5#include "../Util/Render/ShaderUtil.h"
6#include "../Util/Render/SMaterial.h"
7#include "../Util/Settings.h"
8#include "TransformComponent.h"
9#include "DrawableSkinnedMeshComponent.h"
18RenderComponent::~RenderComponent() =
default;
20void RenderComponent::Exterminate() {
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);
28 SAFE_DELETE(m_material_clone);
32void RenderComponent::Init() {
34 if (!m_disableShadow) {
35 m_lightMgr = CORE->GetCore(
LightMgr);
36 m_renderMgr->Register(
this, RenderContainer::DEPTH_ONLY);
40 if (m_mesh !=
nullptr) {
44 if (material ==
nullptr) {
45 isEnable = isRenderActive =
false;
48 isRenderActive = isEnable;
51void RenderComponent::Tick(
float elapsedTime) {
53 if (m_mesh ==
nullptr) {
55 if (m_mesh !=
nullptr) {
64 cameraMatrixStruct.projection,
70 if (m_mesh ==
nullptr || m_material_clone ==
nullptr || gameObject->isPrefab())
return;
72 SetJointMatrix(handle);
76void RenderComponent::SetIsEnable(
bool is_enable) {
77 SComponent::SetIsEnable(is_enable);
79 isRenderActive = isEnable;
85 clone->isRenderActive = isRenderActive;
86 clone->SetMaterial(material);
91void RenderComponent::SetJointMatrix(
const GLProgramHandle* handle)
const {
93 m_skinningMesh !=
nullptr ?
94 m_skinningMesh->GetJointMatrix() : std::vector<
mat4>());
97SMaterial* RenderComponent::GetMaterial()
const {
98 return m_material_clone;
101void RenderComponent::SetMaterial(
SMaterial* material) {
102 auto renderMgr = CORE->GetCore(
RenderMgr);
103 if (this->material ==
nullptr)
104 this->material = SResource::Create<SMaterial>(Settings::GetDefaultDeferredMaterialId());
106 const auto& mode = this->material->GetMode();
107 renderMgr->Remove(
this, (RenderContainer::RenderGroupMode) mode);
108 this->material = material;
111 const auto& mode = this->material->GetMode();
112 renderMgr->Register(
this, (RenderContainer::RenderGroupMode) mode);
114 SAFE_DELETE(m_material_clone)
115 m_material_clone =
new SMaterial(this->material);
118void RenderComponent::SetValue(std::string name_str, VariableBinder::Arguments value) {
119 if (name_str ==
"material") {
120 SetMaterial(SResource::Create<SMaterial>(value[0]));
124std::string RenderComponent::PrintValue()
const {
125 PRINT_START(
"component");
127 PRINT_VALUE(material, ConvertSpaceStr(material->GetHash()));
129 PRINT_END(
"component");
Class for managing rendering operations.
static void BindAttributeToShader(const GLProgramHandle &handle, const GLMeshID &meshId)
Binds the attributes to the shader.
static void BindSkinningDataToShader(const GLProgramHandle &handle, const GLMeshID &meshId, const std::vector< mat4 > &jointMatrix)
Binds the skinning data to the shader.
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.