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_renderMgr->Register(
this, RenderContainer::DEPTH_ONLY);
41 if (m_mesh !=
nullptr) {
45 if (material ==
nullptr) {
46 isEnable = isRenderActive =
false;
49 isRenderActive = isEnable;
52void RenderComponent::Tick(
float elapsedTime) {
54 if (m_mesh ==
nullptr) {
58 if (m_mesh !=
nullptr) {
67 cameraMatrixStruct.projection,
73 if (m_mesh ==
nullptr || m_material_clone ==
nullptr || gameObject->isPrefab())
return;
75 SetJointMatrix(handle);
79void RenderComponent::SetIsEnable(
bool is_enable) {
80 SComponent::SetIsEnable(is_enable);
82 isRenderActive = isEnable;
88 clone->isRenderActive = isRenderActive;
89 clone->SetMaterial(material);
94void RenderComponent::SetJointMatrix(
const GLProgramHandle* handle)
const {
96 m_skinningMesh !=
nullptr ?
97 m_skinningMesh->GetJointMatrix() : std::vector<mat4>());
100SMaterial* RenderComponent::GetMaterial()
const {
101 return m_material_clone;
104void RenderComponent::SetMaterial(
SMaterial* material) {
105 auto renderMgr = CORE->GetCore(
RenderMgr);
106 if (this->material ==
nullptr)
107 this->material = SResource::Create<SMaterial>(Settings::GetDefaultDeferredMaterialId());
109 const auto& mode = this->material->GetMode();
110 renderMgr->Remove(
this, (RenderContainer::RenderGroupMode) mode);
111 this->material = material;
114 const auto& mode = this->material->GetMode();
115 renderMgr->Register(
this, (RenderContainer::RenderGroupMode) mode);
117 SAFE_DELETE(m_material_clone)
118 m_material_clone =
new SMaterial(this->material);
122 if (name_str ==
"material") {
123 SetMaterial(SResource::Create<SMaterial>(value[0]));
127std::string RenderComponent::PrintValue()
const {
128 PRINT_START(
"component");
132 PRINT_END(
"component");
void SetValue(std::string name_str, Arguments value) override
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.